问题原文
原帖链接 · Oscar Andersson · CC BY-SA 4.0
I host a lab server where I am root (and a regular user).
The domain name is example.org and I give each member a subdomain, for example bob.example.org for Bob and anna.example.org for user Anna. I think you get the deal. :) The subdomains are reversed proxied using nginx to a specific port.
My question is, is there any way that I can give permission to non root users to start docker containers on their specific range of ports. For example Anna is given range 1300-1350 where port 1300 is bound to anna.example.org and the other ones are in reserve.
The system runs Debian 11 Bullseye and the latest Docker version.
已采纳解答
原帖链接 · Matt · CC BY-SA 4.0
First of all, only trusted users should be allowed to control your Docker daemon
The docker daemon runs as root by default on a Debian Bullseye installation. Adding a user to the docker group gives that user psuedo root access due to having control of the docker daemon having that amount of access. Every user in the docker group will have complete control of the host and others containers and can run a container that --publishes any port.
There are a few options to providing security to users docker access.
- Rootless docker
sudo- API
1. Rootless docker
A rootless docker setup would enable each user to run a docker deamon. For ports lower than 1024 it would need to abide by the unprivileged ports information bob provided as each user will "own" their own deamon. Docker also provides related guidance. This wouldn't stop Anna from taking Bobs port.
2. sudo
The simplest method to allow users to run docker commands is to provide a root controlled script via sudo that is either static, or controls the user input for optional arguments:
#!/bin/bash
docker run --detach --publish 1300:1300 anna/app-image
anna ALL=(root) NOPASSWD: /usr/local/bin/start-anna-image
If you want users to be able to add their own options you need to be very careful about controlling their input as it's vert easy to
3. Authorization plugin or API for Docker
As Docker doesn't provide any authorization layer on the daemon you need to add something to control user access.
Docker provides an in built authorization plugin framework to enable this. Some examples are opa-docker-authz and casbin-authz-plugin
You could give the users access to a form of proxy API that provides the authentication and authorization over what is passed on to the Docker REST API. There are docker libraries for most programming languages. Kubernetes+RBAC is an example of an API that sits in front of the Docker daemon and controls access (just a very big/complex one that does a lot more).
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
