jagdish-kumawat opened a new issue, #77805:
URL: https://github.com/apache/airflow/issues/77805

   ### 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`:
   - 
https://github.com/apache/airflow/blob/6196a32433a70e9d0da76644dfffdd47161a7420/airflow-core/src/airflow/configuration.py#L646
   - 
https://github.com/apache/airflow/blob/6196a32433a70e9d0da76644dfffdd47161a7420/airflow-core/src/airflow/configuration.py#L505
 (the same 16 bytes)
   
   #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):
   
   ```bash
   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
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to