Skip to content

feat(infra): WIF for notifications-job development deploys - #13673

Merged
Git-on-my-level merged 2 commits into
BasedHardware:mainfrom
Git-on-my-level:feat/gha-wif-notifications-dev
Sep 13, 2026
Merged

Git-on-my-level merged 2 commits into
BasedHardware:mainfrom
Git-on-my-level:feat/gha-wif-notifications-dev

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Sep 13, 2026 •

Copy link
Copy Markdown
Member

Product invariants affected

  • INV-DATA-1

Path glob only: no production-family routing change. Development gcp_notifications_job.yml authenticates via GitHub WIF; prod input keeps GCP_CREDENTIALS until a later slice.

Summary

Slice 1 of replacing dying GitHub GCP_CREDENTIALS JSON with WIF.

Test Plan

  • python3 .github/scripts/check_opentofu_gha_wif_notifications.py
  • tofu plan 8 creates; apply 8; refresh no-diff
  • After merge: gh workflow run gcp_notifications_job.yml -f environment=development -f branch=1399a48ab3d43e39d12cade24183a150d90603cb from main (WIF workflow_ref is @refs/heads/main)

Review in cubic

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.

@cubic-dev-ai cubic-dev-ai 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.

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.json files, allowing unreviewed privilege or deployment-scope expansion. Validate critical resource bodies and include .tf.json files in the exact-file scan, with negative fixtures.
  • infrastructure/opentofu/slices/gha-wif-notifications/main.tf can let a run dispatched from main check 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.py will not detect weakened or removed security guards. Add negative tests covering forbidden roles, credentials_json, based-hardware, changed resource bodies, and *.tf.json additions.
  • infrastructure/opentofu/slices/gha-wif-notifications/variables.tf declares and validates an unused project_number that 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:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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")}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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>
Suggested change
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'"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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" {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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>

@Git-on-my-level
Git-on-my-level merged commit 7778149 into BasedHardware:main Sep 13, 2026
38 of 39 checks passed
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