diff --git a/README.md b/README.md index aa1cf96..b05949b 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,10 @@ You can execute `docker-compose up -d --build --force-recreate` to start and bui It is possible to adapt the `pretixuser` crontab entries by modifying the [crontab](docker/pretix/crontab.bak) file. +## TLS setup + +You can specify the used TLS certificates by adapting the mounted [certificate](docker/pretix/files/config/ssl/domain.crt) and [key](docker/pretix/files/config/ssl/domain.key) e.g. from LetsEncrypt or generating new self-signed certificates by following the [manual](scripts/EXAMPLE-CERT-CREATION.md) and moving the generated files. + ## Contribution If you would like to contribute something, have an improvement request, or want to make a change inside the code, please open a pull request. diff --git a/docker-compose.yml b/docker-compose.yml index 6bf72d6..db59894 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,9 +12,11 @@ services: volumes: - pretix_data:/data - ./docker/pretix/pretix.cfg:/etc/pretix/pretix.cfg + - ./docker/pretix/nginx/nginx.conf:/etc/nginx/nginx.conf - ./docker/pretix/crontab:/tmp/crontab ports: - - "8000:80" + - "80:80" + - "443:443" networks: - backend diff --git a/docker/pretix/Dockerfile b/docker/pretix/Dockerfile index 1130fe3..b228d44 100644 --- a/docker/pretix/Dockerfile +++ b/docker/pretix/Dockerfile @@ -2,15 +2,18 @@ FROM pretix/standalone:stable USER root -ENV IMAGE_CRON_DIR="/image/cron" +ENV IMAGE_CRON_DIR="/image/cron" \ + IMAGE_CONFIG_DIR="/image/config" ADD files /image COPY crontab /tmp/crontab RUN mv /image/supervisord/crond.conf /etc/supervisord/crond.conf && \ - pip install crontab && chmod +x $IMAGE_CRON_DIR/cron.py + pip install crontab && chmod 644 $IMAGE_CONFIG_DIR/ssl/*.crt && chmod +x $IMAGE_CRON_DIR/cron.py USER pretixuser +EXPOSE 443 + ENTRYPOINT ["pretix"] CMD ["all"] \ No newline at end of file diff --git a/docker/pretix/files/config/ssl/.placeholder b/docker/pretix/files/config/ssl/.placeholder new file mode 100644 index 0000000..e69de29 diff --git a/docker/pretix/files/config/ssl/domain.crt b/docker/pretix/files/config/ssl/domain.crt new file mode 100644 index 0000000..e69de29 diff --git a/docker/pretix/files/config/ssl/domain.key b/docker/pretix/files/config/ssl/domain.key new file mode 100644 index 0000000..e69de29 diff --git a/docker/pretix/nginx/nginx.conf b/docker/pretix/nginx/nginx.conf new file mode 100644 index 0000000..3cd39fd --- /dev/null +++ b/docker/pretix/nginx/nginx.conf @@ -0,0 +1,89 @@ +user www-data www-data; +worker_processes auto; +pid /var/run/nginx.pid; +daemon off; +worker_rlimit_nofile 262144; + +events { + worker_connections 16384; + multi_accept on; + use epoll; +} + +http { + server_tokens off; + sendfile on; + charset utf-8; + tcp_nopush on; + tcp_nodelay on; + + log_format private '[$time_local] $host "$request" $status $body_bytes_sent'; + + types_hash_max_size 2048; + server_names_hash_bucket_size 64; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + add_header X-Content-Type-Options nosniff; + + access_log /var/log/nginx/access.log private; + error_log /var/log/nginx/error.log; + add_header Referrer-Policy same-origin; + + gzip on; + gzip_disable "msie6"; + gzip_types text/plain text/css application/json application/javascript application/x-javascript text/javascript text/xml application/xml application/rss+xml application/atom+xml application/rdf+xml image/svg+xml; + gzip_vary on; + gzip_proxied any; + gzip_comp_level 6; + gzip_buffers 16 8k; + + include /etc/nginx/conf.d/*.conf; + + server { + listen 80 backlog=4096 default_server; + listen [::]:80 ipv6only=on default_server; + listen 443 backlog=4096 default_server ssl; + listen [::]:443 ipv6only=on default_server ssl; + server_name _; + ssl_certificate /image/config/ssl/domain.crt; + ssl_certificate_key /image/config/ssl/domain.key; + + index index.php index.html; + root /var/www; + + location /media/ { + alias /data/media/; + expires 7d; + access_log off; + } + location ^~ /media/cachedfiles { + deny all; + return 404; + } + location ^~ /media/invoices { + deny all; + return 404; + } + location /static/ { + alias /pretix/src/pretix/static.dist/; + access_log off; + expires 365d; + add_header Cache-Control "public"; + add_header Access-Control-Allow-Origin "*"; + gzip on; + } + location / { + # Very important: + # proxy_pass http://unix:/tmp/pretix.sock:; + # is not the same as + # proxy_pass http://unix:/tmp/pretix.sock:/; + # In the latter case, nginx will apply its URL parsing, in the former it doesn't. + # There are situations in which pretix' API will deal with "file names" containing %2F%2F, which + # nginx will normalize to %2F, which can break ticket validation. + proxy_pass http://unix:/tmp/pretix.sock:; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + } + } +} \ No newline at end of file diff --git a/scripts/EXAMPLE-CERT-CREATION.md b/scripts/EXAMPLE-CERT-CREATION.md new file mode 100644 index 0000000..1cbb6b6 --- /dev/null +++ b/scripts/EXAMPLE-CERT-CREATION.md @@ -0,0 +1,21 @@ +# Example of the cert creation for the Nginx setup + +## Creation + +Please execute the following script `bash create-tls-certs.sh` to create all necessary certificates for the complete setup of all related components. + +## Adaptation + +Please adjust the configuration files inside the [config](./config) folder and adapt the corresponding values for the req_distinguished_names and subjectAltNames based on your organisation and configuration. You can find [here](https://support.dnsimple.com/articles/what-is-common-name/) and [here](https://learn.microsoft.com/en-us/azure/application-gateway/self-signed-certificates) more information about the corresponding values and CA certificates in general. + +## Ca Certificates + +### Nginx + +Describes the Certificate Authority (certificate & key) for the Nginx server. + +## Server Certificates + +### Nginx + +Describes the server certificate and key for the Nginx server, and it's signed by the Nginx CA. \ No newline at end of file diff --git a/scripts/certs/.placeholder b/scripts/certs/.placeholder new file mode 100644 index 0000000..e69de29 diff --git a/scripts/config/ca_nginx.conf b/scripts/config/ca_nginx.conf new file mode 100644 index 0000000..f9e047d --- /dev/null +++ b/scripts/config/ca_nginx.conf @@ -0,0 +1,20 @@ +[req] +distinguished_name = req_distinguished_name +default_bits = 4096 +prompt = no +default_md = sha256 + +[req_distinguished_name] +C = DE +ST = Baden-Wuerttemberg +L = Mannheim +O = TheIOTStudio +CN = Pretix Nginx CA +emailAddress = info@theiotstudio.com + +[ext] +subjectKeyIdentifier=hash +authorityKeyIdentifier=keyid:always,issuer +basicConstraints = critical, CA:TRUE, pathlen:3 +keyUsage = critical, cRLSign, keyCertSign +nsCertType = sslCA, emailCA \ No newline at end of file diff --git a/scripts/config/server_nginx.conf b/scripts/config/server_nginx.conf new file mode 100644 index 0000000..3d981e0 --- /dev/null +++ b/scripts/config/server_nginx.conf @@ -0,0 +1,19 @@ +[req] +distinguished_name = req_distinguished_name +req_extensions = v3_req +default_bits = 4096 +prompt = no +default_md = sha256 + +[req_distinguished_name] +C = DE +ST = Baden-Wuerttemberg +L = Mannheim +O = TheIOTStudio +CN = Pretix Nginx Server +emailAddress = info@theiotstudio.com + +[v3_req] +keyUsage = keyEncipherment, dataEncipherment, digitalSignature +extendedKeyUsage = serverAuth, clientAuth +subjectAltName=IP: or DNS: \ No newline at end of file diff --git a/scripts/create-tls-certs.sh b/scripts/create-tls-certs.sh new file mode 100755 index 0000000..823d930 --- /dev/null +++ b/scripts/create-tls-certs.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +# Switch the directory +echo "Switch the directory" +path=$(pwd)/config +cd certs + +# Create the Nginx ca +echo "Create the Nginx ca" +openssl req -new -x509 -sha256 -newkey rsa:4096 -nodes -keyout ca_nginx.key -out ca_nginx.crt -days 3650 \ +-extensions ext \ +-config $path/ca_nginx.conf + +# Create the server certificates +echo "Create the Nginx server certificates" +openssl genrsa -out nginx.key 4096 +openssl req -new -key nginx.key -out nginx.csr -extensions v3_req -config $path/server_nginx.conf +openssl x509 -inform pem -req -days 1825 -in nginx.csr -CA ca_nginx.crt -CAkey ca_nginx.key -CAcreateserial -out nginx.crt -extensions v3_req -extfile $path/server_nginx.conf \ No newline at end of file