Repository navigation
Description
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
Metadataforconfigmapsin namespacedevops. - One query over the audit log lists each
patchandeditof ConfigMapdevops-cli-configin 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
patchand aneditof ConfigMapdevops-cli-configin the last 7 days, and agetof it. - THEN
uv run devops k8s audit-check --since 7d --audit-log <fixture>prints the two writers with their user and time, and prints noget.
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
requestObjectthat carries adatavalue. - 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
kubectlprocess.
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-checkexits 1 and names--audit-policy-fileand--audit-log-pathas the flags thatdan-petty/homelab#314must 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#314sets--audit-policy-fileand--audit-log-path, a person runsuv run devops k8s audit-checkagainst the cluster. - THEN The command exits 0, prints the dry-run patch event with its user, the verb
patchand the time, and prints noconfig.yamlvalue.
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
Metadatalevel. It records the user, the verb, the object, the response code and the time. It holds no request or response body. TheRequestandRequestResponselevels hold the body, which is the privateconfig.yamldata. (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.yamldata. - 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 nodepod with ahostPathmount. 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 issuedan-petty/homelab#314sets the policy file and the two flags. This repository documents the cluster commands ink8s/README.mdand 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-checkwith--since,--audit-log,--historyand--dry-runto thedevops k8scommand group. The dry run prints each request and starts nokubectlprocess. (best practice) [sources: docs/CLI_REFERENCE.md, k8s/README.md, tests/commands/k8s/test_k8s.py]- Chosen: A
devops k8s audit-checksubcommand. It uses the existing CLI, config and test patterns of thek8sgroup. - Rejected: A standalone script. It adds a second entry point and bypasses the CLI checks.
- Chosen: A
- 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
--sinceoption changes the window. (best practice) [sources: openspec/specs/devops-configmap-change-record/spec.md]- Chosen: Seven days. It matches the history query of feat(k8s): record each live ConfigMap change of the Service #5221 and shows a week of writers.
- Rejected: 24 hours. It hides a writer that ran earlier in the week.
- Rejected: 30 days. It reads more audit lines than the history query needs.
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
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
devops-cli-service commentedon Nov 19, 2026
Both record ConfigMap changes, but #5221 covers the deploy-stack path and the candidate adds audit-log capture for direct kubectl writes.[-]feat(k8s): record direct kubectl writers of the Service ConfigMap from the audit log[/-][+]feat(k8s): Record kubectl writers of the ConfigMap[/+]devops-cli-service commentedon Nov 19, 2026
The job shortened the title of this item. The summary had 73 characters, and the limit is 60. The type and the scope stay.
feat(k8s): record direct kubectl writers of the Service ConfigMap from the audit logfeat(k8s): Record kubectl writers of the ConfigMapdevops-cli-service commentedon Nov 19, 2026
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.
devops-cli-service commentedon Nov 27, 2026
Owner question: See Suspected block and Watched files in the section Proposed design of the body.
Options
Recommendation: Decide the question: only a person can answer it.
Evidence
devops-cli-service commentedon Nov 28, 2026
Owner question: See Suspected block and Watched files in the section Proposed design of the body.
Options
Recommendation: Decide the question: only a person can answer it.
Evidence