Skip to content

Add ABAC, OAuth auth, and environment presets#28

Merged
pevans merged 5 commits into
mainfrom
pevans/abac-functionality
May 21, 2026
Merged

Add ABAC, OAuth auth, and environment presets#28
pevans merged 5 commits into
mainfrom
pevans/abac-functionality

Conversation

@pevans

@pevans pevans commented May 21, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds ABAC (attribute-based access control): top-level policy-set (create/list/get/update/delete/validate) and api-key (settings, policy-set attachments, evaluate, explain) commands, backed by a new internal/abac client.
  • Adds browser-based bearer auth: auth login/logout/status via OAuth (PKCE), structured keyring credentials, and a credential-typed client that pins the project via X-Zep-Project on bearer flows. --api-key / ZEP_API_KEY still override.
  • Adds environment presets and per-profile config: config add-environment/update-environment/delete-environment/get-environments, config update-profile, config set-project, and a persistent --project flag at the root.

Test plan

  • go build ./... clean
  • go vet ./... clean
  • golangci-lint run ./... -- 0 issues
  • go test ./... -- all packages pass (new tests for abac, auth, cli, client, config, keyring)
  • zepctl --help lists api-key, auth, policy-set, plus existing commands
  • zepctl config --help shows add-environment, update-profile, set-project
  • zepctl auth --help shows login, logout, status

🤖 Generated with Claude Code

@claude

claude Bot commented May 21, 2026

Copy link
Copy Markdown

Code Quality Review: ABAC, OAuth Authentication, and Environment Presets (PR #28)

Summary

This is an impressive and comprehensive PR that adds significant functionality to zepctl. The implementation is well-structured, follows Go best practices, and includes comprehensive tests. The documentation is thorough and matches the implementation well.

Strengths 🟢

Code Quality

  • Excellent separation of concerns: New internal/abac client is cleanly separated from CLI logic
  • Comprehensive test coverage: All new packages include thorough unit tests with httptest servers
  • Idiomatic Go patterns: Proper error handling with wrapped errors, interface design, and struct composition
  • Security-conscious: Proper credential storage in system keychain, OAuth PKCE flow, token refresh handling

API Design

  • Consistent CLI patterns: New commands follow existing conventions (list, get, create, update, delete)
  • Bearer vs API key authentication: Clear separation of credential types with appropriate command annotations
  • Exit codes: Proper exit code handling for policy-set validate (0/1/2 pattern)
  • Error categorization: IsNotFound(), IsConflict() helper functions for structured error handling

Documentation

  • Comprehensive updates: Both docs/cli.mdx and docs/cli-specification.md are thoroughly updated
  • Command documentation: All new commands, flags, and examples are documented
  • Authentication modes: Clear explanation of API key vs bearer token usage
  • Migration guide: Good coverage of the new authentication flows

Areas for Improvement 🟡

Code Organization

  1. File location: internal/cli/api_key_abac.go - Consider renaming to internal/cli/api_key.go for consistency, since this handles the main api-key command.

Error Handling

  1. UUID validation: The validateUUID() function in policy_set.go:48 could be moved to a shared utilities package since it's used across multiple commands.

  2. Context cancellation: In auth.go:214-270, the autoSelectProject function should check for context cancellation during the interactive project selection loop.

Security Considerations

  1. Token masking: In auth.go:273-278, the maskKey function should handle edge cases better (empty strings, very short keys).

Testing

  1. Integration tests: While unit tests are excellent, consider adding integration tests for the OAuth flow (though this may require mocking external services).

Minor Issues 🔵

Documentation

  1. CLI specification: Line 128 in docs/cli-specification.md - the --config flag description should specify the default path more explicitly.

  2. Environment examples: In the documentation, consider adding more concrete examples of environment preset configurations for common scenarios (dev, staging, prod).

Code Style

  1. Constants: In api_key_abac.go:15, consider moving abacModeEnforce and validModesList to a shared constants file or the abac package.

  2. Magic numbers: The UUID truncation in truncateUUID (8 characters) could be a named constant.

Security Assessment ✅

The security implementation is solid:

  • ✅ Credentials stored in system keychain (not in config files)
  • ✅ OAuth PKCE flow implementation
  • ✅ Token refresh handling with revocation
  • ✅ Proper JWT parsing (unverified for ID token extraction)
  • ✅ No credential logging or exposure in error messages
  • ✅ Context-aware HTTP requests with timeouts

Testing Quality ✅

Excellent test coverage across all new functionality:

  • ✅ Comprehensive unit tests for ABAC client (401 lines)
  • ✅ CLI command validation tests
  • ✅ OAuth flow tests
  • ✅ Keyring migration tests
  • ✅ Error condition testing
  • ✅ HTTP mocking with proper assertions

Documentation Compliance ✅

The documentation is comprehensive and accurate:

  • ✅ All new commands documented in both MDX and specification
  • ✅ Flag descriptions match implementation
  • ✅ Examples are accurate and helpful
  • ✅ Authentication modes clearly explained
  • ✅ Environment variable documentation updated

Overall Assessment

Recommendation: APPROVE 🎉

This is high-quality work that significantly enhances zepctl's capabilities. The code is well-structured, thoroughly tested, and properly documented. The few minor improvements suggested above are non-blocking and could be addressed in follow-up PRs.

The implementation demonstrates strong understanding of Go best practices, security considerations, and CLI design principles. The comprehensive test suite gives confidence in the reliability of the new features.

Great work on this substantial addition to the codebase!

@claude

claude Bot commented May 21, 2026

Copy link
Copy Markdown

Code Review: Add ABAC, OAuth auth, and environment presets

This is a substantial and well-implemented PR that adds significant functionality to zepctl. I've reviewed the code for quality, security, and documentation consistency. Overall, this is excellent work! 🎉

Strengths

Code Quality & Go Best Practices:

  • Excellent error handling: Consistent use of wrapped errors with fmt.Errorf("operation: %w", err) pattern
  • Proper separation of concerns: Clean layered architecture with internal/abac, internal/auth, internal/keyring packages
  • Idiomatic Go: Good use of interfaces, proper HTTP client patterns, and consistent naming conventions
  • Strong test coverage: Comprehensive unit tests with proper mocking using httptest.Server
  • Type safety: Well-defined structs with appropriate JSON tags and validation

Security Considerations:

  • Proper credential storage: Uses OS keychain via github.com/zalando/go-keyring for sensitive data
  • No credential leakage: API keys and tokens are never logged or printed in plain text (good masking in maskKey())
  • PKCE implementation: Proper OAuth 2.0 PKCE flow for security in public clients
  • Token refresh handling: Robust token refresh with proper error handling for expired/invalid tokens
  • Backward compatibility: Graceful migration from legacy API key storage to new JSON format

API Design & Consistency:

  • Consistent CLI patterns: All new commands follow existing conventions (list, get, create, update, delete)
  • Proper flag handling: Good use of Cobra flags with validation
  • Bearer token requirement: Appropriately restricts ABAC commands to authenticated users only
  • Project scoping: Proper X-Zep-Project header handling for multi-tenant scenarios

Documentation Quality

The documentation updates in docs/cli.mdx and docs/cli-specification.md are excellent and thoroughly match the implementation:

  • Complete command coverage: All new commands (auth, policy-set, api-key) are fully documented
  • Accurate flag documentation: All flags, their types, and defaults are correctly specified
  • Good examples: Practical usage examples that match actual command syntax
  • Clear authentication flow: Well-explained dual auth mode (API key + bearer token)
  • Environment preset concept: Well-documented new feature with proper examples

🔍 Technical Implementation Highlights

ABAC Client (internal/abac/client.go):

  • Clean HTTP client wrapper with proper error handling
  • Good use of doRequest/doRequestRaw pattern for consistency
  • Preserves raw JSON responses for forward compatibility
  • Appropriate error types with helper functions (IsNotFound, IsConflict)

OAuth Session Management (internal/auth/session.go):

  • Proper OAuth 2.0 flow implementation
  • Secure keychain integration
  • Good separation of token storage and flow state management

CLI Integration (internal/cli/auth.go):

  • Excellent auto-project selection logic
  • Proper profile bootstrapping on first login
  • Good error messages and user feedback

📋 Minor Observations

  1. Exit Code Handling: Nice addition of ExitCodeError in cmd/zepctl/main.go:9-13 for proper CLI exit codes
  2. Test Quality: Tests use proper table-driven patterns and good mocking
  3. Keyring Migration: Elegant backward compatibility for existing API key storage
  4. HTTP Transport: Clean bearer token transport implementation

🎯 Overall Assessment

This PR demonstrates excellent engineering practices:

  • Comprehensive feature implementation with proper testing
  • Security-conscious design with proper credential handling
  • Excellent documentation that matches the implementation
  • Clean, idiomatic Go code following established patterns
  • Good separation of concerns and modular design

The 8,545 line addition is substantial but well-organized and thoroughly tested. The new authentication and ABAC functionality significantly enhances zepctl's capabilities while maintaining backward compatibility.

Recommendation: ✅ APPROVE

Great work on this feature! The code quality, security considerations, and documentation are all top-notch.

@pevans pevans merged commit 54d3ac3 into main May 21, 2026
10 checks passed
@pevans pevans deleted the pevans/abac-functionality branch May 21, 2026 15:39
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.

1 participant