feat: use dedicated 'libretime' user

BREAKING CHANGE: The default `www-data` user has been replaced by a dedicated  `libretime` user to run the services. Be sure to change the ownership of the libretime files.
This commit is contained in:
jo 2022-07-06 16:21:40 +02:00 committed by Kyle Robbertze
parent 0bb792d047
commit 2f205544c2
16 changed files with 50 additions and 25 deletions

View File

@ -23,16 +23,16 @@ rabbitmqctl set_permissions -p /airtime airtime .\* .\* .\*
## Usage ## Usage
This program must run as a user with permissions to write to your Airtime music library This program must run as a user with permissions to write to your Airtime music library
directory. For standard Airtime installations, run it as the www-data user: directory. For standard Airtime installations, run it as the libretime user:
```bash ```bash
sudo -u www-data libretime-analyzer --daemon sudo -u libretime libretime-analyzer --daemon
``` ```
Or during development, add the --debug flag for more verbose output: Or during development, add the --debug flag for more verbose output:
```bash ```bash
sudo -u www-data libretime-analyzer --debug sudo -u libretime libretime-analyzer --debug
``` ```
To print usage instructions, run: To print usage instructions, run:

View File

@ -8,8 +8,8 @@ Environment=LIBRETIME_CONFIG_FILEPATH=@@CONFIG_FILEPATH@@
WorkingDirectory=@@WORKING_DIR@@/analyzer WorkingDirectory=@@WORKING_DIR@@/analyzer
ExecStart=/usr/local/bin/libretime-analyzer ExecStart=/usr/local/bin/libretime-analyzer
User=libretime-analyzer User=libretime
Group=libretime-analyzer Group=libretime
Restart=always Restart=always
[Install] [Install]

View File

@ -64,7 +64,7 @@ cd /vagrant/api
sudo pip3 install -e . sudo pip3 install -e .
sudo systemctl stop libretime-api sudo systemctl stop libretime-api
sudo -u www-data LIBRETIME_DEBUG=True libretime-api runserver 0.0.0.0:8081 sudo -u libretime LIBRETIME_DEBUG=True libretime-api runserver 0.0.0.0:8081
``` ```
## 3rd Party Licences ## 3rd Party Licences

View File

@ -16,8 +16,8 @@ ExecStart=/usr/bin/gunicorn \
--bind 127.0.0.1:8081 \ --bind 127.0.0.1:8081 \
libretime_api.wsgi libretime_api.wsgi
ExecReload=/bin/kill -s HUP $MAINPID ExecReload=/bin/kill -s HUP $MAINPID
User=libretime-api User=libretime
Group=libretime-api Group=libretime
Restart=always Restart=always
[Install] [Install]

View File

@ -10,7 +10,7 @@ This page describe the available options to manage the LibreTime library.
To scan a directory and import the files into the library, you can use the following command: To scan a directory and import the files into the library, you can use the following command:
```bash ```bash
sudo -u www-data libretime-api bulk_import --path PATH_THE_DIRECTORY_TO_SCAN sudo -u libretime libretime-api bulk_import --path PATH_THE_DIRECTORY_TO_SCAN
``` ```
See the command usage to get available options. See the command usage to get available options.

View File

@ -162,10 +162,10 @@ Feel free to run `./install --help` to get more details.
#### Using hardware audio output #### Using hardware audio output
If you plan to output analog audio directly to a mixing console or transmitter, the user running LibreTime (by default `www-data`) needs to be added to the `audio` user group using the command below: If you plan to output analog audio directly to a mixing console or transmitter, the user running LibreTime needs to be added to the `audio` user group using the command below:
```bash ```bash
sudo adduser www-data audio sudo adduser libretime audio
``` ```
### Setup ### Setup
@ -175,7 +175,7 @@ Once the installation is completed, edit the [configuration file](./configuratio
Next, run the following commands to setup the database: Next, run the following commands to setup the database:
```bash ```bash
sudo -u www-data libretime-api migrate sudo -u libretime libretime-api migrate
``` ```
Synchronize the new Icecast passwords into the database: Synchronize the new Icecast passwords into the database:

View File

@ -36,7 +36,7 @@ Be sure to carefully read **all** the [releases notes](../../releases/README.md)
Run the following command to apply the database migrations: Run the following command to apply the database migrations:
```bash ```bash
sudo -u www-data libretime-api migrate sudo -u libretime libretime-api migrate
``` ```
## Restart the services ## Restart the services

View File

@ -49,7 +49,7 @@ On a common setup, to access LibreTime specific logs you should search for the f
For some LibreTime services, you can set a higher log level using the `LIBRETIME_LOG_LEVEL` environment variable, or by running the service by hand and using a command line flag: For some LibreTime services, you can set a higher log level using the `LIBRETIME_LOG_LEVEL` environment variable, or by running the service by hand and using a command line flag:
```bash ```bash
sudo -u www-data libretime-analyzer --config /etc/libretime/config.yml --log-level debug sudo -u libretime libretime-analyzer --config /etc/libretime/config.yml --log-level debug
``` ```
The `/var/log/apache2/libretime.error.log` file contains logs from the web server. The `/var/log/apache2/libretime.error.log` file contains logs from the web server.

View File

@ -110,6 +110,21 @@ The worker service no longer uses a dedicated `celery` user to run. The old `cel
sudo deluser celery sudo deluser celery
``` ```
### LibreTime user
The LibreTime services now run using a dedicated `libretime` user instead of the default `www-data` user. Be sure to change the ownership of the LibreTime files:
```bash
# Configuration directory
sudo chown -R libretime:libretime /etc/libretime
# Logs directory
sudo chown -R libretime:libretime /var/log/libretime
# Runtime directory
sudo chown -R libretime:libretime /var/lib/libretime
# Storage directory
sudo chown -R libretime:libretime /srv/libretime
```
### New configuration schema ### New configuration schema
The configuration schema was updated. The configuration schema was updated.

View File

@ -311,7 +311,7 @@ sudo nano /etc/cron.d/libretime-schedule
containing the line: containing the line:
``` ```
* * * * * www-data /usr/local/bin/libretime-schedule.sh * * * * * libretime /usr/local/bin/libretime-schedule.sh
``` ```
The schedule server will now be serving the same show information as the LibreTime server, with a cache lifetime of one minute. You can adjust the cache lifetime by altering the frequency of the cron job that polls the LibreTime server. The schedule server will now be serving the same show information as the LibreTime server, with a cache lifetime of one minute. You can adjust the cache lifetime by altering the frequency of the cron job that polls the LibreTime server.

View File

@ -98,7 +98,7 @@ EOF
# Configuration # Configuration
# > User used to run LibreTime. # > User used to run LibreTime.
LIBRETIME_USER=${LIBRETIME_USER:-"www-data"} LIBRETIME_USER=${LIBRETIME_USER:-"libretime"}
# > Listen port for LibreTime. # > Listen port for LibreTime.
LIBRETIME_LISTEN_PORT=${LIBRETIME_LISTEN_PORT:-"80"} LIBRETIME_LISTEN_PORT=${LIBRETIME_LISTEN_PORT:-"80"}
# > Public URL for LibreTime. # > Public URL for LibreTime.
@ -177,6 +177,8 @@ done
PYTHON="python3" PYTHON="python3"
PIP="$PYTHON -m pip" PIP="$PYTHON -m pip"
DEFAULT_WEB_USER="www-data"
# Paths # Paths
CONFIG_DIR="/etc/libretime" CONFIG_DIR="/etc/libretime"
CONFIG_FILEPATH="$CONFIG_DIR/config.yml" CONFIG_FILEPATH="$CONFIG_DIR/config.yml"
@ -394,6 +396,11 @@ prepare_packages_install
install_packages git make install_packages git make
make VERSION make VERSION
info "creating project user"
if ! id "$LIBRETIME_USER" &> /dev/null; then
useradd --no-create-home --home-dir "$WORKING_DIR" "$LIBRETIME_USER"
fi
info "creating project directories" info "creating project directories"
# TODO: Config dir should not be owned by www-data and should be readonly # TODO: Config dir should not be owned by www-data and should be readonly
mkdir_and_chown "$LIBRETIME_USER" "$CONFIG_DIR" mkdir_and_chown "$LIBRETIME_USER" "$CONFIG_DIR"

View File

@ -6,6 +6,4 @@ DEBIAN_FRONTEND=noninteractive apt-get update --allow-releaseinfo-change
DEBIAN_FRONTEND=noninteractive apt-get -y -qq install auto-apt-proxy DEBIAN_FRONTEND=noninteractive apt-get -y -qq install auto-apt-proxy
# Install utils # Install utils
DEBIAN_FRONTEND=noninteractive apt-get -y -qq install alsa-utils vim DEBIAN_FRONTEND=noninteractive apt-get -y -qq install vim
usermod -a -G audio vagrant
usermod -a -G audio www-data

View File

@ -15,3 +15,8 @@ systemctl restart postgresql.service
# Setup rabbitmq management interface # Setup rabbitmq management interface
rabbitmq-plugins enable rabbitmq_management rabbitmq-plugins enable rabbitmq_management
rabbitmqctl set_user_tags libretime administrator rabbitmqctl set_user_tags libretime administrator
# Setup audio
DEBIAN_FRONTEND=noninteractive apt-get -y -qq install alsa-utils
usermod -a -G audio vagrant
usermod -a -G audio libretime

View File

@ -8,8 +8,8 @@ Environment=LIBRETIME_CONFIG_FILEPATH=@@CONFIG_FILEPATH@@
WorkingDirectory=@@WORKING_DIR@@/playout WorkingDirectory=@@WORKING_DIR@@/playout
ExecStart=/usr/local/bin/libretime-liquidsoap ExecStart=/usr/local/bin/libretime-liquidsoap
User=libretime-playout User=libretime
Group=libretime-playout Group=libretime
Restart=always Restart=always
[Install] [Install]

View File

@ -8,8 +8,8 @@ Environment=LIBRETIME_CONFIG_FILEPATH=@@CONFIG_FILEPATH@@
WorkingDirectory=@@WORKING_DIR@@/playout WorkingDirectory=@@WORKING_DIR@@/playout
ExecStart=/usr/local/bin/libretime-playout ExecStart=/usr/local/bin/libretime-playout
User=libretime-playout User=libretime
Group=libretime-playout Group=libretime
Restart=always Restart=always
[Install] [Install]

View File

@ -14,8 +14,8 @@ ExecStart=/usr/bin/sh -c 'celery worker \
--concurrency=1 \ --concurrency=1 \
--loglevel=INFO \ --loglevel=INFO \
--logfile=$LIBRETIME_LOG_FILEPATH' --logfile=$LIBRETIME_LOG_FILEPATH'
User=libretime-worker User=libretime
Group=libretime-worker Group=libretime
Restart=always Restart=always
[Install] [Install]