mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
3c375a8418
For some reason, ssh-keygen is unable to write to /root even as root on
AlmaLinux 8:
# id
uid=0(root) gid=0(root) groups=0(root) context=system_u:system_r:initrc_t:s0
# id -Z
ls -ld /root
# ssh-keygen -t ecdsa -N "" -f /root/rootless.key || cat /var/log/audit/audit.log
Saving key "/root/rootless.key" failed: Permission denied
The audit.log shows:
> type=AVC msg=audit(1744834995.352:546): avc: denied { dac_override } for pid=13471 comm="ssh-keygen" capability=1 scontext=system_u:system_r:ssh_keygen_t:s0 tcontext=system_u:system_r:ssh_keygen_t:s0 tclass=capability permissive=0
> type=SYSCALL msg=audit(1744834995.352:546): arch=c000003e syscall=257 success=no exit=-13 a0=ffffff9c a1=5641c7587520 a2=241 a3=180 items=0 ppid=4978 pid=13471 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="ssh-keygen" exe="/usr/bin/ssh-keygen" subj=system_u:system_r:ssh_keygen_t:s0 key=(null)␝ARCH=x86_64 SYSCALL=openat AUID="unset" UID="root" GID="root" EUID="root" SUID="root" FSUID="root" EGID="root" SGID="root" FSGID="root"
A workaround is to use /root/.ssh directory instead of just /root.
While at it, let's unify rootless user and key setup into a single place.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit 87ae2f8466)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
27 lines
914 B
Bash
Executable File
27 lines
914 B
Bash
Executable File
#!/bin/bash
|
|
set -eux -o pipefail
|
|
DNF=(dnf -y --setopt=install_weak_deps=False --setopt=tsflags=nodocs --exclude="kernel,kernel-core")
|
|
RPMS=(bats git-core glibc-static golang jq libseccomp-devel make)
|
|
# Work around dnf mirror failures by retrying a few times.
|
|
for i in $(seq 0 2); do
|
|
sleep "$i"
|
|
"${DNF[@]}" update && "${DNF[@]}" install "${RPMS[@]}" && break
|
|
done
|
|
dnf clean all
|
|
|
|
# To avoid "avc: denied { nosuid_transition }" from SELinux as we run tests on /tmp.
|
|
mount -o remount,suid /tmp
|
|
|
|
# Setup rootless user.
|
|
"$(dirname "${BASH_SOURCE[0]}")"/setup_rootless.sh
|
|
|
|
# Delegate cgroup v2 controllers to rootless user via --systemd-cgroup
|
|
mkdir -p /etc/systemd/system/user@.service.d
|
|
cat >/etc/systemd/system/user@.service.d/delegate.conf <<EOF
|
|
[Service]
|
|
# default: Delegate=pids memory
|
|
# NOTE: delegation of cpuset requires systemd >= 244 (Fedora >= 32, Ubuntu >= 20.04).
|
|
Delegate=yes
|
|
EOF
|
|
systemctl daemon-reload
|