Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions debian/authd-example-broker.examples
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
examplebroker/ExampleBroker.conf
debian/authd-example-broker.service
debian/authd-example-broker.installer.sh
6 changes: 6 additions & 0 deletions debian/authd-example-broker.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/dh-exec

usr/bin/examplebroker-bin => ${env:AUTHD_DAEMONS_PATH}/authd-examplebroker

examplebroker/com.ubuntu.authd.ExampleBroker.conf /usr/share/dbus-1/system.d
examplebroker/com.ubuntu.authd.ExampleBroker.service /usr/share/dbus-1/system-services
Comment on lines +1 to +6
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is still not what we want. IMHO, the examplebroker should be an executable that, when executed, exports the broker on dbus and cleans it up when the program finishes running. This way, we don't need to worry about having to install/uninstall it. Its purpose is to test authd, not the broker behaviour, so we don't need anything directly configured on dbus (as authd does not directly care about it).

Copy link
Copy Markdown
Contributor Author

@3v1n0 3v1n0 Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the point, but that wouldn't allow proper testing, especially if we want to do proper autopkgtests were you just install everything and then you run a client that would work as the system would be configured properly.

so we don't need anything directly configured on dbus (as authd does not directly care about it).

In fact authd does care about it, because if that would happen when we run the daemon, then we wouldn't be able of testing the case that authd does dbus-activation of the service when that you select the broker on the brokers list.

Also, not having a script like this would imply that we rely on the autopkgtest script to do that, but IMHO it's not nice to maintain the same in two different places.

What we may want to do, in case, is to make the examplebrorker to do the conf setup in case that's not set, and I can do that, but I feel we should still provide a way to create what would be the real setup in a properly configured machine.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, also having those files installed doesn't allow anything but just having the service to own the name, and while these may be handled by the service itself, as I said, I'd prefer to be able to do dbus-activation (but only through systemd that it's not installed by default).

45 changes: 45 additions & 0 deletions debian/authd-example-broker.installer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/sh

set -eu

usage() {
echo "$0 [install | uninstall | help]"
}

if [ -z "$0" ]; then
usage
exit 1
fi

if [ "$(id -u)" != 0 ]; then
echo "Need to run as root"
exit
fi

SYSTEMD_SERVICE=authd-example-broker.service
CONFIG_FILE=ExampleBroker.conf

if [ "$1" = "install" ]; then
install -m644 \
/usr/share/doc/authd-example-broker/examples/"${CONFIG_FILE}" \
-Dt /etc/authd/brokers.d

install -m644 \
/usr/share/doc/authd-example-broker/examples/"${SYSTEMD_SERVICE}" \
-Dt /usr/lib/systemd/system

systemctl daemon-reload
elif [ "$1" = "uninstall" ]; then
rm -fv /etc/authd/brokers.d/"${CONFIG_FILE}"
rmdir -v /etc/authd/brokers.d 2>/dev/null || true
rm -fv /usr/lib/systemd/system/"${SYSTEMD_SERVICE}"

systemctl daemon-reload
elif [ "$1" = "help" ]; then
usage
exit 0
else
echo "unknown command '$1'"
usage
exit 1
fi
20 changes: 20 additions & 0 deletions debian/authd-example-broker.service.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[Unit]
Description=Authd Example Broker
After=authd.service
Requires=authd.service

[Service]
Type=dbus
BusName=com.ubuntu.authd.ExampleBroker
ExecStart=@AUTHD_DAEMONS_PATH@/authd-examplebroker
Restart=on-failure

# Some daemon restrictions
ProtectSystem=strict
ProtectControlGroups=true
ProtectHome=true
ProtectKernelModules=true
PrivateTmp=true
RestrictAddressFamilies=AF_UNIX AF_LOCAL AF_NETLINK
MemoryDenyWriteExecute=true
RestrictRealtime=true
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion debian/install → debian/authd.install
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ ${env:BUILT_PAM_LIBS_PATH}/pam_authd.so ${env:AUTHD_PAM_MODULES_PATH}
${env:BUILT_PAM_LIBS_PATH}/go-loader/pam_go_loader.so ${env:AUTHD_PAM_MODULES_PATH}

# Install NSS library with right soname
target/${DEB_HOST_RUST_TYPE}/release/libnss_authd.so => /usr/lib/${DEB_TARGET_GNU_TYPE}/libnss_authd.so.2
target/${env:DEB_HOST_RUST_TYPE}/release/libnss_authd.so => /usr/lib/${env:DEB_TARGET_GNU_TYPE}/libnss_authd.so.2
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 12 additions & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Build-Depends: debhelper-compat (= 13),
dbus <!nocheck>,
dh-apport,
dh-cargo,
dh-exec,
dh-exec (>= 0.29),
dh-golang,
dctrl-tools,
golang-go (>= 2:1.22~),
Expand Down Expand Up @@ -41,3 +41,14 @@ Description: ${source:Synopsis}
.
This package contains the authentication daemon together with the PAM & NSS
modules.

Package: authd-example-broker
Recommends: authd
Architecture: any
Built-Using: ${misc:Built-Using},
Depends: ${shlibs:Depends},
${misc:Depends},
Description: ${source:Synopsis} - Example broker
${source:Extended-Description}
.
This package contains an example broker for testing and autopkgtests purposes.
13 changes: 11 additions & 2 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ export AUTHD_SKIP_ROOT_TESTS := 1
export DH_GOLANG_BUILDPKG := $(AUTHD_GO_PACKAGE)/... \
$(NULL)

BUILDDIR := $(CURDIR)/obj-$(DEB_HOST_GNU_TYPE)

export BUILT_PAM_LIBS_PATH := obj-$(DEB_HOST_GNU_TYPE)/src/$(AUTHD_GO_PACKAGE)/pam

EXAMPLE_BROKER_BUILD_TAG := with_standalone_examplebroker

%:
# --without=single-binary can be removed with dh 15.
dh $@ --buildsystem=golang --with=golang,apport --without=single-binary
Expand Down Expand Up @@ -93,6 +93,11 @@ override_dh_auto_build:
# Build the daemon
dh_auto_build -- $(AUTHD_GO_PACKAGE)/cmd/authd

# Build the example broker because otherwise it's not
# part of the normal install.
dh_auto_build -- -tags $(EXAMPLE_BROKER_BUILD_TAG) \
$(AUTHD_GO_PACKAGE)/examplebroker/examplebroker-bin

override_dh_auto_install:
dh_auto_install --destdir=debian/tmp -- --no-source

Expand All @@ -101,3 +106,7 @@ override_dh_auto_install:

# Install gdm-PAM config file
dh_installpam -pauthd --name=gdm-authd

override_dh_installsystemd:
# Install example-broker service file only by default
dh_installsystemd -pauthd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Add this to /etc/authd/broker.d to configure the ExampleBroker
# Add this to /etc/authd/brokers.d to configure the ExampleBroker
[authd]
name = ExampleBroker
brand_icon = /usr/share/backgrounds/warty-final-ubuntu.png
Expand Down
5 changes: 5 additions & 0 deletions examplebroker/com.ubuntu.authd.ExampleBroker.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[D-BUS Service]
Name=com.ubuntu.authd.ExampleBroker
Exec=/bin/false
User=root
SystemdService=authd-example-broker.service
28 changes: 28 additions & 0 deletions examplebroker/examplebroker-bin/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//go:build with_standalone_examplebroker

package main

import (
"context"
"log"
"os"

"github.com/ubuntu/authd/examplebroker"
)

func main() {
// Create the directory for the broker configuration files.
cfgPath, err := os.MkdirTemp(os.TempDir(), "standalonebroker.d")
if err != nil {
log.Fatal(err)
}
defer os.RemoveAll(cfgPath)

conn, err := examplebroker.StartBus(cfgPath)
if err != nil {
log.Fatal("Error starting standalone broker:", err)
}
defer conn.Close()

<-context.Background().Done()
}