summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorash <smashwilson@gmail.com>2013-05-22 23:55:48 +0000
committerash <smashwilson@gmail.com>2013-05-22 23:55:48 +0000
commite444c7f6babe956ef22a775b8ec197d58765b6a0 (patch)
tree680ef8dff86ef7756e1fbb3480b3437cff918806
parentc5de01f824ff640e1aebdf8b5058434766948a94 (diff)
downloadgitlab-ce-e444c7f6babe956ef22a775b8ec197d58765b6a0.tar.gz
Generate the Rails secret token on first run.
Store the secret token in a .gitignored file called ".secret", which is created by the initializer if it doesn't exist.
-rw-r--r--.gitignore1
-rw-r--r--config/initializers/secret_token.rb18
2 files changed, 18 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 2a7e605a350..1210ac3b44a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -29,3 +29,4 @@ db/data.yml
vendor/bundle/*
rails_best_practices_output.html
doc/code/*
+.secret
diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb
index 6d3a9f07787..16d1d4a9fdd 100644
--- a/config/initializers/secret_token.rb
+++ b/config/initializers/secret_token.rb
@@ -1,7 +1,23 @@
# Be sure to restart your server when you modify this file.
+require 'securerandom'
+
# Your secret key for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
-Gitlab::Application.config.secret_token = '0a38e9a40ca5d66d7002a6ade0ed0f8b71058c820163f66cf65d91521ab55255ff708b9909b138008a7f13d68fec575def1dc3ff7200cd72b065896315e0bed2'
+
+def find_secure_token
+ token_file = Rails.root.join('.secret')
+ if File.exist? token_file
+ # Use the existing token.
+ File.read(token_file).chomp
+ else
+ # Generate a new token of 64 random hexadecimal characters and store it in token_file.
+ token = SecureRandom.hex(64)
+ File.write(token_file, token)
+ token
+ end
+end
+
+Gitlab::Application.config.secret_token = find_secure_token