Skip to content

Fix airflow info --anonymize leaking the machine hostname - #73074

Open
roykoand wants to merge 3 commits into
apache:mainfrom
roykoand:fix-anonymize-uname-hostname
Open

roykoand wants to merge 3 commits into
apache:mainfrom
roykoand:fix-anonymize-uname-hostname

Conversation

@roykoand

@roykoand roykoand commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

airflow info --anonymize is meant to strip personally identifying information. It already redacts the home directory, OS username, and database credentials but it never touched the uname line, which leaks the machine hostname.

The problem

platform.uname() returns a named tuple whose node field is the machine hostname, and on managed
devices that hostname routinely encodes a real name or an asset tag:

# --anonymize was already scrubbing these lines:
sql_alchemy_conn    | postgresql+psycopg2://p...s:PASSWORD@postgres/airflow
python_location     | ${HOME}/.venv/bin/python

# ...but left this one completely untouched:
uname               | uname_result(system='Darwin', node='Andriis-MacBook.local', release='10.6.1', ...)

Before / after, same machine:

# without --anonymize (unchanged)
uname               | uname_result(system='Darwin', node='Andriis-MacBook.local', release='10.6.1', ...)

# with --anonymize (new)
uname               | uname_result(system='Darwin', node='${HOSTNAME}', release='10.6.1', ...)

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

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

🤖 Generated with Claude Code

The uname line in `airflow info` reports platform.uname(), whose node
field is the machine hostname. On managed devices this hostname often
encodes an asset tag or device name, but --anonymize never masked it
even though it already redacts the home directory, OS username, and
database credentials elsewhere in the report.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
roykoand and others added 2 commits September 13, 2026 13:55
Building a synthetic uname_result inline is clearer than caching a
real one at import time to work around mock.patch timing.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

@Vamsi-klu Vamsi-klu left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

​

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

Looks great!

@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. The hostname should not be in an anonymized report, but this only covers one of the places it shows up (inline). A few other points:

  • Please drop airflow-core/newsfragments/73074.bugfix.rst. Under the current policy airflow-core uses only significant newsfragments, for changes users must read before upgrading, and this small fix isn't one.
  • An end-to-end test that the real hostname does not appear anywhere in the airflow info --anonymize output would protect the actual promise, rather than only the uname field.
  • platform.uname is patched without autospec, and since Architecture.get_current() reads platform.machine() through the same patched module, the architecture in these tests is faked as well.

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

operating_system = OperatingSystem.get_current()
arch = Architecture.get_current()
uname = platform.uname()
uname = uname._replace(node=self.anonymizer.process_hostname(uname.node))

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.

This replaces the hostname only in the uname node field. It still leaks through the database URL's host (postgresql://u:[email protected]/airflow, which process_url leaves alone) and through any path that contains it (process_path only replaces HOME and USER). Adding socket.gethostname(): "${HOSTNAME}" to PiiAnonymizer._path_replacements, and applying the same replacements in process_url, would scrub it everywhere and cover this line too, without the new process_hostname() method.

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.

A correction to my suggestion above, since it has some problems:

  • Please don't run the hostname replacement over the whole URL in process_url. A plain substring replace has the same problem Keep the URL scheme out of path masking in airflow info --anonymize #73599 fixed for the username: on a machine named postgres, the scheme would become ${HOSTNAME}ql+psycopg2://. Compare only the URL's host, without the port, and replace it if it matches the machine's hostname.
  • My db01.corp.example example was misleading. This only catches a database host that is the same machine, and a separate database host is out of scope here.
  • The uname line isn't covered automatically, because _system_info doesn't pass it through process_path. It needs that call too.

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

Comment on lines +53 to +54
def process_hostname(self, value) -> str:
"""Remove pii from hostname."""

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.

Adding a required method to the Anonymizer protocol breaks any outside implementation with only the three existing methods: _system_info now calls process_hostname() unconditionally and raises AttributeError. Nothing in the repo is affected, but the replacement-based approach above avoids the protocol change entirely.

This branch has not been deployed

No deployments
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.

4 participants