Skip to content

feat(k8s): Record kubectl writers of the ConfigMap #6428

Open

Description

@devops-cli-service

Update 2026-11-26 (infra move): the k3s host settings are in dan-petty/homelab.

  • The audit policy file and the two kube-apiserver flags are a follow-up issue there (ansible/).
  • This issue keeps devops k8s audit-check, its tests and the live query.
  • The design writes dan-pety/homelab; the name is dan-petty/homelab.

Follow-up: dan-petty/homelab#314.


Split from #5221.

The live ConfigMap devops-cli-config can change with no deploy-stack run: a kubectl edit or a kubectl patch writes it directly, and k8s/README.md tells a person not to do it because no record stays. The annotations, the history object and the log record of #5221 do not see such a change. The Kubernetes audit log is the standard record of each writer, and k3s logs no audit event without a policy file and a log path. Both are kube-apiserver flags of the k3s server in ansible/ of dan-petty/homelab (follow-up issue), so this part is a host setting and an owner step outside this repository. The Request level holds the request body, which is the private config.yaml data, so the policy MUST use the Metadata level. This part is deferred so that the rest of #5221 records the deploy-stack path in one pull request.

Acceptance criteria:

  • A live check on a node shows the audit log file and the two server flags in the k3s configuration, with level Metadata for configmaps in namespace devops.
  • One query over the audit log lists each patch and edit of ConfigMap devops-cli-config in the last 7 days with its user name and its time.
  • A live check over the last 7 days returns no value of the ConfigMap data.
  • A record joins each audit entry to the history key of feat(k8s): record each live ConfigMap change of the Service #5221 by its time when both exist.

Proposed design

Problem statement

ConfigMap devops-cli-config can change with no deploy-stack run. A kubectl edit or kubectl patch writes it directly, and no record stays. The annotations, the history object and the log record of #5221 do not see such a write. The Kubernetes audit log records each writer, but the k3s server needs a policy file and two kube-apiserver flags from dan-petty/homelab. This change adds devops k8s audit-check: it lists the writers, fails on ConfigMap data, and joins each entry to the history key of #5221. The live proof waits for dan-petty/homelab#314.

Acceptance criteria

Requirement: List the ConfigMap writers

devops k8s audit-check SHALL list each patch and each edit of ConfigMap devops-cli-config in the requested window with its user name and its time.

Scenario: A patch and an edit in the window

  • WHEN The audit log fixture holds a patch and an edit of ConfigMap devops-cli-config in the last 7 days, and a get of it.
  • THEN uv run devops k8s audit-check --since 7d --audit-log <fixture> prints the two writers with their user and time, and prints no get.

Requirement: Fail on ConfigMap data

devops k8s audit-check MUST exit 1 when an event for ConfigMap devops-cli-config in the window holds a request or a response body.

Scenario: A Request-level event holds the ConfigMap data

  • WHEN The audit log fixture holds an event for the ConfigMap with a requestObject that carries a data value.
  • THEN uv run devops k8s audit-check --since 7d --audit-log <fixture> exits 1, names the event time and the key, and prints no value.

Requirement: Join an audit entry to the history key

devops k8s audit-check SHALL show the history key of #5221 on an audit row when the audit time and the history time match at second precision.

Scenario: An audit entry and a history record share a time

  • WHEN The audit log fixture holds a patch at time T, the history fixture holds a record with key K at time T, and another patch at a time with no history record.
  • THEN uv run devops k8s audit-check --since 7d --audit-log <fixture> --history <fixture> prints K on the row of the patch at T and no key on the other row.

Requirement: Dry run prints the requests

devops k8s audit-check SHALL make no request under --dry-run and SHALL print each request that a run makes.

Scenario: A dry run of the audit check

  • WHEN A person runs uv run devops k8s audit-check --dry-run.
  • THEN The command exits 0, prints the server-side dry-run patch and the audit log read, and starts no kubectl process.

Requirement: Unreadable audit log fails

devops k8s audit-check MUST exit 1 when the audit log cannot be read.

Scenario: The node proxy answers 404 for the audit log path

  • WHEN The node proxy answers 404 for the audit log path.
  • THEN uv run devops k8s audit-check exits 1 and names --audit-policy-file and --audit-log-path as the flags that dan-petty/homelab#314 must set.

Requirement: Pending a person after the merge

The live check MUST show the audit event of a server-side dry-run patch of the ConfigMap, with its user, its verb and its time, and MUST show no ConfigMap data.

Scenario: The k3s server holds the two flags and the Metadata policy

  • WHEN After dan-petty/homelab#314 sets --audit-policy-file and --audit-log-path, a person runs uv run devops k8s audit-check against the cluster.
  • THEN The command exits 0, prints the dry-run patch event with its user, the verb patch and the time, and prints no config.yaml value.

Existing Tool Considered

No alternatives check has run on this issue. jq filters the JSON lines of an audit log, and kubectl sends the server-side dry-run patch and reads the kubelet node proxy. Neither checks the k3s audit settings, joins an audit entry to the history key of #5221, or fails on a ConfigMap body. So the change builds devops k8s audit-check: about 150 lines with its test, about 40k tokens to build, keep and fix, and about 2 hours.

Key questions

  • Which audit level records a ConfigMap writer and keeps the ConfigMap data out of the log?: Use the Metadata level. It records the user, the verb, the object, the response code and the time. It holds no request or response body. The Request and RequestResponse levels hold the body, which is the private config.yaml data. (best practice) [sources: k8s/README.md, SECURITY.md, AGENTS.md]
    • Chosen: Metadata. It names the writer, the verb, the object and the time, and it holds no request or response body.
    • Rejected: Request. It holds the request body, which is the private config.yaml data.
    • Rejected: RequestResponse. It holds the request and the response body, so the ConfigMap data goes into the log.
    • Rejected: No rule for ConfigMaps. It writes no event for the ConfigMap, so no record of the writer stays.
  • How does the check read the audit log and prove a writer with no host login and no privileged pod?: The check sends kubectl -n devops patch configmap devops-cli-config --dry-run=server -p '{}'. The API server audits the request and persists nothing. The check reads the new lines through the kubelet node proxy at /api/v1/nodes/<node>/proxy/logs/<path>. (best practice) [sources: k8s/README.md, docs/guidelines/kubernetes.md]
    • Chosen: Server-side dry-run patch and the node-proxy log read. The API server audits the request, changes nothing, and the node proxy reads the log with no host login and no privileged pod.
    • Rejected: A kubectl debug node pod with a hostPath mount. It needs a privileged pod and reads the host, which the check does not need.
    • Rejected: A read of the k3s config file over SSH. It needs a host login, and the check runs from a workstation.
    • Rejected: A Loki query of the audit log. The audit log is not shipped to Loki today, so it would add a manifest change and wait on the host path.
  • Which repository holds the audit policy file and the two kube-apiserver flags of the k3s server?: dan-petty/homelab holds them in ansible/. Follow-up issue dan-petty/homelab#314 sets the policy file and the two flags. This repository documents the cluster commands in k8s/README.md and writes neither. [sources: k8s/README.md, CONTEXT.md]
  • How does an audit entry join the history key of feat(k8s): record each live ConfigMap change of the Service #5221?: Join on the audit event time and the history record time, both in UTC at second precision. Show the key on the audit row when the two times match, and no key when no history record matches. Do not use a nearest-time match. (best practice) [sources: openspec/specs/devops-configmap-change-record/spec.md, src/devops_cli/k8s/configmap.py]
    • Chosen: Exact time match at second precision. It gives one deterministic key for each audit row and no false join.
    • Rejected: Nearest-time match. It can join an audit entry to an unrelated history record.
    • Rejected: No join. It does not meet the requirement to join each audit entry to the history key when both exist.
  • Which command surface does the check use?: Add devops k8s audit-check with --since, --audit-log, --history and --dry-run to the devops k8s command group. The dry run prints each request and starts no kubectl process. (best practice) [sources: docs/CLI_REFERENCE.md, k8s/README.md, tests/commands/k8s/test_k8s.py]
    • Chosen: A devops k8s audit-check subcommand. It uses the existing CLI, config and test patterns of the k8s group.
    • Rejected: A standalone script. It adds a second entry point and bypasses the CLI checks.
  • Which window does the audit query read by default?: Seven days, as the history query of feat(k8s): record each live ConfigMap change of the Service #5221 does. The --since option changes the window. (best practice) [sources: openspec/specs/devops-configmap-change-record/spec.md]

Fit

Fits in one pull request.

Suspected block

dan-petty/homelab#314 sets the k3s audit policy file and the two kube-apiserver flags, so the live check of the audit record waits for that issue.

Dependencies

#5221

Watched files

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

  • src/devops_cli/k8s/configmap.py

Activity

  1. added
    type/feature
    scope/k8s
    source/agent
    status/new
    value/medium
    effort/medium
    on Nov 19, 2026
  2. devops-cli-service commented on Nov 19, 2026

    @devops-cli-service
    ContributorAuthor
  3. changed the title [-]feat(k8s): record direct kubectl writers of the Service ConfigMap from the audit log[/-] [+]feat(k8s): Record kubectl writers of the ConfigMap[/+] on Nov 19, 2026
  4. devops-cli-service commented on Nov 19, 2026

    @devops-cli-service
    ContributorAuthor

    The job shortened the title of this item. The summary had 73 characters, and the limit is 60. The type and the scope stay.

    • Before: feat(k8s): record direct kubectl writers of the Service ConfigMap from the audit log
    • After: feat(k8s): Record kubectl writers of the ConfigMap
    • Source of the summary: the background model
  5. devops-cli-service commented on Nov 19, 2026

    @devops-cli-service
    ContributorAuthor

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

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

    @devops-cli-service
    ContributorAuthor

    Owner question: See Suspected block and Watched files in the section Proposed design of the body.

    Options

    1. Decide the question: The job refines the item with your answer.
    2. Leave it to the job: The job records the best-practice answer and goes on.

    Recommendation: Decide the question: only a person can answer it.

    Evidence

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

    @devops-cli-service
    ContributorAuthor

    Owner question: See Suspected block and Watched files in the section Proposed design of the body.

    Options

    1. Decide the question: The job refines the item with your answer.
    2. Leave it to the job: The job records the best-practice answer and goes on.

    Recommendation: Decide the question: only a person can answer it.

    Evidence

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