Server Deployment

This section covers how to deploy the Parsec server.

Requirements

Preamble

The Parsec server depends on the following external components in order to work properly:

Avertissement

For security reasons, the installation of these components is outside the scope of this guide. In order to securely configure and manage them, please refer to their official documentations.

This guide provides instructions for quickly settings up mock-ups or basic installs of those components. Keep in mind that these instructions are provided for convenience and should not be used in production.

Parsec testing infra

With Docker

Generating the required TLS certificates

For this guide, the required TLS certificates will be generated with a custom Certificate Authority (CA) created for this purpose.

 1#!/usr/bin/env bash
 2
 3function generate_cert_conf() {
 4    local name=$1
 5    local san=$2
 6
 7    echo "Generating $name.crt.conf"
 8
 9    cat << EOF > $name.crt.conf
10[req]
11distinguished_name = req_dist_name
12req_extensions = req_ext
13prompt = no
14
15[req_dist_name]
16CN = $name
17
18[req_ext]
19subjectAltName = $san
20EOF
21}
22
23function generate_certificate_request() {
24    local name=$1
25    echo "Generate certificate request $name.csr"
26    openssl req -batch \
27        -new -sha512 -noenc -newkey rsa:4096 \
28        -config $name.crt.conf \
29        -keyout $name.key -out $name.csr
30}
31
32function sign_crt_with_ca() {
33    local ca_crt=$1
34    local ca_key=$2
35    local name=$3
36
37    echo "Sign certificate request $name.crt"
38
39    openssl x509 -req -in $name.csr \
40        -CA $ca_crt -CAkey $ca_key \
41        -extfile $name.crt.conf \
42        -extensions req_ext \
43        -CAcreateserial -out $name.crt \
44        -days 10 -sha512
45}
46
47if [ ! -f custom-ca.key ]; then
48    echo "Generate a mini Certificate Authority"
49    openssl req -batch \
50        -x509 -sha512 -nodes -days 10 -newkey rsa:4096 \
51        -subj "/CN=Mini Certificate Authority" \
52        -keyout custom-ca.key -out custom-ca.crt
53fi
54
55for service in parsec-{s3,server}; do
56    if [ ! -f $service.crt.conf ]; then
57        generate_cert_conf $service DNS:$service,DNS:localhost,IP:127.0.0.1
58    fi
59
60    if [ ! -f $service.key ]; then
61        generate_certificate_request $service
62    fi
63
64    if [ ! -f $service.crt ]; then
65        sign_crt_with_ca custom-ca.{crt,key} $service
66    fi
67done
68
69if [ "$(stat -c %g parsec-server.key)" -ne 1234 ]; then
70    echo "Changing group id of parsec-server.key to 1234"
71    sudo chown $USER:1234 parsec-server.key
72fi
73
74if [ "$(stat -c %a parsec-server.key)" -ne 640 ]; then
75    echo "Changing permission of parsec-server.key to 640"
76    chmod 640 parsec-server.key
77fi

The script will:

  1. Generate the CA key & self-signed certificate (custom-ca.{key,crt}).

  2. For parsec-s3 and parsec-server services:

    1. Generate the service key & Certificate Signing Request (CSR) parsec-{service}.{key,csr}.

    2. Generate the certificate using the CSR and the CA.

  3. For the service parsec-server:

    1. Change the group id of the key file to 1234 (That is the GID used by the parsec-server container).

    2. Change the file mode to give read permission to the group 1234.

    Note

    This is required because docker-compose does not allow to mount the file with the correct permissions in the container.

Avertissement

For production, you should use certificates issued from a trusted CA

The env files

We split the configuration of the parsec server into multiple env files so it’s simpler to understand how to configure each part.

The administration token

To be able to perform admin tasks (like creating an organization) on the server, an administration token is required. Below you will find a simple script to generate a token:

 1#!/usr/bin/env bash
 2
 3ENV_FILE=parsec-admin-token.env
 4if [ ! -f $ENV_FILE ]; then
 5    TOKEN=$(openssl rand 63 | base64 --wrap=86)
 6    echo "PARSEC_ADMINISTRATION_TOKEN=$TOKEN" > $ENV_FILE
 7    echo "Parsec administration token generated in: $ENV_FILE"
 8else
 9    echo "Parsec administration token already exists in: $ENV_FILE"
10fi

The script will generate a random token (openssl rand 63 | base64 --wrap=86) and create the env file parsec-admin-token.env

Note

The step TOKEN=$(openssl rand 63 | base64 --wrap=86) could also be replaced by a value generated by a password-generator for example.

It doesn’t need to be encoded in base64 (we encode it in the script just to have printable characters).

Database configuration

Create the file parsec-db.env with the following content to configure the access to the PostgreSQL database:

1# The Database url.
2PARSEC_DB=postgresql://DB_USER:DB_PASS@parsec-postgres:5432/parsec
3# The minimum number of connections to the database.
4PARSEC_DB_MIN_CONNECTIONS=5
5# The maximum number of connections to the database.
6PARSEC_DB_MAX_CONNECTIONS=7
SMTP configuration

Create the file parsec-smtp.env to configure the access to the SMTP server (mailhog in this case).

We need to set the connection informations, the sender information, in which the default language the emails are sent:

 1# The SMTP host to use for sending email.
 2PARSEC_EMAIL_HOST=parsec-smtp
 3# The port to use when connecting to the SMTP server.
 4PARSEC_EMAIL_PORT=1025
 5# The username to use for the SMTP server.
 6PARSEC_EMAIL_HOST_USER=SMTP_USER
 7# The password to use for the SMTP server.
 8PARSEC_EMAIL_HOST_PASSWORD=SMTP_PASS
 9PARSEC_EMAIL_SENDER=parsec@test.xyz
10
11# PARSEC_EMAIL_USE_SSL
12# PARSEC_EMAIL_USE_TLS
13PARSEC_EMAIL_LANGUAGE=en
S3 service configuration

Create the file parsec-s3.env with the following content to set the URL for the S3-like service:

1# The blockstore URL.
2# Can be S3, Switch or POSTGRESQL URL
3PARSEC_BLOCKSTORE=s3:parsec-s3\:9000:region1:parsec:S3_ROOT_USER:S3_ROOT_PASS

Note

We need to escape the : with a \ when specifying the port of the service.

Parsec server configuration

Create the file parsec.env with the following content to configure the parsec-server service:

 1# Host to listen to.
 2PARSEC_HOST=0.0.0.0
 3
 4# The SSL key file.
 5PARSEC_SSL_KEYFILE=/run/secrets/parsec-pem-key
 6
 7# The SSL certificate file.
 8PARSEC_SSL_CERTFILE=/run/secrets/parsec-pem-crt
 9
10# Enforce HTTPS by redirecting HTTP request.
11PARSEC_FORWARD_PROTO_ENFORCE_HTTPS=X-Forwarded-Proto:https
12
13# The granularity of Error log outputs.
14PARSEC_LOG_LEVEL=WARNING
15
16# The log formatting to use (`CONSOLE` or `JSON`).
17PARSEC_LOG_FORMAT=CONSOLE
18
19# The log file to write to (default to `stderr`).
20# PARSEC_LOG_FILE
21
22# The URL to reach Parsec server.
23PARSEC_SERVER_ADDR=parsec3://127.0.0.1:6777
24
25# Keep SSE connection open by sending keepalive messages to client (pass <=0 to disable).
26PARSEC_SSE_KEEPALIVE=30
27
28# Sentry Data Source Name for telemetry report.
29# PARSEC_SENTRY_DSN
30
31# Sentry environment for telemetry report.
32PARSEC_SENTRY_ENVIRONMENT=production

Note

To see the full list of environment variables that you can use to configure Parsec, you can run:

python -m parsec run --help

Look for the sections [env var: VARIABLE] next to each configuration option. For example:

--administration-token TOKEN    Secret token to access the Administration API
                                [env var: PARSEC_ADMINISTRATION_TOKEN; required]

The docker-compose file

You can use the following docker-compose file (parsec-server.docker.yaml) to deploy the Parsec server for testing:

 1services:
 2  parsec-postgres:
 3    image: postgres:14.10-alpine
 4    container_name: parsec-postgres
 5    environment:
 6      POSTGRES_USER: DB_USER
 7      POSTGRES_PASSWORD: DB_PASS
 8      POSTGRES_DB: parsec
 9    volumes:
10      - parsec-db-data:/var/lib/postgresql/data
11
12  parsec-s3:
13    image: quay.io/minio/minio:RELEASE.2024-09-13T20-26-02Z
14    container_name: parsec-s3
15    command: server --console-address ":9090" --certs-dir /opts/certs /data
16    environment:
17      MINIO_ROOT_USER: S3_ROOT_USER
18      MINIO_ROOT_PASSWORD: S3_ROOT_PASS
19    ports:
20      # Admin console exposed to https://127.0.0.1:9090
21      - 127.0.0.1:9090:9090
22    volumes:
23      - parsec-object-data:/data
24      - ./parsec-s3.key:/opts/certs/private.key:ro
25      - ./parsec-s3.crt:/opts/certs/public.crt:ro
26      - ./custom-ca.crt:/opts/certs/CAs/ca.test.crt:ro
27
28  parsec-smtp:
29    image: mailhog/mailhog:v1.0.1
30    container_name: parsec-smtp
31    ports:
32      - 1025:1025
33      # Web interface exposed to http://127.0.0.1:8025
34      - 127.0.0.1:8025:8025
35
36  parsec-server:
37    depends_on:
38      - parsec-smtp
39      - parsec-s3
40      - parsec-postgres
41    image: ghcr.io/scille/parsec-cloud/parsec-server:3.0.3
42    container_name: parsec-server
43    env_file:
44      - parsec.env
45      - parsec-s3.env
46      - parsec-db.env
47      - parsec-smtp.env
48      - parsec-admin-token.env
49    environment:
50      AWS_CA_BUNDLE: /run/secrets/mini-ca-crt
51    secrets:
52      - mini-ca-crt
53      - parsec-pem-crt
54      - parsec-pem-key
55    ports:
56      - 127.0.0.1:6777:6777
57
58volumes:
59  parsec-db-data: {}
60  parsec-object-data: {}
61
62secrets:
63  parsec-pem-crt:
64    file: ./parsec-server.crt
65  parsec-pem-key:
66    file: ./parsec-server.key
67  mini-ca-crt:
68    file: ./custom-ca.crt

It will setup 4 services:

Service name

Description

parsec-postgres

The PostgreSQL database

parsec-s3

The Object Storage service

parsec-smtp

A mock SMTP server

parsec-server

The Parsec server

Starting the services

The docker containers can be started as follow:

docker compose -f parsec-server.docker.yaml up

Initial configuration

On the first start, a one-time configuration is required for the database and s3 services.

Applying the database migration

(optional) Check that the database is accessible with:

set -a
source parsec-db.env
docker exec -t parsec-postgres psql 'postgresql://DB_USER:DB_PASS@0.0.0.0:5432/parsec' -c "\conninfo"

Note

You should have something like display on your console:

You are connected to database "parsec" as user "parsec" on host "0.0.0.0" at port "5432".

To bootstrap the database we just need to apply the migrations with:

docker compose -f parsec-server.docker.yaml run parsec-server migrate
Create the S3 Bucket

Access the console at https://127.0.0.1:9090, you will need to use the credential specified in the docker-compose file at services.parsec-s3.environment.MINIO_ROOT_{USER,PASSWORD}.

Go to https://127.0.0.1:9090/buckets/add-bucket to create a new bucket named parsec with the features object locking toggled on.

After that you will need to restart the parsec-server (that likely exited because it wasn’t able to access the S3 bucket):

docker compose -f parsec-server.docker.yaml restart parsec-server
Test the SMTP configuration & server

You can test mailhog with:

 1#!/usr/bin/env bash
 2
 3set -a
 4source parsec-smtp.env
 5
 6curl \
 7    --url "smtp://127.0.0.1:$PARSEC_EMAIL_PORT" \
 8    --user "$PARSEC_EMAIL_HOST_USER@localhost:$PARSEC_EMAIL_HOST_PASSWORD" \
 9    --mail-from $PARSEC_EMAIL_SENDER \
10    --mail-rcpt rcpt@test.com \
11    --upload-file <(date --rfc-3339=seconds)

You can then check if the email is present in the web interface at http://127.0.0.1:8025

On Bare Metal

If you don’t want to install Parsec server via Docker, you can install it on bare metal.

Requirements

  • Python v3.12 with pip and venv modules

  • A S3 like object storage endpoint.

  • A postgres-14 database endpoint.

  • A TLS certificate & key for the server.

Configure the environment

  1. Configure the env files, follow the env files.

Installation

  1. Set up a virtual env:

python -m venv venv
  1. Configure your shell to use the virtual env:

source venv/bin/activate
  1. Install parsec-server

The parsec-server is available as a python package hosted on https://pypi.org/project/parsec-cloud/.

You need to install it with the extra backend enabled.

python -m pip install 'parsec-cloud==3.0.3'
  1. Prepare the database by applying the migrations:

source venv/bin/activate
set -a
source parsec-db.env
python -m parsec migrate

Start the server

  1. Create a wrapper script run-parsec-server

#!/bin/bash

# Load the virtualenv.
source venv/bin/activate

# Load the env file into the environment table.
set -a
source parsec-admin-token.env
source parsec-db.env
source parsec-smtp.env
source parsec-s3.env
source parsec.env
set +a

# Start the parsec server.
python -m parsec run
  1. Execute the wrapper script run-parsec-server

Note

To run the wrapper with only run-parsec-server you need to have set the executable mode on the script file (chmod +x run-parsec-server). Otherwise, you need to execute it with the bash shell (bash run-parsec-server).

Start using Parsec server

Create the first organization

set -a
source parsec-admin-token.env
export SSL_CAFILE=$PWD/custom-ca.crt
parsec-cli organization create --addr parsec3://127.0.0.1:6777 <orgname>

Note

Change <orgname> to the organization’s name that suit you.

Save the link after Bootstrap organization url: you will need it to create the first user (owner) of the organization.

Add the first user to the organization

First, start parsec with the custom CA:

export SSL_CAFILE=$PWD/custom-ca.crt
parsec

After that go to Menu/Join an organization (or CTRL+O) and paste the link from before (should already be filled in the text field). Follow the instructions to create the first user of the organization.