Skip to content

Stop airflowctl sending an old token to a new API URL - #76287

Merged
shahar1 merged 7 commits into
apache:mainfrom
Andrushika:airflowctl-skip-keyring-stale-token
Nov 4, 2026
Merged

shahar1 merged 7 commits into
apache:mainfrom
Andrushika:airflowctl-skip-keyring-stale-token

Conversation

@Andrushika

@Andrushika Andrushika commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Why

airflowctl auth login writes the API URL to <env>.json. It writes the token to the keyring, or to debug_creds_<env>.json in debug mode. If a login does not replace the token that later commands read, the next command sends the old token to the new URL. This happens with --skip-keyring, around debug-mode logins, and when keyring.set_password fails, for example on a locked macOS Keychain. I checked these cases on main.

What

<env>.json now has "token_in_keyring": false until keyring.set_password succeeds. While the key is there, commands do not read the keyring for that environment. Every login also removes debug_creds_<env>.json first.

related: #76280


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 5.5)

Generated-by: Claude Code (Opus 5.5) following the guidelines

auth login writes the API URL of an environment to a file and its
token to the keyring. The URL is written first. If no new token
reaches the keyring after that, the token of an earlier login stays
next to the new URL, and the next command sends it there. This
happens with --skip-keyring, and when keyring.set_password fails,
for example with a wrong password for an encrypted keyring.
The fixture already uses monkeypatch, so one patching tool is enough.
The match string is now escaped, so it checks the exact message.
@github-actions github-actions Bot added the fork ci required Gated by AIP-120: CI must pass in the contributor's fork. Managed by the fork CI reconciler. label Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Fork CI: green. CI for the latest commit passed in your fork. The pull request is ready for maintainer review.

Pull requests from contributors run their CI in the contributor's own fork. GitHub Actions is free and has no minute limit on public forks, while the CI capacity of the Apache Software Foundation is shared by every ASF project and is finite.

Latest run: https://github.com/Andrushika/airflow/actions/runs/41773467815

How this works: fork CI for external contributors.


This comment was posted automatically by the fork CI monitor from templates drafted with an AI-assisted tool, so it may contain mistakes. An Apache Airflow maintainer, a real person, will review the pull request once its fork CI is green. Why the first pass is automated.

@github-actions github-actions Bot added the ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green. label Nov 2, 2026

@shahar1 shahar1 left a comment

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.

The fix is correct and the regression tests are the right ones; two edge cases of the same stale-token pairing deserve a decision before merge: --skip-keyring against a locked keyring, and a debug-mode login.

Smaller observations

  • See inline comments on airflow-ctl/src/airflowctl/api/client.py:257, airflow-ctl/src/airflowctl/api/client.py:252.

This review was drafted by an AI-assisted tool and
confirmed by an Apache Airflow maintainer. The findings
below are observations, not blockers; an Apache Airflow
maintainer — a real person — will take the next look at the
PR. If you think a finding is mis-applied, please reply on
the PR and a maintainer will weigh in.

More on how Apache Airflow handles maintainer review:
Contributing guide.

A debug-mode login stores its token in the debug file and left the
keyring alone. Once debug mode is off, the next command read the URL
from the file and the earlier token from the keyring, which is the
same mismatch as before.

--skip-keyring and debug mode are meant for systems where the keyring
does not work. A keyring that cannot remove the token now only logs a
warning there, so it no longer blocks those logins.
@github-actions github-actions Bot removed the ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green. label Nov 4, 2026
The earlier token is removed at login, but a locked keyring cannot
remove it. Once the keyring unlocks, later commands still read that
token and send it to the new API URL.

The config file now records that the token of the environment is not
in the keyring, so commands no longer read the keyring for it.
The previous approach removed the old token before the login. On
macOS, a locked Keychain raises PasswordDeleteError for the removal,
which looks like "no token", and then KeyringLocked for the new token.
The old token stayed in the keyring next to the new URL.

The config file now says the token is not in the keyring until
keyring.set_password succeeds, so no token removal is needed.
A debug-mode login leaves its token in debug_creds_<env>.json. A
later login outside debug mode pointed the environment at a new URL,
and a command run with debug mode on again sent that token there.
In debug mode the file was only overwritten after the config file
already pointed at the new URL. If that write failed, the next
debug-mode command sent the earlier debug token to the new URL.
@github-actions github-actions Bot added the ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green. label Nov 4, 2026
@shahar1
shahar1 merged commit 596dd41 into apache:main Nov 4, 2026
84 checks passed
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Backport successfully created: airflow-ctl/v0-1-test

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
✅ airflow-ctl/v0-1-test PR Link

shahar1 pushed a commit that referenced this pull request Nov 4, 2026
… API URL (#76287) (#76475)

(cherry picked from commit 596dd41)

Co-authored-by: Andrew Chang <69671930+Andrushika@users.noreply.github.com>
shahar1 pushed a commit to shahar1/airflow that referenced this pull request Nov 4, 2026
… API URL (apache#76287) (apache#76475)

(cherry picked from commit 596dd41)

Co-authored-by: Andrew Chang <69671930+Andrushika@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:airflow-ctl backport-to-airflow-ctl/v0-1-test fork ci required Gated by AIP-120: CI must pass in the contributor's fork. Managed by the fork CI reconciler. kind:documentation ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants