Installation sur Debian 12
Prérequis
Serveur web
apt install apache2 libapache2-mod-wsgi-py3
systemctl enable apache2
Bases de données
apt install postgresql
systemctl enable postgresql
cat /etc/postgresql/15/main/pg_hba.conf
local all postgres peer
local db user md5
Création d'un utilisateur:
su - postgres
createuser --pwprompt user
createdb --owner=user db
exit
Accès à la socket Postgres:
adduser www-data postgres
systemctl restart postgresql
Application web
Pour l'installation, vous pouvez soit récupérer la dernière version disponible ou utiliser directement le dépôt git.
Utilisation d'une version
La liste des versions se trouve ici: https://gitlab.insa-rouen.fr/dsi/dev/greves/-/releases
La dernière version git
cd /opt
git clone https://gitlab.insa-rouen.fr/dsi/dev/greves.git
Configuration
Toute la configuration doit être dans le fichier conf/local_settings.py (nouveau fichier). Cette configuration va remplacer la configuration se trouvant dans conf/settings.py. Voici un exemple de contenu:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": "db",
"USER": "user",
"PASSWORD": "PASS",
"HOST": "/var/run/postgresql",
}
}
DEBUG = False
SECURE_SSL_REDIRECT = True
SECURE_HSTS_SECONDS = 31536000
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
CSRF_COOKIE_SECURE = True
SESSION_COOKIE_SECURE = True
SECURE_HSTS_PRELOAD = True
ALLOWED_HOSTS = ["greves.example.com"]
SECRET_KEY = "django-insecure--9w@7o0@qn^o$fby#equd3&()qfzyean3ew75(+lytfr0(+n*7"
ADMINS = [
("Admin", "admin@example.com"),
]
EMAIL_HOST = "smtp.example.com"
EMAIL_PORT = 25
SERVER_EMAIL = "noreply@example.com"
EMAIL_SUBJECT_PREFIX = "[GRV] "
CAS_SERVER_URL = "https://cas.example.com/cas/"
LDAP_SERVER = "ldap://ldap.example.com"
LDAP_USER = "cn=manager,dc=example,dc=com"
LDAP_PASSWD = "admin"
# PosixGroups
LDAP_GROUPS = "ou=SambaGroups,dc=example,dc=com"
LDAP_GROUP_ATTR = "cn"
LDAP_USERS = "ou=people,dc=example,dc=com"
LDAP_USER_ATTR = "uid"
# les groupes d'utilisateurs
GROUPS = ["personnels"]
# durée de conservation des déclarations
NB_JOURS_CONSERVATION = 90
Python
apt install python3-pip python3-poetry
cd /opt/greves
poetry config virtualenvs.in-project true
./oto.sh prod_up_2
Configuration des tâches automatiques (crontab)
0 7 * * 1-5 /opt/greves/.venv/bin/python /opt/greves/manage.py sync_ldap_users_and_groups > /dev/null
0 7 * * 1-5 /opt/greves/.venv/bin/python /opt/greves/manage.py suppression_des_anciennes_greves > /dev/null
Import des utilisateurs
On peut maintenant importer les utilisateurs autorisés depuis le LDAP:
/opt/greves/.venv/bin/python /opt/greves/manage.py sync_ldap_users_and_groups
Activation d'un compte administrateur
cd /opt/greves
./oto.sh prod_sh
> user = User.objects.get(username="votre_login")
> user.is_staff = True
> user.is_superuser = True
> user.save()
Configuration Apache
Référence: https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/modwsgi/
Exemple de configuration Apache (/etc/apache2/sites-available/greves.conf):
ServerSignature off
ServerTokens prod
ServerAdmin admin@example.com
Header edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure;SameSite=None
<VirtualHost greves.example.com:80>
Redirect permanent / https://greves.example.com/
</VirtualHost>
<VirtualHost greves.example.com:443>
ServerName greves.example.com
SSLEngine on
SSLProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1
SSLCipherSuite ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384
SSLHonorCipherOrder off
SSLSessionTickets off
SSLOptions +StrictRequire
SSLCertificateFile /etc/apache2/ssl/greves.crt
SSLCertificateKeyFile /etc/apache2/ssl/greves.key
SSLCertificateChainFile /etc/apache2/ssl/greves.ac
Header set Content-Security-Policy "script-src 'self' https://greves.example.com"
DocumentRoot /var/www/html/
Alias /favicon.ico /opt/greves/static/core/images/favicon.png
Alias /static/ /opt/greves/static/
<Directory /opt/greves/static>
Require all granted
</Directory>
WSGIDaemonProcess greves python-home=/opt/greves/.venv python-path=/opt/greves
WSGIProcessGroup greves
WSGIScriptAlias / /opt/greves/conf/wsgi.py process-group=greves
<Directory /opt/greves/conf>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
Activation des modules complémentaires et démarrage:
a2dissite 000-default
a2ensite greves
a2enmod ssl
a2enmod rewrite
a2enmod headers
systemctl restart apache2