Remove `include/grpcpp/impl/codegen/security/auth_context.h` (#31292)

pull/31312/head^2
Cheng-Yu Chung 2 years ago committed by GitHub
parent a63c81135c
commit 9143627664
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      doc/server_side_auth.md
  2. 80
      include/grpcpp/impl/codegen/security/auth_context.h
  3. 77
      include/grpcpp/security/auth_context.h

@ -12,7 +12,7 @@ The authentication context is structured as a multi-map of key-value pairs - the
The contents of the *auth properties* are populated by an *auth interceptor*. The interceptor also chooses which property key will act as the peer identity (e.g. for client certificate authentication this property will be `"x509_common_name"` or `"x509_subject_alternative_name"`).
Note that AuthContext is generally not modifiable, except when used via an AuthMetadataProcessor([reference](https://github.com/grpc/grpc/blob/master/include/grpcpp/impl/codegen/security/auth_context.h)).
Note that AuthContext is generally not modifiable, except when used via an AuthMetadataProcessor([reference](https://github.com/grpc/grpc/blob/master/include/grpcpp/security/auth_context.h)).
However, because the AuthContext is a connection-level object, when it is modified via an AuthMetadataProcessor, the modifications will be visible on all subsequent calls on the same connection.
WARNING: AuthContext is the only reliable source of truth when it comes to authenticating RPCs. Using any other call/context properties for authentication purposes is wrong and inherently unsafe.

@ -19,83 +19,9 @@
#ifndef GRPCPP_IMPL_CODEGEN_SECURITY_AUTH_CONTEXT_H
#define GRPCPP_IMPL_CODEGEN_SECURITY_AUTH_CONTEXT_H
// IWYU pragma: private, include <grpcpp/security/auth_context.h>
// IWYU pragma: private
#include <iterator>
#include <vector>
#include <grpcpp/impl/codegen/config.h>
#include <grpcpp/impl/codegen/string_ref.h>
struct grpc_auth_context;
struct grpc_auth_property;
struct grpc_auth_property_iterator;
namespace grpc {
class SecureAuthContext;
typedef std::pair<string_ref, string_ref> AuthProperty;
class AuthPropertyIterator {
public:
using iterator_category = std::forward_iterator_tag;
using value_type = const AuthProperty;
using pointer = void;
using reference = void;
using difference_type = std::ptrdiff_t;
~AuthPropertyIterator();
AuthPropertyIterator& operator++();
AuthPropertyIterator operator++(int);
bool operator==(const AuthPropertyIterator& rhs) const;
bool operator!=(const AuthPropertyIterator& rhs) const;
AuthProperty operator*();
protected:
AuthPropertyIterator();
AuthPropertyIterator(const grpc_auth_property* property,
const grpc_auth_property_iterator* iter);
private:
friend class SecureAuthContext;
const grpc_auth_property* property_;
// The following items form a grpc_auth_property_iterator.
const grpc_auth_context* ctx_;
size_t index_;
const char* name_;
};
/// Class encapsulating the Authentication Information.
///
/// It includes the secure identity of the peer, the type of secure transport
/// used as well as any other properties required by the authorization layer.
class AuthContext {
public:
virtual ~AuthContext() {}
/// Returns true if the peer is authenticated.
virtual bool IsPeerAuthenticated() const = 0;
/// A peer identity.
///
/// It is, in general, comprised of one or more properties (in which case they
/// have the same name).
virtual std::vector<grpc::string_ref> GetPeerIdentity() const = 0;
virtual std::string GetPeerIdentityPropertyName() const = 0;
/// Returns all the property values with the given name.
virtual std::vector<grpc::string_ref> FindPropertyValues(
const std::string& name) const = 0;
/// Iteration over all the properties.
virtual AuthPropertyIterator begin() const = 0;
virtual AuthPropertyIterator end() const = 0;
/// Mutation functions: should only be used by an AuthMetadataProcessor.
virtual void AddProperty(const std::string& key, const string_ref& value) = 0;
virtual bool SetPeerIdentityPropertyName(const std::string& name) = 0;
};
} // namespace grpc
/// TODO(chengyuc): Remove this file after solving compatibility.
#include <grpcpp/security/auth_context.h>
#endif // GRPCPP_IMPL_CODEGEN_SECURITY_AUTH_CONTEXT_H

@ -19,6 +19,81 @@
#ifndef GRPCPP_SECURITY_AUTH_CONTEXT_H
#define GRPCPP_SECURITY_AUTH_CONTEXT_H
#include <grpcpp/impl/codegen/security/auth_context.h> // IWYU pragma: export
#include <iterator>
#include <vector>
#include <grpcpp/support/config.h>
#include <grpcpp/support/string_ref.h>
struct grpc_auth_context;
struct grpc_auth_property;
struct grpc_auth_property_iterator;
namespace grpc {
class SecureAuthContext;
typedef std::pair<string_ref, string_ref> AuthProperty;
class AuthPropertyIterator {
public:
using iterator_category = std::forward_iterator_tag;
using value_type = const AuthProperty;
using pointer = void;
using reference = void;
using difference_type = std::ptrdiff_t;
~AuthPropertyIterator();
AuthPropertyIterator& operator++();
AuthPropertyIterator operator++(int);
bool operator==(const AuthPropertyIterator& rhs) const;
bool operator!=(const AuthPropertyIterator& rhs) const;
AuthProperty operator*();
protected:
AuthPropertyIterator();
AuthPropertyIterator(const grpc_auth_property* property,
const grpc_auth_property_iterator* iter);
private:
friend class SecureAuthContext;
const grpc_auth_property* property_;
// The following items form a grpc_auth_property_iterator.
const grpc_auth_context* ctx_;
size_t index_;
const char* name_;
};
/// Class encapsulating the Authentication Information.
///
/// It includes the secure identity of the peer, the type of secure transport
/// used as well as any other properties required by the authorization layer.
class AuthContext {
public:
virtual ~AuthContext() {}
/// Returns true if the peer is authenticated.
virtual bool IsPeerAuthenticated() const = 0;
/// A peer identity.
///
/// It is, in general, comprised of one or more properties (in which case they
/// have the same name).
virtual std::vector<grpc::string_ref> GetPeerIdentity() const = 0;
virtual std::string GetPeerIdentityPropertyName() const = 0;
/// Returns all the property values with the given name.
virtual std::vector<grpc::string_ref> FindPropertyValues(
const std::string& name) const = 0;
/// Iteration over all the properties.
virtual AuthPropertyIterator begin() const = 0;
virtual AuthPropertyIterator end() const = 0;
/// Mutation functions: should only be used by an AuthMetadataProcessor.
virtual void AddProperty(const std::string& key, const string_ref& value) = 0;
virtual bool SetPeerIdentityPropertyName(const std::string& name) = 0;
};
} // namespace grpc
#endif // GRPCPP_SECURITY_AUTH_CONTEXT_H

Loading…
Cancel
Save