Skip to content

Commit

Permalink
Use DynamicUser instead of static users
Browse files Browse the repository at this point in the history
To allow this, we need a more lenient policy for owning the service's
name on the system bus.
  • Loading branch information
dylanmccall committed Feb 12, 2021
1 parent 7708c46 commit 1ce3358
Show file tree
Hide file tree
Showing 12 changed files with 13 additions and 41 deletions.
6 changes: 1 addition & 5 deletions data/dbus/org.learningequality.Kolibri.Daemon.conf.in
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <!-- -*- XML -*- -->
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<!-- Only @KOLIBRI_USER@ can own the service -->
<policy user="@KOLIBRI_USER@">
<allow own="@KOLIBRI_DAEMON_SERVICE@" />
</policy>

<!-- Any user can call into the service -->
<policy context="default">
<allow own="@KOLIBRI_DAEMON_SERVICE@" />
<allow send_destination="@KOLIBRI_DAEMON_SERVICE@" send_interface="org.freedesktop.DBus.Introspectable" />
<allow send_destination="@KOLIBRI_DAEMON_SERVICE@" send_interface="org.freedesktop.DBus.Properties" />
<allow send_destination="@KOLIBRI_DAEMON_SERVICE@" send_interface="org.learningequality.Kolibri.Daemon" />
Expand Down
2 changes: 1 addition & 1 deletion data/dbus/org.learningequality.Kolibri.Daemon.service.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[D-BUS Service]
Name=@KOLIBRI_DAEMON_SERVICE@
Exec=/bin/false
User=@KOLIBRI_USER@
User=root
SystemdService=dbus-@KOLIBRI_DAEMON_SERVICE@.service
2 changes: 0 additions & 2 deletions data/meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
subdir('dbus')
subdir('environment.d')
subdir('systemd')
subdir('sysusers.d')
subdir('tmpfiles.d')

Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ ConditionPathExists=/var/lib/flatpak/app/@KOLIBRI_FLATPAK_ID@
Type=dbus
BusName=@KOLIBRI_DAEMON_SERVICE@
ExecStart=@libexecdir@/eos-kolibri-daemon
DynamicUser=yes
User=@KOLIBRI_USER@
PrivateTmp=yes
RuntimeDirectory=kolibri
StateDirectory=kolibri
Environment=HOME=%t/kolibri
1 change: 0 additions & 1 deletion data/sysusers.d/eos-kolibri.conf.in

This file was deleted.

6 changes: 0 additions & 6 deletions data/sysusers.d/meson.build

This file was deleted.

3 changes: 0 additions & 3 deletions data/tmpfiles.d/eos-kolibri.conf.in

This file was deleted.

6 changes: 0 additions & 6 deletions data/tmpfiles.d/meson.build

This file was deleted.

7 changes: 1 addition & 6 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,8 @@ dbus_system_conf_dir = join_paths(datadir, 'dbus-1', 'system.d')

kolibri_user = get_option('kolibri_user')

kolibri_user_home = get_option('kolibri_user_home')
if kolibri_user_home == ''
kolibri_user_home = join_paths(get_option('prefix'), get_option('localstatedir'), 'lib', 'kolibri')
endif
kolibri_data_dir = join_paths(get_option('prefix'), get_option('localstatedir'), 'lib', 'kolibri', 'data')

kolibri_data_dir = join_paths(kolibri_user_home, 'data')
kolibri_flatpak_id = get_option('kolibri_flatpak_id')
kolibri_daemon_service = '@0@.Daemon'.format(kolibri_flatpak_id)

Expand All @@ -66,7 +62,6 @@ eos_kolibri_config.set('libexecdir', libexecdir)
eos_kolibri_config.set('PYTHON', 'python3')
eos_kolibri_config.set('PYTHON_INSTALL_DIR', python_install_dir)
eos_kolibri_config.set('KOLIBRI_USER', kolibri_user)
eos_kolibri_config.set('KOLIBRI_USER_HOME', kolibri_user_home)
eos_kolibri_config.set('KOLIBRI_DATA_DIR', kolibri_data_dir)
eos_kolibri_config.set('KOLIBRI_FLATPAK_ID', kolibri_flatpak_id)
eos_kolibri_config.set('KOLIBRI_DAEMON_SERVICE', kolibri_daemon_service)
Expand Down
7 changes: 0 additions & 7 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ option(
description: 'user to create for the system service'
)

option(
'kolibri_user_home',
type: 'string',
value: '',
description: 'home directory for the system user [default=$localstatedir/lib/kolibri]'
)

option(
'kolibri_flatpak_id',
type: 'string',
Expand Down
6 changes: 5 additions & 1 deletion src/eos-kolibri-daemon.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/bin/sh

: ${KOLIBRI_HOME:="@KOLIBRI_DATA_DIR@"}
: ${STATE_DIRECTORY:=/var/lib/kolibri}

export KOLIBRI_HOME="${STATE_DIRECTORY}/data"

mkdir -p "${KOLIBRI_HOME}"

@bindir@/flatpak run \
--no-desktop \
Expand Down
3 changes: 1 addition & 2 deletions src/eos_kolibri/config.py.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/python3

KOLIBRI_DATA_DIR = '@KOLIBRI_DATA_DIR@'
KOLIBRI_FLATPAK_ID = '@KOLIBRI_FLATPAK_ID@'
KOLIBRI_SYSTEMD_SERVICE_NAME = 'dbus-@KOLIBRI_DAEMON_SERVICE@.service'

KOLIBRI_USER = '@KOLIBRI_USER@'
KOLIBRI_DATA_DIR = '@KOLIBRI_DATA_DIR@'

0 comments on commit 1ce3358

Please sign in to comment.