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.
5NOTE2: `CallCredentials` class is only valid for secure channels in C-Core. So, for connections under insecure channels, features below might not be avaiable.
6
7## AuthContext
8
9To 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.
10
11The 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*.
12
13The 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"`).
14
15WARNING: 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.
16
17#### Example AuthContext contents
18
19For secure channel using mutual TLS authentication with both client and server certificates (test certificates from this repository are used).
20
21Populated auth properties:
22```
23"transport_security_type": "ssl"  # connection is secured using TLS/SSL
24"x509_common_name": "*.test.google.com"  # from client's certificate
25"x509_pem_cert": "-----BEGIN CERTIFICATE-----\n..."  # client's PEM encoded certificate
26"x509_subject_alternative_name": "*.test.google.fr"
27"x509_subject_alternative_name": "waterzooi.test.google.be"
28"x509_subject_alternative_name": "*.test.youtube.com"
29"x509_subject_alternative_name": "192.168.1.3"
30```
31
32The peer identity is set of all properties named `"x509_subject_alternative_name"`:
33```
34peer_identity_property_name = "x509_subject_alternative_name"
35```
36
37## AuthProperty
38
39Auth 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.
40
41## Auth Interceptors
42
43Auth interceptors are gRPC components that populate contents of the auth context based on gRPC's internal state and/or call metadata.
44gRPC comes with some basic "interceptors" already built-in.
45
46WARNING: While there is a public API that allows anyone to write their own custom interceptor, please think twice before using it.
47There 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.
48
49#### Available auth interceptors
50- TLS/SSL certificate authentication (built into gRPC's security layer, automatically used whenever you use a secure connection)
51- (coming soon) JWT auth token authentication
52- more will be added over time
53
54## Status (by language)
55C-core exposes low level API to access auth context contents and to implement an auth interceptor.
56In C++, the auth interceptor API is exposed as `AuthMetadataProcessor`.
57
58A high level API to access AuthContext contents is available in these languages:
59- C++
60- C# (implementation in-progress)
61- other languages coming soon
62