-
Notifications
You must be signed in to change notification settings - Fork 14.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[AIRFLOW-3383] Rotate fernet keys. #4225
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4225 +/- ##
==========================================
+ Coverage 74.1% 74.11% +<.01%
==========================================
Files 421 421
Lines 27662 27679 +17
==========================================
+ Hits 20498 20513 +15
- Misses 7164 7166 +2
Continue to review full report at Codecov.
|
Ideally, this isn't anything that I would use. In my case I would:
What do you think? |
By the way, I also submitted #4232, which should make it easier to programmatically update credentials. |
Ping @Fokko @ashb @kaxil. I agree that storing credentials in an external service like Vault would be a useful feature, but as long as we're supporting credential storage in the airflow database with fernet encryption, I think we should support fernet key rotation. This was the simplest implementation that came to mind. WDYT? I would also be happy to write up some options for using external encryption and credential services if you'd be open to it. |
Agreed. |
@ashb thanks! Can you take a look and let me know if this approach makes sense? I'll write up docs if so. |
airflow/bin/cli.py
Outdated
@@ -614,6 +614,16 @@ def next_execution(args): | |||
print(None) | |||
|
|||
|
|||
@cli_utils.action_logging | |||
def rotate_credentials(args): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good, only comment is that I think this name needs changing - even knowning what the PR was for I thought this was about rotating the credentials in the connection.
How about reencrypt_connections
, rotate_fernet_key
, or rotate_encryption_keys
?
b44cbd5
to
0ed3e20
Compare
Thanks for reviewing @ashb. I agree that |
The build is passing again after rebasing on master. Ready for review when you have time @ashb. |
airflow/bin/cli.py
Outdated
}, | ||
{ | ||
'func': rotate_fernet_key, | ||
'help': 'Rotate all encrypted connection credentials.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh argh! We also encrypt variables too. Sorry, forgot about that before.
Good call, I updated the help text for the |
Merge conflicts resolved. Should be ready for another look @ashb. |
Sorry @ashb, I was in a hurry earlier and totally misread your point about encrypting variables. I pushed up some changes to rotate keys on encrypted variables too. |
684f636
to
222c1d9
Compare
Ready for another look when you have time @ashb. |
Ping @ashb |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically good to go now (thanks for the ping) but one or two small possible improvements now
Thanks @ashb, updated the patch. |
Add the ability to change the encryption key of all encrypted variables and connections
Add the ability to change the encryption key of all encrypted variables and connections
Make sure you have checked all steps below.
Jira
Description
As far as I can tell, it's not straightforward to rotate the fernet key for encrypted passwords and extras. A user would have to generate a new key, restart airflow, and manually re-enter each value to be encrypted via the web interface. It should be possible to specify multiple fernet keys at once, and to easily re-encrypt values with a new key. The cryptography package provides a MultiFernet class with a rotate method that handles this use case, so I wrote up a patch that uses MultiFernet to support multiple keys and rotation via the command line.
With this approach, we can rotate keys by adding a new key at the start of the FERNET_KEYS config variable, then running the rotate_credentials command from the command line. If the approach makes sense, I'll write up some documentation.
Tests
Commits
Documentation
Code Quality
flake8