Compare commits

...

No commits in common. "d31846f77c07da61f252308b06c2a63530689ce8" and "4232b0758dde467c21877e25b9148e770bc64fc0" have entirely different histories.

19 changed files with 554 additions and 3 deletions

@ -1 +0,0 @@
Subproject commit c56205576e35708527051055203cbabe6764f73e

2
nextcloud-pica/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.secrets
.env

View File

39
nextcloud-pica/README.md Normal file
View File

@ -0,0 +1,39 @@
## NextCloud
Ce dossier contient les ressources nécessaires pour lancer une ou plusieurs instances NextCloud.
Voir également le [wiki](https://wiki.picasoft.net/doku.php?id=technique:adminserv:nextcloud).
### Configuration
Quasiment aucune configuration n'est effectuée via les fichiers de ce dépôt, et on préfère l'interface web.
Le défaut est qu'il n'est pas possible de lancer des instances NextCloud **vraiment** personnalisées depuis ce dépôt, mais c'est parce que le format des fichiers de configuration est amené à évoluer et que NextCloud effectue des migrations automatiques lors des mises à jour.
Versionner les fichiers de configuration serait donc en conflit avec les modifications automatiques effectuées par NextCloud lors des mises à jour et des changements dans l'interface.
Les fichiers `nginx.conf` sont repris de [cet exemple](https://github.com/nextcloud/docker/blob/master/.examples/docker-compose/with-nginx-proxy/postgres/fpm/web/nginx.conf).
### Lancement
Copier les fichiers `.secrets.example` en `.secrets` et remplacer les valeurs.
Lancer `docker-compose up -d`.
### Mise à jour
Pour mettre à jour l'instance de Picasoft, il suffit de mettre à jour le tag de l'image officielle de NextCloud.
Attention : **toutes les mises à jour de version majeure doivent se faire une par une**. Les logs applicatifs détaillent la mise à jour.
Exemple :
* 15 -> 16, puis
* 16 -> 17, puis
* 17 -> 18.
Sinon, il y a risque de casse.
### Mise à jour de MariaDB
[Selon la documentation](https://mariadb.com/kb/en/upgrading-between-major-mariadb-versions/) :
> MariaDB is designed to allow easy upgrades. You should be able to trivially upgrade from ANY earlier MariaDB version to the latest one (for example MariaDB 5.5.x to MariaDB 10.5.x), usually in a few seconds.
L'idée est d'éteindre le conteneur applicatif (NextCloud), puis de lancer la nouvelle version du conteneur, d'entrer dedans, de lancer la commande `mysql_upgrade` et de redémarrer le conteneur.

View File

@ -0,0 +1,114 @@
version: '3.7'
volumes:
nextcloud-db:
name: docker_nextcloud-db
nextcloud:
name: docker_nextcloud
networks:
nextcloud:
proxy:
external: true
services:
nextcloud-app:
image: nextcloud:23.0.4-fpm-alpine
container_name: nextcloud-app
restart: unless-stopped
volumes:
- nextcloud:/var/www/html
- ./zz-php-custom.ini:/usr/local/etc/php/conf.d/zz-php-custom.ini
- ./zz-php-fpm-custom.conf:/usr/local/etc/php-fpm.d/zz-php-custom.conf
environment:
- "TZ=Europe/Paris"
- POSTGRES_HOST=nextcloud-db
- REDIS_HOST=redis
env_file: ./secrets/librezo.secrets
extra_hosts:
- code.librezo.xyz:192.168.1.70
depends_on:
- nextcloud-db
- redis
networks:
- nextcloud
restart: unless-stopped
nextcloud-web:
image: nginx:alpine
container_name: nextcloud-web
volumes:
- nextcloud:/var/www/html:ro
- ./nginx.conf:/etc/nginx/nginx.conf:ro
env_file: ./secrets/librezo.secrets
extra_hosts:
- code.librezo.xyz:192.168.1.70
depends_on:
- nextcloud-app
environment:
TZ: Europe/Paris
networks:
- nextcloud
- proxy
labels:
traefik.http.routers.nextcloud-web.entrypoints: websecure
traefik.http.routers.nextcloud-web.rule: Host(`cloud.librezo.xyz`)
traefik.http.services.nextcloud-web.loadbalancer.server.port: 80
traefik.enable: true
# https://docs.nextcloud.com/server/16/admin_manual/configuration_server/reverse_proxy_configuration.html
traefik.http.routers.nextcloud-web.middlewares: nextcloud-web@docker
traefik.http.middlewares.nextcloud-web.redirectregex.permanent: true
traefik.http.middlewares.nextcloud-web.redirectregex.regex: ^/.well-known/(card|cal)dav
traefik.http.middlewares.nextcloud-web.redirectregex.replacement: /remote.php/dav/
restart: unless-stopped
redis:
image: redis
image: 'bitnami/redis:latest'
container_name: redis
environment:
- ALLOW_EMPTY_PASSWORD=yes
- "TZ=Europe/Paris"
networks:
- nextcloud
nextcloud-db:
image: postgres:11
container_name: nextcloud-db
volumes:
- nextcloud-db:/var/lib/postgresql/data
networks:
- nextcloud
env_file: ./secrets/librezo.secrets
environment:
- "TZ=Europe/Paris"
restart: unless-stopped
collabora:
image: libreoffice/online:master
container_name: collabora
# ports:
# - 9980:9980
# expose:
# - "9980"
environment:
- "TZ=Europe/Paris"
- domain=cloud\.librezo\.xyz
- username=nextcloud
- password=password
- serveur_name=code\.librezo\.xyz
- "extra_params=--o:ssl.enable=false --o:ssl.termination=true"
networks:
- nextcloud
- proxy
cap_add:
- MKNOD
restart:
unless-stopped
labels:
traefik.http.routers.collabora.entrypoints: websecure
traefik.http.routers.collabora.rule: Host(`code.librezo.xyz`)
traefik.http.services.collabora.loadbalancer.server.port: 9980
traefik.enable: true

182
nextcloud-pica/nginx.conf Normal file
View File

@ -0,0 +1,182 @@
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
set_real_ip_from 10.0.0.0/8;
set_real_ip_from 172.16.0.0/12;
set_real_ip_from 192.168.0.0/16;
real_ip_header X-Real-IP;
#gzip on;
upstream php-handler {
server nextcloud-app:9000;
}
server {
listen 80;
# HSTS settings
# WARNING: Only add the preload option once you read about
# the consequences in https://hstspreload.org/. This option
# will add the domain to a hardcoded list that is shipped
# in all major browsers and getting removed from this list
# could take several months.
#add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;" always;
# set max upload size and increase upload timeout:
client_max_body_size 512M;
client_body_timeout 300s;
fastcgi_buffers 64 4K;
# Enable gzip but do not remove ETag headers
gzip on;
gzip_vary on;
gzip_comp_level 4;
gzip_min_length 256;
gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/wasm application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;
# Pagespeed is not supported by Nextcloud, so if your server is built
# with the `ngx_pagespeed` module, uncomment this line to disable it.
#pagespeed off;
# HTTP response headers borrowed from Nextcloud `.htaccess`
add_header Referrer-Policy "no-referrer" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Download-Options "noopen" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Permitted-Cross-Domain-Policies "none" always;
add_header X-Robots-Tag "none" always;
add_header X-XSS-Protection "1; mode=block" always;
# Remove X-Powered-By, which is an information leak
fastcgi_hide_header X-Powered-By;
# Path to the root of your installation
root /var/www/html;
# Specify how to handle directories -- specifying `/index.php$request_uri`
# here as the fallback means that Nginx always exhibits the desired behaviour
# when a client requests a path that corresponds to a directory that exists
# on the server. In particular, if that directory contains an index.php file,
# that file is correctly served; if it doesn't, then the request is passed to
# the front-end controller. This consistent behaviour means that we don't need
# to specify custom rules for certain paths (e.g. images and other assets,
# `/updater`, `/ocm-provider`, `/ocs-provider`), and thus
# `try_files $uri $uri/ /index.php$request_uri`
# always provides the desired behaviour.
index index.php index.html /index.php$request_uri;
# Rule borrowed from `.htaccess` to handle Microsoft DAV clients
location = / {
if ( $http_user_agent ~ ^DavClnt ) {
return 302 /remote.php/webdav/$is_args$args;
}
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Make a regex exception for `/.well-known` so that clients can still
# access it despite the existence of the regex rule
# `location ~ /(\.|autotest|...)` which would otherwise handle requests
# for `/.well-known`.
location ^~ /.well-known {
# The rules in this block are an adaptation of the rules
# in `.htaccess` that concern `/.well-known`.
location = /.well-known/carddav { return 301 /remote.php/dav/; }
location = /.well-known/caldav { return 301 /remote.php/dav/; }
location /.well-known/acme-challenge { try_files $uri $uri/ =404; }
location /.well-known/pki-validation { try_files $uri $uri/ =404; }
# Let Nextcloud's API for `/.well-known` URIs handle all other
# requests by passing them to the front-end controller.
return 301 /index.php$request_uri;
}
# Rules borrowed from `.htaccess` to hide certain paths from clients
location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/) { return 404; }
location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) { return 404; }
# Ensure this block, which passes PHP files to the PHP process, is above the blocks
# which handle static assets (as seen below). If this block is not declared first,
# then Nginx will encounter an infinite rewriting loop when it prepends `/index.php`
# to the URI, resulting in a HTTP 500 error response.
location ~ \.php(?:$|/) {
# Required for legacy support
rewrite ^/(?!index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+|.+\/richdocumentscode\/proxy) /index.php$request_uri;
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
set $path_info $fastcgi_path_info;
try_files $fastcgi_script_name =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $path_info;
fastcgi_param HTTPS on;
fastcgi_param modHeadersAvailable true; # Avoid sending the security headers twice
fastcgi_param front_controller_active true; # Enable pretty urls
fastcgi_pass php-handler;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
fastcgi_max_temp_file_size 0;
}
location ~ \.(?:css|js|svg|gif|png|jpg|ico|wasm|tflite|map)$ {
try_files $uri /index.php$request_uri;
expires 6M; # Cache-Control policy borrowed from `.htaccess`
access_log off; # Optional: Don't log access to assets
location ~ \.wasm$ {
default_type application/wasm;
}
}
location ~ \.woff2?$ {
try_files $uri /index.php$request_uri;
expires 7d; # Cache-Control policy borrowed from `.htaccess`
access_log off; # Optional: Don't log access to assets
}
# Rule borrowed from `.htaccess`
location /remote {
return 301 /remote.php$request_uri;
}
location / {
try_files $uri $uri/ /index.php$request_uri;
}
}
}

View File

@ -0,0 +1,4 @@
MYSQL_ROOT_PASSWORD=password
MYSQL_DATABASE=nextcloud
MYSQL_USER=nextcloud
MYSQL_PASSWORD=password

View File

View File

@ -0,0 +1,7 @@
[www]
pm = dynamic
pm.max_children = 50
pm.start_servers = 15
pm.min_spare_servers = 15
pm.max_spare_servers = 25
pm.max_requests = 500

@ -1 +0,0 @@
Subproject commit 3a0455e5772c13e6b92689f08347c1e7d777f0bc

3
traefik/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*.secrets
.env
certs

46
traefik/README.md Normal file
View File

@ -0,0 +1,46 @@
## Traefik
Ce dossier contient les ressources nécessaires pour lancer Traefik, un reverse proxy adapté pour Docker.
C'est la pièce la plus importante de l'infrastructure, puisque l'ensemble des communications HTTP(S) passent d'abord par Traefik, et il est aussi utilisé pour [générer des certificats pour les services TCP](../pica-tls-certs-monitor).
Ce service doit être lancé sur l'ensemble des machines de l'infrastructure.
Les explications sont sur le Wiki et doivent être modifiées en cas de changement majeur de configuration : https://wiki.picasoft.net/doku.php?id=technique:tech_team:traefik
### Configuration
La configuration a lieu dans les fichiers [traefik.toml](./traefik.toml) et [traefik_dynamic.toml](./traefik_dynamic.toml).
Notez que toute modification dans ce fichier impactera l'ensemble des machines, puisque le même fichier est utilisé pour l'ensemble des machines.
À des fins de tests, il peut être modifié localement sur les machines, mais doit toujours rester synchronisé avec ce dépôt à long terme.
Pour la génération des certificats, Traefik utilise Let's Encrypt. Il n'y a aucune configuration à faire de ce côté. Attention, le nombre de certificats générables est limité à 50 par semaine.
Si on lance plein de conteneurs de tests, on utilisera temporairement [l'environnement de qualification](https://letsencrypt.org/fr/docs/staging-environment/) de Let's Encrypt, en ajoutant la directive `caServer = "https://acme-staging-v02.api.letsencrypt.org/directory"` sous la section `[certificatesResolvers.letsencrypt.acme]`.
### Lancement
#### Certs
Au premier lancement, assurez-vous que :
- Le dossier `/DATA/docker/traefik/certs` existe
- Créez un fichier `acme.json` à l'intérieur
- Changez son propriétaire à `root`
- Changez ses permissions à `600`
C'est dans ce fichier que seront conservés tous les certificats générés par Traefik.
#### Métriques
Pour le bon fonctionnement des métriques, il faut aussi créer un fichier `.env` (dans le même dossier que le Docker Compose) qui devra contenir 2 variables :
- `SERVER_NAME` qui correspond au nom du serveur, par exemple `SERVER_NAME=pica01-test.picasoft.net`
- `METRICS_AUTH` qui correspond à la chaîne d'identification htpasswd utilisée pour authentifier sur l'endpoint des métriques, par exemple `METRICS_AUTH="traefik:$apr1$bXnknJ0S$GsC.ozNJc/dAkh9uH7Qlg."`
### Mise à jour
Il suffit de mettre à jour le tag de l'image dans Compose.
Lire la documentation [sur les mises à jour mineures](https://docs.traefik.io/v2.2/migration/v2/) pour voir s'il y a des opérations à effectuer ou des options dépréciées.
La mise à jour vers Traefik v2 a été effectuée ; quelques détails sont à consulter [sur le wiki](https://wiki.picasoft.net/doku.php?id=technique:adminsys:migration-traefik-v2).

View File

@ -0,0 +1,32 @@
version: "3.7"
networks:
proxy:
name: "proxy"
services:
traefik:
image: traefik:2.6
container_name: traefik
ports:
- 80:80
- 443:443
- 8080:8080
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./traefik.toml:/traefik.toml
- ./traefik_dynamic.toml:/traefik_dynamic.toml
- /DATA/docker/traefik/certs:/certs
environment:
TZ: Europe/Paris
# labels:
# traefik.http.routers.traefik-metrics.entrypoints: websecure
# traefik.http.routers.traefik-metrics.rule: "Host(`${SERVER_NAME}`) && PathPrefix(`/metrics`)"
# traefik.http.routers.traefik-metrics.service: traefik-metrics
# traefik.http.routers.traefik-metrics.middlewares: "traefik-metrics-auth@docker"
# traefik.http.middlewares.traefik-metrics-auth.basicauth.users: "${METRICS_AUTH}"
# traefik.http.services.traefik-metrics.loadbalancer.server.port: 8082
# traefik.enable: true
networks:
- proxy
restart: unless-stopped

57
traefik/traefik.toml Normal file
View File

@ -0,0 +1,57 @@
[global]
sendAnonymousUsage = false
checkNewVersion = true
[entryPoints]
[entryPoints.web]
address = ":80"
[entryPoints.web.http.redirections.entryPoint]
to = "websecure"
scheme = "https"
[entryPoints.websecure]
address = ":443"
[entryPoints.websecure.http]
middlewares = ["hardening@file", "compression@file"]
[entryPoints.websecure.http.tls]
# certResolver = "letsencrypt"
options = "tls12@file"
# [entryPoints.metrics]
# address = ":8082"
[providers]
providersThrottleDuration = "2s"
[providers.docker]
watch = true
endpoint = "unix:///var/run/docker.sock"
exposedByDefault = true
network = "proxy"
[providers.file]
filename = "/traefik_dynamic.toml"
watch = true
[api]
insecure = true
[log]
level = "DEBUG"
[accessLog]
format = "json"
[accessLog.fields.headers]
defaultMode = "keep"
# See https://doc.traefik.io/traefik/observability/access-logs/#time-zones
[accessLog.fields.names]
"StartUTC" = "drop"
"ClientUsername" = "drop"
#[certificatesResolvers]
# [certificatesResolvers.letsencrypt]
# [certificatesResolvers.letsencrypt.acme]
# email = "picasoft@assos.utc.fr"
# storage = "/certs/acme.json"
# [certificatesResolvers.letsencrypt.acme.httpChallenge]
# entryPoint = "web"
#[metrics]
# [metrics.prometheus]
# entryPoint = "metrics"

View File

@ -0,0 +1,34 @@
[tls.options]
[tls.options.tls12]
minVersion = "VersionTLS12"
cipherSuites = [
"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
"TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305",
"TLS_AES_256_GCM_SHA384",
"TLS_CHACHA20_POLY1305_SHA256",
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"
]
curvePreferences = ["CurveP521","CurveP384", "CurveP256"]
[http]
[http.middlewares.hardening.headers]
browserXssFilter = true
contentTypeNosniff = true
forceSTSHeader = true
frameDeny = true
stsIncludeSubdomains = true
stsPreload = true
customFrameOptionsValue = "SAMEORIGIN"
referrerPolicy = "same-origin"
permissionsPolicy = "vibrate='self'"
stsSeconds = 315360000
[http.middlewares.compression.compress]
excludedContentTypes = ["text/event-stream"]
[http.middlewares.allowFrameAndCORS.headers]
contentSecurityPolicy = "frame-ancestors *"
accessControlAllowHeaders = ["*"]
accessControlAllowMethods = ["GET", "POST", "OPTIONS"]
accessControlAllowOriginList = ["*"]
accessControlExposeHeaders = ["*"]

@ -1 +0,0 @@
Subproject commit de2740993bf9e71bea04209b7a48ed8cf6b517b0

3
website/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*.secrets
.env
certs

View File

@ -0,0 +1,24 @@
version: "3.7"
volumes:
website:
name: website
networks:
proxy:
external: true
services:
website:
container_name: website
image: nginx:1.21-alpine
volumes:
- website:/usr/share/nginx/html
labels:
traefik.http.routers.website.entrypoints: web, websecure
traefik.http.routers.website.rule: Host(`www.librezo.xyz`)
traefik.http.services.website.loadbalancer.server.port: 80
traefik.enable: true
networks:
- proxy
restart: unless-stopped

7
website/index.html Normal file
View File

@ -0,0 +1,7 @@
<html>
<body>
le monocycle c'est la vie
</body>
</html>