fix(audit): record template and agent-config imports - #85
Open
antiv wants to merge 1 commit into
Open
Conversation
Deleting a template wrote an audit row; creating agents in bulk did not. None of the four import/sync write endpoints called audit_service, so the trail was asymmetric — the log showed agents and templates being deleted, but not created or bulk-modified. For a log whose docstring says "EU AI Act compliance", that is the wrong half to be missing: `agents/import` with `overwrite=true` can rewrite every agent in an installation and left no record of who did it. Audit all four endpoints, passing `request` so the actor's IP is recorded: POST /dashboard/api/agents/import agents.import POST /dashboard/api/templates/import template.import POST /dashboard/api/templates/create-from-agents template.create POST /dashboard/api/templates/sync template.sync ACTION_TEMPLATE_IMPORT had been defined since the constant list was written with nothing referencing it — the intent was there, the call never was. It is now used for the template import; agents.import, template.create and template.sync are new. Details carry the blast radius: agent counts, project id, synced version, and for agents/import whether overwrite was set, since that is the difference between adding and destroying. Every call sits after the error check, so a failed operation is not audited as if it succeeded. Closes #82 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #82
Problem
Deleting a template writes an audit row (#73). Creating agents in bulk does not — none of the four import/sync write endpoints called
audit_service.The result was an asymmetric trail: the audit log showed agents and templates being deleted, but not created or bulk-modified. For a log whose module docstring says "Audit logging service for EU AI Act compliance", that is the wrong half to be missing.
agents/importwithoverwrite=truecan rewrite every agent in an installation and left no record of who did it.ACTION_TEMPLATE_IMPORT = "template.import"had been defined since the constant list was written and nothing referenced it — the intent was there, the call never was.Change
All four endpoints now audit, passing
requestso the actor's IP is recorded:POST /dashboard/api/agents/importagents.import(new)POST /dashboard/api/templates/importtemplate.import(was dead)POST /dashboard/api/templates/create-from-agentstemplate.create(new)POST /dashboard/api/templates/synctemplate.sync(new)detailscarries the blast radius — agent counts, project id, synced version — and foragents/importwhetheroverwritewas set, since that is the difference between adding and destroying.Every call sits after the
if "error" in resultcheck, so a failed operation is not audited as if it succeeded. No plumbing was needed:audit_servicewas already imported, andusernameandrequestwere already in scope in all four handlers.audit_service.lognever raises and resolves its own database client, so notry/exceptguard — same shape as the existingdelete_templatecall site.Deliberately out of scope, per the issue: a general "audit every mutating dashboard route" sweep.
Tests
New
shared/test/test_import_audit.py(11 tests), modelled ontest_template_delete_audit.py. Per endpoint: a successful call writes exactly one row with the expected action/resource/actor and details; a failed call writes none. Plusoverwrite=truevisible in the row's details, and an assertion thatACTION_TEMPLATE_IMPORTis now referenced from the call site.Verified the tests fail against the unpatched endpoints (6 of 11 fail). Full suite: 736 tests, all passing.
🤖 Generated with Claude Code