大网数据广告活动
服务器运维问答

How non root user able to listen on priviledge port

· 52CE 我爱测

I supposed to get a bind exception instead it's binding on privilege port % docker run --rm -u nobody alpine nc -l 0.0.0.0 443 % docker exec -it b2b471d05398 sh ~ $ id uid=65534(nobody) gid=65534(nobody) ~ $ ps PID USER TIME COMM…

问题原文

原帖链接 · anish · CC BY-SA 4.0

I supposed to get a bind exception instead it's binding on privilege port

% docker run --rm -u nobody  alpine  nc -l 0.0.0.0 443
% docker exec -it b2b471d05398 sh
~ $ id
uid=65534(nobody) gid=65534(nobody)
~ $ ps
PID   USER     TIME  COMMAND
    1 nobody    0:00 nc -l 0.0.0.0 443
    8 nobody    0:00 sh
   15 nobody    0:00 ps
~ $ %

Even tried with another approach by building a Dockerfile

FROM python:latest
COPY index.html /
EXPOSE 80
USER nobody
CMD python -m http.server 80
docker build -t test .
docker run --rm -u nobody  test
~ % docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS     NAMES
b40c6c33a187   test      "/bin/sh -c 'python …"   28 seconds ago   Up 27 seconds   80/tcp    practical_lumiere

Tried this one too, still it is able to bind port less than 1024

docker run --rm -u nobody --cap-drop=SETUID --cap-drop=NET_BIND_SERVICE --cap-drop=SETFCAP --cap-drop=NET_RAW  alpine  nc -l 0.0.0.0 443

已采纳解答

原帖链接 · Jimmy · CC BY-SA 4.0

The default kernel tuning parameter net.ipv4.ip_unprivileged_port_start for containers is set to 0 which makes all ports in the docker container unprivileged.

All processes inside the container can bind to any port (of the container) even as an unprivileged user.

With regards to exposing privileged ports as a non-priviliged user on the host OS, see https://docs.docker.com/engine/security/rootless/#exposing-privileged-ports

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2021-09-03)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。