1Server-side API for Authenticating Clients 2========================================== 3 4NOTE: This document describes how server-side authentication works in C-core based gRPC implementations only. In gRPC Java and Go, server side authentication is handled differently. 5 6## AuthContext 7 8To perform server-side authentication, gRPC exposes the *authentication context* for each call. The context exposes important authentication-related information about the RPC such as the type of security/authentication type being used and the peer identity. 9 10The authentication context is structured as a multi-map of key-value pairs - the *auth properties*. In addition to that, for authenticated RPCs, the set of properties corresponding to a selected key will represent the verified identity of the caller - the *peer identity*. 11 12The 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"`). 13 14WARNING: 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. 15 16#### Example AuthContext contents 17 18For secure channel using mutual TLS authentication with both client and server certificates (test certificates from this repository are used). 19 20Populated auth properties: 21``` 22"transport_security_type": "ssl" # connection is secured using TLS/SSL 23"x509_common_name": "*.test.google.com" # from client's certificate 24"x509_pem_cert": "-----BEGIN CERTIFICATE-----\n..." # client's PEM encoded certificate 25"x509_subject_alternative_name": "*.test.google.fr" 26"x509_subject_alternative_name": "waterzooi.test.google.be" 27"x509_subject_alternative_name": "*.test.youtube.com" 28"x509_subject_alternative_name": "192.168.1.3" 29``` 30 31The peer identity is set of all properties named `"x509_subject_alternative_name"`: 32``` 33peer_identity_property_name = "x509_subject_alternative_name" 34``` 35 36## AuthProperty 37 38Auth properties are elements of the AuthContext. They have a name (a key of type string) and a value which can be a string or binary data. 39 40## Auth Interceptors 41 42Auth interceptors are gRPC components that populate contents of the auth context based on gRPC's internal state and/or call metadata. 43gRPC comes with some basic "interceptors" already built-in. 44 45WARNING: While there is a public API that allows anyone to write their own custom interceptor, please think twice before using it. 46There are legitimate uses for custom interceptors but you should keep in mind that as auth interceptors essentially decide which RPCs are authenticated and which are not, their code is very sensitive from the security perspective and getting things wrong might have serious consequences. If unsure, we strongly recommend to rely on official & proven interceptors that come with gRPC. 47 48#### Available auth interceptors 49- TLS/SSL certificate authentication (built into gRPC's security layer, automatically used whenever you use a secure connection) 50- (coming soon) JWT auth token authentication 51- more will be added over time 52 53## Status (by language) 54C-core exposes low level API to access auth context contents and to implement an auth interceptor. 55In C++, the auth interceptor API is exposed as `AuthMetadataProcessor`. 56 57A high level API to access AuthContext contents is available in these languages: 58- C++ 59- C# (implementation in-progress) 60- other languages coming soon 61