Skip to content

Deprecation warning for airflow.sdk.execution_time.secrets_masker points at the wrong module for mask_secret #70875

Open

Description

@1fanwang

Apache Airflow version

3.2.2 (apache-airflow-task-sdk 1.2.2). Also present on main at 79fa2e6.

If "Other Airflow 2/3 version" selected, which one?

No response

What happened?

The deprecation shim at airflow.sdk.execution_time.secrets_masker tells you to migrate to airflow.sdk._shared.secrets_masker. For mask_secret its own code deliberately does something else, and the two are not equivalent: airflow.sdk.log.mask_secret also forwards the secret to the supervisor, airflow.sdk._shared.secrets_masker.mask_secret does not. Following the warning silently drops supervisor masking.

The warning says _shared (L33-L37):

warnings.warn(
    "Importing from 'airflow.sdk.execution_time.secrets_masker' is deprecated and will be "
    "removed in a future version. Please use 'airflow.sdk._shared.secrets_masker' instead.",
    DeprecatedImportWarning,
    stacklevel=2,
)

The code hands you airflow.sdk.log (L43-L47):

def __getattr__(name: str):
    if name == "mask_secret":
        from airflow.sdk.log import mask_secret

        return mask_secret

Confirmed by object identity on 3.2.2:

shim.mask_secret is airflow.sdk.log.mask_secret                    -> True
shim.mask_secret is airflow.sdk._shared.secrets_masker.mask_secret -> False

That special case is correct, and it is load bearing. airflow.sdk.log.mask_secret registers with the shared masker and notifies the supervisor (log.py L250-L266):

def mask_secret(secret: JsonValue, name: str | None = None) -> None:
    """Mask a secret in both task process and supervisor process. ..."""
    _secrets_masker().add_mask(secret, name)

    with suppress(Exception):
        from airflow.sdk.execution_time import task_runner
        from airflow.sdk.execution_time.comms import MaskSecret

        if comms := getattr(task_runner, "SUPERVISOR_COMMS", None):
            comms.send(MaskSecret(value=secret, name=name))

The _shared one the warning recommends stops at the first line (secrets_masker.py L92-…); there is no SUPERVISOR_COMMS reference anywhere in that module. Under AIP-72 the supervisor is a separate process, so a secret registered only through _shared can still appear in supervisor log output.

The failure is silent. Both modules import, both expose mask_secret, both accept the call and return None. A test asserting the symbol is importable and callable passes against either one, including the one that misses the supervisor.

What you think should happen instead?

The warning text and the module docstring should name airflow.sdk.log for mask_secret, matching what __getattr__ already does. Either carve out the exception in the message, or drop the special case so the message becomes true.

The shim came in with #54915, added defensively after #54449 removed the path, so this reads as incidental rather than intended.

How to reproduce

import warnings
warnings.simplefilter("ignore")

import airflow.sdk.execution_time.secrets_masker as shim
import airflow.sdk._shared.secrets_masker as shared
import airflow.sdk.log as sdklog

print(shim.mask_secret is sdklog.mask_secret)  # True, what the shim gives you
print(shim.mask_secret is shared.mask_secret)  # False, what the warning tells you to use

Operating System

macOS 15 (not OS specific)

Versions of Apache Airflow Providers

No response

Deployment

Other

Deployment details

No response

Anything else?

Two engineers migrating the same codebase independently read the deprecation message, moved to airflow.sdk._shared.secrets_masker, and ended up with weaker masking than they started with. Neither noticed, because every wrong answer in this area imports and runs fine. The human readable guidance is the only signal most people act on, and right now it points away from the implementation the shim itself chose.

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added
    kind:bug
    on Jul 31, 2026
  2. kutsibalci commented on Aug 6, 2026

    @kutsibalci
    Contributor

    @1fanwang you ticked "willing to submit a PR" — are you still working on this? If so I will stay out of the way.

    If you would rather not, I am happy to pick it up. I checked the three files on current main before offering, and the asymmetry still holds:

    • the shim warns to use airflow.sdk._shared.secrets_masker, but its __getattr__ special-cases mask_secret to airflow.sdk.log;
    • airflow.sdk.log.mask_secret calls add_mask and sends MaskSecret over SUPERVISOR_COMMS;
    • the _shared one calls add_mask only — SUPERVISOR_COMMS, MaskSecret and task_runner appear zero times in that module.

    So following the warning does drop supervisor-side masking. (Read from the sources rather than executed — I have not run a task under a supervisor to watch it happen, so I am reporting what the code says, not an observed leak.)

    One thing I would want a maintainer's view on first, since the issue offers two directions and they are not equivalent:

    • Correct the message. __getattr__ already routes mask_secret to airflow.sdk.log, so the warning and the module docstring would name airflow.sdk.log for that symbol and airflow.sdk._shared.secrets_masker for the rest. Smallest change, and it makes the guidance match what the shim actually does.
    • Drop the special case. The message becomes true on its own, but then every caller of the shim loses supervisor masking — which is the behaviour being reported as the bug, so this looks like the wrong way round.

    I would go with the first unless the special case is meant to be temporary. Happy either way — I just did not want to open a PR that picks a direction on someone else's issue.

  3. 1fanwang commented on Aug 6, 2026

    @1fanwang
    ContributorAuthor

    @1fanwang you ticked "willing to submit a PR" — are you still working on this? If so I will stay out of the way.

    If you would rather not, I am happy to pick it up. I checked the three files on current main before offering, and the asymmetry still holds:

    • the shim warns to use airflow.sdk._shared.secrets_masker, but its __getattr__ special-cases mask_secret to airflow.sdk.log;
    • airflow.sdk.log.mask_secret calls add_mask and sends MaskSecret over SUPERVISOR_COMMS;
    • the _shared one calls add_mask only — SUPERVISOR_COMMS, MaskSecret and task_runner appear zero times in that module.

    So following the warning does drop supervisor-side masking. (Read from the sources rather than executed — I have not run a task under a supervisor to watch it happen, so I am reporting what the code says, not an observed leak.)

    One thing I would want a maintainer's view on first, since the issue offers two directions and they are not equivalent:

    • Correct the message. __getattr__ already routes mask_secret to airflow.sdk.log, so the warning and the module docstring would name airflow.sdk.log for that symbol and airflow.sdk._shared.secrets_masker for the rest. Smallest change, and it makes the guidance match what the shim actually does.
    • Drop the special case. The message becomes true on its own, but then every caller of the shim loses supervisor masking — which is the behaviour being reported as the bug, so this looks like the wrong way round.

    I would go with the first unless the special case is meant to be temporary. Happy either way — I just did not want to open a PR that picks a direction on someone else's issue.

    thanks however I see a pr already #70883

  4. kutsibalci commented on Aug 6, 2026

    @kutsibalci
    Contributor

    Thanks — I had missed #70883, and it takes the direction I would have taken (correct the message, leave __getattr__ alone). Leaving it with that PR; sorry for the extra round trip.

  5. divyanshus2404 commented on Nov 13, 2026

    @divyanshus2404
    Contributor

    Noting that #70883 fixed this and was approved, but got auto-closed as stale before a committer merged it. @bujjibabukatta are you planning to reopen it? If not, happy to carry it forward with your commit credited — seems a shame to lose an approved fix.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:corekind:bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions