Skip to content

feat(security): credential lifecycle — validation, rotation, audit, revocation (Fixes #62) - #190

Merged
OkiriGabriel merged 1 commit into
mainfrom
feat/credential-lifecycle-62
Nov 25, 2026
Merged

OkiriGabriel merged 1 commit into
mainfrom
feat/credential-lifecycle-62

Conversation

@OkiriGabriel

Copy link
Copy Markdown
Collaborator

Fixes #62.

What the issue asked for, and what's here

# Ask Done
1 Format validation for high-risk keys validate_credentials: control chars and line breaks, an 8 KB cap, secret length and whitespace, http(s) URLs, hooks.slack.com, sk-ant- / sk- / xoxb-, GitHub token formats (ghp_ … github_pat_, 40-hex classic), AWS AKIA/ASIA key IDs, SMTP port, AUTO_APPLY, LLM_PROVIDER. Returns 422 {"errors": {key: reason}} and never echoes a value. CREDENTIAL_VALIDATION=strict (default), warn or off, in case a vendor changes its format. _SENSITIVE_SUFFIXES is now used.
2 Structured audit events Every replace, update or delete writes {action, org_id, actor, timestamp, added, changed, removed} to {org}/credential_audit/<y>/<m>/. actor is the role plus the first 12 hex characters of the token's SHA-256 (or mcp), never the token. Changes are detected by comparing hashes, so values never appear in events or logs. New GET /orgs/{org}/config/audit (admin).
3 Revocation over HTTP and MCP DELETE /orgs/{org}/config (all keys) or ?keys=A,B (admin). MCP revoke_org_credentials. The stored blob is overwritten before it's deleted.
4 Rotation metadata updated_at / updated_by per key. GET …/config/status now adds details (source, sensitive, age, updater) and stale (secrets older than CREDENTIAL_MAX_AGE_DAYS, default 90).
5 Rotation runbook docs/CREDENTIAL_ROTATION.md (in the mkdocs nav) covers the endpoints, validation rules, audit format, the step-by-step rotation, the leak response, and a versioned-bucket caveat.

Also:

  • PATCH /orgs/{org}/config merges: send one key to rotate it, and null removes a key. Without it, PUT replaces the org's whole set, so rotating one key meant resending every other key too (the same gotcha noted in fix(security): per-org webhook secrets and tenant binding (Fixes #61) #189). MCP configure_org_credentials gets merge: true for the same behaviour.
  • PUT now reports ignored_keys (unknown names) instead of dropping them silently.

Tests

  • tests/test_credential_lifecycle.py, 41 tests: the validation matrix (reject and accept), no values in errors, warn mode, merge/remove, ignored keys, per-key metadata, unchanged values keep their timestamp, stale detection, audit events without values, selective and full deletion with overwrite, and API 422/PATCH/DELETE/audit.
  • RBAC: a viewer and another org's admin can't change, revoke or read the history.
  • MCP: validation, merge and revoke.
  • tests/conftest.py turns validation off for the rest of the suite, which stores placeholder keys such as "gh-token". The new tests turn strict mode back on.
  • Full suite: 1346 passed, 4 skipped. Flake8 (CI selection) and bandit are clean.

🤖 Generated with Claude Code

… audit trail, revocation (#62)

- Validate org credentials at save time (strict by default, CREDENTIAL_VALIDATION
  =warn|off): no control chars/line breaks, size cap, secret length, URL shape,
  vendor prefixes (sk-ant-, sk-, xoxb-, hooks.slack.com, GitHub token formats),
  AWS key ID, port, bool, LLM provider. 422 lists keys and reasons, never values.
  _SENSITIVE_SUFFIXES is now used (is_sensitive).
- PATCH /orgs/{org}/config merges (null removes) so a key can be rotated
  without resending the rest; PUT still replaces and now reports ignored keys.
- DELETE /orgs/{org}/config (all or ?keys=) revokes; the blob is overwritten
  before deletion. MCP: revoke_org_credentials, configure_org_credentials(merge).
- Per-key updated_at/updated_by metadata; status shows source, age_days and
  stale secrets (CREDENTIAL_MAX_AGE_DAYS, default 90).
- Audit events (actor = role + token fingerprint, keys added/changed/removed,
  never values) under {org}/credential_audit/; GET /orgs/{org}/config/audit.
- docs/CREDENTIAL_ROTATION.md runbook (rotation and leak response).

Fixes #62

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@OkiriGabriel
OkiriGabriel merged commit ac71dda into main Nov 25, 2026
16 checks passed
@OkiriGabriel
OkiriGabriel deleted the feat/credential-lifecycle-62 branch November 26, 2026 10:12
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.

[SECURITY] Credential lifecycle: validation, rotation audit trail, and secure deletion

1 participant