Update documentation
[flowspy] / doc / source / install.rst
1 ************
2 Installation
3 ************
4
5 .. toctree::
6    :maxdepth: 2
7
8 Ubuntu 12.04.3 (64) - Django 1.3.x
9 ==================================
10
11 This guide assumes that installation is carried out in /srv/flowspy directory. If other directory is to be used, please change the corresponding configuration files. It is also assumed that the root user will perform every action.
12
13 Required system packages
14 ------------------------
15
16 Update and install the required packages::
17
18         apt-get update
19         apt-get upgrade
20         apt-get install mysql-server apache2 memcached libapache2-mod-proxy-html gunicorn beanstalkd python-django python-django-extensions python-django-south python-django-tinymce tinymce python-mysqldb python-yaml python-memcache python-django-registration python-ipaddr python-lxml mysql-client git python-django-celery python-paramiko python-gevent vim
21
22 .. note::
23  Set username and password for mysql if used
24
25 .. note::
26         If you wish to deploy an outgoing mail server, now it is time to do it. Otherwise you could set FoD to send out mails via a third party account
27
28 Create a database
29 -----------------
30 If you are using mysql, you should create a database::
31
32         mysql -u root -p -e 'create database fod'
33
34
35 Required application packages
36 -----------------------------
37 Get the required packages and install them
38
39 - ncclient: NETCONF python client::
40
41         cd ~
42         git clone https://github.com/leopoul/ncclient.git
43         cd ncclient
44         python setup.py install
45
46 - nxpy: Python Objects from/to XML proxy::
47
48         cd ~
49         git clone https://code.grnet.gr/git/nxpy
50         cd nxpy
51         python setup.py install
52
53 - flowspy: core application. Installation is done at /srv/flowspy::
54
55         cd /srv
56         git clone https://code.grnet.gr/git/flowspy
57         cd flowspy
58
59 Application configuration
60 =========================
61
62 Copy settings.py.dist to settings.py::
63
64         cp settings.py.dist settings.py
65
66 Edit settings.py file and set the following according to your configuration::
67
68         ADMINS: set your admin name and email (assuming that your server can send notifications)
69         DATABASES (to point to your local database). You could use views instead of tables for models: peer, peercontacts, peernetworks. For this to work we suggest MySQL with MyISAM db engine
70         SECRET_KEY : Make this unique, and don't share it with anybody
71         STATIC_URL (static media directory) . If you have followed the above this should be: /srv/flowspy/static
72         TEMPLATE_DIRS : If you have followed the above this should be: /srv/flowspy/templates
73         CACHE_BACKEND:  If you have followed the above this should be: memcached://127.0.0.1:11211/?timeout=3600
74         Alternatively you could go for redis with the corresponding Django client lib.
75         NETCONF_DEVICE (tested with Juniper EX4200 but any BGP enabled Juniper should work). This is the flowspec capable device
76         NETCONF_USER (enable ssh and netconf on device)
77         NETCONF_PASS
78         If beanstalk is selected the following should be left intact.
79         BROKER_HOST (beanstalk host)
80         BROKER_PORT (beanstalk port)
81         SERVER_EMAIL
82         EMAIL_SUBJECT_PREFIX
83         If beanstalk is selected the following should be left intact.
84         BROKER_URL (beanstalk url)
85         SHIB_AUTH_ENTITLEMENT (if you go for Shibboleth authentication)
86         NOTIFY_ADMIN_MAILS (bcc mail addresses)
87         PROTECTED_SUBNETS (subnets for which source or destination address will prevent rule creation and notify the NOTIFY_ADMIN_MAILS)
88         The whois client is meant to be used in case you have inserted peers with their ASes in the peers table and wish to get network info for each one in an automated manner.
89         PRIMARY_WHOIS
90         ALTERNATE_WHOIS
91         If you wish to deploy FoD with Shibboleth change the following attributes according to your setup:
92         SHIB_AUTH_ENTITLEMENT = 'urn:mace'
93         SHIB_ADMIN_DOMAIN = 'example.com'
94         SHIB_LOGOUT_URL = 'https://example.com/Shibboleth.sso/Logout'
95         SHIB_USERNAME = ['HTTP_EPPN']
96         SHIB_MAIL = ['mail', 'HTTP_MAIL', 'HTTP_SHIB_INETORGPERSON_MAIL']
97         SHIB_FIRSTNAME = ['HTTP_SHIB_INETORGPERSON_GIVENNAME']
98         SHIB_LASTNAME = ['HTTP_SHIB_PERSON_SURNAME']
99         SHIB_ENTITLEMENT = ['HTTP_SHIB_EP_ENTITLEMENT']
100
101 If you have not installed an outgoing mail server you can always use your own account (either corporate or gmail, hotmail ,etc) by adding the following lines in settings.py::
102
103         EMAIL_USE_TLS = True #(or False)
104         EMAIL_HOST = 'smtp.example.com'
105         EMAIL_HOST_USER = 'username'
106         EMAIL_HOST_PASSWORD = 'yourpassword'
107         EMAIL_PORT = 587 #(outgoing)
108
109
110 .. note::
111         Soon we will release a version with django-registration as a means to add users and Shibboleth as an alternative
112
113 Let's move on with some copies and dir creations::
114
115         cp urls.py.dist urls.py
116         mkdir log
117         chown -R root:www-data log/
118         chmod -R g+w log
119
120 System configuration
121 ====================
122 Apache operates as a gunicorn Proxy with WSGI and Shibboleth modules enabled.
123 Depending on the setup the apache configuration may vary::
124
125         a2enmod rewrite
126         a2enmod proxy
127         a2enmod ssl
128         a2enmod proxy_http
129
130 If shibboleth is to be used::
131
132         apt-get install libapache2-mod-shib2
133         a2enmod shib2
134
135 Now it is time to configure beanstalk, gunicorn, celery and apache.
136
137 beanstalkd
138 ----------
139
140 Enable beanstalk by editting /etc/default/beanstalkd::
141
142         vim /etc/default/beanstalkd
143
144 Uncomment the line **START=yes** to enable beanstalk
145
146 Start beanstalkd::
147
148         service beanstalkd start
149
150 gunicorn.d
151 ----------
152
153 create and edit /etc/gunicorn.d/fod::
154
155         vim /etc/gunicorn.d/fod
156
157 FoD is served via gunicorn and is then proxied by Apache. If the above directory conventions have been followed so far, then your configuration should be::
158
159         CONFIG = {
160             'mode': 'django',
161             'working_dir': '/srv/flowspy',
162             'args': (
163                 '--bind=127.0.0.1:8081',
164                 '--workers=1',
165                 '--timeout=360',
166                 '--worker-class=egg:gunicorn#gevent',
167                 '--log-level=debug',
168                 'settings.py',
169             ),
170         }
171
172 celery.d
173 --------
174
175 Celery is used over beanstalkd to apply firewall rules in a serial manner so that locks are avoided on the flowspec capable device. In our setup celery runs via django. That is why the python-django-celery package was installed.
176
177 .. note::
178         Make sure that /etc/init.d/celeryd exists.
179
180 celeryd requires a /etc/default/celeryd file to be in place.
181 Thus we are going to create this file (/etc/default/celeryd)::
182
183         vim /etc/default/celeryd
184
185 Again if the directory conventions have been followed the file should be::
186
187         # Name of nodes to start, here we have a single node
188         CELERYD_NODES="w1"
189         # or we could have three nodes:
190         #CELERYD_NODES="w1 w2 w3"
191
192         # Where to chdir at start.
193         CELERYD_CHDIR="/srv/flowspy/"
194         # How to call "manage.py celeryd_multi"
195         CELERYD_MULTI="$CELERYD_CHDIR/manage.py celeryd_multi"
196
197         # How to call "manage.py celeryctl"
198         CELERYCTL="$CELERYD_CHDIR/manage.py celeryctl"
199
200         # Extra arguments to celeryd
201         #CELERYD_OPTS="--time-limit=300 --concurrency=8"
202         CELERYD_OPTS="-E -B"
203         # Name of the celery config module.
204         CELERY_CONFIG_MODULE="celeryconfig"
205
206         # %n will be replaced with the nodename.
207         CELERYD_LOG_FILE="$CELERYD_CHDIR/celery_var/log/celery/%n.log"
208         CELERYD_PID_FILE="$CELERYD_CHDIR/celery_var/run/celery/%n.pid"
209
210         # Workers should run as an unprivileged user.
211         CELERYD_USER="root"
212         CELERYD_GROUP="root"
213
214         # Name of the projects settings module.
215         export DJANGO_SETTINGS_MODULE="settings"
216
217 Apache
218 ------
219 Apache proxies gunicorn. Things are more flexible here as you may follow your own configuration and conventions. Create and edit /etc/apache2/sites-available/fod. You should set <server_name> and <admin_mail> along with your certificates. If under testing environment, you can use the provided snakeoil certs. If you do not intent to use Shibboleth delete or comment the corresponding configuration parts inside **Shibboleth configuration** ::
220
221         vim /etc/apache2/sites-available/fod
222
223 Again if the directory conventions have been followed the file should be::
224
225         <VirtualHost *:80>
226                 ServerAdmin webmaster@localhost
227                 ServerName      <server_name>
228                 DocumentRoot /var/www
229                 <Directory />
230                         Options FollowSymLinks
231                         AllowOverride None
232                 </Directory>
233                 <Directory /var/www/>
234                         Options Indexes FollowSymLinks MultiViews
235                         AllowOverride None
236                         Order allow,deny
237                         allow from all
238                 </Directory>
239
240                 ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
241                 <Directory "/usr/lib/cgi-bin">
242                         AllowOverride None
243                         Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
244                         Order allow,deny
245                         Allow from all
246                 </Directory>
247
248                 ErrorLog ${APACHE_LOG_DIR}/error.log
249
250                 # Possible values include: debug, info, notice, warn, error, crit,
251                 # alert, emerg.
252                 LogLevel warn
253
254                 CustomLog ${APACHE_LOG_DIR}/access.log combined
255
256             Alias /doc/ "/usr/share/doc/"
257             <Directory "/usr/share/doc/">
258                 Options Indexes MultiViews FollowSymLinks
259                 AllowOverride None
260                 Order deny,allow
261                 Deny from all
262                 Allow from 127.0.0.0/255.0.0.0 ::1/128
263             </Directory>
264
265                 RewriteEngine On
266                 RewriteCond %{HTTPS} off
267                 RewriteRule ^/(.*) https://<server_name>/$1 [L,R]
268
269         </VirtualHost>
270         <VirtualHost *:443>
271                 ServerName       <server_name>
272                 ServerAdmin             <admin_mail>
273                 ServerSignature         On
274
275                 SSLEngine on
276                 SSLCertificateFile      /etc/ssl/certs/example.com.crt
277                 SSLCertificateChainFile /etc/ssl/certs/example.com.crt
278                 SSLCertificateKeyFile   /etc/ssl/private/example.com.key
279
280                 AddDefaultCharset       UTF-8
281                 IndexOptions            +Charset=UTF-8
282
283                 # Shibboleth configuration
284                 ShibConfig              /etc/shibboleth/shibboleth2.xml
285                 Alias                   /shibboleth-sp  /usr/share/shibboleth
286
287                 <Location /fod/login>
288                 AuthType shibboleth
289                 ShibRequireSession On
290                 ShibUseHeaders On
291                 require valid-user
292             </Location>
293
294                 # Shibboleth debugging CGI script
295                 ScriptAlias /shibboleth/test /usr/lib/cgi-bin/shibtest.cgi
296                 <Location /shibboleth/test>
297                         AuthType shibboleth
298                         ShibRequireSession On
299                         ShibUseHeaders On
300                         require valid-user
301                 </Location>
302
303                 <Location /Shibboleth.sso>
304                         SetHandler shib
305                 </Location>
306
307                 # End of Shibboleth configuration
308
309                 <Location /admin/media/>
310                         SetHandler      None
311                 </Location>
312
313                 Alias /admin/media      /usr/share/pyshared/django/contrib/admin/media
314                 Alias /media  /usr/share/pyshared/django/contrib/admin/media
315                         DocumentRoot /var/www
316                 <Directory /var/www/>
317                         Options Indexes FollowSymLinks MultiViews
318                         AllowOverride None
319                         Order allow,deny
320                         allow from all
321                 </Directory>
322
323
324
325                 <Proxy *>
326                 Order allow,deny
327                 Allow from all
328                 </Proxy>
329
330                 SSLProxyEngine        off
331                 ProxyErrorOverride    off
332             ProxyTimeout    28800
333                 ProxyPass        /fod http://localhost:8081/fod retry=0
334                 ProxyPassReverse /fod http://localhost:8081/fod
335
336                 LogLevel warn
337                 ErrorLog /var/log/apache2/ssl-error.log
338                 CustomLog /var/log/apache2/ssl-access.log combined
339
340
341
342
343                 Alias /fodstatic        /srv/flowspy/static
344
345         </VirtualHost>
346
347 You are not far away from deploying FoD. When asked for a super user, create one::
348
349         cd /srv/flowspy
350         python manage.py syncdb
351         python manage.py migrate
352
353 Restart, gunicorn and apache::
354
355         service gunicorn restart && service apache2 restart
356
357 Testing the platform
358 ====================
359 Log in to the admin interface via https://<your ip>/fod/admin. Go to Peer ranges and add a new range (part of/or a complete subnet), eg. 83.212.0.0/19
360 Go to Peers and add a new peer, eg. id: 1, name: Test, AS: 16503, tag: TEST and move the network you have crteated from Avalable to Chosen. From the admin front, go to User, and edit your user. From the bottom of the page, select the TEST peer and save.
361 Last but not least, modify as required the existing (example.com) Site instance. You are done. As you are logged-n via the admin, there is no need for Shibboleth. Go to https://<your ip>/fod/ and create a new rule. Your rule should be applied on the flowspec capable device after aprox. 10 seconds.
362
363 Branding
364 ========
365 Via the admin interface you can modify flatpages to suit your needs
366
367 Logos
368 -----
369 Inside the static folder you will find two empty png files: fod_logo.xcf (Gimp file) and shib_login.dist.png. Edit those two with your favourite image processing software and save them as fod_logo.png (under static/img/) and shib_login.png (under static/). Image sizes are optimized to operate without any other code changes. In case you want to incorporate images of different sizes you have to fine tune css and/or html as well.
370
371 Footer
372 ------
373 Under the templates folder (templates), you can alter the footer.html file to include your own footer messages, badges, etc.
374
375 Welcome Page
376 ------------
377 Under the templates folder (templates), you can alter the welcome page - welcome.html with your own images, carousel, videos, etc.