Use 401 error when missing token and 403 when forbidden.
[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-mysqldb 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 /pithos/htdocs
35     Alias /ui "/var/www/pithos_web_client"
36     Alias /docs "/pithos/docs/build/html"
37
38     <Directory />
39         Options Indexes FollowSymLinks
40         AllowOverride None
41         Order allow,deny
42         Allow from all
43     </Directory>
44
45     RewriteEngine On
46     RewriteRule ^/v(.*) /api/v$1 [PT]
47     RewriteRule ^/public(.*) /api/public$1 [PT]
48     RewriteRule ^/login(.*) https://%{HTTP_HOST}%{REQUEST_URI}
49     RewriteRule ^/admin(.*) https://%{HTTP_HOST}%{REQUEST_URI}
50
51     WSGIScriptAlias /api /pithos/pithos/wsgi/pithos.wsgi
52     # WSGIDaemonProcess pithos
53     # WSGIProcessGroup pithos
54
55     LogLevel warn
56     ErrorLog ${APACHE_LOG_DIR}/pithos.error.log
57     CustomLog ${APACHE_LOG_DIR}/pithos.access.log combined
58   </VirtualHost>
59
60 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)::
61
62   <IfModule mod_ssl.c>
63   <VirtualHost _default_:443>
64     ServerAdmin webmaster@pithos.dev.grnet.gr
65     ServerName pithos.dev.grnet.gr
66
67     DocumentRoot /pithos/htdocs
68     Alias /ui "/var/www/pithos_web_client"
69     Alias /docs "/pithos/docs/build/html"
70
71     <Directory />
72         Options Indexes FollowSymLinks
73         AllowOverride None
74         Order allow,deny
75         Allow from all
76     </Directory>
77
78     RewriteEngine On
79     RewriteRule ^/v(.*) /api/v$1 [PT]
80     RewriteRule ^/public(.*) /api/public$1 [PT]
81     RewriteRule ^/login(.*) /api/login$1 [PT]
82     RewriteRule ^/admin(.*) /api/admin$1 [PT]
83
84     WSGIScriptAlias /api /pithos/pithos/wsgi/pithos.wsgi
85     # WSGIDaemonProcess pithos
86     # WSGIProcessGroup pithos
87
88     ShibConfig /etc/shibboleth/shibboleth2.xml
89     Alias      /shibboleth-sp /usr/share/shibboleth 
90
91     <Location /api/login>
92         AuthType shibboleth
93         ShibRequireSession On
94         ShibUseHeaders On
95         require valid-user
96     </Location>
97
98     LogLevel warn
99     ErrorLog ${APACHE_LOG_DIR}/pithos.error.log
100     CustomLog ${APACHE_LOG_DIR}/pithos.access.log combined
101
102     SSLEngine on
103     SSLCertificateFile    /etc/ssl/certs/pithos.dev.grnet.gr.crt
104     SSLCertificateKeyFile /etc/ssl/private/pithos.dev.grnet.gr.key
105   </VirtualHost>
106   </IfModule>
107
108 Add in ``/etc/apache2/mods-available/wsgi.conf``::
109
110   WSGIChunkedRequest On
111
112 Configure and run apache::
113
114   a2enmod ssl
115   a2enmod rewrite
116   a2dissite default
117   a2ensite pithos
118   a2ensite pithos-ssl
119   mkdir /var/www/pithos
120   mkdir /var/www/pithos_web_client
121   /etc/init.d/apache2 restart
122
123 Useful alias to add in ``~/.bashrc``::
124
125   alias pithos-sync='cd /pithos && git pull && python setup.py build_sphinx && /etc/init.d/apache2 restart'
126
127 Gunicorn Setup
128 --------------
129
130 Add in ``/etc/apt/sources.list``::
131
132   deb http://backports.debian.org/debian-backports squeeze-backports main
133
134 Then::
135
136   apt-get update
137   apt-get -t squeeze-backports install gunicorn
138   apt-get -t squeeze-backports install python-gevent
139
140 Create ``/etc/gunicorn.d/pithos``::
141
142   CONFIG = {
143    'mode': 'django',
144    'working_dir': '/pithos/pithos',
145    'user': 'www-data',
146    'group': 'www-data',
147    'args': (
148         '--bind=[::]:8080',
149         '--worker-class=egg:gunicorn#gevent',
150         '--workers=4',
151         '--log-level=debug',
152         '/pithos/pithos/settings.py',
153    ),
154   }
155
156 Replace the ``WSGI*`` directives in ``/etc/apache2/sites-available/pithos`` and ``/etc/apache2/sites-available/pithos-ssl`` with::
157
158   <Proxy *>
159     Order allow,deny
160     Allow from all
161   </Proxy>
162
163   SetEnv                proxy-sendchunked
164   SSLProxyEngine        off
165   ProxyErrorOverride    off
166
167   ProxyPass        /api http://localhost:8080 retry=0
168   ProxyPassReverse /api http://localhost:8080
169
170 Configure and run::
171
172   /etc/init.d/gunicorn restart
173   a2enmod proxy
174   a2enmod proxy_http
175   /etc/init.d/apache2 restart
176
177 Shibboleth Setup
178 ----------------
179
180 Install package::
181
182   apt-get install libapache2-mod-shib2
183
184 Setup the files in ``/etc/shibboleth``.
185
186 Add in ``/etc/apache2/sites-available/pithos-ssl``::
187
188   ShibConfig /etc/shibboleth/shibboleth2.xml
189   Alias      /shibboleth-sp /usr/share/shibboleth 
190
191   <Location /api/login>
192     AuthType shibboleth
193     ShibRequireSession On
194     ShibUseHeaders On
195     require valid-user
196   </Location>
197
198 Configure and run apache::
199
200   a2enmod shib2
201   /etc/init.d/apache2 restart
202   /etc/init.d/shibd restart
203
204 The following tokens should be available at the destination, after passing through the apache module::
205
206   eppn # eduPersonPrincipalName
207   Shib-InetOrgPerson-givenName
208   Shib-Person-surname
209   Shib-Person-commonName
210   Shib-InetOrgPerson-displayName
211   Shib-EP-Affiliation
212   Shib-Session-ID
213
214 MySQL Setup
215 -----------
216
217 If using MySQL instead of SQLite for the database engine, consider the following.
218
219 Server side::
220
221   apt-get install mysql-server
222
223 Add in ``/etc/mysql/conf.d/pithos.cnf``::
224
225   [mysqld]
226   sql-mode="NO_AUTO_VALUE_ON_ZERO"
227
228 Edit ``/etc/mysql/my.cnf`` to allow network connections and restart the server.
229
230 Create database and user::
231
232   CREATE DATABASE pithos CHARACTER SET utf8 COLLATE utf8_bin;
233   GRANT ALL ON pithos.* TO pithos@localhost IDENTIFIED BY 'password';
234   GRANT ALL ON pithos.* TO pithos@'%' IDENTIFIED BY 'password';
235
236 Client side::
237
238   apt-get install mysql-client
239
240 It helps to create a ``~/.my.cnf`` file, for automatically connecting to the server::
241
242   [client]
243   user = pithos
244   password = 'password'
245   host = pithos-storage.dev.grnet.gr
246
247   [mysql]
248   database = pithos
249
250 PostgreSQL Setup
251 ----------------
252
253 If using PostgreSQL instead of SQLite for the database engine, consider the following.
254
255 Server side::
256
257   apt-get install postgresql
258
259 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.
260
261 Create database and user::
262
263   CREATE DATABASE pithos WITH ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' TEMPLATE=template0;
264   CREATE USER pithos WITH PASSWORD 'password';
265   GRANT ALL PRIVILEGES ON DATABASE pithos TO pithos;
266
267 Client side::
268
269   apt-get install postgresql-client
270
271 It helps to create a ``~/.pgpass`` file, for automatically passing the password to the server::
272
273   pithos-storage.dev.grnet.gr:5432:pithos:pithos:password
274
275 Connect with::
276
277   psql -h pithos-storage.dev.grnet.gr -U pithos
278