feat(profiles): add sshd profile.

This commit is contained in:
Alexandre Pujol 2022-05-02 17:56:06 +01:00
parent b87f1859cf
commit c61181b548
Failed to generate hash of commit
3 changed files with 115 additions and 0 deletions

View file

@ -0,0 +1,16 @@
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2022 Alexandre Pujol <alexandre@pujol.io>
# SPDX-License-Identifier: GPL-2.0-only
abi <abi/3.0>,
include <tunables/global>
@{exec_path} = /{usr/,}lib/openssh/sftp-server
profile sftp-server @{exec_path} {
include <abstractions/base>
@{exec_path} mr,
include if exists <local/sftp-server>
}

View file

@ -0,0 +1,97 @@
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2002-2005 Novell/SUSE
# Copyright (C) 2012 Canonical Ltd.
# Copyright (C) 2015-2016 Simon Deziel
# Copyright (C) 2022 Alexandre Pujol <alexandre@pujol.io>
# SPDX-License-Identifier: GPL-2.0-only
# Adapted from https://gitlab.com/apparmor/apparmor/-/blob/master/profiles/apparmor/profiles/extras/usr.sbin.sshd
# As SSH is used to administrate a server this is limited.
# If you want real protection disallow SSH access.
abi <abi/3.0>,
include <tunables/global>
@{exec_path} = /{usr/,}{s,}bin/sshd
profile sshd @{exec_path} flags=(attach_disconnected) {
include <abstractions/base>
include <abstractions/authentication>
include <abstractions/consoles>
include <abstractions/hosts_access>
include <abstractions/nameservice-strict>
include <abstractions/openssl>
include <abstractions/ssl_certs>
include <abstractions/wutmp>
capability audit_write,
capability chown,
capability dac_read_search,
capability kill,
capability net_bind_service,
capability setgid,
capability setuid,
capability sys_chroot,
capability sys_resource,
# sshd doesn't require net_admin. libpam-systemd tries to
# use it if available to set the send/receive buffers size,
# but will fall back to a non-privileged version if it fails.
deny capability net_admin,
ptrace (read,trace) peer=unconfined,
@{exec_path} mrix,
/{usr/,}bin/{,b,d,rb}ash rUx,
/{usr/,}bin/{c,k,tc,z}sh rUx,
/{usr/,}{s,}bin/nologin rPx,
/{usr/,}bin/false rix,
/{usr/,}bin/passwd rPx,
/{usr/,}lib/openssh/sftp-server rPx,
/etc/default/locale r,
/etc/environment r,
/etc/gss/mech.d/{,*} r,
/etc/security/limits.d/ r,
/etc/motd r,
/etc/ssh/ssh_host_* r,
/etc/ssh/sshd_config r,
/etc/ssh/sshd_config.d/{,*} r,
# For scp
owner @{HOME}/@{XDG_DOWNLOAD_DIR}/{,**} rwl,
owner @{user_sync_dirs}/{,**} rwl,
owner @{HOME}/@{XDG_SSH_DIR}/authorized_keys{,.*} r,
owner @{run}/sshd{,.init}.pid wl,
@{run}/motd.dynamic rw,
@{run}/motd.dynamic.new rw,
@{run}/resolvconf/resolv.conf r,
@{run}/systemd/sessions/[0-9]*.ref rw,
@{run}/systemd/userdb/ r,
@{sys}/fs/cgroup/*/user/*/[0-9]*/ rw,
@{sys}/fs/cgroup/systemd/user.slice/user-[0-9]*.slice/session-c[0-9]*.scope/ rw,
owner @{PROC}/@{pid}/limits r,
owner @{PROC}/@{pid}/loginuid rw,
owner @{PROC}/@{pid}/mounts r,
owner @{PROC}/@{pid}/oom_adj rw,
owner @{PROC}/@{pid}/oom_score_adj rw,
owner @{PROC}/@{pid}/uid_map r,
@{PROC}/@{pids}/fd/ r,
@{PROC}/1/environ r,
@{PROC}/cmdline r,
@{PROC}/cmdline r,
@{PROC}/filesystems r,
@{PROC}/sys/kernel/ngroups_max r,
/dev/ptmx rw,
include if exists <local/sshd>
}

View file

@ -72,8 +72,10 @@ run-parts complain
runuser complain runuser complain
s3fs complain s3fs complain
scrcpy complain scrcpy complain
sftp-server complain
slirp4netns attach_disconnected,complain slirp4netns attach_disconnected,complain
ssh complain ssh complain
sshd attach_disconnected,complain
su complain su complain
sudo complain sudo complain
sysctl complain sysctl complain