-
Notifications
You must be signed in to change notification settings - Fork 21.9k
Make it possible to rotate the secret key gracefully for ActiveStorage #39623
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
base: main
Are you sure you want to change the base?
Conversation
Hey @georgeclaghorn did you have a chance to take a look at it? I'd like to know if this PR makes sense or if I'm missing something, thanks 😄 |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
83321af
to
0c74115
Compare
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
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.
Good idea! We should fix this. We also gotta find a place to document this in the Active Storage guide.
0c74115
to
34928c7
Compare
@kaspth From your comments I understand that you:
I tried using the That said, I agree that changing |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
What happened to this? It would be great to see it merged |
@santib do you want to finish this? I think we should add a new rotation object only for Active Storage with a simpler API. We don't need a app.config.active_storage.key_rotation.rotate "old secret" |
Hey @rafaelfranca sure I can finish this but I'll need a couple of days to find some time if that's ok, thanks for the heads up |
34928c7
to
497ac32
Compare
@jonathanhefner I think you PR to add the message_verifies invalidate this one right? |
497ac32
to
9c5a26a
Compare
Yes, with #44179, users could call Note that the So, if I understand this PR correctly, the configuration would look something like: key_generator = ActiveSupport::KeyGenerator.new(old_secret_key_base, iterations: 1000)
config.active_storage.key_rotations.tap do |rotations|
rotations.rotate(key_generator.generate_key("ActiveStorage"))
end With #44179, the configuration would look something like: key_generator = ActiveSupport::KeyGenerator.new(old_secret_key_base, iterations: 1000)
Rails.application.message_verifiers.rotate(secret_generator: key_generator.method(:generate_key)) We could possibly simplify these configurations by modifying Or we could add a Rails.application.message_verifiers.rotate(
secret_generator: Rails.application.secret_generator(old_secret_key_base)
) |
One year ping on this in case it can still be completed |
I just posted a related question on Reddit. It would be useful to have a plan or documentation in case you need to change the secret key. |
Summary
Currently, when for some reason we need to change the app secret key, ActiveStorage's previously generated urls will stop working. By supporting rotation in the ActiveStorage verifier, we can rotate the app secret key while still supporting old generated urls either for a grace period or forever.
Other Information
I based the solution on
config.action_dispatch.cookies_rotations
.I wanted to validate the idea and solution before adding anything else (like a section in the rails guides).
I don't like how this looks
app.config.active_storage.rotations.active_storage
but couldn't think of a better name.