-
Notifications
You must be signed in to change notification settings - Fork 0
Imroved systemd example #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -63,28 +63,73 @@ An example systemd service to run fmsgd as a service on startup | |||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| ASSUMES: | ||||||||||||||||||||||||||||||||||||||||||||||||
| * Directory `/opt/fmsgd` has been created and contains built executable: `fmsgd` | ||||||||||||||||||||||||||||||||||||||||||||||||
| * Text file `/opt/fmsgd/env` exists containing environment variables | ||||||||||||||||||||||||||||||||||||||||||||||||
| * Text file `/opt/fmsgd/env` exists containing environment variables (example below) | ||||||||||||||||||||||||||||||||||||||||||||||||
| * User `fmsg` has been created and has | ||||||||||||||||||||||||||||||||||||||||||||||||
| - read and execute permissions to `/opt/fmsgd/`, e.g. with `chown -R fmsg:fmsg /opt/fmsgd` after `mkdir /opt/fmsgd` | ||||||||||||||||||||||||||||||||||||||||||||||||
| - write permissions to FMSG_DATA_DIR | ||||||||||||||||||||||||||||||||||||||||||||||||
| * Directory `/var/lib/fmsgd` has been created and owned by fmsg | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| `/etc/systemd/system/fmsgd.service` | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||||||||||
| [Unit] | ||||||||||||||||||||||||||||||||||||||||||||||||
| Description=fmsg Host | ||||||||||||||||||||||||||||||||||||||||||||||||
| After=network.target | ||||||||||||||||||||||||||||||||||||||||||||||||
| After=network-online.target | ||||||||||||||||||||||||||||||||||||||||||||||||
| Wants=network-online.target | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| [Service] | ||||||||||||||||||||||||||||||||||||||||||||||||
| EnvironmentFile=/opt/fmsgd/env | ||||||||||||||||||||||||||||||||||||||||||||||||
| ExecStart=/opt/fmsgd/fmsgd "0.0.0.0" | ||||||||||||||||||||||||||||||||||||||||||||||||
| Type=simple | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| User=fmsg | ||||||||||||||||||||||||||||||||||||||||||||||||
| Group=fmsg | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| EnvironmentFile=/opt/fmsgd/env | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| ExecStart=/opt/fmsgd/fmsgd 0.0.0.0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| WorkingDirectory=/opt/fmsgd | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Restart=on-failure | ||||||||||||||||||||||||||||||||||||||||||||||||
| RestartSec=3 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| # --- Filesystem access --- | ||||||||||||||||||||||||||||||||||||||||||||||||
| ReadWritePaths=/opt/fmsgd | ||||||||||||||||||||||||||||||||||||||||||||||||
| ReadWritePaths=/var/lib/fmsgd | ||||||||||||||||||||||||||||||||||||||||||||||||
| PrivateTmp=true | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| # --- Hardening --- | ||||||||||||||||||||||||||||||||||||||||||||||||
| NoNewPrivileges=true | ||||||||||||||||||||||||||||||||||||||||||||||||
| PrivateTmp=true | ||||||||||||||||||||||||||||||||||||||||||||||||
| ProtectSystem=strict | ||||||||||||||||||||||||||||||||||||||||||||||||
| ProtectHome=true | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| # --- Logging --- | ||||||||||||||||||||||||||||||||||||||||||||||||
| StandardOutput=journal | ||||||||||||||||||||||||||||||||||||||||||||||||
| StandardError=journal | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| [Install] | ||||||||||||||||||||||||||||||||||||||||||||||||
| WantedBy=multi-user.target | ||||||||||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||||||||||
| FMSG_DATA_DIR=/var/lib/fmsgd/ | ||||||||||||||||||||||||||||||||||||||||||||||||
| FMSG_DOMAIN=example.com | ||||||||||||||||||||||||||||||||||||||||||||||||
| FMSG_ID_URL=http://127.0.0.1:8080 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| FMSG_MAX_MSG_SIZE=10240 | ||||||||||||||||||||||||||||||||||||||||||||||||
| FMSG_MAX_PAST_TIME_DELTA=604800 | ||||||||||||||||||||||||||||||||||||||||||||||||
| FMSG_MAX_FUTURE_TIME_DELTA=300 | ||||||||||||||||||||||||||||||||||||||||||||||||
| FMSG_MIN_DOWNLOAD_RATE=5000 | ||||||||||||||||||||||||||||||||||||||||||||||||
| FMSG_MIN_UPLOAD_RATE=5000 | ||||||||||||||||||||||||||||||||||||||||||||||||
| FMSG_READ_BUFFER_SIZE=1600 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| PGHOST=127.0.0.1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| PGPORT=5432 | ||||||||||||||||||||||||||||||||||||||||||||||||
| PGUSER= | ||||||||||||||||||||||||||||||||||||||||||||||||
| PGPASSWORD= | ||||||||||||||||||||||||||||||||||||||||||||||||
| PGDATABASE=fmsgd | ||||||||||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+113
to
133
|
||||||||||||||||||||||||||||||||||||||||||||||||
| ``` | |
| FMSG_DATA_DIR=/var/lib/fmsgd/ | |
| FMSG_DOMAIN=example.com | |
| FMSG_ID_URL=http://127.0.0.1:8080 | |
| FMSG_MAX_MSG_SIZE=10240 | |
| FMSG_MAX_PAST_TIME_DELTA=604800 | |
| FMSG_MAX_FUTURE_TIME_DELTA=300 | |
| FMSG_MIN_DOWNLOAD_RATE=5000 | |
| FMSG_MIN_UPLOAD_RATE=5000 | |
| FMSG_READ_BUFFER_SIZE=1600 | |
| PGHOST=127.0.0.1 | |
| PGPORT=5432 | |
| PGUSER= | |
| PGPASSWORD= | |
| PGDATABASE=fmsgd | |
| ``` | |
| ``` | |
| See `src/.env.example` for the canonical environment-variable example and the full, current set of `FMSG_*` and PostgreSQL `PG*` variables to configure. | |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,22 @@ | ||||||||
| # fmsgd Environment Variables | ||||||||
|
|
||||||||
| # Required | ||||||||
| FMSG_DATA_DIR=/var/lib/fmsgd/ | ||||||||
| FMSG_DOMAIN=example.com | ||||||||
| FMSG_ID_URL=http://127.0.0.1:8080 | ||||||||
|
|
||||||||
|
|
||||||||
| FMSG_MAX_MSG_SIZE=10240 | ||||||||
| FMSG_MAX_PAST_TIME_DELTA=604800 | ||||||||
| FMSG_MAX_FUTURE_TIME_DELTA=300 | ||||||||
| FMSG_MIN_DOWNLOAD_RATE=5000 | ||||||||
| FMSG_MIN_UPLOAD_RATE=5000 | ||||||||
| FMSG_READ_BUFFER_SIZE=1600 | ||||||||
|
|
||||||||
| # PostgreSQL connection variables (see https://www.postgresql.org/docs/current/libpq-envars.html) | ||||||||
| PGHOST=127.0.0.1 | ||||||||
| PGPORT=5432 | ||||||||
| PGUSER= | ||||||||
| PGPASSWORD= | ||||||||
| PGDATABASE=fmsgd | ||||||||
| PGSSLMODE=disable | ||||||||
|
||||||||
| PGSSLMODE=disable | |
| # Use disable only for local socket or trusted localhost development. | |
| PGSSLMODE=require |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ReadWritePaths=/opt/fmsgdgrants write access to the installation directory. The daemon code appears to write only underFMSG_DATA_DIR(e.g.,filepath.Join(DataDir, ...)in src/host.go), so this is broader than necessary. For least privilege, consider removing write access to/opt/fmsgd(keep it read-only) and only allow writes to/var/lib/fmsgd(or whateverFMSG_DATA_DIRis set to).