|
| 1 | +--- |
| 2 | +id: 4119 |
| 3 | +scope: auth |
| 4 | +state: draft |
| 5 | +created: 2022-09-09 |
| 6 | +--- |
| 7 | + |
| 8 | +# mTLS Token Binding |
| 9 | + |
| 10 | +Token binding allows issuing Google access tokens that are bound to mTLS |
| 11 | +credentials. The advantage of such mTLS bound tokens is that they are meant to |
| 12 | +only be used over secure channels established via mTLS credentials they are |
| 13 | +bound to. Therefore, using bound tokens is more secure than bearer tokens which |
| 14 | +can be stolen and adversarially replayed. |
| 15 | + |
| 16 | +This AIP describes the flow of (1) obtaining access tokens bound to X.509 |
| 17 | +certificate identities, called identity-bound tokens and (2) how to use them to |
| 18 | +access Google APIs using the Google auth libraries. |
| 19 | + |
| 20 | +**Note:** Because this AIP describes guidance and requirements in a |
| 21 | +language-neutral way, it uses generic terminology which may be imprecise or |
| 22 | +inappropriate in certain languages or environments. |
| 23 | + |
| 24 | +## Guidance |
| 25 | + |
| 26 | +If users enable token binding, they **should** do so via [ADC][0]. This section |
| 27 | +describes the general guidance of supporting such tokens. |
| 28 | + |
| 29 | +### Prerequisites |
| 30 | + |
| 31 | +Identity-bound access tokens require that the clients have |
| 32 | +[X.509 SPIFFE Verifiable Identity Documents][1] (SVIDs). [Mutual Authentication |
| 33 | +Using Workload Credentials][2] describes how such SVIDs are provisioned in |
| 34 | +Google Cloud. |
| 35 | + |
| 36 | +Additionally, identity-bound access tokens tokens require configuring a workload |
| 37 | +identity pool and identity provider with Google Cloud's IAM. The instructions on |
| 38 | +how to do this are out of scope of this AIP. |
| 39 | + |
| 40 | +### Using mTLS Token Binding |
| 41 | + |
| 42 | +The auth libraries **must** support the following values in the |
| 43 | +**"~/.config/gcloud/certificate_config.json"** configuration file. Note that the |
| 44 | +default location of this file can be changed using the |
| 45 | +`GOOGLE_API_CERTIFICATE_CONFIG` environment variable. |
| 46 | + |
| 47 | +```json |
| 48 | +{ |
| 49 | + “version”: 1 |
| 50 | + "cert_configs": { |
| 51 | + "workload": { |
| 52 | + "cert_path": "path/to/cert/file" |
| 53 | + "key_path": "path/to/key/file" |
| 54 | + “workload_identity_provider”: “...” |
| 55 | + "authenticate_as_identity_type": "gsa/native" |
| 56 | + “service_account_email”: “...” |
| 57 | + }, |
| 58 | + "keychain": { |
| 59 | + ... |
| 60 | + }, |
| 61 | + "pkcs11": { |
| 62 | + ... |
| 63 | + }, |
| 64 | + "windows": { |
| 65 | + ... |
| 66 | + }, |
| 67 | + }, |
| 68 | + "libs": { |
| 69 | + ... |
| 70 | + } |
| 71 | +} |
| 72 | +``` |
| 73 | + |
| 74 | +The following lists the fields relevant to mTLS token binding configuration: |
| 75 | + |
| 76 | + - **"workload_identity_provider"**: The specified value will be used to |
| 77 | + populate the request to Security Token Service (STS) to request |
| 78 | + identity-bound access tokens. This value refers to the fully qualified name |
| 79 | + of the workload identity pool and identity provider configured in IAM. The |
| 80 | + specified value **must** be of the following format. |
| 81 | + |
| 82 | +``` |
| 83 | +"workload_identity_provider":"//iam.googleapis.com/projects/<project_number>/locations/global/workloadIdentityPools/<pool_identifier>/providers/<provider_identifier>" |
| 84 | +``` |
| 85 | + |
| 86 | + - **"authenticate_as_identity_type"**: This field specifies what identity is |
| 87 | + used to authenticate to Google APIs. The value can be set to `gsa` or |
| 88 | + `native`, where `gsa` is the GCP service account of the workload, e.g., the |
| 89 | + GCP service account of a GCE VM, and `native` is the native workload |
| 90 | + identity, e.g., the GKE pod kubernetes service account. If not specified, |
| 91 | + the default value is `gsa`. |
| 92 | + |
| 93 | + - **"service_account_email"**: If set, the specified value will be used to |
| 94 | + populate the request to the IAM Credentials service to request |
| 95 | + identity-bound access tokens. This value refers to the service account email |
| 96 | + to be used for resource access. If not set, the service account email will |
| 97 | + be determined automatically by querying the following Metadata Service |
| 98 | + endpoint: |
| 99 | + `http://metadata/computeMetadata/v1/instance/service-accounts/default/email`. |
| 100 | + The value of this field is only relevant if |
| 101 | + **"authenticate_as_identity_type"** is set to `gsa`. |
| 102 | + |
| 103 | +The description of the **"cert_path"** and **"key_path"** fields can be found in |
| 104 | +[Mutual Authentication Using Workload Credentials][2]. |
| 105 | + |
| 106 | +To enable using token binding when communicating with Google APIs the following |
| 107 | +conditions are required: |
| 108 | + |
| 109 | + - [Mutual Authentication Using Workload Credentials][2] **must** be enabled. |
| 110 | + - The **"workload_identity_provider"** **must** be present, |
| 111 | + **"authenticate_as_identity_type"** __may__ be set and |
| 112 | + **"service_account_email"** __may__ be set in the **"workload"** |
| 113 | + section of the **"~/.config/gcloud/certificate_config.json"** configuration |
| 114 | + file. |
| 115 | + |
| 116 | +### Expected Behavior |
| 117 | + |
| 118 | +To support the usage of identity-bound access tokens, the auth libraries |
| 119 | +**must** follow the steps below when sending requests to Google APIs: |
| 120 | + |
| 121 | + 1. Connect to the mTLS endpoint of the [STS API][3] using the workload |
| 122 | + credentials provisioned as described in [Mutual Authentication Using |
| 123 | + Workload Credentials][2]. This endpoint **must** be |
| 124 | + `sts.mtls.googleapis.com`. |
| 125 | + 1. Send an HTTP request to STS’s [ExchangeToken][5] method requesting an |
| 126 | + identity-bound token using the information in the |
| 127 | + **"workload_identity_provider"** field in the |
| 128 | + **"~/.config/gcloud/certificate_config.json"** configuration file. The |
| 129 | + scope of the requested token **must** be |
| 130 | + `https://www.googleapis.com/auth/iam`. |
| 131 | + 1. Connect to the mTLS endpoint of the [IAM Credentials Service API][4] using |
| 132 | + the workload credentials provisioned as described in [Mutual Authentication |
| 133 | + Using Workload Credentials][2]. This endpoint **must** be |
| 134 | + `iamcredentials.mtls.googleapis.com`. |
| 135 | + 1. If **"authenticate_as_identity_type"** is set to `gsa`, send an HTTP |
| 136 | + request to the IAM Credentials Service’s [GenerateAccessToken][6] method |
| 137 | + requesting an identity bound token asserting the service account email in |
| 138 | + the **"service_account_email"** field in the |
| 139 | + **"~/.config/gcloud/certificate_config.json"** configuration file. The |
| 140 | + scope of this token **must** be the same scope defined by the user for |
| 141 | + accessing the requested Google API. |
| 142 | + 1. Attach the returned token in Step 4 to the request. Note that this request |
| 143 | + **must** be sent over an mTLS channel using the same workload credentials |
| 144 | + in Step 1. |
| 145 | + |
| 146 | +<!-- prettier-ignore-start --> |
| 147 | +[0]: https://google.aip.dev/auth/4110 |
| 148 | +[1]: https://github.com/spiffe/spiffe/blob/main/standards/X509-SVID.md |
| 149 | +[2]: https://google.aip.dev/auth/4118 |
| 150 | +[3]: https://cloud.google.com/iam/docs/reference/sts/rest |
| 151 | +[4]: https://cloud.google.com/iam/docs/reference/credentials/rest |
| 152 | +[5]: https://cloud.google.com/iam/docs/reference/sts/rest/v1/TopLevel/token |
| 153 | +[6]: https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/generateAccessToken |
| 154 | +<!-- prettier-ignore-end --> |
0 commit comments