Skip to content

Commit bbd77f5

Browse files
authored
feat(audit): add audit logging with invoker identity tracking (#21)
1 parent 2977e8e commit bbd77f5

File tree

25 files changed

+4323
-4
lines changed

25 files changed

+4323
-4
lines changed

cmd/nylas/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/nylas/cli/internal/cli"
1010
"github.com/nylas/cli/internal/cli/admin"
1111
"github.com/nylas/cli/internal/cli/ai"
12+
"github.com/nylas/cli/internal/cli/audit"
1213
"github.com/nylas/cli/internal/cli/auth"
1314
"github.com/nylas/cli/internal/cli/calendar"
1415
"github.com/nylas/cli/internal/cli/config"
@@ -34,6 +35,7 @@ func main() {
3435
// Enable command typo suggestions (e.g., "Did you mean 'email'?")
3536
rootCmd.SuggestionsMinimumDistance = 2
3637
rootCmd.AddCommand(ai.NewAICmd())
38+
rootCmd.AddCommand(audit.NewAuditCmd())
3739
rootCmd.AddCommand(auth.NewAuthCmd())
3840
rootCmd.AddCommand(config.NewConfigCmd())
3941
rootCmd.AddCommand(otp.NewOTPCmd())
@@ -55,6 +57,7 @@ func main() {
5557
rootCmd.AddCommand(update.NewUpdateCmd())
5658

5759
if err := cli.Execute(); err != nil {
60+
cli.LogAuditError(err)
5861
fmt.Fprintln(os.Stderr, "Error:", err)
5962
os.Exit(1)
6063
}

docs/COMMANDS.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,51 @@ nylas admin grants stats # Grant statistics
693693

694694
---
695695

696+
## Audit Logging
697+
698+
Track CLI command execution for compliance, debugging, and AI agent monitoring.
699+
700+
```bash
701+
# Setup
702+
nylas audit init # Interactive setup
703+
nylas audit init --enable # Quick setup with defaults
704+
nylas audit logs enable # Enable logging
705+
nylas audit logs disable # Disable logging
706+
nylas audit logs status # Check status
707+
708+
# View logs
709+
nylas audit logs show # Show last 20 entries
710+
nylas audit logs show --limit 50 # More entries
711+
nylas audit logs show --command email # Filter by command
712+
nylas audit logs show --invoker alice # Filter by username
713+
nylas audit logs show --source claude-code # Filter by source (AI agents, etc.)
714+
nylas audit logs show --status error # Filter by status
715+
nylas audit logs show --request-id req_abc123 # Find by Nylas request ID
716+
717+
# Statistics and export
718+
nylas audit logs summary # Summary for last 7 days
719+
nylas audit logs summary --days 30 # Summary for 30 days
720+
nylas audit export --output audit.json # Export to JSON
721+
nylas audit export --output audit.csv # Export to CSV
722+
723+
# Configuration
724+
nylas audit config show # Show configuration
725+
nylas audit config set retention_days 30 # Set retention
726+
nylas audit logs clear # Clear all logs
727+
```
728+
729+
**Invoker detection:** Automatically tracks who ran commands:
730+
- `terminal` - Interactive terminal session
731+
- `claude-code` - Anthropic's Claude Code
732+
- `github-copilot` - GitHub Copilot CLI
733+
- `ssh` - Remote SSH session
734+
- `script` - Non-interactive automation
735+
- Custom via `NYLAS_INVOKER_SOURCE` env var
736+
737+
**Details:** `docs/commands/audit.md`
738+
739+
---
740+
696741
## Utility Commands
697742

698743
```bash
@@ -735,6 +780,7 @@ All commands follow consistent pattern:
735780
- Admin: `docs/commands/admin.md`
736781
- Workflows: `docs/commands/workflows.md` (OTP, automation)
737782
- Timezone: `docs/commands/timezone.md`
783+
- Audit: `docs/commands/audit.md`
738784
- AI: `docs/commands/ai.md`
739785
- MCP: `docs/commands/mcp.md`
740786
- TUI: `docs/commands/tui.md`

docs/INDEX.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Quick navigation guide to find the right documentation for your needs.
7373
- **Scheduler**[commands/scheduler.md](commands/scheduler.md)
7474
- **Admin**[commands/admin.md](commands/admin.md)
7575
- **Timezone**[commands/timezone.md](commands/timezone.md)
76+
- **Audit**[commands/audit.md](commands/audit.md)
7677
- **TUI**[commands/tui.md](commands/tui.md)
7778
- **Workflows (OTP)**[commands/workflows.md](commands/workflows.md)
7879
- **Templates**[commands/templates.md](commands/templates.md)
@@ -119,7 +120,7 @@ docs/
119120
├── ARCHITECTURE.md # System design
120121
├── DEVELOPMENT.md # Development setup
121122
122-
├── commands/ # Detailed command guides (16 files)
123+
├── commands/ # Detailed command guides (17 files)
123124
│ ├── ai.md # AI features
124125
│ ├── mcp.md # MCP integration
125126
│ ├── calendar.md # Calendar events
@@ -133,6 +134,7 @@ docs/
133134
│ ├── scheduler.md # Booking pages
134135
│ ├── admin.md # API management
135136
│ ├── timezone.md # Timezone utilities
137+
│ ├── audit.md # Audit logging & invoker tracking
136138
│ ├── tui.md # Terminal UI
137139
│ ├── templates.md # Email templates
138140
│ └── workflows.md # OTP & automation
@@ -206,4 +208,4 @@ docs/
206208

207209
---
208210

209-
**Last Updated:** February 4, 2026
211+
**Last Updated:** February 5, 2026

0 commit comments

Comments
 (0)