Skip to content

feat(k8s): find GitHub settings drift every night with a read-only App #5328

Open

Description

@dan-petty

Update 2026-11-26 (infra move): the root stacks go to tf/github/ of dan-petty/homelab (ADR 0032), and tf/ is not in this repository. Repository settings belong to devops repos onboard (ADR 0035), and CronJob repos-drift already checks them each night. OpenTofu keeps only the organization checks and the transfer check. Check this design again before a build; the environment values and rule files that it cites are in homelab.


Problem or Motivation

A UI change or a lost setting stays hidden until someone runs a plan.

Order 13 of the plan in #5311. The owner approved the plan on 2026-11-13.

Proposed Solution & Architectural Design

Add the CronWorkflow github-settings-drift. For each stack it runs 'devops tf drift -lock=false' and 'devops tf plan -detailed-exitcode -lock=false', with the reader App credentials from a Secret that the owner creates. Timeouts nest: tofu < step < activeDeadlineSeconds. A failed Workflow raises the existing alert.

Target Subsystem

Kubernetes & Minikube Automation

Existing Tool Considered

A GitHub App with read permissions and no webhook, an Argo Workflows CronWorkflow, and the existing failed-Workflow alert through Alertmanager to Mattermost.

Cost: Build: about 800k tokens, 1 day. Keep: about 50k tokens a month. Fix: about 200k tokens for each break. Owner: about 30 min.

Acceptance Criteria

  • A UI change that the owner makes on the probe repo fails the next run.
  • Then 7 nights pass with exit 0, or with an explanation for each drift.

Dependencies

#5319, dan-petty/homelab#358, #5325 and dan-petty/homelab#360; the owner creates devops-settings-reader and its Secret. Part of #5311.

Source: #5311

Proposed design

Problem statement

A UI change or a lost GitHub setting stays hidden until someone runs a plan. This issue adds a nightly Argo Workflows CronWorkflow that runs devops tf drift and devops tf plan --detailed-exitcode for the GitHub stacks with a read-only GitHub App. A plan with changes exits 2 and fails the Workflow. A Prometheus rule routes that failure through the existing Alertmanager receiver to Mattermost. The live probe check waits on the owner-created App and Secret and on seven nights of runs, so it is deferred.

Acceptance criteria

Requirement: Nightly CronWorkflow

The devops kustomize base SHALL declare CronWorkflow github-settings-drift with a nightly schedule, concurrencyPolicy Forbid, an activeDeadlineSeconds, a ttlStrategy and a podGC.

Scenario: Kubernetes render of the CronWorkflow

  • WHEN A developer runs uv run devops ci --check --only k8s.
  • THEN The check passes for the rendered CronWorkflow github-settings-drift in namespace devops with schedule 17 3 * * *, concurrencyPolicy Forbid, activeDeadlineSeconds 3600, a ttlStrategy and a podGC.

Requirement: Parallel stack steps

The CronWorkflow SHALL run one step for each GitHub stack in a DAG that starts the stack steps in parallel.

Scenario: Stack step render

  • WHEN A developer runs uv run devops ci --check --only k8s.
  • THEN The check passes for the rendered DAG that holds one parallel step for each GitHub stack, including tf/github/dan-petty and tf/github/retric-ai.

Requirement: Drift and plan commands

Each stack step SHALL run devops tf drift <stack> --no-lock and devops tf plan <stack> --detailed-exitcode --no-lock.

Scenario: Workflow command render

  • WHEN A developer runs uv run devops ci --check --only k8s.
  • THEN The check passes for the rendered CronWorkflow that runs both commands with the stack directory for each GitHub stack.

Requirement: Detailed exit code and no-lock options

devops tf plan MUST accept --detailed-exitcode and --no-lock, devops tf drift MUST accept --no-lock, and devops tf plan --detailed-exitcode MUST exit 2 when the plan has changes.

Scenario: Command options and exit code

  • WHEN A developer runs uv run devops ci test tests/commands/test_tf.py tests/commands/test_tf_dry_run.py tests/tf/test_tf_analysis.py.
  • THEN The tests pass for build_tf_plan_cmd with -detailed-exitcode -lock=false, for devops tf plan --detailed-exitcode that exits 2 without a traceback, and for devops tf drift --no-lock that passes -lock=false.

Requirement: Read-only App credentials

The CronWorkflow MUST mount Secret devops-settings-reader as a volume for the PEM file, set GITHUB_APP_PEM_FILE to that file path, and set GITHUB_APP_ID and GITHUB_APP_INSTALLATION_ID from the Secret; it MUST set no GITHUB_TOKEN or GH_TOKEN.

Scenario: Credential reference render

  • WHEN A developer runs uv run devops ci --check --only k8s.
  • THEN The check passes for the rendered CronWorkflow that mounts only Secret devops-settings-reader for the App values, sets GITHUB_APP_PEM_FILE to the mounted file path, and sets no GITHUB_TOKEN or GH_TOKEN.

Requirement: Nested timeouts

The CronWorkflow MUST set the tofu timeout below the step timeout and the step timeout below activeDeadlineSeconds.

Scenario: Timeout order render

  • WHEN A developer runs uv run devops ci --check --only k8s.
  • THEN The check passes for the rendered CronWorkflow whose timeouts are tofu 1800s below the step 2700s below activeDeadlineSeconds 3600s.

Requirement: Failed-run alert

A Prometheus rule MUST fire when a Workflow of CronWorkflow github-settings-drift fails, and it MUST route through the existing Alertmanager receiver to Mattermost.

Scenario: Alert rule render

  • WHEN A developer runs uv run devops ci --check --only k8s.
  • THEN The check passes for the rendered rule group whose alert selects the Argo Workflows controller's failed-Workflow series for github-settings-drift and carries severity warning.

Requirement: State and network access

The CronWorkflow ServiceAccount MUST read the tofu state Secret in namespace tofu-state, and its pods MUST reach GitHub over HTTPS.

Scenario: Role and NetworkPolicy render

  • WHEN A developer runs uv run devops ci --check --only k8s.
  • THEN The check passes for the rendered Role and RoleBinding that grant get on the tofu state Secret and the egress rule that admits TCP 443 from the github-settings-drift pods.

Existing Tool Considered

No alternatives check has run. OpenTofu covers the plan with -detailed-exitcode and -lock=false, but it has no scheduler and no GitHub App credential injection. Argo Workflows covers the nightly CronWorkflow and the failed-Workflow status, but it runs no OpenTofu plan. The integrations/github provider covers a read-only App's app_auth, but the project's devops tf plan and devops tf drift pass neither -detailed-exitcode nor -lock=false. The change adds two pass-through options. Cost: about 40k tokens to build, 5k a month to keep, 20k for each break, and about 2 hours. It builds no planner and no scheduler.

Key questions

  • Which scheduler runs the nightly drift check?: Use an Argo Workflows CronWorkflow named github-settings-drift, with schedule 17 3 * * * in UTC and concurrencyPolicy Forbid. (best practice) [sources: docs/adr/0008-argo-workflows-run-the-roadmap-jobs-after-a-measured-go.md, docs/adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md, k8s/devops/cronworkflow-rag-ingest.yaml, docs/guidelines/kubernetes.md]
    • Chosen: Argo Workflows CronWorkflow. ADR 0008 and ADR 0021 choose Argo Workflows. The repository already has a CronWorkflow, and the controller exposes the Workflow status that the alert reads.
    • Rejected: Kubernetes CronJob. It would need a second failure path and would not use the Argo Workflows controller's Workflow status.
    • Rejected: GitHub Actions schedule. It runs outside the cluster and cannot mount the cluster Secret that holds the App credentials.
  • Which namespace runs the CronWorkflow, and where does its Secret live?: Put the CronWorkflow and Secret devops-settings-reader in namespace devops, after feat(k8s): let Argo Workflows run roadmap pods in devops #4566 makes the controller watch devops. (best practice) [sources: k8s/argo-workflows/values.yaml, k8s/README.md, docs/adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md]
    • Chosen: devops after feat(k8s): let Argo Workflows run roadmap pods in devops #4566. The Secret and the devops-cli config already live in devops. The existing CronWorkflow is there. ADR 0021 makes the controller watch devops from the engine step on.
    • Rejected: argo-workflows. Its perimeter admits no public HTTPS. Its executor ServiceAccount can only patch workflowtaskresults. The k8s gate forbids Secret references in that directory.
    • Rejected: Cluster mode with a ClusterRole. It expands the controller's RBAC and contradicts the one-namespace decision of ADR 0008.
  • Which commands detect GitHub settings drift?: Run devops tf drift <stack> --no-lock and devops tf plan <stack> --detailed-exitcode --no-lock for each GitHub stack. Add the two pass-through options to the CLI so it maps them to OpenTofu's -lock=false and -detailed-exitcode. (best practice) [sources: src/devops_cli/commands/tf.py, src/devops_cli/tf/tf_plans.py, src/devops_cli/tf/analysis.py, tests/commands/test_tf.py]
    • Chosen: Extend the devops tf commands. The body names devops tf. The CLI already builds the OpenTofu command. Only the two options and the exit code 2 handling are missing.
    • Rejected: Run tofu directly in the workflow. It duplicates the CLI interface and skips the project's config and dry-run handling.
    • Rejected: Plan only. It loses the drift report and the remote-change detail.
  • How do the timeouts nest?: Set the tofu timeout to 1800s, the step timeout to 2700s and activeDeadlineSeconds to 3600s. Run the two stack steps in parallel so both fit. (best practice) [sources: docs/guidelines/kubernetes.md, docs/adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md, k8s/devops/workflowtemplate-rag-ingest.yaml]
    • Chosen: Nested timeouts with parallel stack steps. The Kubernetes guideline requires a bounded Workflow. Parallel steps keep two 2700s steps below 3600s.
    • Rejected: One timeout. It cannot tell which layer failed and gives no bounded step.
    • Rejected: Sequential stack steps. Two 2700s steps exceed activeDeadlineSeconds 3600s.
  • How does a failed run raise an alert?: Add a Prometheus rule on the Argo Workflows controller's failed-Workflow series for github-settings-drift, with severity warning. Let the existing Alertmanager receiver route it to Mattermost. (best practice) [sources: k8s/argo-workflows/values.yaml, k8s/devops/monitoring/prometheus-rules-values.yaml, k8s/monitoring/prometheus-values.yaml, k8s/README.md]
    • Chosen: New Prometheus rule. The controller already exposes metrics. The Alertmanager receiver already routes warning and critical alerts to Mattermost. The body gives no rule name or expression to reuse.
    • Rejected: Existing failed-Workflow alert. The body names the existing Alertmanager route, not a Workflow rule text.
    • Rejected: Workflow onExit webhook. It adds glue that duplicates the alert route.
  • How does the CronWorkflow authenticate to GitHub?: Mount Secret devops-settings-reader as a volume for the PEM file. Set GITHUB_APP_PEM_FILE to that file path. Set GITHUB_APP_ID and GITHUB_APP_INSTALLATION_ID from the Secret. Set no GITHUB_TOKEN or GH_TOKEN. (best practice) [sources: docs/adr/0026-github-settings-are-opentofu-code-the-owner-applies.md, k8s/devops/workflowtemplate-rag-ingest.yaml]
    • Chosen: Read-only GitHub App with the PEM file on a volume. ADR 0026 records the App as read-only, with no webhook, installed on both accounts. The provider reads the App credentials. The PEM file needs a file path.
    • Rejected: Personal access token. It carries broader scopes and is not tied to an App installation.
    • Rejected: GitHub Actions token. It is not available to an in-cluster Workflow.
  • How does the drift pod read the tofu state and reach GitHub?: Give the CronWorkflow its own ServiceAccount with a Role and RoleBinding in tofu-state for get on the state Secret. Add an egress rule to the devops perimeter for TCP 443 from the github-settings-drift pods. (best practice) [sources: docs/adr/0026-github-settings-are-opentofu-code-the-owner-applies.md, k8s/devops/serviceaccount.yaml, k8s/devops/networkpolicy.yaml]
    • Chosen: Dedicated ServiceAccount and egress rule. The devops-cli ServiceAccount has automountServiceAccountToken false and no Role. The devops perimeter already admits public HTTPS but not the Kubernetes API.
    • Rejected: Reuse the devops-cli ServiceAccount. It holds no token and no permission on the tofu-state Secret.
    • Rejected: Local state file. ADR 0026 requires the Kubernetes backend and forbids local state.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#5319, dan-petty/homelab#358, #5325, dan-petty/homelab#360, #4566

Watched files

A commit on the default branch that changes one of these files starts the next refine round.

  • k8s/argo-workflows/values.yaml

Alternatives check of 2026-11-28: partly.
Tool: opentofu/opentofu (https://github.com/opentofu/opentofu), MPL-2.0, last activity 2026-11-27, maintained.
Reason: Searches found no tool that runs the whole nightly GitHub-settings drift check: OpenTofu, already in use, supplies plan and drift detection only, scheduling and alerts need Argo Workflows, and ADR 0035 gives repository settings to repos-drift.

Covers:

  • Plan with detailed exit code returns 2 on any drift
  • Reads the Kubernetes backend state with locking disabled
  • Applies the GitHub provider to the remaining organization checks
  • No new planner or state engine is needed

Lacks:

  • No scheduler, so a CronWorkflow or CronJob must call it
  • No GitHub App credential injection, the pod mounts the PEM file
  • No alert path, a Prometheus rule and receiver stay separate
  • A read-only token reads merge settings as false, reporting drift nightly
  • Repository settings now belong to repos-drift, not to the roots

Activity

  1. added
    source/agent
    on Nov 13, 2026
  2. added
    type/feature
    scope/k8s
    status/new
    value/medium
    effort/medium
    on Nov 13, 2026
  3. dan-petty commented on Nov 13, 2026

    @dan-petty
    OwnerAuthor
    • Related: feat(infra): run drift in the cluster and plan infra PRs #5129, which asks for a different change. Both use Argo CronWorkflows in the cluster for nightly drift detection, but the candidate checks GitHub settings via a read-only App while dan-petty/devops-cli#5129 checks infra repos via devops infra drift.
  4. added
    priority/p2-medium
    on Nov 13, 2026
  5. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor

    Refine cannot set this item to Ready at 551a0c3 while the items below stay open. The next refine round looks at the item again when they close, or when a person replies in a comment or edits the body.

    The next refine round also looks at the item again when a commit on the default branch changes one of these files: k8s/argo-workflows/values.yaml.

  6. devops-cli-service commented on Nov 21, 2026

    @devops-cli-service
    Contributor

    Next step: the open items close, or a person replies in a comment or edits the body. See Dependencies and Watched files in the section Proposed design of the body.

  7. devops-cli-service commented on Nov 23, 2026

    @devops-cli-service
    Contributor

    The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.

    Searches (10)

    Tools considered:

    Searches run:

    • OpenTofu Terraform scheduled drift detection open source tool, results: 5
    • GitHub organization settings drift detection open source tool, results: 5
    • driftctl terraform drift detection github, results: 5
    • atlantis terraform drift detection schedule, results: 5
    • driftctl, results: 5
    • terramate drift detection, results: 5
    • digger terraform drift detection open source, results: 5
    • github safe-settings dry run detect settings drift, results: 5
    • digger drift detection docs terraform, results: 5
    • terramate cloud drift detection docs, results: 5

    Sources:

  8. dan-petty commented on Nov 27, 2026

    @dan-petty
    OwnerAuthor

    Evidence from dan-petty/homelab#379 (2026-11-27) for the next design check of this item:

    • dan-petty/homelab#379 declares ServiceAccount github-settings-drift in namespace tofu-state as the drift identity, and its acceptance criteria test system:serviceaccount:tofu-state:github-settings-drift. The design of this item runs the CronWorkflow in namespace devops with its own ServiceAccount. A Pod runs only as a ServiceAccount of its own namespace, so the two subjects do not match. One of the two items must name the subject of the other.
    • OpenTofu v1.13.9, internal/backend/remote-state/kubernetes/backend_state.go: when a workspace has no state, StateMgr creates a Lease and writes an empty state Secret, also with -lock=false. A read-only Role (get and list on secrets) works only after a person's first tofu init or apply wrote the state Secret.
    • CronJob repos-drift (ADR 0035) already checks the repository settings each night and reads no OpenTofu state.
  9. dan-petty commented on Nov 28, 2026

    @dan-petty
    OwnerAuthor

    The plan of #7497 (pull request #7521, design D7) found a fault in the token of this design.

  10. dan-petty commented on Nov 28, 2026

    @dan-petty
    OwnerAuthor

    Update from the apply flow of ADR 0041 (#7497, the follow-up plan pull request names this item as the drift job):

    • The roots moved. tf/github/dan-petty (the public repositories) is in dan-petty/infra (feat(tf): add the root tf/github/dan-petty and its apply workflow infra#241). tf/github/dan-petty-private (the private repositories) stays in dan-petty/homelab (dan-petty/homelab#643). Both keep the state in namespace tofu-state.
    • This item stays the drift job, in the cluster. It checks out the public root with no token and the private root with the token of the App, reads the state with the read-only identity of dan-petty/homelab#523, and runs tofu plan -detailed-exitcode -lock=false on each root with the token of CONST_GITHUB_APP_DRIFT_TOKEN_PERMISSIONS (my comment above).
    • A scheduled job in infra would need a key that can read the merge settings (Contents write) outside the environment github-settings, where an agent's merge could use it. So the drift job does not move to infra.
    • No job of this item applies. The apply is the job of feat(tf): add the root tf/github/dan-petty and its apply workflow infra#241, which waits for the approval of the owner.
  11. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    Contributor

    The result in the alternatives block of the issue body changed. Before this check: in-use, tool https://github.com/opentofu/opentofu. A person decides what the new result means for the item.

    Searches (6)

    Tools considered:

    Searches run:

    • GitHub repository settings drift detection nightly OpenTofu, results: 5
    • open source scheduled terraform drift detection tool, results: 5
    • Atlantis Terraform pull request automation drift detection, results: 5
    • terrateam drift detection terraform open source, results: 5
    • digger terraform drift detection github, results: 5
    • terraform-provider-github app_auth read-only app permissions merge settings, results: 5

    Sources:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p2-mediumscope/k8ssource/agentstatus/newtype/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions