6676: Install docs recommend running SSO server behind Nginx.
[arvados.git] / doc / install / install-sso.html.textile.liquid
1 ---
2 layout: default
3 navsection: installguide
4 title: Install Single Sign On (SSO) server
5 ...
6
7 h2(#dependencies). Install dependencies
8
9 h3(#install_git_curl). Install git and curl
10
11 {% include 'install_git_curl' %}
12
13 h3(#install_ruby_and_bundler). Install Ruby and Bundler
14
15 {% include 'install_ruby_and_bundler' %}
16
17 h3(#install_postgres). Install PostgreSQL
18
19 {% include 'install_postgres' %}
20
21 h2(#install). Install SSO server
22
23 h3. Get SSO server code and run bundle
24
25 <notextile>
26 <pre><code>~$ <span class="userinput">cd $HOME</span> # (or wherever you want to install)
27 ~$ <span class="userinput">git clone https://github.com/curoverse/sso-devise-omniauth-provider.git</span>
28 ~$ <span class="userinput">cd sso-devise-omniauth-provider</span>
29 ~/sso-devise-omniauth-provider$ <span class="userinput">bundle install --without=development</span>
30 </code></pre></notextile>
31
32 h2. Configure the SSO server
33
34 First, copy the example configuration file:
35
36 <notextile>
37 <pre><code>~/sso-devise-omniauth-provider$ <span class="userinput">cp -i config/application.yml.example config/application.yml</span>
38 </code></pre></notextile>
39
40 The SSO server reads the @config/application.yml@ file, as well as the @config/application.defaults.yml@ file. Values in @config/application.yml@ take precedence over the defaults that are defined in @config/application.defaults.yml@. The @config/application.yml.example@ file is not read by the SSO server and is provided for installation convenience only.
41
42 Consult @config/application.default.yml@ for a full list of configuration options.  Local configuration goes in @config/application.yml@, do not edit @config/application.default.yml@.
43
44 h3(#uuid_prefix). uuid_prefix
45
46 Generate a uuid prefix for the single sign on service.  This prefix is used to identify user records as originating from this site.  It must be exactly 5 lowercase ASCII letters and/or digits.  You may use the following snippet to generate a uuid prefix:
47
48 <notextile>
49 <pre><code>~/sso-devise-omniauth-provider$ <span class="userinput">ruby -e 'puts "#{rand(2**64).to_s(36)[0,5]}"'</span>
50 abcde
51 </code></pre></notextile>
52
53 Edit @config/application.yml@ and set @uuid_prefix@ in the "common" section.
54
55 h3(#secret_token). secret_token
56
57 Generate a new secret token for signing cookies:
58
59 <notextile>
60 <pre><code>~/sso-devise-omniauth-provider$ <span class="userinput">ruby -e 'puts rand(2**400).to_s(36)'</span>
61 zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
62 </code></pre></notextile>
63
64 Edit @config/application.yml@ and set @secret_token@ in the "common" section.
65
66 h2(#database). Set up the database
67
68 Generate a new database password. Nobody ever needs to memorize it or type it, so make a strong one:
69
70 <notextile>
71 <pre><code>~/sso-devise-omniauth-provider$ <span class="userinput">ruby -e 'puts rand(2**128).to_s(36)'</span>
72 abcdefghijklmnopqrstuvwxyz012345689
73 </code></pre></notextile>
74
75 Create a new database user with permission to create its own databases.
76
77 <notextile>
78 <pre><code>~/sso-devise-omniauth-provider$ <span class="userinput">sudo -u postgres createuser --createdb --encrypted -R -S --pwprompt arvados_sso</span>
79 Enter password for new role: <span class="userinput">paste-database-password-you-generated</span>
80 Enter it again: <span class="userinput">paste-database-password-you-generated</span>
81 </code></pre></notextile>
82
83 Configure SSO server to connect to your database by creating and updating @config/database.yml@. Replace the @xxxxxxxx@ database password placeholders with the new password you generated above.  If you are planning a production system, update the @production@ section, otherwise use @development@.
84
85 <notextile>
86 <pre><code>~/sso-devise-omniauth-provider$ <span class="userinput">cp -i config/database.yml.example config/database.yml</span>
87 ~/sso-devise-omniauth-provider$ <span class="userinput">edit config/database.yml</span>
88 </code></pre></notextile>
89
90 Create and initialize the database. If you are planning a production system, choose the @production@ rails environment, otherwise use @development@.
91
92 <notextile>
93 <pre><code>~/sso-devise-omniauth-provider$ <span class="userinput">RAILS_ENV=production bundle exec rake db:setup</span>
94 </code></pre></notextile>
95
96 Alternatively, if the database user you intend to use for the SSO server is not allowed to create new databases, you can create the database first and then populate it with rake. Be sure to adjust the database name if you are using the @development@ environment. This sequence of commands is functionally equivalent to the rake db:setup command above:
97
98 <notextile>
99 <pre><code>~/sso-devise-omniauth-provider$ <span class="userinput">sudo -u postgres createdb arvados_sso_production -E UTF8 -O arvados_sso -T template0</span>
100 ~/sso-devise-omniauth-provider$ <span class="userinput">RAILS_ENV=production bundle exec rake db:schema:load</span>
101 ~/sso-devise-omniauth-provider$ <span class="userinput">RAILS_ENV=production bundle exec rake db:seed</span>
102 </code></pre></notextile>
103
104 h2(#client). Create arvados-server client
105
106 Use @rails console@ to create a @Client@ record that will be used by the Arvados API server.  The values of @app_id@ and @app_secret@ correspond to the values for @sso_app_id@ and @sso_app_secret@ in the "API server's SSO settings.":install-api-server.html#omniauth
107
108 <notextile>
109 <pre><code>~/sso-devise-omniauth-provider$ <span class="userinput">ruby -e 'puts rand(2**400).to_s(36)'</span>
110 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
111 ~/sso-devise-omniauth-provider$ <span class="userinput">RAILS_ENV=production bundle exec rails console</span>
112 :001 &gt; <span class="userinput">c = Client.new</span>
113 :002 &gt; <span class="userinput">c.name = "joshid"</span>
114 :003 &gt; <span class="userinput">c.app_id = "arvados-server"</span>
115 :004 &gt; <span class="userinput">c.app_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"</span>
116 :005 &gt; <span class="userinput">c.save!</span>
117 :006 &gt; <span class="userinput">quit</span>
118 </code></pre>
119 </notextile>
120
121 h2(#assets). Precompile assets
122
123 If you are running in the production environment, you must precompile the assets:
124
125 <notextile>
126 <pre><code>~/sso-devise-omniauth-provider$ <span class="userinput">RAILS_ENV=production bundle exec rake assets:precompile</span>
127 </code></pre>
128 </notextile>
129
130 h2(#authentication_methods). Authentication methods
131
132 Authentication methods are configured in @application.yml@.  Currently three authentication methods are supported: local accounts, LDAP, and Google+.  If neither Google+ nor LDAP are enabled, the SSO server defaults to local user accounts.   Only one authentication mechanism should be in use at a time.
133
134 h3(#local_accounts). Local account authentication
135
136 There are two configuration options for local accounts:
137
138 <pre>
139   # If true, allow new creation of new accounts in the SSO server's internal
140   # user database.
141   allow_account_registration: false
142
143   # If true, send an email confirmation before activating new accounts in the
144   # SSO server's internal user database (otherwise users are activated immediately.)
145   require_email_confirmation: false
146 </pre>
147
148 For more information about configuring backend support for sending email (required to send email confirmations) see "Configuring Action Mailer":http://guides.rubyonrails.org/configuring.html#configuring-action-mailer
149
150 If @allow_account_registration@ is false, you may manually create local accounts on the SSO server from the rails console:
151
152 <notextile>
153 <pre><code>~/sso-devise-omniauth-provider$ <span class="userinput">RAILS_ENV=production bundle exec rails console</span>
154 :001 &gt; <span class="userinput">user = User.new(:email =&gt; "test@example.com")</span>
155 :002 &gt; <span class="userinput">user.password = "passw0rd"</span>
156 :003 &gt; <span class="userinput">user.save!</span>
157 :004 &gt; <span class="userinput">quit</span>
158 </code></pre>
159 </notextile>
160
161 h3(#ldap). LDAP authentication
162
163 The following options are available to configure LDAP authentication.  Note that you must preserve the indentation of the fields listed under @use_ldap@.
164
165 <pre>
166   use_ldap:
167     title: Example LDAP
168     host: ldap.example.com
169     port: 636
170     method: ssl
171     base: "ou=Users, dc=example, dc=com"
172     uid: uid
173     email_domain: example.com
174     #bind_dn: "some_user"
175     #password: "some_password"
176 </pre>
177
178 table(table).
179 |_. Option|_. Description|
180 |title |Title displayed to the user on the login page|
181 |host  |LDAP server hostname|
182 |port  |LDAP server port|
183 |method|One of "plain", "ssl", "tls"|
184 |base  |Directory lookup base|
185 |uid   |User id field used for directory lookup|
186 |email_domain|Strip off specified email domain from login and perform lookup on bare username|
187 |bind_dn|If required by server, username to log with in before performing directory lookup|
188 |password|If required by server, password to log with before performing directory lookup|
189
190 h3(#google). Google+ authentication
191
192 In order to use Google+ authentication, you must use the <a href="https://console.developers.google.com" target="_blank">Google Developers Console</a> to create a set of client credentials.
193
194 # Go to the <a href="https://console.developers.google.com" target="_blank">Google Developers Console</a> and select or create a project; this will take you to the project page.
195 # On the sidebar, click on *APIs & auth* then select *APIs*.
196 ## Search for *Contacts API* and click on *Enable API*.
197 ## Search for *Google+ API* and click on *Enable API*.
198 # On the sidebar, click on *Credentials*; under *OAuth* click on *Create new Client ID* to bring up the *Create Client ID* dialog box.
199 # Under *Application type* select *Web application*.
200 # If the authorization origins are not displayed, clicking on *Create Client ID* will take you to *Consent screen* settings.
201 ## On consent screen settings, enter the appropriate details and click on *Save*.
202 ## This will return you to the *Create Client ID* dialog box.
203 # You must set the authorization origins.  Edit @sso.your-site.com@ to the appropriate hostname that you will use to access the SSO service:
204 ## JavaScript origin should be @https://sso.your-site.com/@
205 ## Redirect URI should be @https://sso.your-site.com/users/auth/google_oauth2/callback@
206 # Copy the values of *Client ID* and *Client secret* from the Google Developers Console into the Google section of @config/application.yml@, like this:
207
208 <notextile>
209 <pre><code>  # Google API tokens required for OAuth2 login.
210   google_oauth2_client_id: <span class="userinput">"---YOUR---CLIENT---ID---HERE--"-</span>
211   google_oauth2_client_secret: <span class="userinput">"---YOUR---CLIENT---SECRET---HERE--"-</span></code></pre></notextile>
212
213 h2(#start). Set up a Web server
214
215 For best performance, we recommend you use Nginx as your Web server front-end, with a Passenger backend to serve the SSO server.  To do that:
216
217 <notextile>
218 <ol>
219 <li><a href="https://www.phusionpassenger.com/documentation/Users%20guide%20Nginx.html">Install Nginx and Phusion Passenger</a>.</li>
220
221 <li><p>Edit the http section of your Nginx configuration to run the Passenger server, and act as a front-end for it.  You might add a block like the following, adding SSL and logging parameters to taste:</p>
222
223 <pre><code>server {
224   listen 127.0.0.1:8900;
225   server_name localhost-sso;
226
227   root   <span class="userinput">/YOUR/PATH/TO/sso-devise-omniauth-provider/public</span>;
228   index  index.html index.htm index.php;
229
230   passenger_enabled on;
231   # If you're using RVM, uncomment the line below.
232   #passenger_ruby /usr/local/rvm/wrappers/default/ruby;
233 }
234
235 upstream sso {
236   server     127.0.0.1:8900  fail_timeout=10s;
237 }
238
239 proxy_http_version 1.1;
240
241 server {
242   listen       <span class="userinput">[your public IP address]</span>:443 ssl;
243   server_name  auth.<span class="userinput">your.domain</span>;
244
245   ssl on;
246
247   index  index.html index.htm index.php;
248
249   location / {
250     proxy_pass            http://sso;
251     proxy_redirect        off;
252     proxy_connect_timeout 90s;
253     proxy_read_timeout    300s;
254
255     proxy_set_header      X-Forwarded-Proto https;
256     proxy_set_header      Host $http_host;
257     proxy_set_header      X-Real-IP $remote_addr;
258     proxy_set_header      X-Forwarded-For $proxy_add_x_forwarded_for;
259   }
260 }
261 </code></pre>
262 </li>
263
264 <li>Restart Nginx.</li>
265
266 </ol>
267 </notextile>
268
269 {% include 'notebox_begin' %}
270
271 If you see the following warning "you may safely ignore it":https://stackoverflow.com/questions/10374871/no-secret-option-provided-to-racksessioncookie-warning:
272
273 <pre>
274 SECURITY WARNING: No secret option provided to Rack::Session::Cookie.
275 This poses a security threat. It is strongly recommended that you
276 provide a secret to prevent exploits that may be possible from crafted
277 cookies. This will not be supported in future versions of Rack, and
278 future versions will even invalidate your existing user cookies.
279
280 Called from: /var/lib/gems/2.1.0/gems/actionpack-3.2.8/lib/action_dispatch/middleware/session/abstract_store.rb:28:in `initialize'.
281 </pre>
282
283 {% include 'notebox_end' %}