@@ -50,6 +50,7 @@ Additionally to the environment variables you define in the `ci-setup.json` file
50
50
51
51
- ` PROJECT_ID ` : The project used by the testing infrastructure.
52
52
- ` RUN_ID ` : A random unique identifier, different on every test run.
53
+ - ` SERVICE_ACCOUNT ` : The email of the testing service account.
53
54
54
55
> ** Note** : An environment variable explicitly defined under ` env ` with the same name as an automatic variable overrides the automatic variable.
55
56
@@ -98,6 +99,67 @@ For example:
98
99
99
100
The test infrastructure then fetches the actual secret data and exports them as environment variables.
100
101
102
+ ### Automatic secret values
103
+
104
+ Additional to any secret values you define in the ` ci-setup.json ` file, the test infrastructure always exports the following secret value:
105
+
106
+ - ` ID_TOKEN ` : an ID token for interacting with private Cloud Run services.
107
+
108
+
109
+ <details >
110
+ <summary >
111
+ Adapting <b >` ID_TOKEN ` </b > use in system testing
112
+ </summary >
113
+
114
+ Due to organization policies, Cloud Run services cannot be deployed with public
115
+ access. This means authentication is required in order to perform integration
116
+ testing. We do this by using ID Tokens (JWT) provided by [ Google GitHub Actions
117
+ Auth] ( https://github.com/google-github-actions/auth/blob/main/docs/EXAMPLES.md#generating-an-id-token-jwt ) .
118
+
119
+ By default, the audience of a Cloud Run service is [ the full URL of the service
120
+ itself] ( https://cloud.google.com/run/docs/configuring/custom-audiences#:~:text=By%20convention%2C%20the%20audience%20is ) .
121
+ Since we cannot know all the URLs for all samples ahead of time (since unique
122
+ IDs are in use), we instead define a custom audience in the GitHub Action, then
123
+ apply that as an additional audience to all Cloud Run services.
124
+
125
+ To use this method, some changes are required:
126
+
127
+ 1 . As part of testing setup, add a step to customize the Cloud Run service to have the custom audience ` https://action.test/ `
128
+
129
+ ``` shell
130
+ gcloud run services deploy ${_SERVICE} \
131
+ ... \
132
+ --add-custom-audiences=" https://action.test/"
133
+ ```
134
+
135
+ 1. Use the environment variable ID_TOKEN in any Authorization: Bearer calls.
136
+
137
+ For example, a curl command:
138
+
139
+ ` ` ` shell
140
+ # ❌ Previous version: calls gcloud
141
+ curl -H " Authorization: Bearer $( gcloud auth print-identity-token) " https://my-service-hash.a.run.app
142
+
143
+ # ✅ New version: uses environment variable
144
+ curl -H " Authorization: Bearer ${ID_TOKEN} " https://my-service-hash.a.run.app
145
+ ` ` `
146
+
147
+ For example, a Node.JS script:
148
+
149
+ ` ` ` javascript
150
+ // ❌ Previous version: auth.getIdTokenClient ()
151
+ const client = await auth.getIdTokenClient(BASE_URL);
152
+ const clientHeaders = await client.getRequestHeaders ();
153
+ ID_TOKEN = clientHeaders['Authorization'].trim ();
154
+ if (! ID_TOKEN) throw Error(' Unable to acquire an ID token.' );
155
+
156
+ // ✅ New version: uses environment variable
157
+ {ID_TOKEN} = process.env;
158
+ if (! ID_TOKEN) throw Error(' "ID_TOKEN" not found in environment variables.' );
159
+ ` ` `
160
+
161
+ < /details>
162
+
101
163
# ## Secrets vs environment variables
102
164
103
165
Most configuration should be directly set with environment variables.
0 commit comments