
容器技术
1 前言
一个问题,一篇文章,一出故事。
上一篇笔者针对通过sudo授权容器用户podman使用root权限做了一些限制,详细如下,
但是笔者发现mount命令也需要限制,于是整理此章节。
2 最佳实践
2.1 环境信息
2.2 配置sudo授权
vim /etc/sudoers.d/podman
加入如下配置,
%podman ALL=(root) NOPASSWD: /usr/bin/podman podman ALL=(root) NOPASSWD: !/*/* /*,!/*/* * /*,!/*/* *sudoers*,\ !/usr/bin/podman run *source=/*,\ /usr/bin/podman run *source=/data/podman/*
2.3 测试挂载
2.3.1 切换到授权用户
su - podman
2.3.2 拉取测试所需的镜像
podman pull registry.access.redhat.com/ubi8/ubi:8.10-1020
2.3.3 测试授权的挂载
mkdir -p /data/podman/test sudo podman run --privileged --rm -it --mount type=bind,source=/data/podman/test,target=/host registry.access.redhat.com/ubi8/ubi /bin/bash
2.3.4 测试非授权的挂载
sudo podman run --privileged --rm -it --mount type=bind,source=/,target=/host registry.access.redhat.com/ubi8/ubi /bin/bash sudo podman run --privileged --rm -it --mount type=bind,source=/etc,target=/host registry.access.redhat.com/ubi8/ubi /bin/bash
注意,以上操作为用户想通过挂载宿主机的文件系统的根实现提升权限。
参阅文档
========================
https://catalog.redhat.com/software/containers/ubi8/ubi/5c359854d70cc534b3a3784e?container-tabs=gti
没有评论