Document authentication.
[pithos] / docs / source / adminguide.rst
1 Administrator Guide
2 ===================
3
4 Simple Setup
5 ------------
6
7 Assuming a clean debian squeeze (stable) installation, use the following steps to run the software.
8
9 Install packages::
10
11   apt-get install git python-django python-setuptools python-sphinx
12   apt-get install python-sqlalchemy python-psycopg2
13   apt-get install apache2 libapache2-mod-wsgi
14
15 Get the source::
16
17   cd /
18   git clone https://code.grnet.gr/git/pithos
19
20 Setup the files (choose where to store data in ``settings.py`` and change ``SECRET_KEY``)::
21
22   cd /pithos/pithos
23   cp settings.py.dist settings.py
24   python manage.py syncdb
25   cd /pithos
26   python setup.py build_sphinx
27
28 Edit ``/etc/apache2/sites-available/pithos`` (change the ``ServerName`` directive)::
29
30   <VirtualHost *:80>
31         ServerAdmin webmaster@pithos.dev.grnet.gr
32         ServerName pithos.dev.grnet.gr
33
34         DocumentRoot /var/www/pithos_web_client
35         <Directory />
36                 Options FollowSymLinks
37                 AllowOverride None
38         </Directory>
39         <Directory /var/www/>
40                 Options Indexes FollowSymLinks MultiViews
41                 AllowOverride None
42                 Order allow,deny
43                 allow from all
44         </Directory>
45
46         Alias /docs "/pithos/docs/build/html"
47         <Directory /pithos/docs/build/html/>
48                 Order allow,deny
49                 Allow from all
50         </Directory>
51
52         RewriteEngine On
53         RewriteRule ^/v(.*) /api/v$1 [PT]
54         RewriteRule ^/public(.*) /api/public$1 [PT]
55         RewriteRule ^/login(.*) /api/login$1 [PT]
56
57         <Directory /pithos/pithos/wsgi/>
58                 Order allow,deny
59                 Allow from all
60         </Directory>
61         WSGIScriptAlias /api /pithos/pithos/wsgi/pithos.wsgi
62
63         # WSGIDaemonProcess pithos
64         # WSGIProcessGroup pithos
65
66         ErrorLog ${APACHE_LOG_DIR}/pithos.error.log
67
68         # Possible values include: debug, info, notice, warn, error, crit,
69         # alert, emerg.
70         LogLevel warn
71
72         CustomLog ${APACHE_LOG_DIR}/pithos.access.log combined
73
74   </VirtualHost>
75
76 Edit ``/etc/apache2/sites-available/pithos-ssl`` (assuming files in ``/etc/ssl/private/pithos.dev.grnet.gr.key`` and ``/etc/ssl/certs/pithos.dev.grnet.gr.crt`` - change the ``ServerName`` directive)::
77
78   <IfModule mod_ssl.c>
79   <VirtualHost _default_:443>
80         ServerAdmin webmaster@pithos.dev.grnet.gr
81         ServerName pithos.dev.grnet.gr
82
83         DocumentRoot /var/www/pithos_web_client
84         <Directory />
85                 Options FollowSymLinks
86                 AllowOverride None
87         </Directory>
88         <Directory /var/www/>
89                 Options Indexes FollowSymLinks MultiViews
90                 AllowOverride None
91                 Order allow,deny
92                 allow from all
93         </Directory>
94
95         Alias /docs "/pithos/docs/build/html"
96         <Directory /pithos/docs/build/html/>
97                 Order allow,deny
98                 Allow from all
99         </Directory>
100
101         RewriteEngine On
102         RewriteRule ^/v(.*) /api/v$1 [PT]
103         RewriteRule ^/public(.*) /api/public$1 [PT]
104         RewriteRule ^/login(.*) /api/login$1 [PT]
105
106         <Directory /pithos/pithos/wsgi/>
107                 Order allow,deny
108                 Allow from all
109         </Directory>
110         WSGIScriptAlias /api /pithos/pithos/wsgi/pithos.wsgi
111
112         ErrorLog ${APACHE_LOG_DIR}/pithos-ssl.error.log
113
114         # Possible values include: debug, info, notice, warn, error, crit,
115         # alert, emerg.
116         LogLevel warn
117
118         CustomLog ${APACHE_LOG_DIR}/pithos-ssl.access.log combined
119
120         #   SSL Engine Switch:
121         #   Enable/Disable SSL for this virtual host.
122         SSLEngine on
123
124         #   A self-signed (snakeoil) certificate can be created by installing
125         #   the ssl-cert package. See
126         #   /usr/share/doc/apache2.2-common/README.Debian.gz for more info.
127         #   If both key and certificate are stored in the same file, only the
128         #   SSLCertificateFile directive is needed.
129         SSLCertificateFile    /etc/ssl/certs/pithos.dev.grnet.gr.crt
130         SSLCertificateKeyFile /etc/ssl/private/pithos.dev.grnet.gr.key
131
132         #   Server Certificate Chain:
133         #   Point SSLCertificateChainFile at a file containing the
134         #   concatenation of PEM encoded CA certificates which form the
135         #   certificate chain for the server certificate. Alternatively
136         #   the referenced file can be the same as SSLCertificateFile
137         #   when the CA certificates are directly appended to the server
138         #   certificate for convinience.
139         #SSLCertificateChainFile /etc/apache2/ssl.crt/server-ca.crt
140
141         #   Certificate Authority (CA):
142         #   Set the CA certificate verification path where to find CA
143         #   certificates for client authentication or alternatively one
144         #   huge file containing all of them (file must be PEM encoded)
145         #   Note: Inside SSLCACertificatePath you need hash symlinks
146         #         to point to the certificate files. Use the provided
147         #         Makefile to update the hash symlinks after changes.
148         #SSLCACertificatePath /etc/ssl/certs/
149         #SSLCACertificateFile /etc/apache2/ssl.crt/ca-bundle.crt
150
151         #   Certificate Revocation Lists (CRL):
152         #   Set the CA revocation path where to find CA CRLs for client
153         #   authentication or alternatively one huge file containing all
154         #   of them (file must be PEM encoded)
155         #   Note: Inside SSLCARevocationPath you need hash symlinks
156         #         to point to the certificate files. Use the provided
157         #         Makefile to update the hash symlinks after changes.
158         #SSLCARevocationPath /etc/apache2/ssl.crl/
159         #SSLCARevocationFile /etc/apache2/ssl.crl/ca-bundle.crl
160
161         #   Client Authentication (Type):
162         #   Client certificate verification type and depth.  Types are
163         #   none, optional, require and optional_no_ca.  Depth is a
164         #   number which specifies how deeply to verify the certificate
165         #   issuer chain before deciding the certificate is not valid.
166         #SSLVerifyClient require
167         #SSLVerifyDepth  10
168
169         #   Access Control:
170         #   With SSLRequire you can do per-directory access control based
171         #   on arbitrary complex boolean expressions containing server
172         #   variable checks and other lookup directives.  The syntax is a
173         #   mixture between C and Perl.  See the mod_ssl documentation
174         #   for more details.
175         #<Location />
176         #SSLRequire (    %{SSL_CIPHER} !~ m/^(EXP|NULL)/ \
177         #            and %{SSL_CLIENT_S_DN_O} eq "Snake Oil, Ltd." \
178         #            and %{SSL_CLIENT_S_DN_OU} in {"Staff", "CA", "Dev"} \
179         #            and %{TIME_WDAY} >= 1 and %{TIME_WDAY} <= 5 \
180         #            and %{TIME_HOUR} >= 8 and %{TIME_HOUR} <= 20       ) \
181         #           or %{REMOTE_ADDR} =~ m/^192\.76\.162\.[0-9]+$/
182         #</Location>
183
184         #   SSL Engine Options:
185         #   Set various options for the SSL engine.
186         #   o FakeBasicAuth:
187         #     Translate the client X.509 into a Basic Authorisation.  This means that
188         #     the standard Auth/DBMAuth methods can be used for access control.  The
189         #     user name is the `one line' version of the client's X.509 certificate.
190         #     Note that no password is obtained from the user. Every entry in the user
191         #     file needs this password: `xxj31ZMTZzkVA'.
192         #   o ExportCertData:
193         #     This exports two additional environment variables: SSL_CLIENT_CERT and
194         #     SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
195         #     server (always existing) and the client (only existing when client
196         #     authentication is used). This can be used to import the certificates
197         #     into CGI scripts.
198         #   o StdEnvVars:
199         #     This exports the standard SSL/TLS related `SSL_*' environment variables.
200         #     Per default this exportation is switched off for performance reasons,
201         #     because the extraction step is an expensive operation and is usually
202         #     useless for serving static content. So one usually enables the
203         #     exportation for CGI and SSI requests only.
204         #   o StrictRequire:
205         #     This denies access when "SSLRequireSSL" or "SSLRequire" applied even
206         #     under a "Satisfy any" situation, i.e. when it applies access is denied
207         #     and no other module can change it.
208         #   o OptRenegotiate:
209         #     This enables optimized SSL connection renegotiation handling when SSL
210         #     directives are used in per-directory context.
211         #SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
212         <FilesMatch "\.(cgi|shtml|phtml|php)$">
213                 SSLOptions +StdEnvVars
214         </FilesMatch>
215         <Directory /usr/lib/cgi-bin>
216                 SSLOptions +StdEnvVars
217         </Directory>
218
219         #   SSL Protocol Adjustments:
220         #   The safe and default but still SSL/TLS standard compliant shutdown
221         #   approach is that mod_ssl sends the close notify alert but doesn't wait for
222         #   the close notify alert from client. When you need a different shutdown
223         #   approach you can use one of the following variables:
224         #   o ssl-unclean-shutdown:
225         #     This forces an unclean shutdown when the connection is closed, i.e. no
226         #     SSL close notify alert is send or allowed to received.  This violates
227         #     the SSL/TLS standard but is needed for some brain-dead browsers. Use
228         #     this when you receive I/O errors because of the standard approach where
229         #     mod_ssl sends the close notify alert.
230         #   o ssl-accurate-shutdown:
231         #     This forces an accurate shutdown when the connection is closed, i.e. a
232         #     SSL close notify alert is send and mod_ssl waits for the close notify
233         #     alert of the client. This is 100% SSL/TLS standard compliant, but in
234         #     practice often causes hanging connections with brain-dead browsers. Use
235         #     this only for browsers where you know that their SSL implementation
236         #     works correctly.
237         #   Notice: Most problems of broken clients are also related to the HTTP
238         #   keep-alive facility, so you usually additionally want to disable
239         #   keep-alive for those clients, too. Use variable "nokeepalive" for this.
240         #   Similarly, one has to force some clients to use HTTP/1.0 to workaround
241         #   their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
242         #   "force-response-1.0" for this.
243         BrowserMatch "MSIE [2-6]" \
244                 nokeepalive ssl-unclean-shutdown \
245                 downgrade-1.0 force-response-1.0
246         # MSIE 7 and newer should be able to use keepalive
247         BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
248
249   </VirtualHost>
250   </IfModule>
251
252 Configure and run apache::
253
254   a2enmod ssl
255   a2enmod rewrite
256   a2dissite default
257   a2ensite pithos
258   a2ensite pithos-ssl
259   mkdir /var/www/pithos
260   mkdir /var/www/pithos_web_client
261   /etc/init.d/apache2 restart
262
263 Useful alias to add in ``~/.bashrc``::
264
265   alias pithos-sync='cd /pithos && git pull && python setup.py build_sphinx && /etc/init.d/apache2 restart'
266
267 Shibboleth Setup
268 ----------------
269
270 Install package::
271
272   apt-get install libapache2-mod-shib2
273
274 Setup the files in ``/etc/shibboleth``.
275
276 Add in ``/etc/apache2/sites-available/pithos`` and ``/etc/apache2/sites-available/pithos-ssl``::
277
278         ShibConfig /etc/shibboleth/shibboleth2.xml
279         Alias      /shibboleth-sp /usr/share/shibboleth 
280
281         <Location /api/login>
282                 AuthType shibboleth
283                 ShibRequireSession On
284                 ShibUseHeaders On
285                 require valid-user
286         </Location>
287
288 Configure and run apache::
289
290   a2enmod shib2
291   /etc/init.d/apache2 restart
292   /etc/init.d/shibd restart
293
294 MySQL Setup
295 -----------
296
297 If using MySQL instead of SQLite for the database engine, consider the following.
298
299 Server side::
300
301   apt-get install mysql-server
302
303 Edit ``/etc/mysql/my.cnf`` to allow network connections and restart the server.
304
305 Create database and user::
306
307   CREATE DATABASE pithos;
308   GRANT ALL ON pithos.* TO pithos@localhost IDENTIFIED BY 'password';
309   GRANT ALL ON pithos.* TO pithos@'%' IDENTIFIED BY 'password';
310
311 Client side::
312
313   apt-get install mysql-client
314
315 It helps to create a ``~/.my.cnf`` file, for automatically connecting to the server::
316
317   [client]
318   user = pithos
319   password = 'password'
320   host = pithos-storage.dev.grnet.gr
321
322   [mysql]
323   database = pithos
324
325 PostgreSQL Setup
326 ----------------
327
328 If using PostgreSQL instead of SQLite for the database engine, consider the following.
329
330 Server side::
331
332   apt-get install postgresql
333
334 Edit ``/etc/postgresql/8.4/main/postgresql.conf`` and ``/etc/postgresql/8.4/main/pg_hba.conf`` to allow network connections and restart the server.
335
336 Create database and user::
337
338   CREATE DATABASE pithos WITH ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' TEMPLATE=template0;
339   CREATE USER pithos WITH PASSWORD 'password';
340   GRANT ALL PRIVILEGES ON DATABASE pithos TO pithos;
341
342 Client side::
343
344   apt-get install postgresql-client
345
346 It helps to create a ``~/.pgpass`` file, for automatically passing the password to the server::
347
348   pithos-storage.dev.grnet.gr:5432:pithos:pithos:password
349
350 Connect with::
351
352   psql -h pithos-storage.dev.grnet.gr -U pithos
353