Docker 镜像构建与分发全解析
1. 构建强化的应用镜像
在构建 Docker 镜像时,强化镜像的安全性至关重要。其中一个关键步骤是处理 SUID 和 SGID 权限。
在 Linux 系统中,除了常见的文件系统权限(读、写、执行)外,还有 SUID 和 SGID 这两种特殊权限。当一个可执行文件设置了 SUID 位时,它将始终以其所有者的身份执行。例如, /usr/bin/passwd 程序由 root 用户拥有并设置了 SUID 权限,当非 root 用户执行该程序时,实际上是以 root 用户的身份执行。
以下是一个示例 Dockerfile,用于演示 SUID 权限的效果:
FROM ubuntu:latest
# Set the SUID bit on whoami
RUN chmod u+s /usr/bin/whoami
# Create an example user and set it as the default
RUN adduser --system --no-create-home --disabled-password --disabled-login \
--shell /bin/sh example
USER example
# Set the default to compare the container user and
# the effective user for whoami
CMD printf "Container running as: %s\n" $(id -u -n) &
Docker镜像构建与分发详解
超级会员免费看
订阅专栏 解锁全文
35

被折叠的 条评论
为什么被折叠?



