Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix env var auth when config file has credentials for a different instance#181

Merged
jlaneve merged 1 commit intomainastronomer/agents:mainfrom
fix/v3-token-exchange-env-varsastronomer/agents:fix/v3-token-exchange-env-varsCopy head branch name to clipboard
Apr 9, 2026
Merged

Fix env var auth when config file has credentials for a different instance#181
jlaneve merged 1 commit intomainastronomer/agents:mainfrom
fix/v3-token-exchange-env-varsastronomer/agents:fix/v3-token-exchange-env-varsCopy head branch name to clipboard

Conversation

@jlaneve
Copy link
Copy Markdown
Contributor

@jlaneve jlaneve commented Apr 8, 2026

Summary

Fixes a bug where af CLI commands return 403 when using AIRFLOW_API_URL to point at a local Airflow instance while ~/.af/config.yaml has credentials for a different (e.g., cloud) instance.

Root cause

The env var precedence logic in CLIContext.init() resolves each field independently:

URL:      AIRFLOW_API_URL env var → http://localhost:8080  ✓
Token:    no AIRFLOW_AUTH_TOKEN   → config_values.token    ✗ (cloud token!)
Username: AIRFLOW_USERNAME       → admin                  ✓
Password: AIRFLOW_PASSWORD       → admin                  ✓

Since auth_token takes precedence over username/password in AdapterManager.configure(), the cloud token is used against localhost — 403.

Fix

When AIRFLOW_API_URL is set via env var (overriding the config's URL), don't inherit auth fields from the config file since they belong to a different instance. Auth from env vars still works.

Testing

# Before: 403 Forbidden on API calls
AIRFLOW_API_URL=http://localhost:8080 AIRFLOW_USERNAME=admin AIRFLOW_PASSWORD=admin af health

# After: works correctly, TokenManager exchanges credentials for JWT
AIRFLOW_API_URL=http://localhost:8080 AIRFLOW_USERNAME=admin AIRFLOW_PASSWORD=admin af health

All 433 unit tests pass.

🤖 Generated with Claude Code

…tance

When AIRFLOW_API_URL is set via env var, don't inherit auth (token,
username, password) from the config file since those credentials are
for the config file's instance, not the env var's. This caused 403
errors when pointing af at a local Airflow while the config had a
cloud instance token.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jlaneve jlaneve merged commit 4fc2366 into main Apr 9, 2026
10 checks passed
@jlaneve jlaneve deleted the fix/v3-token-exchange-env-vars branch April 9, 2026 03:54
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.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.