How to generate a Fernet key?

airflow

Install cryptography:

pip install cryptography

Generate a fernet key:

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

Use a fernet key with Airflow

Paste the key into your airflow.cfg.

fernet_key = 81HqDtbqAywKSOumSha3BhWNOdQ26slT6K0YaZeZyPs=

Alternatively, set the environment variable.

AIRFLOW__CORE__FERNET_KEY='81HqDtbqAywKSOumSha3BhWNOdQ26slT6K0YaZeZyPs='

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.