Skip to content

Conversation

@bagedevimo
Copy link
Contributor

Deploying this will log everyone out, so we may want to consider an intermediate migration step.

@bagedevimo bagedevimo force-pushed the drop-active-record-sessions-store branch from 580f6e3 to b0e44ca Compare February 10, 2023 10:18
@bagedevimo
Copy link
Contributor Author

bagedevimo commented Feb 10, 2023

Merge #161 first

@bagedevimo bagedevimo force-pushed the drop-active-record-sessions-store branch 2 times, most recently from 386ac96 to 60d8d77 Compare February 10, 2023 10:23
Deploying this will log everyone out, so we may want to consider an
intermediate migration step.
@bagedevimo bagedevimo force-pushed the drop-active-record-sessions-store branch from 60d8d77 to ae97aae Compare March 5, 2023 00:12
@bagedevimo
Copy link
Contributor Author

Tested by logging in ticking remember me, stopping the rails server, exiting my browser. change to this branch, start rails, start browser and verify still logged in. The cookie works fine for the non-session remember me, but if you don't click remember me your session will be lost regardless of the browser, etc.

tom93 added a commit that referenced this pull request Dec 20, 2023
secret_key_base was added in Rails 4 and replaces secret_token. It is
used by CookieStore to encrypt cookies (we are not currently using
CookieStore, but we will switch to it in #162).

The Rails 4 convention for setting secret_key_base is to use
config/secrets.yml and the environment variable SECRET_KEY_BASE (see
[1]). We don't use this approach, because secrets.yml will be
deprecated in favour of credentials.yml.enc in Rails 5.2 [2] and
because setting the environment variable is awkward.

Instead, we generate a random secret the first time the app runs and
store it in config/secret_key_base.#{env}.txt. We also support the
environment variable SECRET_KEY_BASE to match the Rails convention; we
don't currently use this environment variable, but it may be useful
(e.g. in situations such as build steps where we don't want to
generate the file, or in environments such as Docker where environment
variables are often more convenient than files).

We don't store the secret in the database (which is how the existing
secret_token is implemented) because it may be useful to start the app
without a database connection. Also, it's probably more secure to keep
the secret out of the database (and its backups).

This commit also adds a rule to .gitignore to make sure the secrets
aren't accidentally committed.

[1]: https://guides.rubyonrails.org/v4.1.8/upgrading_ruby_on_rails.html#config-secrets-yml
[2]: https://www.github.com/rails/rails/pull/30067
tom93 added a commit that referenced this pull request Dec 20, 2023
secret_key_base was added in Rails 4 and replaces secret_token. It is
used by CookieStore to encrypt cookies (we are not currently using
CookieStore, but we will switch to it in #162).

The Rails 4 convention for setting secret_key_base is to use
config/secrets.yml and the environment variable SECRET_KEY_BASE (see
[1]). We don't use this approach, because secrets.yml will be
deprecated in favour of credentials.yml.enc in Rails 5.2 [2] and
because setting the environment variable is awkward.

Instead, we generate a random secret the first time the app runs and
store it in config/secret_key_base.#{env}.txt. We also support the
environment variable SECRET_KEY_BASE to match the Rails convention; we
don't currently use this environment variable, but it may be useful
(e.g. in situations such as build steps where we don't want to
generate the file, or in environments such as Docker where environment
variables are often more convenient than files).

We don't store the secret in the database (which is how the existing
secret_token is implemented) because it may be useful to start the app
without a database connection. Also, it's probably more secure to keep
the secret out of the database (and its backups).

This commit also adds a rule to .gitignore to make sure the secrets
aren't accidentally committed.

[1]: https://guides.rubyonrails.org/v4.1.8/upgrading_ruby_on_rails.html#config-secrets-yml
[2]: https://www.github.com/rails/rails/pull/30067
@tom93
Copy link
Contributor

tom93 commented Dec 20, 2023

Merge #195 first, to skip the legacy signed-but-not-encrypted cookie store mode.

Copy link
Contributor

@tom93 tom93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We decided over Discord not to bother with a migration or a notice about being signed out (if they didn't tick "remember me").

Holmes98 pushed a commit to Holmes98/nztrain that referenced this pull request Dec 21, 2023
secret_key_base was added in Rails 4 and replaces secret_token. It is
used by CookieStore to encrypt cookies (we are not currently using
CookieStore, but we will switch to it in NZOI#162).

The Rails 4 convention for setting secret_key_base is to use
config/secrets.yml and the environment variable SECRET_KEY_BASE (see
[1]). We don't use this approach, because secrets.yml will be
deprecated in favour of credentials.yml.enc in Rails 5.2 [2] and
because setting the environment variable is awkward.

Instead, we generate a random secret the first time the app runs and
store it in config/secret_key_base.#{env}.txt. We also support the
environment variable SECRET_KEY_BASE to match the Rails convention; we
don't currently use this environment variable, but it may be useful
(e.g. in situations such as build steps where we don't want to
generate the file, or in environments such as Docker where environment
variables are often more convenient than files).

We don't store the secret in the database (which is how the existing
secret_token is implemented) because it may be useful to start the app
without a database connection. Also, it's probably more secure to keep
the secret out of the database (and its backups).

This commit also adds a rule to .gitignore to make sure the secrets
aren't accidentally committed.

[1]: https://guides.rubyonrails.org/v4.1.8/upgrading_ruby_on_rails.html#config-secrets-yml
[2]: https://www.github.com/rails/rails/pull/30067
@tom93 tom93 merged commit 65f60ac into NZOI:master Dec 21, 2023
tom93 added a commit that referenced this pull request Dec 21, 2023
We forgot to update Gemfile.lock in #162.
tom93 added a commit that referenced this pull request Dec 22, 2023
@tom93
Copy link
Contributor

tom93 commented Dec 22, 2023

This has been deployed just now, so all users that didn't tick "remember me" will be signed out.

@tom93
Copy link
Contributor

tom93 commented Dec 22, 2023

It appears that users might get signed out even if they ticked "remember me". We are not quite sure why.
Users that have been signed out should be able to sign in again using their password as usual.
If you forgot your password, you can use the "Forgot your password?" option to reset it.
Sorry for any hassle.

@bagedevimo bagedevimo deleted the drop-active-record-sessions-store branch December 22, 2023 19:30
@tom93
Copy link
Contributor

tom93 commented Dec 29, 2023

It turns out that the sign-out issue is because by default Devise sets the "remember me" cookie to expire after 2 weeks, which is very short.
Details: The generated file config/initializers/devise.rb contains the line # config.remember_for = 2.weeks. Since the line is commented out, it falls back to Devise's default, which is also 2 weeks.
Credit: @Holmes98.

In future we should probably increase this duration, and/or set config.extend_remember_period to true so that signing in will restart the "remember me" period. Update: #231

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants