Repository navigation
feat(infra): WIF for notifications-job development deploys - #13673
Git-on-my-level merged 2 commits into
Conversation
Replace dying GCP_CREDENTIALS JSON on the development input with a job-scoped GitHub WIF pool/SA. Prod input stays JSON until a later slice.
There was a problem hiding this comment.
5 issues found across 8 files
Confidence score: 2/5
- The highest risk is in
.github/scripts/check_opentofu_gha_wif_notifications.py: the checker can pass changed IAM/project/member values and ignores added*.tf.jsonfiles, allowing unreviewed privilege or deployment-scope expansion. Validate critical resource bodies and include.tf.jsonfiles in the exact-file scan, with negative fixtures. infrastructure/opentofu/slices/gha-wif-notifications/main.tfcan let a run dispatched frommaincheck out an arbitrary branch and execute it with the WIF identity. Validate the requested revision from trusted main-branch code before requesting credentials, or remove this capability.- The happy-path-only coverage in
.github/scripts/test_check_opentofu_gha_wif_notifications.pywill not detect weakened or removed security guards. Add negative tests covering forbidden roles,credentials_json,based-hardware, changed resource bodies, and*.tf.jsonadditions. infrastructure/opentofu/slices/gha-wif-notifications/variables.tfdeclares and validates an unusedproject_numberthat duplicates a runtime service-account literal; remove the variable or wire it into the implementation to avoid configuration drift.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name=".github/scripts/check_opentofu_gha_wif_notifications.py">
<violation number="1" location=".github/scripts/check_opentofu_gha_wif_notifications.py:48">
P1: When a `*.tf.json` file is added to the slice, this check ignores it and still reports OK, allowing OpenTofu to apply unreviewed resources. Include `.tf.json` files in the exact-file scan and add a negative fixture.</violation>
<violation number="2" location=".github/scripts/check_opentofu_gha_wif_notifications.py:53">
P1: When an expected resource's IAM role, project, or member changes, `found` remains unchanged and this guard passes, allowing privilege or deployment-scope expansion. Validate the expected resource bodies and critical values, not only their addresses.</violation>
</file>
<file name=".github/scripts/test_check_opentofu_gha_wif_notifications.py">
<violation number="1" location=".github/scripts/test_check_opentofu_gha_wif_notifications.py:15">
P2: This test only asserts the checker exits 0 on the current repo slice, so it cannot catch the checker's security guards being weakened or removed. If the FORBIDDEN list (roles/owner, credentials_json, based-hardware), the EXPECTED_RESOURCES set, or the main-ref pin check is deleted, this test still passes. It also duplicates the opentofu-gha-wif-notifications check in checks-manifest.yaml, which already runs the same checker on the same triggers. Follow the test_check_opentofu_foundation.py pattern: import the checker and add negative fixtures that assert each guard rejects a violating slice, so a real regression fails the test.</violation>
</file>
<file name="infrastructure/opentofu/slices/gha-wif-notifications/main.tf">
<violation number="1" location="infrastructure/opentofu/slices/gha-wif-notifications/main.tf:46">
P1: A run dispatched from `main` can still check out an arbitrary `branch` and execute its code with this WIF identity. Validate the requested revision using trusted main-branch code before requesting credentials, or remove the arbitrary branch input; `workflow_ref` does not attest the checkout contents.</violation>
</file>
<file name="infrastructure/opentofu/slices/gha-wif-notifications/variables.tf">
<violation number="1" location="infrastructure/opentofu/slices/gha-wif-notifications/variables.tf:12">
P3: `project_number` is declared, validated, and pinned but never referenced by main.tf or the check script, so it is an unused variable. It also duplicates the 1031333818730 literal that runtime_service_account_email hardcodes. Either remove it or wire it into the runtime SA email construction so the project number has one source of truth.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| errors.append(f"tf files must be {sorted(EXPECTED_TF)}, found {sorted(tf_names)}") | ||
| text = MAIN.read_text(encoding="utf-8") + "\n" + VARS.read_text(encoding="utf-8") | ||
| found = {f"{m.group('type')}.{m.group('name')}" for m in RESOURCE.finditer(text)} | ||
| if found != EXPECTED_RESOURCES: |
There was a problem hiding this comment.
P1: When an expected resource's IAM role, project, or member changes, found remains unchanged and this guard passes, allowing privilege or deployment-scope expansion. Validate the expected resource bodies and critical values, not only their addresses.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At .github/scripts/check_opentofu_gha_wif_notifications.py, line 53:
<comment>When an expected resource's IAM role, project, or member changes, `found` remains unchanged and this guard passes, allowing privilege or deployment-scope expansion. Validate the expected resource bodies and critical values, not only their addresses.</comment>
<file context>
@@ -0,0 +1,83 @@
+ errors.append(f"tf files must be {sorted(EXPECTED_TF)}, found {sorted(tf_names)}")
+ text = MAIN.read_text(encoding="utf-8") + "\n" + VARS.read_text(encoding="utf-8")
+ found = {f"{m.group('type')}.{m.group('name')}" for m in RESOURCE.finditer(text)}
+ if found != EXPECTED_RESOURCES:
+ errors.append(f"resources must be {sorted(EXPECTED_RESOURCES)}, found {sorted(found)}")
+ if DATA.search(text):
</file context>
|
|
||
| def main() -> int: | ||
| errors: list[str] = [] | ||
| tf_names = {p.name for p in SLICE.glob("*.tf")} |
There was a problem hiding this comment.
P1: When a *.tf.json file is added to the slice, this check ignores it and still reports OK, allowing OpenTofu to apply unreviewed resources. Include .tf.json files in the exact-file scan and add a negative fixture.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At .github/scripts/check_opentofu_gha_wif_notifications.py, line 48:
<comment>When a `*.tf.json` file is added to the slice, this check ignores it and still reports OK, allowing OpenTofu to apply unreviewed resources. Include `.tf.json` files in the exact-file scan and add a negative fixture.</comment>
<file context>
@@ -0,0 +1,83 @@
+
+def main() -> int:
+ errors: list[str] = []
+ tf_names = {p.name for p in SLICE.glob("*.tf")}
+ if tf_names != EXPECTED_TF:
+ errors.append(f"tf files must be {sorted(EXPECTED_TF)}, found {sorted(tf_names)}")
</file context>
| tf_names = {p.name for p in SLICE.glob("*.tf")} | |
| tf_names = { | |
| p.name | |
| for p in SLICE.iterdir() | |
| if p.is_file() and p.name.endswith((".tf", ".tf.json")) | |
| } |
| "attribute.environment" = "assertion.environment" | ||
| } | ||
|
|
||
| attribute_condition = "assertion.repository_id == '${var.github_repository_id}' && assertion.repository_owner_id == '${var.github_repository_owner_id}' && assertion.ref == 'refs/heads/main' && assertion.workflow_ref == '${var.github_workflow_ref}' && assertion.environment == 'development'" |
There was a problem hiding this comment.
P1: A run dispatched from main can still check out an arbitrary branch and execute its code with this WIF identity. Validate the requested revision using trusted main-branch code before requesting credentials, or remove the arbitrary branch input; workflow_ref does not attest the checkout contents.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At infrastructure/opentofu/slices/gha-wif-notifications/main.tf, line 46:
<comment>A run dispatched from `main` can still check out an arbitrary `branch` and execute its code with this WIF identity. Validate the requested revision using trusted main-branch code before requesting credentials, or remove the arbitrary branch input; `workflow_ref` does not attest the checkout contents.</comment>
<file context>
@@ -0,0 +1,86 @@
+ "attribute.environment" = "assertion.environment"
+ }
+
+ attribute_condition = "assertion.repository_id == '${var.github_repository_id}' && assertion.repository_owner_id == '${var.github_repository_owner_id}' && assertion.ref == 'refs/heads/main' && assertion.workflow_ref == '${var.github_workflow_ref}' && assertion.environment == 'development'"
+
+ oidc {
</file context>
|
|
||
| class GhaWifNotificationsCheckerTests(unittest.TestCase): | ||
| def test_checker_passes_on_slice(self) -> None: | ||
| result = subprocess.run([sys.executable, str(CHECKER)], cwd=ROOT, capture_output=True, text=True) |
There was a problem hiding this comment.
P2: This test only asserts the checker exits 0 on the current repo slice, so it cannot catch the checker's security guards being weakened or removed. If the FORBIDDEN list (roles/owner, credentials_json, based-hardware), the EXPECTED_RESOURCES set, or the main-ref pin check is deleted, this test still passes. It also duplicates the opentofu-gha-wif-notifications check in checks-manifest.yaml, which already runs the same checker on the same triggers. Follow the test_check_opentofu_foundation.py pattern: import the checker and add negative fixtures that assert each guard rejects a violating slice, so a real regression fails the test.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At .github/scripts/test_check_opentofu_gha_wif_notifications.py, line 15:
<comment>This test only asserts the checker exits 0 on the current repo slice, so it cannot catch the checker's security guards being weakened or removed. If the FORBIDDEN list (roles/owner, credentials_json, based-hardware), the EXPECTED_RESOURCES set, or the main-ref pin check is deleted, this test still passes. It also duplicates the opentofu-gha-wif-notifications check in checks-manifest.yaml, which already runs the same checker on the same triggers. Follow the test_check_opentofu_foundation.py pattern: import the checker and add negative fixtures that assert each guard rejects a violating slice, so a real regression fails the test.</comment>
<file context>
@@ -0,0 +1,21 @@
+
+class GhaWifNotificationsCheckerTests(unittest.TestCase):
+ def test_checker_passes_on_slice(self) -> None:
+ result = subprocess.run([sys.executable, str(CHECKER)], cwd=ROOT, capture_output=True, text=True)
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertIn("OK", result.stdout)
</file context>
| } | ||
| } | ||
|
|
||
| variable "project_number" { |
There was a problem hiding this comment.
P3: project_number is declared, validated, and pinned but never referenced by main.tf or the check script, so it is an unused variable. It also duplicates the 1031333818730 literal that runtime_service_account_email hardcodes. Either remove it or wire it into the runtime SA email construction so the project number has one source of truth.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At infrastructure/opentofu/slices/gha-wif-notifications/variables.tf, line 12:
<comment>`project_number` is declared, validated, and pinned but never referenced by main.tf or the check script, so it is an unused variable. It also duplicates the 1031333818730 literal that runtime_service_account_email hardcodes. Either remove it or wire it into the runtime SA email construction so the project number has one source of truth.</comment>
<file context>
@@ -0,0 +1,82 @@
+ }
+}
+
+variable "project_number" {
+ type = string
+ description = "Immutable based-hardware-dev project number."
</file context>
Product invariants affected
Path glob only: no production-family routing change. Development
gcp_notifications_job.ymlauthenticates via GitHub WIF; prod input keepsGCP_CREDENTIALSuntil a later slice.Summary
Slice 1 of replacing dying GitHub
GCP_CREDENTIALSJSON with WIF.infrastructure/opentofu/slices/gha-wif-notifications(already applied onbased-hardware-dev: poolomi-gha-notif-dev, SAomi-gha-notif-job-dev).Test Plan
python3 .github/scripts/check_opentofu_gha_wif_notifications.pygh workflow run gcp_notifications_job.yml -f environment=development -f branch=1399a48ab3d43e39d12cade24183a150d90603cbfrom main (WIFworkflow_refis@refs/heads/main)