Skip to content

Commit 2a17056

Browse files
committed
feat: add auth input validation
Adds a validation step to the action to ensure that authentication inputs are configured correctly. This prevents common misconfigurations and improves security. The validation is performed by a new script, `scripts/validate-inputs.sh`, which is called as the first step in the action. Key changes: - A new `validate-inputs.sh` script is added to check authentication configuration. - The `action.yml` is updated to call this script. - Follows principle of least privilege by using boolean flags to indicate whether inputs are set. - The validation enforces that exactly one authentication method is used, providing clear error messages to the user if the configuration is invalid. This makes the action more robust, secure, and easier to debug.
1 parent 04eed5c commit 2a17056

2 files changed

Lines changed: 76 additions & 0 deletions

File tree

action.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ outputs:
8080
runs:
8181
using: 'composite'
8282
steps:
83+
- name: 'Validate inputs'
84+
shell: 'bash'
85+
run: '${{ github.action_path }}/scripts/validate-inputs.sh'
86+
env:
87+
INPUT_GEMINI_API_KEY_PRESENT: '${{ inputs.gemini_api_key != '' }}'
88+
INPUT_GOOGLE_API_KEY_PRESENT: '${{ inputs.google_api_key != '' }}'
89+
INPUT_GCP_WORKLOAD_IDENTITY_PROVIDER_PRESENT: '${{ inputs.gcp_workload_identity_provider != '' }}'
90+
INPUT_GCP_PROJECT_ID_PRESENT: '${{ inputs.gcp_project_id != '' }}'
91+
INPUT_GCP_SERVICE_ACCOUNT_PRESENT: '${{ inputs.gcp_service_account != '' }}'
92+
INPUT_USE_VERTEX_AI: '${{ inputs.use_vertex_ai }}'
93+
INPUT_USE_GEMINI_CODE_ASSIST: '${{ inputs.use_gemini_code_assist }}'
8394
- name: 'Configure Gemini CLI'
8495
if: |-
8596
${{ inputs.settings != '' }}

scripts/validate-inputs.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# Auth inputs (as boolean presence flags)
5+
gemini_api_key_present="${INPUT_GEMINI_API_KEY_PRESENT:-false}"
6+
google_api_key_present="${INPUT_GOOGLE_API_KEY_PRESENT:-false}"
7+
gcp_workload_identity_provider_present="${INPUT_GCP_WORKLOAD_IDENTITY_PROVIDER_PRESENT:-false}"
8+
gcp_project_id_present="${INPUT_GCP_PROJECT_ID_PRESENT:-false}"
9+
gcp_service_account_present="${INPUT_GCP_SERVICE_ACCOUNT_PRESENT:-false}"
10+
11+
# Other inputs (values needed)
12+
use_vertex_ai="${INPUT_USE_VERTEX_AI:-false}"
13+
use_gemini_code_assist="${INPUT_USE_GEMINI_CODE_ASSIST:-false}"
14+
15+
# Count number of auth methods
16+
auth_methods=0
17+
if [[ "${gemini_api_key_present}" == 'true' ]]; then ((auth_methods++)); fi
18+
if [[ "${google_api_key_present}" == 'true' ]]; then ((auth_methods++)); fi
19+
if [[ "${gcp_workload_identity_provider_present}" == 'true' ]]; then ((auth_methods++)); fi
20+
21+
if [[ ${auth_methods} -eq 0 ]]; then
22+
echo "::error title=Configuration error::No authentication method provided. Please provide one of 'gemini_api_key', 'google_api_key', or 'gcp_workload_identity_provider'."
23+
exit 1
24+
fi
25+
26+
if [[ ${auth_methods} -gt 1 ]]; then
27+
echo "::error title=Configuration error::Multiple authentication methods provided. Please use only one of 'gemini_api_key', 'google_api_key', or 'gcp_workload_identity_provider'."
28+
exit 1
29+
fi
30+
31+
# WIF validation
32+
if [[ "${gcp_workload_identity_provider_present}" == 'true' ]]; then
33+
if [[ "${gcp_project_id_present}" != 'true' || "${gcp_service_account_present}" != 'true' ]]; then
34+
echo "::error title=Configuration error::When using Workload Identity Federation ('gcp_workload_identity_provider'), you must also provide 'gcp_project_id' and 'gcp_service_account'."
35+
exit 1
36+
fi
37+
if [[ "${use_vertex_ai}" != 'true' && "${use_gemini_code_assist}" != 'true' ]]; then
38+
echo "::error title=Configuration error::When using Workload Identity Federation, you must set either 'use_vertex_ai' or 'use_gemini_code_assist' to 'true'."
39+
exit 1
40+
fi
41+
if [[ "${use_vertex_ai}" == 'true' && "${use_gemini_code_assist}" == 'true' ]]; then
42+
echo "::error title=Configuration error::'use_vertex_ai' and 'use_gemini_code_assist' cannot both be 'true'."
43+
exit 1
44+
fi
45+
fi
46+
47+
# Vertex AI API Key validation
48+
if [[ "${google_api_key_present}" == 'true' ]]; then
49+
if [[ "${use_vertex_ai}" != 'true' ]]; then
50+
echo "::error title=Configuration error::When using 'google_api_key', you must set 'use_vertex_ai' to 'true'."
51+
exit 1
52+
fi
53+
if [[ "${use_gemini_code_assist}" == 'true' ]]; then
54+
echo "::error title=Configuration error::'use_gemini_code_assist' cannot be 'true' when using 'google_api_key'."
55+
exit 1
56+
fi
57+
fi
58+
59+
# Gemini API Key validation
60+
if [[ "${gemini_api_key_present}" == 'true' ]]; then
61+
if [[ "${use_vertex_ai}" == 'true' || "${use_gemini_code_assist}" == 'true' ]]; then
62+
echo "::error title=Configuration error::When using 'gemini_api_key', both 'use_vertex_ai' and 'use_gemini_code_assist' must be 'false'."
63+
exit 1
64+
fi
65+
fi

0 commit comments

Comments
 (0)