How to generate a Fernet key?


Install cryptography:

pip install cryptography

Generate a fernet key:

$ python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())"

Use a fernet key with Airflow

Paste the key into your airflow.cfg.

fernet_key = 81HqDtbqAywKSOumSha3BhWNOdQ26slT6K0YaZeZyPs=

Alternatively, set the environment variable.


Restart Airflow’s webserver.

For existing connections (the ones that were defined before setting the Fernet key), you need to open each connection in the web admin, re-type the password and save it.