Skip to content
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

systemd: Use systemd-sysusers to create cockpit-wsinstance user #20365

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/systemd/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ install-exec-hook::
tmpfilesconfdir = $(prefix)/lib/tmpfiles.d
nodist_tmpfilesconf_DATA = src/systemd/tmpfiles.d/cockpit-ws.conf

sysusersconfdir = $(prefix)/lib/sysusers.d
dist_sysusersconf_DATA = src/systemd/sysusers.d/cockpit-ws.conf

# we can't generate these with config.status because,
# eg. it does "@libexecdir@" -> "${exec_prefix}/libexec"
src/systemd/%: src/systemd/%.in
Expand Down
4 changes: 3 additions & 1 deletion src/systemd/cockpit.service.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ Description=Cockpit Web Service
Documentation=man:cockpit-ws(8)
Requires=cockpit.socket
Requires=cockpit-wsinstance-http.socket cockpit-wsinstance-https-factory.socket
After=cockpit-wsinstance-http.socket cockpit-wsinstance-https-factory.socket
# we need to start before the sockets so that the dynamic user exists
Before=cockpit-wsinstance-http.socket cockpit-wsinstance-https-factory.socket

[Service]
RuntimeDirectory=cockpit/tls
# systemd ≥ 241 sets this automatically
Environment=RUNTIME_DIRECTORY=/run/cockpit/tls
ExecStartPre=+@libexecdir@/cockpit-certificate-ensure --for-cockpit-tls
ExecStart=@libexecdir@/cockpit-tls
DynamicUser=true
User=cockpit-ws
Group=cockpit-ws
NoNewPrivileges=true
Expand Down
1 change: 1 addition & 0 deletions src/systemd/sysusers.d/cockpit-ws.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
u cockpit-wsinstance - "User for cockpit-ws instances" -
1 change: 1 addition & 0 deletions src/systemd/tmpfiles.d/cockpit-ws.conf.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
z @libexecdir@/cockpit-session - - cockpit-wsinstance -
travier marked this conversation as resolved.
Show resolved Hide resolved
C /run/cockpit/inactive.motd 0640 root @admin_group@ - @datadir@/@PACKAGE@/motd/inactive.motd
f /run/cockpit/active.motd 0640 root @admin_group@ -
L+ /run/cockpit/motd - - - - inactive.motd
1 change: 0 additions & 1 deletion test/verify/check-connection
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ class TestConnection(testlib.MachineCase):
if not m.ostree_image:
m.execute("""cat /etc/cockpit/ws-certs.d/cert-chain.key >> /etc/cockpit/ws-certs.d/cert-chain.crt
chmod 640 /etc/cockpit/ws-certs.d/cert-chain.crt
chown root:cockpit-ws /etc/cockpit/ws-certs.d/cert-chain.crt
rm /etc/cockpit/ws-certs.d/cert-chain.key""")
check_cert_chain()

Expand Down
12 changes: 2 additions & 10 deletions tools/arch/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@ makedepends=(krb5 libssh accountsservice json-glib glib-networking
git intltool gtk-doc gobject-introspection networkmanager xmlto npm pcp
python-build python-installer python-wheel)
source=("cockpit-${pkgver}.tar.xz"
"cockpit.pam"
"cockpit-ws.sysuser.conf"
"cockpit-wsinstance.sysuser.conf")
"cockpit.pam")
sha256sums=('SKIP'
'079bb6751214e642673f9e1212df2a17fed1a3cc6cfdd6375af2b68ed6ddd340'
'1ad9dad75858264778bd94799b60c651f7cc1c7f7fa1c54622174303e639287a'
'46ee8ecad7bc97ba588ab9471dde76e41c00daf40658902425626c3a1938b438')
'079bb6751214e642673f9e1212df2a17fed1a3cc6cfdd6375af2b68ed6ddd340')

prepare() {
cd cockpit-$pkgver
Expand Down Expand Up @@ -61,10 +57,6 @@ package_cockpit() {
make DESTDIR="$pkgdir" install
rm -rf "$pkgdir"/usr/{src,lib/firewalld}
install -Dm644 "$srcdir"/cockpit.pam "$pkgdir"/etc/pam.d/cockpit
install -Dm644 "$srcdir"/cockpit-ws.sysuser.conf "$pkgdir"/usr/lib/sysusers.d/cockpit-ws.conf
install -Dm644 "$srcdir"/cockpit-wsinstance.sysuser.conf "$pkgdir"/usr/lib/sysusers.d/cockpit-wsinstance.conf

echo "z /usr/lib/cockpit/cockpit-session - - cockpit-wsinstance -" >> "$pkgdir"/usr/lib/tmpfiles.d/cockpit-ws.conf

# remove unused plugins
rm -rf "$pkgdir"/usr/share/cockpit/{selinux,playground,sosreport} \
Expand Down
1 change: 0 additions & 1 deletion tools/arch/cockpit-ws.sysuser.conf

This file was deleted.

1 change: 0 additions & 1 deletion tools/arch/cockpit-wsinstance.sysuser.conf

This file was deleted.

6 changes: 1 addition & 5 deletions tools/cockpit.spec
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ authentication via sssd/FreeIPA.
%{_unitdir}/cockpit-wsinstance-https@.service
%{_unitdir}/system-cockpithttps.slice
%{_prefix}/%{__lib}/tmpfiles.d/cockpit-ws.conf
%{_sysusersdir}/cockpit-ws.conf
%{pamdir}/pam_ssh_add.so
%{pamdir}/pam_cockpit_cert.so
%{_libexecdir}/cockpit-ws
Expand All @@ -419,11 +420,6 @@ authentication via sssd/FreeIPA.
%ghost %{_sharedstatedir}/selinux/%{selinuxtype}/active/modules/200/%{name}

%pre ws
getent group cockpit-ws >/dev/null || groupadd -r cockpit-ws
getent passwd cockpit-ws >/dev/null || useradd -r -g cockpit-ws -d /nonexisting -s /sbin/nologin -c "User for cockpit web service" cockpit-ws
getent group cockpit-wsinstance >/dev/null || groupadd -r cockpit-wsinstance
getent passwd cockpit-wsinstance >/dev/null || useradd -r -g cockpit-wsinstance -d /nonexisting -s /sbin/nologin -c "User for cockpit-ws instances" cockpit-wsinstance

if %{_sbindir}/selinuxenabled 2>/dev/null; then
%selinux_relabel_pre -s %{selinuxtype}
fi
Expand Down
1 change: 1 addition & 0 deletions tools/debian/cockpit-ws.install
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ${env:deb_systemdsystemunitdir}/system-cockpithttps.slice
${env:deb_pamlibdir}/security/pam_ssh_add.so
${env:deb_pamlibdir}/security/pam_cockpit_cert.so
usr/lib/tmpfiles.d/cockpit-ws.conf
usr/lib/sysusers.d/cockpit-ws.conf
usr/lib/cockpit/cockpit-session
usr/lib/cockpit/cockpit-ws
usr/lib/cockpit/cockpit-wsinstance-factory
Expand Down
11 changes: 1 addition & 10 deletions tools/debian/cockpit-ws.postinst
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
#!/bin/sh
set -e

adduser --system --group --home /nonexistent --no-create-home --quiet cockpit-ws
adduser --system --group --home /nonexistent --no-create-home --quiet cockpit-wsinstance

# change group of cockpit-session on upgrades (changed in version 203)
if OUT=$(dpkg-statoverride --list /usr/lib/cockpit/cockpit-session) && [ "$OUT#root cockpit-ws 4750}" != "$OUT" ]; then
echo "Adjusting /usr/lib/cockpit/cockpit-session permissions..."
dpkg-statoverride --remove /usr/lib/cockpit/cockpit-session
fi
#DEBHELPER#

if ! dpkg-statoverride --list /usr/lib/cockpit/cockpit-session >/dev/null; then
dpkg-statoverride --update --add root cockpit-wsinstance 4750 /usr/lib/cockpit/cockpit-session
fi

#DEBHELPER#

# restart cockpit.service on package upgrades, if it's already running
if [ -d /run/systemd/system ] && [ -n "$2" ]; then
deb-systemd-invoke try-restart cockpit.service >/dev/null || true
Expand Down
2 changes: 2 additions & 0 deletions tools/debian/cockpit-ws.postrm
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ if [ "$1" = purge ]; then
[ -L /etc/motd.d/cockpit ] && rm /etc/motd.d/cockpit || true
[ -L /etc/issue.d/cockpit.issue ] && rm /etc/issue.d/cockpit.issue || true
rm -f /etc/cockpit/disallowed-users

dpkg-statoverride --remove /usr/lib/cockpit/cockpit-session
fi
4 changes: 4 additions & 0 deletions tools/debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,7 @@ else
pytest -vv -k 'not linter and not test_descriptions' -opythonpath=$$(ls -d debian/cockpit-bridge/usr/lib/python3*/dist-packages)
endif
endif

# dh compat 14 does that automatically, remove when upgrading
execute_before_dh_installtmpfiles:
dh_installsysusers