Skip to content

Fix airflowctl always using production creds when --env is passed - #70584

Open
bujjibabukatta wants to merge 1 commit into
apache:mainfrom
bujjibabukatta:fix/#70519
Open

Fix airflowctl always using production creds when --env is passed#70584
bujjibabukatta wants to merge 1 commit into
apache:mainfrom
bujjibabukatta:fix/#70519

Conversation

@bujjibabukatta

Copy link
Copy Markdown
Contributor

Ran into this while poking around the CLI — turns out --env/-e is accepted by pretty much every airflowctl command, but it's basically decorative outside of auth login. Everything else (dags list, connections list, dags trigger, you name it) quietly ignores it and talks to production no matter what you pass.

The reason is that provide_api_client's wrapper only ever forwards api_token down to get_client(), and get_client() doesn't even accept an environment argument. So Credentials falls back to its own default of "production" every single time, regardless of what you typed. auth login works fine because it builds Credentials directly with api_environment=args.env — it just never went through this shared path.

Practically, this means something like airflowctl dags trigger --env staging some_dag looks like it's targeting staging, but it's actually hitting production with whatever token happens to be sitting in the production keychain entry. Best case you get a confusing Token Expired/Invalid JWT error. Worst case it silently works — against the wrong environment.

Fix is pretty small: get_client() now takes an api_environment param, and provide_api_client reads args.env and passes it through, same as auth login already does. While I was in there I noticed version_command.py had the exact same bug on its own direct get_client() call for version --remote --env ..., so fixed that too.

AIRFLOW_CLI_ENVIRONMENT still takes priority over --env if both are set — that precedence already lived inside Credentials.init and I didn't touch it.

Added tests for both get_client (spins up real per-environment config files and checks it resolves the right one) and provide_api_client, which didn't actually have any direct test coverage before this.

Closes #70519

AI Disclosure

  • This contribution used AI assistance.

Model(s) used: Claude

AI was used for:

  • Helping write this PR description.
  • Running the test suite locally to make sure everything passes before submitting.
  • Reviewing the implementation from a performance perspective.

The implementation and code changes were developed and validated by me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

airflowctl ignores --env/AIRFLOW_CLI_ENVIRONMENT on non-auth commands — always uses production credentials

1 participant