File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- # Be sure to restart your server when you modify this file.
1+ require 'active_support/secure_random'
22
3- # Your secret key for verifying the integrity of signed cookies.
4- # If you change this key, all old signed cookies will become invalid!
5- # Make sure the secret is at least 30 characters and all random,
6- # no regular words or you'll be exposed to dictionary attacks.
7- Src ::Application . config . secret_token = 'f466b184ef680822293d7130f57593a7087a34b5de0607c64d1ceb66fcac4dce6810a6f176feba3fbbf2489de93c0918397c0c275996eb476b2fa6079ab849c1'
3+ begin
4+ # Read token string from the file.
5+ token = IO . read ( '/etc/katello/secret_token' )
6+ raise RuntimeError , 'Size is too small' if token . length < 9
7+ Src ::Application . config . secret_token = token . chomp
8+ rescue Exception => e
9+ # If anything is wrong make sure the token is random. This is safe even when
10+ # Katello is not configured correctly for any reason (but session is lost
11+ # after each restart).
12+ Rails . logger . warn "Using randomly generated secure token: #{ e . message } "
13+ Src ::Application . config . secret_token = ActiveSupport ::SecureRandom . hex ( 80 )
14+ end
Original file line number Diff line number Diff line change @@ -364,19 +364,20 @@ install -m 644 man/katello-service.8 %{buildroot}/%{_mandir}/man8
364364/sbin/chkconfig --add %{name }
365365/sbin/chkconfig --add %{name }-jobs
366366
367- %postun common
368- #update config/initializers/secret_token.rb with new key
369- NEWKEY= $( < /dev/urandom tr -dc A-Za-z0-9 | head -c128 )
370- sed -i " s/^Src::Application.config.secret_token = '.*'/Src::Application.config.secret_token = ' $NEWKEY '/ " \
371- %{ homedir }/config/initializers/secret_token.rb
367+ # Generate secret token if the file does not exist
368+ #(this must be called both for installation and upgrade)
369+ TOKEN = /etc/katello/secret_token
370+ test -f $TOKEN || (echo $( < /dev/urandom tr -dc A-Za-z0-9 | head -c128) > $TOKEN \
371+ && chmod 600 $TOKEN && chown katello:katello $TOKEN)
372372
373373%posttrans common
374- rm %{datadir }/Gemfile.lock
374+ rm -f %{datadir }/Gemfile.lock 2 > /dev/null
375375/sbin/service %{name } condrestart > /dev/null 2>&1 || :
376376
377377%files
378378%attr (600, katello, katello)
379379%{_bindir }/katello-*
380+ %ghost %attr(600, katello, katello) %{_sysconfdir }/%{name }/secret_token
380381%{homedir }/app/controllers
381382%{homedir }/app/helpers
382383%{homedir }/app/mailers
You can’t perform that action at this time.
0 commit comments