Repository navigation
Fix airflowctl always using production creds when --env is passed - #70584
bujjibabukatta wants to merge 3 commits into
Conversation
|
Hello @bujjibabukatta - thank you for your contributions to Apache Airflow! The Airflow community has introduced a limit of 5 open pull requests at a time for contributors without write access to the repository. You currently have 16 open pull requests, so - as a one-time step of introducing the limit - we closed the ones where maintainers have not engaged yet:
These pull requests stay open because maintainers are already engaged in them - they count towards your limit:
This is not a judgement of you or of your changes. We never told contributors before that opening many pull requests at once was a problem, so there is nothing to feel bad about - and nothing is lost: your branches, commits and the review history stay where they are. What we ask you to do is to make your first prioritization decision: choose which of the pull requests above matter most to you, and reopen them (up to 5 open at a time, including the ones still open) with the "Reopen pull request" button or While your pull requests are waiting for review, the most valuable thing you can do is help in other ways - reviewing other contributors' pull requests, helping with issues, and taking part in the discussions on the devlist and Slack. Why we introduced the limit, what it means for you and how to reopen or restore a pull request is explained in https://github.com/apache/airflow/blob/main/contributing-docs/32_open_pull_request_limit.rst. Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting |
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
Model(s) used: Claude
AI was used for:
The implementation and code changes were developed and validated by me.