Repository navigation
Fix -key suffix stripping in account_keys.py and add dry-run input to PolicyEnforcer - #41591
Conversation
|
/gemini review |
|
/gemini review |
There was a problem hiding this comment.
📋 Review Summary
This PR resolves six CodeQL py/clear-text-logging-sensitive-data alerts in infra/enforcement/account_keys.py by replacing logged secret identifiers and full IAM policy objects with non-sensitive service account identifiers and aggregate counts. It also fixes a subtle string-stripping bug by replacing secret.strip("-key") with secret.removesuffix("-key").
🔍 General Feedback
- The refactoring cleanly eliminates CodeQL taint flows and variable-name heuristic triggers while preserving all compliance checking and generation behavior.
- Reordering the permission check loop before appending undeclared accounts in
generate_compliance()avoids unnecessary skipped iterations on newly added accounts with emptyauthorized_users.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
Assigning reviewers: R: @damccorm added as fallback since no labels match configuration Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
|
Could you please run https://github.com/apache/beam/actions/workflows/beam_Infrastructure_PolicyEnforcer.yml and share the results? FWIW, this is a cleaner way to make these PRs verifiable than a python script to run |
| verified_keys.append(key_id) | ||
| return verified_keys | ||
| except Exception as e: | ||
| self.logger.error(f"Failed to retrieve verified keys from Secret Manager for secret '{secret_name}': {e}") |
There was a problem hiding this comment.
Why does logging the secret name matter? I don't think this is protected in Beam
|
High level feedback on a few of these PRs: I'm supportive of driving down these warnings, but it is unclear at this point what the work to value ratio is - along those lines, I have a few questions:
I've started including a doc with more details on approach/high level impact in similar large scale changes (e.g. see the description in #41272), and would recommend doing something similar. You could also inline it if the answers are simple. |
There was a problem hiding this comment.
📋 Review Summary
This PR updates infra/enforcement/account_keys.py to remediate CodeQL py/clear-text-logging-sensitive-data alerts by replacing secret names and full IAM policies in log messages with service account identifiers and summary counts, and fixes a suffix-stripping bug (strip("-key") -> removesuffix("-key")).
🔍 General Feedback
- Replacing individual undeclared secret warnings in
check_compliance()with a single aggregate count (undeclared_count) removes actionable diagnostic context from compliance reports and announcements. Since secret resource names here follow the<account_id>-keyconvention (which is public metadata in the repo's keys YAML file rather than secret payload material), consider whether suppressing the false-positive CodeQL heuristic or logging the derivedaccount_idis preferable to losing the identifier in drift alerts. - Good catch replacing
secret.strip("-key")withsecret.removesuffix("-key")when derivingaccount_id.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
Practically, why this matters to me as a reviewer: If the value is high and we only need a small number of PRs to realize the value, then I won't care about things like #41591 (comment) (we can just make the switch to make the scanner happy). If the value is low and we need many PRs, then the math is different and I'd push back/look for more systemic changes we can make at a tooling level. I'm still calibrating how to handle all of this (so treat my PRs (and feedback) as an experimental approach to learn from, not my recommendation on how to handle everything moving forward 😅 ) |
Approximately ~40 more merged PRs needed to cleanup everything to this point.
I opened another PR for zizmor to get rid of the Note warnings (~1200) since they are not applicable to this repo - #41637
Some current or near future impact with this cleanup:
|
Thanks, this is helpful! If you're autogenerating descriptions, I'd recommend including this kind of context |
Note: this PR was auto-generated by tooling. Before moving it out of draft, the author has done a full review of the PR, specifically evaluating it on the following criteria:
CodeQL/zizmor) onmasterwithout altering intended public API or workflow semanticsIf you have concerns with the PR or with the underlying methodology used to generate this, please comment below - they will be addressed by the author not the tooling :)
Summary
CodeQLpy/clear-text-logging-sensitive-dataalerts (#1835–#1840): CodeQL'sSensitiveDataHeuristicsflaggedsecret_client.list_secrets()resource names because the variable/method names contain"secret", even though GCP Secret Manager resource IDs (<service-account>-key) are public metadata used in Beam's audit drift reports rather than secret key payloads. Restored all original per-secret logging ininfra/enforcement/account_keys.py.-keysuffix stripping bug ininfra/enforcement/account_keys.py: Replace character-setsecret.strip("-key")with suffix-accuratesecret.removesuffix("-key")ingenerate_compliance()so service account IDs starting or ending withk,e, oryare not corrupted.workflow_dispatchactioninput & scope permissions in.github/workflows/beam_Infrastructure_PolicyEnforcer.yml: Allow manualworkflow_dispatchruns to default toaction=print(exercising live GCP IAM and Secret Manager checks and printing the audit report to workflow logs without updating GitHub issues or emailingdev@beam.apache.org, while keepingannounceon the weekly Monday schedule), and moveissues: writeandid-token: writeto job level (zizmorexcessive-permissions).Verification
Infrastructure Policy Enforcer(action=print) dry-run on branchcodescan/py-account-keys-logging: https://github.com/apache/beam/actions/runs/45252411747 (successacross bothRun IAM Policy EnforcementandRun Account Keys Policy Enforcementwith zero issue/email side effects)zizmor --config .github/zizmor.yml --persona=pedantic .github/workflows/beam_Infrastructure_PolicyEnforcer.yml(0findings)./gradlew :beam-test-gha:preCommitandpython3 -m py_compile infra/enforcement/account_keys.py