Skip to content

ci: update rotate-keys for additional key#16269

Open
scotthart wants to merge 1 commit into
googleapis:mainfrom
scotthart:ci_update_key_rotation
Open

ci: update rotate-keys for additional key#16269
scotthart wants to merge 1 commit into
googleapis:mainfrom
scotthart:ci_update_key_rotation

Conversation

@scotthart

Copy link
Copy Markdown
Member

No description provided.

@scotthart
scotthart requested a review from a team as a code owner July 20, 2026 21:25

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the key rotation script rotate-keys.sh to support multiple service accounts, specifically adding the observability service account. The feedback recommends assigning command substitution outputs to variables to prevent swallowing errors under set -e, and refactoring the space-separated file types into a Bash array to avoid unquoted variable expansion issues.

"--filter=CREATED_AT<-p90d"
"--format=value(KEY_ID)"
)
for old_key in $(gcloud iam service-accounts keys list "${args[@]}"); do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

In Bash, a failure in a command substitution inside a for loop list (e.g., for x in $(command)) does not trigger set -e, which means if gcloud fails, the script will silently continue without deleting old keys. This violates the Demand Explosive Correctness principle in the repository style guide.

To fix this, assign the command output to a variable first so that set -e can properly catch any failures.

Suggested change
for old_key in $(gcloud iam service-accounts keys list "${args[@]}"); do
old_keys=$(gcloud iam service-accounts keys list "${args[@]}")
for old_key in ${old_keys}; do
References
  1. Demand Explosive Correctness: Never swallow errors or ignore Status types. Fail loudly and explicitly when appropriate. (link)

fi

for entry in "${accounts_config[@]}"; do
IFS="|" read -r sa_email prefix filetypes <<<"${entry}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To avoid unquoted variable expansion (which triggers ShellCheck warning SC2086) and ensure robust word splitting, consider reading the space-separated filetypes into a Bash array.

Suggested change
IFS="|" read -r sa_email prefix filetypes <<<"${entry}"
IFS="|" read -r sa_email prefix filetypes_str <<<"${entry}"
read -r -a filetypes <<<"${filetypes_str}"

"${prefix}-$(date +"%Y-%m" --date="now + 2 weeks")"
)
for key_base in "${active_key_bases[@]}"; do
for filetype in ${filetypes}; do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Use the filetypes array with proper quoting to prevent word splitting and globbing issues.

Suggested change
for filetype in ${filetypes}; do
for filetype in "${filetypes[@]}"; do

done
io::log_h2 "Checking for stale keyfiles (${prefix})"
stale_key_base="${prefix}-$(date +"%Y-%m" --date="now - 45 days")"
for filetype in ${filetypes}; do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Use the filetypes array with proper quoting here as well.

Suggested change
for filetype in ${filetypes}; do
for filetype in "${filetypes[@]}"; do

@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.27%. Comparing base (fd956fb) to head (db50235).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16269      +/-   ##
==========================================
- Coverage   92.27%   92.27%   -0.01%     
==========================================
  Files        2218     2218              
  Lines      206654   206654              
==========================================
- Hits       190699   190687      -12     
- Misses      15955    15967      +12     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant