Skip to content

Commit f8a8dc6

Browse files
feat: support direct wif
1 parent f7db4b6 commit f8a8dc6

File tree

2 files changed

+81
-5
lines changed

2 files changed

+81
-5
lines changed

action.yml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ inputs:
3030
gcp_workload_identity_provider:
3131
description: 'The Google Cloud Workload Identity Provider.'
3232
required: false
33+
gcp_token_format:
34+
description: 'The token format for authentication. Set to "access_token" to generate access tokens (requires service account), or set to empty string for direct WIF. Can be "access_token" or "id_token".'
35+
required: false
36+
default: 'access_token'
37+
gcp_access_token_scopes:
38+
description: 'The access token scopes when using token_format "access_token". Comma-separated list of OAuth 2.0 scopes.'
39+
required: false
40+
default: 'https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/userinfo.email,https://www.googleapis.com/auth/userinfo.profile'
3341
gemini_api_key:
3442
description: 'The API key for the Gemini API.'
3543
required: false
@@ -123,8 +131,13 @@ runs:
123131
124132
# Validate Workload Identity Federation inputs
125133
if [[ "${INPUT_GCP_WORKLOAD_IDENTITY_PROVIDER_PRESENT:-false}" == "true" ]]; then
126-
if [[ "${INPUT_GCP_PROJECT_ID_PRESENT:-false}" != "true" || "${INPUT_GCP_SERVICE_ACCOUNT_PRESENT:-false}" != "true" ]]; then
127-
warn "When using Workload Identity Federation ('gcp_workload_identity_provider'), you must also provide 'gcp_project_id' and 'gcp_service_account'."
134+
if [[ "${INPUT_GCP_PROJECT_ID_PRESENT:-false}" != "true" ]]; then
135+
warn "When using Workload Identity Federation ('gcp_workload_identity_provider'), you must also provide 'gcp_project_id'."
136+
fi
137+
# Service account is required when using token_format (default behavior)
138+
# Only optional when explicitly set to empty for direct WIF
139+
if [[ "${INPUT_GCP_TOKEN_FORMAT}" != "" && "${INPUT_GCP_SERVICE_ACCOUNT_PRESENT:-false}" != "true" ]]; then
140+
warn "When using Workload Identity Federation with token generation ('gcp_token_format'), you must also provide 'gcp_service_account'. To use direct WIF without a service account, explicitly set 'gcp_token_format' to an empty string."
128141
fi
129142
if [[ "${INPUT_USE_VERTEX_AI:-false}" == "${INPUT_USE_GEMINI_CODE_ASSIST:-false}" ]]; then
130143
warn "When using Workload Identity Federation, you must set exactly one of 'use_vertex_ai' or 'use_gemini_code_assist' to 'true'."
@@ -153,6 +166,7 @@ runs:
153166
INPUT_GCP_WORKLOAD_IDENTITY_PROVIDER_PRESENT: "${{ inputs.gcp_workload_identity_provider != '' }}"
154167
INPUT_GCP_PROJECT_ID_PRESENT: "${{ inputs.gcp_project_id != '' }}"
155168
INPUT_GCP_SERVICE_ACCOUNT_PRESENT: "${{ inputs.gcp_service_account != '' }}"
169+
INPUT_GCP_TOKEN_FORMAT: '${{ inputs.gcp_token_format }}'
156170
INPUT_USE_VERTEX_AI: '${{ inputs.use_vertex_ai }}'
157171
INPUT_USE_GEMINI_CODE_ASSIST: '${{ inputs.use_gemini_code_assist }}'
158172

@@ -184,8 +198,8 @@ runs:
184198
project_id: '${{ inputs.gcp_project_id }}'
185199
workload_identity_provider: '${{ inputs.gcp_workload_identity_provider }}'
186200
service_account: '${{ inputs.gcp_service_account }}'
187-
token_format: 'access_token'
188-
access_token_scopes: 'https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/userinfo.email,https://www.googleapis.com/auth/userinfo.profile'
201+
token_format: '${{ inputs.gcp_token_format }}'
202+
access_token_scopes: '${{ inputs.gcp_access_token_scopes }}'
189203

190204
- name: 'Install Gemini CLI'
191205
id: 'install'

docs/authentication.md

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ This is the standard method for authenticating directly with the Vertex AI API u
170170

171171
- A Google Cloud project with the **Vertex AI API** enabled.
172172

173+
**Approach 1: With Service Account (Default)**
174+
175+
This is the default authentication approach using a service account with access token generation.
176+
173177
**GitHub Configuration**
174178

175179
After running the `setup_workload_identity.sh` script, add the following variables to your repository's **Settings > Secrets and variables > Actions**:
@@ -196,6 +200,33 @@ After running the `setup_workload_identity.sh` script, add the following variabl
196200
Explain this code
197201
```
198202
203+
**Approach 2: Direct WIF (Without Service Account)**
204+
205+
Alternatively, you can use direct Workload Identity Federation without a service account by explicitly setting `gcp_token_format` to an empty string.
206+
207+
**GitHub Configuration**
208+
209+
| Variable Name | Description |
210+
| --------------------------- | ---------------------------------------------------- |
211+
| `GCP_WIF_PROVIDER` | The resource name of the Workload Identity Provider. |
212+
| `GOOGLE_CLOUD_PROJECT` | Your Google Cloud project ID. |
213+
| `GOOGLE_CLOUD_LOCATION` | Your Google Cloud project Location. |
214+
| `GOOGLE_GENAI_USE_VERTEXAI` | Set to `true` to use Vertex AI. |
215+
216+
**Example**
217+
218+
```yaml
219+
- uses: 'google-github-actions/run-gemini-cli@v0'
220+
with:
221+
gcp_workload_identity_provider: '${{ vars.GCP_WIF_PROVIDER }}'
222+
gcp_project_id: '${{ vars.GOOGLE_CLOUD_PROJECT }}'
223+
gcp_location: '${{ vars.GOOGLE_CLOUD_LOCATION }}'
224+
gcp_token_format: '' # Empty string for direct WIF
225+
use_vertex_ai: '${{ vars.GOOGLE_GENAI_USE_VERTEXAI }}'
226+
prompt: |-
227+
Explain this code
228+
```
229+
199230
#### Connecting to Gemini Code Assist
200231

201232
If you have a **Gemini Code Assist** subscription, you can configure the action to use it for authentication.
@@ -204,16 +235,20 @@ If you have a **Gemini Code Assist** subscription, you can configure the action
204235

205236
- A Google Cloud project with an active Gemini Code Assist subscription.
206237

238+
**Approach 1: With Service Account (Default)**
239+
240+
This is the default authentication approach using a service account with access token generation.
241+
207242
**GitHub Configuration**
208243

209244
After running the `setup_workload_identity.sh` script, add the following variables to your repository's **Settings > Secrets and variables > Actions**:
210245

211246
| Variable Name | Description |
212247
| ----------------------- | ------------------------------------------------------- |
213248
| `GCP_WIF_PROVIDER` | The resource name of the Workload Identity Provider. |
249+
| `SERVICE_ACCOUNT_EMAIL` | The service account with the required permissions. |
214250
| `GOOGLE_CLOUD_PROJECT` | Your Google Cloud project ID. |
215251
| `GOOGLE_CLOUD_LOCATION` | Your Google Cloud project Location. |
216-
| `SERVICE_ACCOUNT_EMAIL` | The email of the service account for Code Assist. |
217252
| `GOOGLE_GENAI_USE_GCA` | Set to `true` to authenticate using Gemini Code Assist. |
218253

219254
**Example**
@@ -230,6 +265,33 @@ After running the `setup_workload_identity.sh` script, add the following variabl
230265
Explain this code
231266
```
232267

268+
**Approach 2: Direct WIF (Without Service Account)**
269+
270+
Alternatively, you can use direct Workload Identity Federation without a service account by explicitly setting `gcp_token_format` to an empty string.
271+
272+
**GitHub Configuration**
273+
274+
| Variable Name | Description |
275+
| ----------------------- | ------------------------------------------------------- |
276+
| `GCP_WIF_PROVIDER` | The resource name of the Workload Identity Provider. |
277+
| `GOOGLE_CLOUD_PROJECT` | Your Google Cloud project ID. |
278+
| `GOOGLE_CLOUD_LOCATION` | Your Google Cloud project Location. |
279+
| `GOOGLE_GENAI_USE_GCA` | Set to `true` to authenticate using Gemini Code Assist. |
280+
281+
**Example**
282+
283+
```yaml
284+
- uses: 'google-github-actions/run-gemini-cli@v0'
285+
with:
286+
gcp_workload_identity_provider: '${{ vars.GCP_WIF_PROVIDER }}'
287+
gcp_project_id: '${{ vars.GOOGLE_CLOUD_PROJECT }}'
288+
gcp_location: '${{ vars.GOOGLE_CLOUD_LOCATION }}'
289+
gcp_token_format: '' # Empty string for direct WIF
290+
use_gemini_code_assist: '${{ vars.GOOGLE_GENAI_USE_GCA }}'
291+
prompt: |-
292+
Explain this code
293+
```
294+
233295
## GitHub Authentication
234296

235297
This action requires a GitHub token to interact with the GitHub API. You can authenticate in two ways:

0 commit comments

Comments
 (0)