Skip to content

feat: secure API authentication system#27

Open
venkidesh04 wants to merge 10 commits into
mainfrom
feat/secure-auth-system
Open

feat: secure API authentication system#27
venkidesh04 wants to merge 10 commits into
mainfrom
feat/secure-auth-system

Conversation

@venkidesh04
Copy link
Copy Markdown
Contributor

Overview

This PR introduces a secure authentication and request validation pipeline between the CLI and controller, replacing the previous plaintext API key approach.


Key Improvements

CLI Enhancements

  • Secure API Key Storage

    • API key is now stored in the OS keychain (via go-keyring)
    • Removes dependency on plaintext storage in ~/.mini/config.json
  • Request Signing

    • All outgoing requests include:

      • Authorization: Bearer <api_key>
      • X-Timestamp
      • X-Signature
  • Centralized Auth Handling

    • attachAuth() and NewSignedRequest() ensure consistent signing across all CLI commands (deploy, logs, etc.)

Controller Enhancements

  • Authentication Middleware

    • Sequential validation pipeline:

      1. API Key validation (constant-time compare)
      2. Timestamp validation (±5 minute window)
      3. HMAC signature verification
  • Replay Protection

    • Timestamp validation prevents reuse of captured requests
  • Request Integrity

    • HMAC ensures request authenticity and tamper detection
  • Rate Limiting

    • Applied globally via middleware
    • Default: 10 req/sec, burst 20
    • Includes cleanup of idle limiter entries

- add cli/keychain/keychain.go wrapping go-keyring
- migrate set-api-key cmd to write into OS keychain
- migrate deploy and logs cmds to read API key from keychain
- remove api_key field from cli/config/config.go (no longer stored on disk)
- add github.com/zalando/go-keyring to cli/go.mod
- add cli/signer/signer.go with Sign() and Headers() helpers
- update cli/client/client.go to attach X-Timestamp and X-Signature on every request
- add NewSignedRequest helper for commands that build requests directly (logs)
- update cli/cmd/logs.go to use NewSignedRequest
- add controller/internal/auth/hmac.go with ValidateTimestamp and ValidateHMAC
- update controller/internal/auth/middleware.go to run timestamp and HMAC checks
  after API key validation
- expose AuthService.Secret() for use within the auth package
- add controller/internal/ratelimit/ratelimit.go
- per-IP token-bucket limiter using golang.org/x/time/rate
- respects X-Forwarded-For for clients behind proxies
- wrap all protected routes with ratelimit.Middleware
- apply rate limiter globally (before routing) using ratelimit.DefaultConfig
- no handler logic changes; purely middleware wiring in main.go
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