Skip to content

feat: add TOWER_API_KEY support for API key authentication#235

Merged
codingcyclist merged 7 commits intodevelopfrom
feat/api-key-auth
Apr 2, 2026
Merged

feat: add TOWER_API_KEY support for API key authentication#235
codingcyclist merged 7 commits intodevelopfrom
feat/api-key-auth

Conversation

@codingcyclist
Copy link
Copy Markdown
Contributor

Summary

  • Add TOWER_API_KEY env var as a new authentication method. When set, the CLI uses the X-API-Key header instead of Bearer JWT, skipping session creation entirely.
  • Auth priority: TOWER_API_KEY > TOWER_JWT > session.json
  • tower teams list and MCP tower_teams_list call the /teams API directly when using API key auth (no session refresh needed)
  • tower login warns that the API key will take precedence over the session and prompts to continue

Test plan

  • TOWER_API_KEY=sk-... tower apps list authenticates via X-API-Key header
  • No session.json is created when using API key auth
  • tower teams list returns the key's team
  • tower login with TOWER_API_KEY set shows warning and prompts
  • Existing TOWER_JWT and tower login flows are unaffected
  • Run existing integration tests for regressions
  • Run new cli_api_key_auth.feature integration tests

🤖 Generated with Claude Code

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 26, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 945d7e76-2e9c-4ec4-a1da-fee631568ab0

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/api-key-auth

Comment @coderabbitai help to get the list of available commands and usage tips.

codingcyclist and others added 6 commits March 26, 2026 16:10
Add `api_key` field to Config, populated from the TOWER_API_KEY env var.
When set, make_api_configuration() uses the X-API-Key header instead of
Bearer JWT auth, skipping session-based authentication entirely.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When TOWER_API_KEY env var is present, skip JWT validation and
session.json loading entirely. The API key is self-contained and
doesn't need a persisted session.

Priority order: TOWER_API_KEY > TOWER_JWT > session.json

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Show a yellow warning explaining that the API key will continue to take
precedence over the session created by the login flow. Prompt the user
to confirm before proceeding.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add cli_api_key_auth.feature with scenarios for:
- Listing apps with API key (verifies JSON output, no session.json created)
- Listing teams with API key (verifies no session.json created)
- Login warning when TOWER_API_KEY is set

Add "via CLI with API key" step that uses TOWER_API_KEY env var with a
temp HOME (no session.json) to prove API key auth works standalone.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When authenticating via API key, call the /teams API endpoint directly
instead of refreshing the session (which requires a session.json).
Add list_teams API wrapper and ResponseEntity impl for ListTeamsSuccess.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When authenticating via API key, call the /teams endpoint directly
instead of refreshing the session. Mirrors the same fix applied to
the CLI teams list command.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@bradhe bradhe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, let's ship it.

Comment on lines +33 to 48
// When TOWER_API_KEY is set, skip session entirely — the API key is self-contained
// and authenticates via X-API-Key header rather than Bearer JWT.
let session = if std::env::var("TOWER_API_KEY").is_ok() {
None
} else if let Ok(token) = std::env::var("TOWER_JWT") {
// Load session from a JWT token for programmatic use cases
Session::from_jwt(&token).ok()
} else {
Session::from_config_dir().ok()
};

Self {
cmd,
session,
args: None,
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm doesn't the session have the tower-url on it?

@codingcyclist codingcyclist merged commit b0f0993 into develop Apr 2, 2026
30 checks passed
@codingcyclist codingcyclist deleted the feat/api-key-auth branch April 2, 2026 13:14
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.

3 participants