feat(audit): add audit logging with invoker identity tracking#21
Merged
qasim-nylas merged 1 commit intonylas:mainfrom Feb 5, 2026
Merged
Conversation
Add comprehensive audit logging system that tracks CLI command execution with automatic detection of who ran commands and from what source. Features: - Automatic invoker detection (Claude Code, GitHub Copilot, SSH, scripts) - Nylas API request ID tracking for full traceability - Sensitive argument redaction (passwords, tokens, API keys) - JSONL storage with configurable retention and rotation - Rich filtering: by user, source, command, status, date, request ID - Export to JSON/CSV for compliance reporting - Summary statistics with invoker breakdown Detection uses documented environment variables: - Claude Code: CLAUDE_PROJECT_DIR, CLAUDE_CODE_* prefix - GitHub Copilot: COPILOT_MODEL, GH_COPILOT - Manual override: NYLAS_INVOKER_SOURCE Includes 60+ unit tests covering all new code paths.
qasim-nylas
approved these changes
Feb 5, 2026
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.
Summary
Add a comprehensive audit logging system that tracks CLI command execution with automatic detection of who ran commands and from what source (terminal, AI agents, CI/CD, SSH, etc.).
Key Features
Invoker Identity Detection - Automatically detects:
claude-code- Anthropic's Claude Code (viaCLAUDE_PROJECT_DIR,CLAUDE_CODE_*)github-copilot- GitHub Copilot CLI (viaCOPILOT_MODEL,GH_COPILOT)ssh- Remote SSH sessions (viaSSH_CLIENT)script- Non-interactive automation (TTY detection)terminal- Interactive terminal (default)NYLAS_INVOKER_SOURCEenv varNylas API Traceability - Logs
request_idfrom API responses for full request tracingSensitive Data Protection - Automatically redacts:
Rich Filtering - Query logs by user, source, command, status, date range, or request ID
Export - JSON/CSV export for compliance reporting and SIEM integration
Commands
Example Output
Technical Details
Architecture
Invoker Detection Logic
Storage Format
JSONL with daily rotation:
{"id":"abc123","timestamp":"2026-02-05T10:30:00Z","command":"email list","invoker":"alice","invoker_source":"claude-code","status":"success","duration":190000000,"request_id":"req_xyz"}Files Changed
audit_hooks.go,domain/audit.go,ports/audit.goadapters/audit/store.go,summary.goaudit/*.go(8 command files)audit_hooks_test.go,store_test.goaudit.md,COMMANDS.md,INDEX.mdmain.go,root.go,client*.goTest Coverage
60+ unit test cases covering:
Key functions at 100% coverage:
SetAuditRequestInfo,SetAuditGrantInfoauditPreRun,auditPostRun,LogAuditErrorgetCommandPath,isExcludedCommandsanitizeArgs,isLongBase64hasClaudeCodeEnv,initAuditHooksSecurity
make securityandgovulncheckDocumentation
Comprehensive documentation added:
docs/commands/audit.md- 700+ line detailed guidedocs/COMMANDS.md- Quick reference sectiondocs/INDEX.md- Navigation updatedTest Plan
make ci-fullpasses