Skip to content

fix(audit): record template and agent-config imports - #85

Open
antiv wants to merge 1 commit into
mainfrom
claude/issue-82-import-audit
Open

fix(audit): record template and agent-config imports#85
antiv wants to merge 1 commit into
mainfrom
claude/issue-82-import-audit

Conversation

@antiv

@antiv antiv commented Sep 1, 2026

Copy link
Copy Markdown
Owner

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/import with overwrite=true can 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 request so the actor's IP is recorded:

Endpoint Action resource_id
POST /dashboard/api/agents/import agents.import (new)
POST /dashboard/api/templates/import template.import (was dead) template id
POST /dashboard/api/templates/create-from-agents template.create (new) sanitized template id
POST /dashboard/api/templates/sync template.sync (new) template id

details carries 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 if "error" in result check, so a failed operation is not audited as if it succeeded. No plumbing was needed: audit_service was already imported, and username and request were already in scope in all four handlers. audit_service.log never raises and resolves its own database client, so no try/except guard — same shape as the existing delete_template call 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 on test_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. Plus overwrite=true visible in the row's details, and an assertion that ACTION_TEMPLATE_IMPORT is 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

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>
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.

fix: template and agent-config imports are never audited

1 participant