Skip to content
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

Improve Web UI session experience #4804

Merged
merged 8 commits into from Feb 12, 2021
Merged

Improve Web UI session experience #4804

merged 8 commits into from Feb 12, 2021

Conversation

mperham
Copy link
Collaborator

@mperham mperham commented Feb 9, 2021

For years many people have struggled to configure a Rack session with the rewritten Web UI introduced in v4.2.0. "Forbidden" is a common complaint and there are many hacks around this area in many apps. This change is an attempt to clean up this problem and hopefully guide people back onto the happy path and away from those hacks.

The Web UI no longer exposes any session configuration. Anything like Sidekiq::Web.sessions = false and Sidekiq::Web.session_secret = ... is no longer available.

The Web UI only supports two modes of operation now:

  1. Running within a Rails app and reusing the existing session.
  2. Running as a bare Rack app, user must explicitly configure a session.

Rails

For Rails, as long as you mount the Web UI within the routes, it should provide a session for anything within the routes.

# config/routes.rb
require 'sidekiq/web'

Rails.application.routes.draw do
  mount Sidekiq::Web => "/sidekiq"
  ....
end

Rack

For Rack, a basic cookie session is straightforward to enable:

  1. First create a shared secret for all Sidekiq processes to use and commit it to git:
require 'securerandom'; File.open(".session.key", "w") {|f| f.write(SecureRandom.hex(32)) }
  1. Update your Rack app to use a session middleware before the Web UI:
use Rack::Session::Cookie, secret: File.read(".session.key"), same_site: :strict, max_age: 86400
run Sidekiq::Web

Remove all of the hacks and support infrastructure around Rack sessions. Rails provides this by default so we don't need it for 90% of users. The other 10% should know and provide a Rack session.

This is a big change and has the potential to break many installs. It will be part of the 7.0 major version bump and require a lengthy beta period to ensure we document as many edge cases and solutions as possible.

See also #4671, #4728 and many others.
* Remove HEAD aliases which don't work
* Add simplest possible heartbeat HEAD which returns 200 or 500.
@mperham mperham merged commit 968bc81 into master Feb 12, 2021
@mperham mperham deleted the better_sessions branch February 12, 2021 22:50
This was referenced Mar 15, 2021
@bf4
Copy link
Contributor

bf4 commented Mar 16, 2021

@mperham you may want to update https://github.com/mperham/sidekiq/wiki/Monitoring#forbidden (I presume you'd rather do it than me :)

nice release

marcelolx added a commit to sidekiq-scheduler/sidekiq-scheduler that referenced this pull request May 14, 2021
Since sidekiq/sidekiq#4804 sidekiq requires to be configured explicitly with a rack session.
Bialogs pushed a commit to SaraAlert/SaraAlert that referenced this pull request Sep 14, 2021
Bialogs pushed a commit to SaraAlert/SaraAlert that referenced this pull request Sep 14, 2021
tstrass pushed a commit to SaraAlert/SaraAlert that referenced this pull request Sep 20, 2021
tstrass pushed a commit to SaraAlert/SaraAlert that referenced this pull request Sep 27, 2021
SuperTux88 added a commit to SuperTux88/diaspora that referenced this pull request Oct 27, 2021
SuperTux88 added a commit to diaspora/diaspora that referenced this pull request Oct 30, 2021
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.

None yet

2 participants