Skip to content

Generated [api_auth] jwt_secret is 24 bytes, so PyJWT warns on every token: "The HMAC key is 24 bytes long, which is below the minimum recommended length of 64 bytes for SHA512" #77805

Description

@jagdish-kumawat

Under which category would you file this issue?

Airflow Core

Apache Airflow version

3.4.0

What happened and how to reproduce it?

When airflow.cfg doesn't exist, Airflow writes one with a generated [api_auth] jwt_secret of b64encode(os.urandom(16)), which is 24 characters. With jwt_algorithm unset, Airflow signs its JWTs with HS512, and the constrained PyJWT (2.15.1) warns every time it uses that key. RFC 7518 Section 3.2 asks for a key at least as long as the hash output, which is 64 bytes for SHA-512.

With airflow standalone there are four warnings: one when the UI or POST /auth/token issues a token, one when the scheduler queues a task, and two while the task calls the Execution API:

api-server | 2026-11-30T18:39:27.317726Z [warning  ] The HMAC key is 24 bytes long, which is below the minimum recommended length of 64 bytes for SHA512. See RFC 7518 Section 3.2. [py.warnings] category=InsecureKeyLengthWarning filename=.../site-packages/jwt/api_jwt.py lineno=149
scheduler  | 2026-11-30T18:39:31.454812Z [warning  ] The HMAC key is 24 bytes long, which is below the minimum recommended length of 64 bytes for SHA512. See RFC 7518 Section 3.2. [py.warnings] category=InsecureKeyLengthWarning filename=.../site-packages/jwt/api_jwt.py lineno=149
api-server | 2026-11-30T18:39:34.532058Z [warning  ] The HMAC key is 24 bytes long, which is below the minimum recommended length of 64 bytes for SHA512. See RFC 7518 Section 3.2. [py.warnings] category=InsecureKeyLengthWarning correlation_id=01a22dc1-4d15-7a9a-a330-3fba11837d2b filename=.../site-packages/jwt/api_jwt.py lineno=370
api-server | 2026-11-30T18:39:34.551526Z [warning  ] The HMAC key is 24 bytes long, which is below the minimum recommended length of 64 bytes for SHA512. See RFC 7518 Section 3.2. [py.warnings] category=InsecureKeyLengthWarning correlation_id=01a22dc1-4d15-7a9a-a330-3fba11837d2b filename=.../site-packages/jwt/api_jwt.py lineno=149 ti_id=01a22dc1-44ee-7477-8283-a5b0691a813c

The value comes from write_default_airflow_configuration_if_needed(), which is still the same on main:

#65082 fixed the same thing for the Helm chart: its generated JWT secret went from randAlphaNum 32 to randAlphaNum 128 after this warning showed up in API server logs. The core default used by pip or uv installs and airflow standalone still has 16 random bytes.

Steps to reproduce (Python 3.14.10, uv 0.13.10, macOS):

uv venv --python 3.14
source .venv/bin/activate
uv pip install "apache-airflow==3.4.0" --constraint "https://raw.githubusercontent.com/apache/airflow/constraints-3.4.0/constraints-3.14.txt"
export AIRFLOW_HOME="$PWD"
airflow standalone
# in a second terminal, sign in through the UI, or request a token:
curl -X POST http://localhost:8080/auth/token -H 'Content-Type: application/json' \
  -d '{"username": "admin", "password": "<password from simple_auth_manager_passwords.json.generated>"}'

The api-server prints the warning when it issues the token. Triggering any Dag adds the scheduler and Execution API warnings. (I ran these steps with [api] host = 127.0.0.1 and [api] port = 8085 in airflow.cfg; the address doesn't change the warnings.)

What you think should happen instead?

The generated secret should be long enough for the algorithm Airflow picks, at least 64 bytes for HS512 (for example secrets.token_urlsafe(64)). I set [api_auth] jwt_secret by hand to an 86-character secrets.token_urlsafe(64) value, and the same steps (a token request and a triggered Dag run) printed no warnings, with the run succeeding.

It also matters for later: PyJWT has an enforce_minimum_key_length option that raises InvalidKeyError instead of warning, so a short default key could fail outright if that becomes the default.

Operating System

macOS 26.7.4 (arm64)

Deployment

Virtualenv installation

Apache Airflow Provider(s)

No response

Versions of Apache Airflow Providers

Not relevant (airflow-core). PyJWT 2.15.1 from the 3.4.0 constraints.

Official Helm Chart version

Not Applicable

Kubernetes Version

Not Applicable

Helm Chart configuration

Not Applicable

Docker Image customizations

Not Applicable

Anything else?

It happens every time, on every fresh airflow.cfg. Deployments that set their own long jwt_secret are not affected.

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. adiranjan25 commented on Nov 30, 2026

    @adiranjan25
    Contributor

    Thanks for reporting this issue and providing a reproducible example.

    I'd like to contribute a fix for the JWT secret generation behavior in Airflow Core.

    My proposed approach is to increase the cryptographic strength of newly generated JWT secrets to satisfy the HS512 minimum key-length requirement, while preserving existing user-configured secrets and avoiding unintended token invalidation for existing installations.

    I would also add targeted regression tests covering default configuration generation, JWT signing and verification, and compatibility with existing configurations.

    @jagdish-kumawat, please let me know if you're already working on a fix. Otherwise, I'd be happy to take this forward and submit a PR.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions