Problem with Network Access in Strict Confinment

Hello,

currently I’m facing a problem that my snap does not work after I changed the confinment from devmode -> strict.

Although I configured the plugs and connected them, I still get the following error when my application tries to connect to the AWS cloud: [1].

The snappy debugger tells me:

Time: Apr 20 13:31:15
Log: auid=4294967295 uid=0 gid=0 ses=4294967295 pid=26720 comm="python2" exe="/snap/cavi/x1/usr/bin/python2.7" sig=0 arch=40000028 284(listen) compat=0   ip=0x76e7b7e8 code=0x50000
Syscall: listen
Suggestion:
* add one of 'browser-support, network-bind' to 'plugs'

My application is already connect, compare:

:network                  cavi
:network-bind             cavi
:network-control          cavi          
:process-control          cavi

Am I missing something?

Thanks and best regards

[1]
DEBUG:AWSIoTPythonSDK.core.protocol.internal.clients:Initializing MQTT layer…
Apr 20 13:21:11 localhost cavi.cavi[18699]: Traceback (most recent call last):
Apr 20 13:21:11 localhost cavi.cavi[18699]: File “/snap/cavi/x1/bin/app.py”, line 78, in
Apr 20 13:21:11 localhost cavi.cavi[18699]: main()
Apr 20 13:21:11 localhost kernel: [ 1448.711536] audit: type=1326 audit(1524230471.068:198): auid=4294967295 uid=0 gid=0 ses=4294967295 pid=18699 comm=“python2” exe="/snap/cavi/x1/usr/bin/python2.7" sig=0 arch=40000028 syscall=284 compat=0 ip=0x76e727e8 code=0x50000
Apr 20 13:21:11 localhost cavi.cavi[18699]: File “/snap/cavi/x1/bin/app.py”, line 65, in main
Apr 20 13:21:11 localhost cavi.cavi[18699]: deviceConfiguration.handleStateChange, devicePlayer.handlStateChange)
Apr 20 13:21:11 localhost cavi.cavi[18699]: File “/snap/cavi/x1/lib/python2.7/site-packages/CAVIDeviceSDK/cloudconnect.py”, line 42, in init
Apr 20 13:21:11 localhost cavi.cavi[18699]: self.myMQTTClient = AWSIoTMQTTShadowClient(self.DEVICE_CONFIG[‘NAME’])
Apr 20 13:21:11 localhost cavi.cavi[18699]: File “/snap/cavi/x1/lib/python2.7/site-packages/AWSIoTPythonSDK/MQTTLib.py”, line 882, in init
Apr 20 13:21:11 localhost cavi.cavi[18699]: self._AWSIoTMQTTClient = AWSIoTMQTTClient(clientID, protocolType, useWebsocket, cleanSession)
Apr 20 13:21:11 localhost cavi.cavi[18699]: File “/snap/cavi/x1/lib/python2.7/site-packages/AWSIoTPythonSDK/MQTTLib.py”, line 86, in init
Apr 20 13:21:11 localhost cavi.cavi[18699]: self._mqtt_core = MqttCore(clientID, cleanSession, protocolType, useWebsocket)
Apr 20 13:21:11 localhost cavi.cavi[18699]: File “/snap/cavi/x1/lib/python2.7/site-packages/AWSIoTPythonSDK/core/protocol/mqtt_core.py”, line 72, in init
Apr 20 13:21:11 localhost cavi.cavi[18699]: self._internal_async_client = InternalAsyncMqttClient(client_id, clean_session, protocol, use_wss)
Apr 20 13:21:11 localhost cavi.cavi[18699]: File “/snap/cavi/x1/lib/python2.7/site-packages/AWSIoTPythonSDK/core/protocol/internal/clients.py”, line 57, in init
Apr 20 13:21:11 localhost cavi.cavi[18699]: self._paho_client = self._create_paho_client(client_id, clean_session, None, protocol, use_wss)
Apr 20 13:21:11 localhost cavi.cavi[18699]: File “/snap/cavi/x1/lib/python2.7/site-packages/AWSIoTPythonSDK/core/protocol/internal/clients.py”, line 64, in _create_paho_client
Apr 20 13:21:11 localhost cavi.cavi[18699]: return mqtt.Client(client_id, clean_session, user_data, protocol, use_wss)
Apr 20 13:21:11 localhost cavi.cavi[18699]: File “/snap/cavi/x1/lib/python2.7/site-packages/AWSIoTPythonSDK/core/protocol/paho/client.py”, line 437, in init
Apr 20 13:21:11 localhost cavi.cavi[18699]: self._sockpairR, self._sockpairW = _socketpair_compat()
Apr 20 13:21:11 localhost cavi.cavi[18699]: File “/snap/cavi/x1/lib/python2.7/site-packages/AWSIoTPythonSDK/core/protocol/paho/client.py”, line 268, in _socketpair_compat
Apr 20 13:21:11 localhost cavi.cavi[18699]: listensock.listen(1)
Apr 20 13:21:11 localhost cavi.cavi[18699]: File “/snap/cavi/x1/usr/lib/python2.7/socket.py”, line 228, in meth
Apr 20 13:21:11 localhost cavi.cavi[18699]: return getattr(self._sock,name)(*args)
Apr 20 13:21:11 localhost cavi.cavi[18699]: socket.error: [Errno 1] Operation not permitted

Does anyone has an idea what the problem might be here? Thanks

Hey

Can you please attach the following information:

snap version

cat /var/lib/snapd/seccomp/bpf/snap.cavi.cavi.src

Thank you

Hi,

thanks for your reply.
Snap version is:

snap 2.32.5
snapd 2.32.5
series 16
kernel 4.4.0-1087-raspi2

For the /snapd/seccomp/… compare [1]. Sorry for the fomatting.

Thanks a lot and best regards

[1]

cat /var/lib/snapd/seccomp/bpf/snap.cavi.cavi.src

# Description: Allows access to app-specific directories and basic runtime
#
# The default seccomp policy is default deny with a whitelist of allowed
# syscalls. The default policy is intended to be safe for any application to
# use and should be evaluated in conjunction with other security backends (eg
# AppArmor). For example, a few particularly problematic syscalls that are left
# out of the default policy are (non-exhaustive):
# - kexec_load
# - create_module, init_module, finit_module, delete_module (kernel modules)
# - name_to_handle_at (history of vulnerabilities)
# - open_by_handle_at (history of vulnerabilities)
# - ptrace (can be used to break out of sandbox with <4.8 kernels)
# - add_key, keyctl, request_key (kernel keyring)

#
# Allowed accesses
#

access
faccessat

alarm
brk

# ARM private syscalls
breakpoint
cacheflush
set_tls
usr26
usr32

capget
# AppArmor mediates capabilities, so allow capset (useful for apps that for
# example want to drop capabilities)
capset

chdir
fchdir

# We can't effectively block file perms due to open() with O_CREAT, so allow
# chmod until we have syscall arg filtering (LP: #1446748)
chmod
fchmod
fchmodat

# snappy doesn't currently support per-app UID/GIDs. All daemons run as 'root'
# so allow chown to 'root'. DAC will prevent non-root from chowning to root.
chown - u:root g:root
chown32 - u:root g:root
fchown - u:root g:root
fchown32 - u:root g:root
fchownat - - u:root g:root
lchown - u:root g:root
lchown32 - u:root g:root

clock_getres
clock_gettime
clock_nanosleep
clone
close

# needed by ls -l
connect

chroot

creat
dup
dup2
dup3
epoll_create
epoll_create1
epoll_ctl
epoll_ctl_old
epoll_pwait
epoll_wait
epoll_wait_old
eventfd
eventfd2
execve
execveat
_exit
exit
exit_group
fallocate

# requires CAP_SYS_ADMIN
#fanotify_init
#fanotify_mark

fcntl
fcntl64
flock
fork
ftime
futex
get_mempolicy
get_robust_list
get_thread_area
getcpu
getcwd
getdents
getdents64
getegid
getegid32
geteuid
geteuid32
getgid
getgid32
getgroups
getgroups32
getitimer
getpgid
getpgrp
getpid
getppid
getpriority
getrandom
getresgid
getresgid32
getresuid
getresuid32

getrlimit
ugetrlimit

getrusage
getsid
gettid
gettimeofday
getuid
getuid32

getxattr
fgetxattr
lgetxattr

inotify_add_watch
inotify_init
inotify_init1
inotify_rm_watch

# TIOCSTI allows for faking input (man tty_ioctl)
# TODO: this should be scaled back even more
ioctl - !TIOCSTI

io_cancel
io_destroy
io_getevents
io_setup
io_submit
ioprio_get
# affects other processes, requires CAP_SYS_ADMIN. Potentially allow with
# syscall filtering of (at least) IOPRIO_WHO_USER (LP: #1446748)
#ioprio_set

ipc
kill
link
linkat

listxattr
llistxattr
flistxattr

lseek
llseek
_llseek
lstat
lstat64

madvise
fadvise64
fadvise64_64
arm_fadvise64_64

mbind
membarrier
memfd_create
mincore
mkdir
mkdirat
mlock
mlock2
mlockall
mmap
mmap2

# Allow mknod for regular files, pipes and sockets (and not block or char
# devices)
mknod - |S_IFREG -
mknodat - - |S_IFREG -
mknod - |S_IFIFO -
mknodat - - |S_IFIFO -
mknod - |S_IFSOCK -
mknodat - - |S_IFSOCK -

modify_ldt
mprotect

# LP: #1448184 - these aren't currently mediated by AppArmor. Deny for now
#mq_getsetattr
#mq_notify
#mq_open
#mq_timedreceive
#mq_timedsend
#mq_unlink

mremap
msgctl
msgget
msgrcv
msgsnd
msync
munlock
munlockall
munmap

nanosleep

# Allow using nice() with default or lower priority
# FIXME: https://github.com/seccomp/libseccomp/issues/69 which means we
# currently have to use <=19. When that bug is fixed, use >=0
nice <=19
# Allow using setpriority to set the priority of the calling process to default
# or lower priority (eg, 'nice -n 9 <command>')
# default or lower priority.
# FIXME: https://github.com/seccomp/libseccomp/issues/69 which means we
# currently have to use <=19. When that bug is fixed, use >=0
setpriority PRIO_PROCESS 0 <=19

# LP: #1446748 - support syscall arg filtering for mode_t with O_CREAT
open

openat
pause
personality
pipe
pipe2
poll
ppoll

# LP: #1446748 - support syscall arg filtering
prctl
arch_prctl

read
pread
pread64
preadv
readv

readahead
readdir
readlink
readlinkat

# allow reading from sockets
recv
recvfrom
recvmsg
recvmmsg

remap_file_pages

removexattr
fremovexattr
lremovexattr

rename
renameat
renameat2

# The man page says this shouldn't be needed, but we've seen denials for it
# in the wild
restart_syscall

rmdir
rt_sigaction
rt_sigpending
rt_sigprocmask
rt_sigqueueinfo
rt_sigreturn
rt_sigsuspend
rt_sigtimedwait
rt_tgsigqueueinfo
sched_getaffinity
sched_getattr
sched_getparam
sched_get_priority_max
sched_get_priority_min
sched_getscheduler
sched_rr_get_interval
# enforce pid_t is 0 so the app may only change its own scheduler and affinity.
# Use process-control interface for controlling other pids.
sched_setaffinity 0 - -
sched_setparam 0 -

# 'sched_setscheduler' without argument filtering was allowed in 2.21 and
# earlier and 2.22 added 'sched_setscheduler 0 - -', introducing LP: #1661265.
# For now, continue to allow sched_setscheduler unconditionally.
sched_setscheduler

sched_yield

# Allow configuring seccomp filter. This is ok because the kernel enforces that
# the new filter is a subset of the current filter (ie, no widening
# permissions)
seccomp

select
_newselect
pselect
pselect6

semctl
semget
semop
semtimedop

# allow sending to sockets
send
sendto
sendmsg
sendmmsg

sendfile
sendfile64

# While we don't yet have seccomp arg filtering (LP: #1446748), we must allow
# these because the launcher drops privileges after seccomp_load(). Eventually
# we will only allow dropping to particular UIDs. For now, we mediate this with
# AppArmor
setgid
setgid32
setregid
setregid32
setresgid
setresgid32
setresuid
setresuid32
setreuid
setreuid32
setuid
setuid32
#setgroups
#setgroups32

# These break isolation but are common and can't be mediated at the seccomp
# level with arg filtering
setpgid
setpgrp

set_thread_area
setitimer

# apps don't have CAP_SYS_RESOURCE so these can't be abused to raise the hard
# limits
setrlimit
prlimit64

set_mempolicy
set_robust_list
setsid
set_tid_address

setxattr
fsetxattr
lsetxattr

shmat
shmctl
shmdt
shmget
shutdown
signal
sigaction
signalfd
signalfd4
sigaltstack
sigpending
sigprocmask
sigreturn
sigsuspend
sigtimedwait
sigwaitinfo

# AppArmor mediates AF_UNIX/AF_LOCAL via 'unix' rules and all other AF_*
# domains via 'network' rules. We won't allow bare 'network' AppArmor rules, so
# we can allow 'socket' for all domains except AF_NETLINK and let AppArmor
# handle the rest.
socket AF_UNIX
socket AF_LOCAL
socket AF_INET
socket AF_INET6
socket AF_IPX
socket AF_X25
socket AF_AX25
socket AF_ATMPVC
socket AF_APPLETALK
socket AF_PACKET
socket AF_ALG
socket AF_CAN
socket AF_BRIDGE
socket AF_NETROM
socket AF_ROSE
socket AF_NETBEUI
socket AF_SECURITY
socket AF_KEY
socket AF_ASH
socket AF_ECONET
socket AF_SNA
socket AF_IRDA
socket AF_PPPOX
socket AF_WANPIPE
socket AF_BLUETOOTH
socket AF_RDS
socket AF_LLC
socket AF_TIPC
socket AF_IUCV
socket AF_RXRPC
socket AF_ISDN
socket AF_PHONET
socket AF_IEEE802154
socket AF_CAIF
socket AF_NFC
socket AF_VSOCK
socket AF_MPLS
socket AF_IB

# For usrsctp, AppArmor doesn't support 'network conn,' since AF_CONN is
# userspace and encapsulated in other domains that are mediated. As such, do
# not allow AF_CONN by default here.
# socket AF_CONN

# For AF_NETLINK, we'll use a combination of AppArmor coarse mediation and
# seccomp arg filtering of netlink families.
# socket AF_NETLINK - -

# needed by snapctl
getsockopt
setsockopt
getsockname
getpeername

# Per man page, on Linux this is limited to only AF_UNIX so it is ok to have
# in the default template
socketpair

splice

stat
stat64
fstat
fstat64
fstatat64
lstat
newfstatat
oldfstat
oldlstat
oldstat

statfs
statfs64
fstatfs
fstatfs64
statvfs
fstatvfs
ustat

symlink
symlinkat

sync
sync_file_range
sync_file_range2
arm_sync_file_range
fdatasync
fsync
syncfs
sysinfo
syslog
tee
tgkill
time
timer_create
timer_delete
timer_getoverrun
timer_gettime
timer_settime
timerfd
timerfd_create
timerfd_gettime
timerfd_settime
times
tkill

truncate
truncate64
ftruncate
ftruncate64

umask

uname
olduname
oldolduname

unlink
unlinkat

utime
utimensat
utimes
futimesat

vfork
vmsplice
wait4
oldwait4
waitpid
waitid

write
writev
pwrite
pwrite64
pwritev

# FIXME: remove this after LP: #1446748 is implemented
# This is an older interface and single entry point that can be used instead
# of socket(), bind(), connect(), etc individually.
socketcall

# Description: Can access the network as a client.
bind

# FIXME: some kernels require this with common functions in go's 'net' library.
# While this should remain in network-bind, network-control and
# network-observe, for series 16 also have it here to not break existing snaps.
# Future snapd series may remove this in the future. LP: #1689536
socket AF_NETLINK - NETLINK_ROUTE

# Userspace SCTP
# https://github.com/sctplab/usrsctp/blob/master/usrsctplib/usrsctp.h
socket AF_CONN

Thank you for providing those details.

This indicates that the network-bind, while connected, is not applied to your application. Can you please share your meta/snap.yaml file. Tip: use triple-backtics (```) to delimit text like that, it looks better on the forum.

I suspect that either the particular plug is not associated with the app you have (plugs and slots are scoped to specific applications inside a snap) but I need this information to confirm this.

Thanks for you reply. In the following I’ve attached the snap.yaml file. I hope this helps you further. I am not yet 100% sure if I need all the plugs defined but home and network is definitely needed. Thanks a lot for the support (and for the tip regarding the formatting, somehow I did not find it)

version: 0.1.5
summary: CAVI 
description: 
architectures:
- armhf
confinement: strict
grade: stable
apps:
  cavi:
    command: command-cavi.wrapper
    daemon: simple
    environment:
      PYTHONPATH: $PYTHONPATH:$SNAP/lib/python2.7/site-packages
    plugs:
    - home
    - network
    - network-control
    - process-control
  ffmpeg:
    command: command-ffmpeg.wrapper
    plugs:
    - home
  olad:
    command: command-olad.wrapper
    daemon: simple
    plugs:
    - home
    - network
    - network-bind
    - process-control

Ha, you need to add network-bind plug to the cavi command. That should fix it for you :slight_smile:

Thanks a lot. That solved the problem!
I thought the network interface would have been enough.

1 Like

The network-bind interface (as shown by snap interface network-bind) allows a snap to operate as a network service.