Skip to content

Mask sensitive values in airflow config update dry-run output - #73265

Merged
potiuk merged 1 commit into
apache:mainfrom
keith991001:fix-config-update-mask-sensitive
Nov 2, 2026
Merged

potiuk merged 1 commit into
apache:mainfrom
keith991001:fix-config-update-mask-sensitive

Conversation

@keith991001

Copy link
Copy Markdown
Contributor

The dry-run mode of airflow config update (the default mode) printed the full regenerated airflow.cfg to stdout with real values — sql_alchemy_conn, fernet_key, SMTP credentials and every other sensitive option. Since the command is documented as a preview tool for the Airflow 3 config migration, its output easily lands in CI logs, bug reports and support channels, leaking those credentials.

closes: #73255

What changed

  • AirflowConfigParser.write_custom_config gains a hide_sensitive parameter: options registered as sensitive (via is_sensitive_option, the same registry airflow config list --hide-sensitive uses) are written as < hidden >. Sensitivity is checked against both the original and the post-rename option name, so a renamed sensitive option stays masked.
  • airflow config update dry-run now masks sensitive values by default and prints a hint; a new --show-sensitive flag opts back into real values.
  • The --fix path is unchanged: it always writes real values to airflow.cfg, since a masked value would corrupt the config file. This is asserted by a test.

Behavior

$ airflow config update
Dry-run mode enabled. No changes will be written to airflow.cfg.
Sensitive values are shown as '< hidden >'. Use `--show-sensitive` to display them ...
...
sql_alchemy_conn = < hidden >

$ airflow config update --show-sensitive
...
sql_alchemy_conn = postgresql+psycopg2://airflow:S3cr3tPassword@db:5432/airflow

Verified against a real AIRFLOW_HOME with an embedded DB password, plus three new unit tests (masked by default / --show-sensitive reveals / --fix writes real values).


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: Claude Code (Fable 5) following the guidelines


  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

@keith991001

Copy link
Copy Markdown
Contributor Author

Human review note from @keith991001: CI is green and this PR is ready for review.

@bugraoz93, gentle ping when you have capacity. This masks sensitive values in the config update dry-run output, with focused test coverage. Thank you!


Drafted-by: Codex (GPT-5); reviewed by @keith991001 before posting

@Eason09053360 Eason09053360 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.

Thanks for the patch!
Tried this on an Airflow 2-style airflow.cfg: [smtp] smtp_password, [core] internal_api_secret_key and [core] dataset_manager_kwargs still print in clear in the default dry-run — they were sensitive in Airflow 2, but Airflow 3 no longer registers them. Could these legacy options be masked too? Otherwise LGTM :)

@keith991001

keith991001 commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for catching this. I updated the dry-run masking to cover [smtp] smtp_password, [core] internal_api_secret_key, and [core] dataset_manager_kwargs, and added regression assertions for each. The targeted test and Ruff checks pass locally.

Drafted with assistance from Codex and reviewed by @keith991001 before posting.

@namanjain24-sudo namanjain24-sudo 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.

Independently traced the underlying bug (before finding this PR) — write_custom_config had no equivalent to write()'s hide_sensitive/is_sensitive_option handling, so update_config's dry-run always wrote raw values. This PR's fix mirrors write()'s existing masking approach correctly.

Verified two things empirically:

  • The _AIRFLOW_V2_SENSITIVE_OPTIONS hardcoding (added after @Eason09053360's review) is necessary, not redundant: is_sensitive_option returns False for all three legacy options (smtp.smtp_password, core.internal_api_secret_key, core.dataset_manager_kwargs) since Airflow 3 no longer registers them.
  • Renamed currently-sensitive options are also masked correctly: is_sensitive_option returns True for both the old and new spelling of sql_alchemy_conn (core/database), so checking both (section, option) and (effective_section, effective_option) in write_custom_config covers the rename case. No dedicated test exercises this specific rename+masking path, though — might be worth adding one (e.g. an option present under its pre-3.0 section name that's still sensitive today), non-blocking.

Confirmed the --fix path is unaffected — hide_sensitive isn't passed there, so real values are always written to airflow.cfg, matching the test that asserts this.


Drafted-by: Claude Code (Sonnet 5); reviewed by @namanjain24-sudo before posting

The dry run, the default mode of airflow config update, printed the regenerated airflow.cfg with real values of sql_alchemy_conn, fernet_key and other sensitive options, and that preview output easily ends up in CI logs and bug reports.

closes: apache#73255
Generated-by: Claude Opus 5
@potiuk
potiuk force-pushed the fix-config-update-mask-sensitive branch from 2536e45 to aa1c1ad Compare November 1, 2026 23:51

@potiuk potiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks — config update defaulting to dry-run made this an easy leak, and masking by default with an explicit --show-sensitive opt-out is the right trade-off; good that --fix is pinned to real values by a test, and that the Airflow 2-only sensitive options are covered. I rebased onto main and dropped the bugfix newsfragment (AGENTS.md: airflow-core only takes significant ones). Approving with auto-merge on.


Drafted-by: Claude Code (Claude Opus 5); reviewed by @potiuk before posting

@potiuk
potiuk enabled auto-merge (squash) November 1, 2026 23:52
@potiuk
potiuk merged commit 1b43dce into apache:main Nov 2, 2026
71 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

airflow config update (dry-run, the default) prints unmasked secrets to stdout

4 participants