-
Notifications
You must be signed in to change notification settings - Fork 440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to explicitly set the uid and gid of the mysql user. #554
Comments
What options does your container runtime provide? Is it a rootless mode? The mysql id of 999 is fixed in the container.
I'm also curious why are host volume mounts used instead of named volumes? |
I don't know what 'rootless mode' is.
The host is running ubuntu.
On the host, 999 gets mapped to whatever app first creates a system user so
it is essentially random on the host which is why I'm looking to explicitly
control it.
…On Tue, Jan 16, 2024 at 10:07 AM Daniel Black ***@***.***> wrote:
What options does your container runtime provide? Is it a rootless mode?
The mysql id of 999 is fixed in the container.
$ ls -la build-mariadb-server-10.11-datadir/
total 111012
drwxr-xr-x. 6 dan dan 260 Jan 16 09:53 .
drwxrwxrwt. 24 root root 600 Jan 16 09:53 ..
-rw-rw----. 1 dan dan 417792 Jan 16 09:53 aria_log.00000001
-rw-rw----. 1 dan dan 52 Jan 16 09:53 aria_log_control
-rw-rw----. 1 dan dan 910 Jan 16 09:53 ib_buffer_pool
-rw-rw----. 1 dan dan 12582912 Jan 16 09:51 ibdata1
-rw-rw----. 1 dan dan 100663296 Jan 16 09:51 ib_logfile0
-rw-rw----. 1 dan dan 0 Jan 16 09:51 multi-master.info
drwx------. 2 dan dan 1800 Jan 16 09:51 mysql
-rw-r--r--. 1 dan dan 15 Jan 16 09:51 mysql_upgrade_info
drwx------. 2 dan dan 60 Jan 16 09:51 performance_schema
drwx------. 2 dan dan 2120 Jan 16 09:51 sys
drwx------. 2 dan dan 60 Jan 16 09:51 test
/tmp
$ podman run --userns=keep-id:uid=999,gid=999 -v ./build-mariadb-server-10.11-datadir:/var/lib/mysql --rm mariadb:10.11
2024-01-15 23:01:23+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.11.6+maria~ubu2204 started.
2024-01-15 23:01:23+00:00 [Note] [Entrypoint]: MariaDB upgrade not required
2024-01-15 23:01:23 0 [Note] Starting MariaDB 10.11.6-MariaDB-1:10.11.6+maria~ubu2204 source revision fecd78b83785d5ae96f2c6ff340375be803cd299 as process 1
...
$ podman exec -ti jolly_jepsen ps -ef
UID PID PPID C STIME TTY TIME CMD
mysql 1 0 0 23:01 ? 00:00:00 mariadbd
mysql 33 0 0 23:03 pts/0 00:00:00 ps -ef
I'm also curious why are host volume mounts used instead of named volumes?
—
Reply to this email directly, view it on GitHub
<#554 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAG32OHPJY6UTMHFL4EQCQ3YOWZBVAVCNFSM6AAAAABB33PBWKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOJSHA2TOMBXGU>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Rootless mode is part of some container runtimes that execute containers without (host) root permissions. In the example provided I used the
Also should have worked (containers/common#1802) User ID maps are supported by the container runtime, which is why I'm not looking to explicitly implement a mariadb container control for it. Essentially doing so would modify the container at runtime (not supported on runtimes like apptainer) and slow the initialization speed. Also named volumes exist for providing exclusive storage to containers. Without easy documentation, I can see why you describe it as random, or not within your control. After all we only need to set 1 host -> container uid number correctly, so I'm going to try to document this so every container doesn't need to implement the same thing. |
If I've understood what you are saying, then the problem is that mariadb (partially) ignores the mapping. On docker, I've tried mapping the user with docker-compose option The problem is that they mysql container creates files using the 'mysql' name rather than the uid the container is running with (as per the above The only way I can get it to work is to clone the mariadb docker file and modify the mysql uid/gid. When I do this, it doesn't matter if maria uses the id or the name of the user, the permissions will be correct. By altering https://github.com/MariaDB/mariadb-docker/blob/master/10.11/Dockerfile to have
Note the addition of the -g and -u switches otherwise the file is original. This combined with the container mapping gives the desired results but without the custom container I can't get it to work. |
Here is my docker-compose file:
The full docker file - note that on the above mentioned line has been changed:
|
A slightly simpler form is:
As this is all build time, to do this for a prebuild image of a dynamic uid is more complex. And then in compose for the service There's also usermode_ns: host, which comes down to dockerd user namespace and userns-remap with the notable text:
|
The issue here is that it requires customisation of the container - which I
have successfully done - but it would seem preferable that this is a
supported feature which doesn't require a container mod.
I can't imagine that I'm the only person trying to mount the db from the
host.
…On Wed, Jan 17, 2024 at 1:37 PM Daniel Black ***@***.***> wrote:
A slightly simpler form is:
FROM mariadb:10.11
RUN useradd -u 2002 -r localuser --home-dir /var/lib/mysql
As this is all build time, to do this for a prebuild image of a dynamic
uid is more complex.
And then in compose for the service user: localuser. The container
started as a non-root user will not switch to mysql.
There's also usermode_ns: host
<https://docs.docker.com/compose/compose-file/compose-file-v3/#userns_mode>,
which comes down to dockerd user namespace
<https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-user-namespace-options>
and userns-remap <https://docs.docker.com/engine/security/userns-remap/>
with the notable text:
This re-mapping is transparent to the container, but introduces some
configuration complexity in situations where the container needs access to
resources on the Docker host, such as bind mounts into areas of the
filesystem that the system user cannot write to. From a security
standpoint, it is best to avoid these situations.
—
Reply to this email directly, view it on GitHub
<#554 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAG32OADTSJWHTTMVLA7IU3YO42OTAVCNFSM6AAAAABB33PBWKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOJUHA2DENBQGA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Actually
Note, I'm not saying "no", just understanding the domain a bit more in the complexity of multiple runtime implementations, root(full|less) modes, an standard behaviour, OCI, runtime and other containers. ref: https://github.com/opencontainers/runtime-spec/blob/main/config-linux.md#user-namespace-mappings |
Actually user: 2002 in compose might be sufficient on an unmod container.
I don't believe so, as this is where I started my journey.
The problem is that some of the mariad db processes create some file using
the 'mysql' username rather than uid that they are running under.
The result is that in the log and data directory you have some files owned
by 2002 and some owned by 'mysql' .
This ends badly.
…On Wed, Jan 17, 2024 at 3:57 PM Daniel Black ***@***.***> wrote:
The issue here is that it requires customisation of the container - which
I have successfully done - but it would seem preferable that this is a
supported feature which doesn't require a container mod.
Actually user: 2002 in compose might be sufficient on an unmod container.
I can't imagine that I'm the only person trying to mount the db from the
host.
Note, I'm not saying "no", just understanding the domain a bit more in the
complexity of multiple runtime implementations, root(full|less) modes, an
standard behaviour, OCI, runtime and other containers.
ref:
https://github.com/opencontainers/runtime-spec/blob/main/config-linux.md#user-namespace-mappings
ref:
https://github.com/opencontainers/runtime-spec/blob/main/config.md#configLinuxMountOptions
idMap SHOULD be implemented by runtimes
—
Reply to this email directly, view it on GitHub
<#554 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAG32OHYZYOGKKWQW3433EDYO5K3RAVCNFSM6AAAAABB33PBWKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOJUHE2DCNJZHA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Chim in because out of curiousity, so I tried the compose
It run as 2002 as expected, I just need to ensure that host path the |
The problem is that the |
No no, docker pattern and security should drop |
Seems to work fine over here with version: "3"
services:
mariadb:
container_name: mariadb
image: mariadb:10.6.16
restart: unless-stopped
command: --transaction-isolation=READ-COMMITTED --log-bin=binlog --binlog-format=ROW
user: 2002:2002
cap_drop:
- ALL
security_opt:
- no-new-privileges:true
read_only: true
tmpfs:
- /tmp:noexec
- /run:noexec
- /run/mysqld:noexec
volumes:
- ./mariadb:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD
- MYSQL_PASSWORD
- MYSQL_DATABASE=mariadb
- MYSQL_USER=mariadb
- MARIADB_AUTO_UPGRADE=1
- MARIADB_DISABLE_UPGRADE_BACKUP=0 Running |
Thanks @Jip-Hop, for highlighting the read_only mode. Highlighting I just read though a number of best practices guides to be sure, and none mention going to a non-root user. So if we go back to security principles of risk/convenience tradeoff lets look at exactly what's is/needed.
So options:
|
Are the FAQs sufficient? |
My project uses host volume mounts for data and log directories.
The problem is that the mysql uid and gid are allocated randomly within the container and as such are 'mapped' to a random user/group on the host ( I guess technically it's not random, just not within my control).
If we could set the uid:gid for the mysql user and group within the container, then we could setup host uid:gid that match and is mapped to a coherent name.
The text was updated successfully, but these errors were encountered: