Files
Gitea-Tools/.env.example
T
sysadmin c3c48fb7c2 feat: audit-log Gitea MCP mutating actions with profile metadata (#18)
Add durable, opt-in audit logging for every mutating Gitea MCP action so an
operator can see which execution profile and authenticated Gitea user
performed (or was blocked from / failed) each mutation.

- New gitea_audit.py: pure, no-network module — recursive secret redaction
  (token/password/authorization keys; token/Basic/Bearer value runs),
  build_event (timestamp, action, result, profile, audit label, authenticated
  username, repo, issue/PR, target branch, head SHA, redacted request
  metadata), and an append-only JSON Lines sink.
- mcp_server.py: _audit helper + _audited context manager (simple mutations)
  and an _audit_pr_result decorator (gated review/merge tools, reading their
  own result dict) wired into create_issue, create_pr, edit_pr, close_issue,
  commit_files, delete_branch, create_label, set_issue_labels, mark_issue
  (label/unlabel), gitea_submit_pr_review, and gitea_merge_pr.
- Outcomes recorded as allowed/blocked/failed/succeeded; blocked and failed
  eligibility checks are logged, not just successes.

Off by default: records are written only when GITEA_AUDIT_LOG is set. When it
is unset every audit path short-circuits — no records, no extra API calls — so
existing tool behaviour and API call sequences are unchanged. Auditing never
raises; sink writes are best-effort. Tokens are never written.

Docs: README env table + audit note, .env.example placeholder.
Tests: tests/test_audit.py (19 cases) — redaction, event build, sink writes,
per-tool success/failure/blocked records, secret-free output, off-by-default
no-op, and audit-failure-never-breaks-action.

Closes #18

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-01 22:20:51 -04:00

41 lines
1.8 KiB
Bash

# Gitea MCP runtime profile — EXAMPLE / PLACEHOLDERS ONLY.
#
# Copy to a real, gitignored env file (e.g. .env.reviewer) per runtime profile.
# The same MCP server code is launched as separate MCP entries, each pointed at
# a different env file so each process authenticates as ONE token and carries
# ONE profile name. Do NOT put real tokens in this file.
#
# The token is read only by the auth layer; it is never returned, logged, or
# committed. Profile name and allowed operations are non-secret metadata.
# Base URL of the Gitea instance (informational).
GITEA_BASE_URL=https://gitea.example.invalid
# The API token for THIS runtime profile. Placeholder only — replace in a real,
# gitignored env file. Never commit a real token.
GITEA_TOKEN=replace-with-token
# Human label for the running profile (non-secret metadata).
# Examples: gitea-author, gitea-reviewer, gitea-merger, gitea-issue-manager.
GITEA_PROFILE_NAME=gitea-reviewer
# Optional, comma-separated operation categories this profile is intended for
# (descriptive only in this issue; enforcement is a later roadmap item).
GITEA_ALLOWED_OPERATIONS=read,review,approve
# Optional, comma-separated operation categories this profile must NOT perform
# (descriptive metadata; surfaced by gitea_get_profile).
GITEA_FORBIDDEN_OPERATIONS=merge,branch.push
# Optional short label attached to this runtime for audit purposes.
GITEA_AUDIT_LABEL=reviewer-runtime
# Optional path to an audit log file (#18). When set, each mutating action
# appends one redacted JSON record (profile + authenticated user + outcome).
# Leave unset to disable auditing entirely (no records, no extra API calls).
GITEA_AUDIT_LOG=/path/to/gitea-mcp-audit.log
# Optional NAME of the token's source (e.g. an env var name). This is a name
# only — never the token value. Surfaced by gitea_get_profile.
GITEA_TOKEN_SOURCE=GITEA_TOKEN