From 0c1a2e565cccbd459c768a942fd5ea9ecb2dbf84 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sat, 7 Dec 2019 09:20:39 +0100 Subject: [PATCH] changing default port to 8080, keeping port 80 for backwards compatibility. updating documentation. ensure the image can be run as root user and services drop privileges, fixes #11 --- Dockerfile | 2 +- README.md | 15 +++++++++------ etc/nginx/nginx.conf | 3 +++ etc/nginx/sites-available/site.conf | 1 + etc/php7/php-fpm.d/zz-docker.conf | 4 ++++ 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index a3e7ee2..b303643 100644 --- a/Dockerfile +++ b/Dockerfile @@ -67,6 +67,6 @@ USER nobody:www-data # mark dirs as volumes that need to be writable, allows running the container --read-only VOLUME /srv/data /tmp /var/tmp/nginx /run /var/log -EXPOSE 80 +EXPOSE 80 8080 ENTRYPOINT ["/init"] diff --git a/README.md b/README.md index 30678e9..797658f 100644 --- a/README.md +++ b/README.md @@ -9,25 +9,27 @@ This repository contains the Dockerfile and resources needed to create a docker Assuming you have docker successfully installed and internet access, you can fetch and run the image from the docker hub like this: ```bash -docker run -d --restart="always" --read-only -p 8080:80 -v privatebin-data:/srv/data privatebin/nginx-fpm-alpine +docker run -d --restart="always" --read-only -p 8080:8080 -v privatebin-data:/srv/data privatebin/nginx-fpm-alpine ``` The parameters in detail: - `-v privatebin-data:/srv/data` - replace `privatebin-data` with the path to the folder on your system, where the pastes and other service data should be persisted. This guarantees that your pastes aren't lost after you stop and restart the image or when you replace it. May be skipped if you just want to test the image. -- `-p 8080:80` - The Nginx webserver inside the container listens on port 80, this parameter exposes it on your system on port 8080. Be sure to use a reverse proxy for HTTPS termination in front of it for production environments. +- `-p 8080:8080` - The Nginx webserver inside the container listens on port 8080, this parameter exposes it on your system on port 8080. Be sure to use a reverse proxy for HTTPS termination in front of it for production environments. - `--read-only` - This image supports running in read-only mode. Using this reduces the attack surface slightly, since an exploit in one of the images services can't overwrite arbitrary files in the container. Only /tmp, /var/tmp, /var/run & /srv/data may be written into. - `-d` - launches the container in the background. You can use `docker ps` and `docker logs` to check if the container is alive and well. - `--restart="always"` - restart the container if it crashes, mainly useful for production setups > Note that the volume mounted must be owned by UID 65534 / GID 82. If you run the container in a docker instance with "userns-remap" you need to add your subuid/subgid range to these numbers. +> +> Note, too, that this image exposes the same service on port 80, for backwards compatibility with older versions of the image. To use port 80 with the current image, you either need to have a filesystem with extended attribute support so the nginx binary can be granted the capability to bind to ports below 1024 as non-root user or you need to start the image with user id 0 (root) using the parameter `-u 0`. ### Custom configuration In case you want to use a customized [conf.php](https://github.com/PrivateBin/PrivateBin/blob/master/cfg/conf.sample.php) file, for example one that has file uploads enabled or that uses a different template, add the file as a second volume: ```bash -docker run -d --restart="always" --read-only -p 8080:80 -v conf.php:/srv/cfg/conf.php:ro -v privatebin-data:/srv/data privatebin/nginx-fpm-alpine +docker run -d --restart="always" --read-only -p 8080:8080 -v conf.php:/srv/cfg/conf.php:ro -v privatebin-data:/srv/data privatebin/nginx-fpm-alpine ``` Note: The `Filesystem` data storage is supported out of the box. The image includes PDO modules for MySQL, PostgreSQL and SQLite, required for the `Database` one, but you still need to keep the /srv/data persisted for the server salt and the traffic limiter. @@ -57,8 +59,9 @@ docker build -t privatebin/nginx-fpm-alpine . The two processes, Nginx and php-fpm, are started by supervisord, which will also try to restart the services in case they crash. -Nginx is required to serve static files and caches them, too. Requests to the index.php (which is the only PHP file exposed in the document root at /var/www) are passed on to php-fpm via fastCGI to port 9000. All other PHP files and the data are stored in /srv. +Nginx is required to serve static files and caches them, too. Requests to the index.php (which is the only PHP file exposed in the document root at /var/www) are passed on to php-fpm via a socket at /run/php-fpm.sock. All other PHP files and the data are stored under /srv. -The Nginx setup supports only HTTP, so make sure that you run another webserver as reverse proxy in front of this for HTTPS offloading and reducing the attack surface on your TLS stack. The Nginx in this image is set up to deflate/gzip text content. +The Nginx setup supports only HTTP, so make sure that you run a reverse proxy in front of this for HTTPS offloading and reducing the attack surface on your TLS stack. The Nginx in this image is set up to deflate/gzip text content. + +During the build of the image the PrivateBin release archive and the s6 overlay binaries are downloaded from Github. All the downloaded Alpine packages, s6 overlay binaries and the PrivateBin archive are validated using cryptographic signatures to ensure they have not been tempered with, before deploying them in the image. -During the build of the image, the opcache & GD PHP modules are compiled from source and the PrivateBin release archive is downloaded from Github. All the downloaded Alpine packages and the PrivateBin archive are validated using cryptographic signatures to ensure the have not been tempered with, before deploying them in the image. diff --git a/etc/nginx/nginx.conf b/etc/nginx/nginx.conf index 279f76d..e465ee3 100644 --- a/etc/nginx/nginx.conf +++ b/etc/nginx/nginx.conf @@ -1,3 +1,6 @@ +# Run as a unique, less privileged user for security reasons. +user nobody www-data; + # Sets the worker threads to the number of CPU cores available in the system for best performance. # Should be > the number of CPU cores. # Maximum number of connections = worker_processes * worker_connections diff --git a/etc/nginx/sites-available/site.conf b/etc/nginx/sites-available/site.conf index d17ec18..e25789c 100644 --- a/etc/nginx/sites-available/site.conf +++ b/etc/nginx/sites-available/site.conf @@ -1,5 +1,6 @@ server { listen 80 default_server; + listen 8080 default_server; root /var/www; index index.php index.html index.htm; diff --git a/etc/php7/php-fpm.d/zz-docker.conf b/etc/php7/php-fpm.d/zz-docker.conf index 2817ad1..c0f3ca9 100644 --- a/etc/php7/php-fpm.d/zz-docker.conf +++ b/etc/php7/php-fpm.d/zz-docker.conf @@ -4,7 +4,11 @@ daemonize = no error_log = /dev/stderr [www] +user = nobody +group = www-data listen = /run/php-fpm.sock +listen.owner = nobody +listen.group = www-data access.log = /dev/null clear_env = On pm = dynamic