Fixed: "The HMAC key is 24 bytes long, which is below the minimum recommended length of 64 bytes for SHA512" in Apache Airflow®
A fresh Apache Airflow® 3.4.0 installation printed the same warning four times while I signed in and ran one Dag: The HMAC key is 24 bytes long, which is below the minimum recommended length of 64 bytes for SHA512. The key in question is the secret Airflow signs its access tokens with, and the one it generates for you is too short. Here's how I traced it, and the one setting that fixes it.
What I Was Doing
I had installed Airflow 3.4.0 with uv on Python 3.14 and started it with airflow standalone in a new AIRFLOW_HOME. Then I asked the API for a token, the way the UI does when you sign in, and unpaused and triggered a one-task Dag, hello.
What I Expected
A token, a successful run, and no warnings.
What I Got
Both worked, but four warnings came with them:
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 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 filename=.../site-packages/jwt/api_jwt.py lineno=149

One came when the API server issued the token, one when the scheduler queued the task, and two while the task talked to the API server.
What I Checked
Who prints it. The filename field points at jwt/api_jwt.py: PyJWT, the library Airflow uses for its JSON Web Tokens. Its warning class is InsecureKeyLengthWarning.
Which key is 24 bytes. Airflow signs its tokens with [api_auth] jwt_secret in airflow.cfg. Airflow generated mine when it created the file, and the value is 24 characters long. The configuration reference says that when jwt_secret is set and no algorithm is chosen, Airflow uses HS512: HMAC with SHA-512.
What the warning asks for. RFC 7518, Section 3.2, which the warning cites, says an HMAC key must be at least as long as the hash's output. SHA-512's output is 512 bits, 64 bytes, and the key is 24.
Where the short key comes from. Airflow 3.4.0 generates the secret from 16 random bytes, encoded as 24 characters, when it writes a new airflow.cfg. That's the value it then signs every token with.
Why It Happens
The secret Airflow generates is shorter than the HS512 algorithm it then uses needs, so PyJWT warns every time it signs or checks a token with it.
The Fix
Generate a 64-byte random secret with Python's secrets module:
python -c "import secrets; print(secrets.token_urlsafe(64))"
<86 random characters; mine is hidden here>
secrets.token_urlsafe(64) makes 64 random bytes and prints them as 86 characters that are safe to put in a file.
Stop Airflow with Ctrl+C. In airflow.cfg, find jwt_secret in the [api_auth] section and replace its value with the new one:
jwt_secret = <the 86 characters you generated>
Then start Airflow again. Changing the secret invalidates the tokens signed with the old one, so sign in to the UI again.
The configuration reference also suggests that for security-sensitive deployments, you pass this value in the AIRFLOW__API_AUTH__JWT_SECRET environment variable instead of keeping it in a file.
After the Fix
I repeated the same steps: a token request, then a run of hello. This time Airflow's output had no HMAC warning anywhere. The API server logged the token request with status 201, and the scheduler marked the run successful:
api-server | 2026-11-30T18:41:07.781824Z [info ] request finished [http.access] client_addr=127.0.0.1:63057 duration_us=15518 loc=http_access_log.py:130 method=POST path=/auth/token query= status_code=201
...
scheduler | 2026-11-30T18:41:16.148196Z [info ] Marking run <DagRun hello @ None: manual__2026-11-30T18:41:11.187065+00:00, state:running, queued_at: 2026-11-30 18:41:11.192113+00:00. run_type: manual> successful [airflow.models.dagrun.DagRun]

Before the fix, the same token request line came right after the first warning.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Changing [api] secret_key instead | The warning stays: it's about [api_auth] jwt_secret | Change jwt_secret |
| Typing a short secret by hand | The warning comes back with a new length | Generate 64 bytes with secrets.token_urlsafe(64) |
Committing airflow.cfg with the new secret | Your secret is in Git | Keep airflow.cfg out of Git, or use the environment variable |
| Different secrets in different components | Tokens one component signs don't work in another | Use the same jwt_secret everywhere, as the reference requires |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Still 24 bytes after the edit | Airflow wasn't restarted, or another airflow.cfg is in use | Restart; check echo $AIRFLOW_HOME |
| Signed out of the UI after the change | Old tokens were signed with the old secret | Sign in again |
FAQ
Is the warning dangerous?
It's a warning, not an error: Airflow keeps working. But a short key is weaker than the algorithm is designed for, which is why it's worth fixing.
Why 86 characters for 64 bytes?
token_urlsafe encodes the bytes in URL-safe Base64, which uses 4 characters for every 3 bytes.
Conclusion
The HMAC key is 24 bytes long came from PyJWT, because the [api_auth] jwt_secret that Airflow 3.4.0 generates is 24 characters while HS512 asks for 64 bytes. A secret from secrets.token_urlsafe(64) in its place, and a restart, ended all four warnings.
Additional Resources
- Configuration reference: [api_auth] —
jwt_secretandjwt_algorithm. - RFC 7518, Section 3.2 — the key size rule for HMAC.
- Python secrets module —
token_urlsafe.
Related
- How to Get an Access Token for the Apache Airflow® REST API
- How to Start Apache Airflow® on Your Computer with airflow standalone
- How to Keep Apache Airflow® Files Out of Git with .gitignore
Apache®, Apache Airflow and Airflow® are either registered trademarks or trademarks of The Apache Software Foundation in the United States and/or other countries. No endorsement by The Apache Software Foundation is implied by the use of these marks.
