This commit is contained in:
Jorijn van der Graaf 2026-11-01 18:35:23 +01:00
commit 1ea50c50bc
62 changed files with 9982 additions and 608 deletions

42
packaging/system/install.sh Executable file
View file

@ -0,0 +1,42 @@
#!/bin/sh
# SPDX-License-Identifier: LGPL-3.0-only
# SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
#
# Installs nostro for every user of this machine: the system files nostrod needs (its user, its D-Bus and polkit
# policies, its systemd unit, the nostro command) and the net.catcrafts.Nostro Flatpak, system-wide. Run as root.
#
# install.sh the Flatpak from the system remote "catcrafts" (packaging/flatpak/net.catcrafts.Nostro.flatpakref
# sets it up: flatpak install --system net.catcrafts.Nostro.flatpakref)
# install.sh --repo DIR the Flatpak from a local repository, as flatpak-builder --repo=DIR makes one, for testing
#
# Running it again updates. packaging/arch/PKGBUILD installs the same files from a package; uninstall.sh removes them.
set -eu
here=$(cd "$(dirname "$0")" && pwd)
repo=
if [ "${1:-}" = --repo ]; then
repo=$(cd "${2:?--repo needs a directory}" && pwd)
fi
install -Dm644 "$here/nostro.sysusers" /usr/lib/sysusers.d/nostro.conf
systemd-sysusers /usr/lib/sysusers.d/nostro.conf
install -Dm644 "$here/net.catcrafts.Nostro1.conf" /usr/share/dbus-1/system.d/net.catcrafts.Nostro1.conf
install -Dm644 "$here/net.catcrafts.Nostro1.service" /usr/share/dbus-1/system-services/net.catcrafts.Nostro1.service
install -Dm644 "$here/net.catcrafts.Nostro1.Checkout.service" /usr/share/dbus-1/system-services/net.catcrafts.Nostro1.Checkout.service
install -Dm644 "$here/net.catcrafts.Nostro1.policy" /usr/share/polkit-1/actions/net.catcrafts.Nostro1.policy
install -Dm644 "$here/nostrod.service" /etc/systemd/system/nostrod.service
install -Dm755 "$here/nostro" /usr/local/bin/nostro
if [ -n "$repo" ]; then
# A local repository is unsigned: for a build of your own, never for one from elsewhere.
flatpak remote-add --system --if-not-exists --no-gpg-verify nostro-local "file://$repo"
flatpak install --system -y --noninteractive --or-update nostro-local net.catcrafts.Nostro//stable
else
flatpak install --system -y --noninteractive --or-update catcrafts net.catcrafts.Nostro//stable
fi
systemctl daemon-reload
busctl call org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus ReloadConfig
# A nostrod already running keeps the old files until it ends; stop it, and the next call starts the new one.
systemctl try-restart nostrod.service
echo "nostro is installed: nostrod starts with the first call, such as 'nostro connectors add bunq'"

View file

@ -0,0 +1,8 @@
# SPDX-License-Identifier: LGPL-3.0-only
# SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
# An app's first checkout starts nostrod, through systemd. Install: /usr/share/dbus-1/system-services/
[D-BUS Service]
Name=net.catcrafts.Nostro1.Checkout
Exec=/bin/false
User=nostro
SystemdService=nostrod.service

View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<!-- SPDX-License-Identifier: LGPL-3.0-only -->
<!-- SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts® -->
<!-- nostrod owns its two names as the user nostro, and anyone may call them: nostrod answers each caller for their own
bank connections alone, and asks polkit first (net.catcrafts.Nostro1.policy).
Install: /usr/share/dbus-1/system.d/net.catcrafts.Nostro1.conf -->
<busconfig>
<policy user="nostro">
<allow own="net.catcrafts.Nostro1"/>
<allow own="net.catcrafts.Nostro1.Checkout"/>
</policy>
<policy context="default">
<allow send_destination="net.catcrafts.Nostro1"/>
<allow send_destination="net.catcrafts.Nostro1.Checkout"/>
</policy>
</busconfig>

View file

@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?> <!--*-nxml-*-->
<!-- SPDX-License-Identifier: LGPL-3.0-only -->
<!-- SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts® -->
<!DOCTYPE policyconfig PUBLIC "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
"http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
<!-- What nostrod (net.catcrafts.Nostro1) asks polkit before it does anything for a caller.
Every action is owned by unix-user:nostro, the user nostrod runs as: polkit lets only root or an action's owner
check a call made by another user, or pass the details the dialog shows. $(summary) is what nostrod read for the
call itself, such as the amount, the payee and the account of a payment; the details amount_minor, currency,
counterparty, account_iban, environment and, at checkout, reference are there for rules (an amount above which an
administrator must approve, say).
No action keeps an authorization: polkit ties a kept one to the calling process, so the CLI would ask every time
anyway. Viewing and the changes that move no money are free in an active session; whatever moves money (an app's
checkout included), unfreezes or blocks a card, or changes the bank connections or the account checkouts pay from
asks for the user's password every time.
Install: /usr/share/polkit-1/actions/net.catcrafts.Nostro1.policy. Tune with rules in /etc/polkit-1/rules.d/. -->
<policyconfig>
<vendor>Catcrafts</vendor>
<action id="net.catcrafts.Nostro1.View">
<description>See your bank accounts, transactions, requests and cards</description>
<message>Authentication is required to $(summary)</message>
<defaults>
<allow_any>auth_self</allow_any>
<allow_inactive>auth_self</allow_inactive>
<allow_active>yes</allow_active>
</defaults>
<annotate key="org.freedesktop.policykit.owner">unix-user:nostro</annotate>
</action>
<action id="net.catcrafts.Nostro1.Change">
<description>Ask for money, make draft payments, cancel what is pending, or freeze a card</description>
<message>Authentication is required to $(summary)</message>
<defaults>
<allow_any>auth_self</allow_any>
<allow_inactive>auth_self</allow_inactive>
<allow_active>yes</allow_active>
</defaults>
<annotate key="org.freedesktop.policykit.owner">unix-user:nostro</annotate>
</action>
<action id="net.catcrafts.Nostro1.Pay">
<description>Make a payment, schedule one, or accept a request or a draft payment</description>
<message>Authentication is required to $(summary)</message>
<defaults>
<allow_any>auth_self</allow_any>
<allow_inactive>auth_self</allow_inactive>
<allow_active>auth_self</allow_active>
</defaults>
<annotate key="org.freedesktop.policykit.owner">unix-user:nostro</annotate>
</action>
<action id="net.catcrafts.Nostro1.UnfreezeCard">
<description>Let a frozen card pay again</description>
<message>Authentication is required to $(summary)</message>
<defaults>
<allow_any>auth_self</allow_any>
<allow_inactive>auth_self</allow_inactive>
<allow_active>auth_self</allow_active>
</defaults>
<annotate key="org.freedesktop.policykit.owner">unix-user:nostro</annotate>
</action>
<action id="net.catcrafts.Nostro1.BlockCard">
<description>Report a card lost or stolen, which blocks it for good</description>
<message>Authentication is required to $(summary)</message>
<defaults>
<allow_any>auth_self</allow_any>
<allow_inactive>auth_self</allow_inactive>
<allow_active>auth_self</allow_active>
</defaults>
<annotate key="org.freedesktop.policykit.owner">unix-user:nostro</annotate>
</action>
<action id="net.catcrafts.Nostro1.Connectors">
<description>Add or remove a bank connection, or choose the account apps may ask you to pay from</description>
<message>Authentication is required to $(summary)</message>
<defaults>
<allow_any>auth_self</allow_any>
<allow_inactive>auth_self</allow_inactive>
<allow_active>auth_self</allow_active>
</defaults>
<annotate key="org.freedesktop.policykit.owner">unix-user:nostro</annotate>
</action>
<action id="net.catcrafts.Nostro1.Checkout">
<description>Pay an order an app asks you to pay</description>
<message>Authentication is required to $(summary)</message>
<defaults>
<allow_any>auth_self</allow_any>
<allow_inactive>auth_self</allow_inactive>
<allow_active>auth_self</allow_active>
</defaults>
<annotate key="org.freedesktop.policykit.owner">unix-user:nostro</annotate>
</action>
</policyconfig>

View file

@ -0,0 +1,8 @@
# SPDX-License-Identifier: LGPL-3.0-only
# SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
# The first call to nostrod starts it, through systemd. Install: /usr/share/dbus-1/system-services/
[D-BUS Service]
Name=net.catcrafts.Nostro1
Exec=/bin/false
User=nostro
SystemdService=nostrod.service

19
packaging/system/nostro Executable file
View file

@ -0,0 +1,19 @@
#!/bin/sh
# SPDX-License-Identifier: LGPL-3.0-only
# SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
#
# The nostro command: the CLI from the net.catcrafts.Nostro Flatpak, run as you. It asks nostrod over the system bus,
# and your session's polkit agent asks for your password before anything moves money. Install: /usr/bin/nostro (a
# package) or /usr/local/bin/nostro (install.sh).
# Before nostrod, nostro kept the bank's secrets in the user's own home, where every program they run can read them.
# (With XDG_CONFIG_HOME set, it looked in $XDG_CONFIG_HOME/.config/nostro.)
for old in "${XDG_CONFIG_HOME:-$HOME/.config}/nostro/connectors.json" "${XDG_CONFIG_HOME:-$HOME}/.config/nostro/connectors.json"; do
if [ -e "$old" ]; then
echo "nostro: $old is an older nostro's, and holds your bank's API key where any program you run can read it." \
"Revoke that key in the bunq app, add a new one with 'nostro connectors add bunq', and delete the file." >&2
break
fi
done
exec /usr/bin/flatpak run --system net.catcrafts.Nostro//stable "$@"

View file

@ -0,0 +1,5 @@
# SPDX-License-Identifier: LGPL-3.0-only
# SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
# The user nostrod runs as. A static user rather than systemd's DynamicUser=, which D-Bus policies and polkit's
# action owners could not name. Its home is nostrod's state directory. Install: /usr/lib/sysusers.d/nostro.conf
u nostro - "nostro banking daemon" /var/lib/nostro

View file

@ -0,0 +1,47 @@
# SPDX-License-Identifier: LGPL-3.0-only
# SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
#
# nostrod: every local user's bank connections, one worker process per user, behind net.catcrafts.Nostro1 and
# net.catcrafts.Nostro1.Checkout on the system bus. The first call starts it (D-Bus activation), and it ends by itself
# once idle, so an updated Flatpak takes over at the next call. It runs from the net.catcrafts.Nostro Flatpak as the
# system user nostro, whose home, the state directory, holds the connections: no other user can read it.
#
# The hardening is what bubblewrap, which flatpak runs the daemon in, works under. Not here, because it breaks it:
# RestrictSUIDSGID= (systemd answers openat2() with ENOSYS for it, and bubblewrap 0.13 has no fallback; NoNewPrivileges=
# voids setuid bits anyway), RestrictNamespaces=, and ProtectKernelTunables=, ProtectKernelLogs=, ProtectProc= and
# ProcSubset=, which overmount the /proc bubblewrap mounts its own over.
#
# Install: /etc/systemd/system/nostrod.service (install.sh) or /usr/lib/systemd/system/nostrod.service (a package).
[Unit]
Description=nostro banking daemon
[Service]
Type=dbus
BusName=net.catcrafts.Nostro1
User=nostro
Group=nostro
ExecStart=/usr/bin/flatpak run --system --no-session-bus --die-with-parent --command=nostrod net.catcrafts.Nostro//stable
StateDirectory=nostro
StateDirectoryMode=0700
# flatpak run needs a runtime directory, which a system user does not have.
RuntimeDirectory=nostro
RuntimeDirectoryMode=0700
Environment=XDG_RUNTIME_DIR=/run/nostro
UMask=0077
# A core dump would hold every key the daemon had in memory; nostrod's workers also make themselves undumpable.
LimitCORE=0
NoNewPrivileges=yes
PrivateTmp=yes
PrivateDevices=yes
ProtectSystem=strict
ProtectHome=yes
ProtectClock=yes
ProtectControlGroups=yes
CapabilityBoundingSet=
MemoryDenyWriteExecute=yes
LockPersonality=yes
RestrictRealtime=yes
# AF_NETLINK: bubblewrap brings up loopback in the network namespace of the sandbox flatpak runs ldconfig in.
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 AF_NETLINK
# @mount, unshare and setns: bubblewrap builds the sandbox with them.
SystemCallFilter=@system-service @mount unshare setns

29
packaging/system/uninstall.sh Executable file
View file

@ -0,0 +1,29 @@
#!/bin/sh
# SPDX-License-Identifier: LGPL-3.0-only
# SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
#
# Removes what install.sh installed. Run as root. Every user's bank connections stay in /var/lib/nostro, for a later
# install to find, unless --purge is given: then they go too, with the user nostro. Revoke the API keys in the bank's app
# as well, since the bank still accepts them.
set -u
systemctl stop nostrod.service 2>/dev/null
flatpak uninstall --system -y --noninteractive net.catcrafts.Nostro 2>/dev/null
flatpak remote-delete --system nostro-local 2>/dev/null
rm -f /usr/share/dbus-1/system.d/net.catcrafts.Nostro1.conf \
/usr/share/dbus-1/system-services/net.catcrafts.Nostro1.service \
/usr/share/dbus-1/system-services/net.catcrafts.Nostro1.Checkout.service \
/usr/share/polkit-1/actions/net.catcrafts.Nostro1.policy \
/etc/systemd/system/nostrod.service \
/usr/local/bin/nostro
systemctl daemon-reload
busctl call org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus ReloadConfig
if [ "${1:-}" = --purge ]; then
rm -rf /var/lib/nostro
rm -f /usr/lib/sysusers.d/nostro.conf
userdel nostro 2>/dev/null
echo "nostro is removed, with every user's bank connections"
else
echo "nostro is removed; the bank connections stay in /var/lib/nostro (uninstall.sh --purge removes them)"
fi