Files
wekan/snap-src/bin/socket-denied
T
Lauri Ojansivu f927cb3c50 Snap: name an AppArmor-refused database connection at once, and stop the snapctl get errors.
The logs in #6746 show the real cause of "write: permission denied" from
database-restore and of WeKan waiting forever for FerretDB: 1300 kernel
lines of apparmor="DENIED" operation="file_perm" class="net" for
snap.wekan.wekan on 127.0.0.1:27019, with the same denial for snap-store
and standard-notes on that computer. FerretDB was running and accepting
connections; the kernel refused the first write. That is snapd 2.77.1 on a
kernel with an AppArmor socket mediation bug (Launchpad snapd bug 2169038),
fixed by a newer kernel and worked around by `snap revert snapd`.

WeKan cannot lift that denial, so it now says what it is. A new
bin/socket-denied recognises the refusal and prints the denial to look for,
the upstream bug and both ways out. wekan-control's FerretDB and MongoDB
wait loops keep each attempt's error and print it on the first refused
attempt instead of "not ready yet" for two minutes; database-backup and
database-restore stop at once instead of starting an already running
service and waiting 90 seconds.

The same log began with "error: snapctl: get which option?" four times:
SAML_IDP_PROFILE, SAML_WANT_RESPONSE_SIGNED, SAML_WANT_ASSERTIONS_SIGNED
and SAML_LOGIN_FLOW were listed in bin/config without a KEY_ name, so
wekan-read-settings ran a bare `snapctl get` for them and `snap set` could
never reach them. They now have their snap keys, the CORS_EXPOSE_HEADERS
description has its right name, and a key without a snap name falls back
to its default instead of calling snapctl.

Tests: snapSocketDenied, snapSettingsKeys, and extended snapDatabaseRestore
and ferretdbWaitTimeout.

Related to #6746: the reporter still has to update the kernel or revert
snapd, so the issue stays open until that is confirmed.

Thanks to fabiosalles and xet7 !
2026-10-07 15:56:19 +03:00

53 lines
2.6 KiB
Bash

#!/bin/bash
# socket-denied — recognise, and explain, a database connection that the
# KERNEL refused rather than the database.
#
# #6746: on the reporter's computer every WeKan command that talks to its own
# database failed with
# write tcp 127.0.0.1:53014->127.0.0.1:27019: write: permission denied
# and `journalctl -k` was full of
# apparmor="DENIED" operation="file_perm" class="net" profile="snap.wekan.wekan"
# ... faddr=127.0.0.1 fport=27019 ... requested="send" denied="send"
# The database was running: the TCP connection was ACCEPTED, and only the first
# write on it was refused. The same log shows the same denial for other snaps on
# that computer (snap-store, standard-notes), so it is not something in WeKan's
# profile - it is snapd 2.77.1 on a kernel with an AppArmor socket mediation
# bug (https://bugs.launchpad.net/snapd/+bug/2169038). A newer kernel fixes it,
# and `snap revert snapd` (to 2.76.x) works around it until then.
#
# Without this, WeKan said only "FerretDB not ready yet" for two minutes and
# then pointed at FerretDB's log - which is clean, because FerretDB never got a
# byte - and database-restore started a service that was already running and
# waited 90 seconds for it. Nothing WeKan can do from inside the snap lifts an
# AppArmor denial, so the useful thing is to say at once what it is and how the
# owner of the computer fixes it.
#
# Source it, then:
# socket_denied "$err" returns 0 when $err is that kernel refusal
# socket_denied_hint [svc] prints the explanation (to stdout)
socket_denied() {
case "$1" in
*"permission denied"*|*"Permission denied"*|*EACCES*|*"operation not permitted"*|*"Operation not permitted"*|*EPERM*)
return 0 ;;
esac
return 1
}
socket_denied_hint() {
local snap="${SNAP_INSTANCE_NAME:-${SNAP_NAME:-wekan}}"
echo " The database IS running: this computer's security policy (AppArmor)"
echo " refused WeKan's own connection to it, before the database saw anything."
echo " Its log will therefore look normal. Confirm with:"
echo " sudo journalctl -k | grep -i denied"
echo " Lines like apparmor=\"DENIED\" operation=\"file_perm\" class=\"net\""
echo " profile=\"snap.${snap}....\" requested=\"send\" - often for OTHER snaps"
echo " too - are a known problem of snapd 2.77.1 on some Linux kernels, not of"
echo " WeKan: https://bugs.launchpad.net/snapd/+bug/2169038"
echo " Fix it by updating the kernel and rebooting:"
echo " sudo apt update && sudo apt full-upgrade && sudo reboot"
echo " or, until the kernel can be updated, go back to the previous snapd:"
echo " sudo snap revert snapd"
echo " sudo snap restart ${snap}"
}