Skip to content
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

container: move volume chown after spec generation #6747

Merged
merged 3 commits into from
Jun 30, 2020

Conversation

giuseppe
Copy link
Member

move the chown for newly created volumes after the spec generation so the correct UID/GID are known.

Closes: #5698

Alternative to: github.com//pull/6730

Signed-off-by: Giuseppe Scrivano [email protected]

@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: giuseppe

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 24, 2020
@rhatdan
Copy link
Member

rhatdan commented Jun 24, 2020

If a second container uses the same volume, does it get chowned?

@TomSweeneyRedHat
Copy link
Member

If a second container uses the same volume, does it get chowned?

might be good to add a test for this.

@vrothberg
Copy link
Member

make validate and repushing should make gating happy

@giuseppe
Copy link
Member Author

If a second container uses the same volume, does it get chowned?

no, it is chowned only the first time. And it should be race free (a second container that accesses the volume between its creation and being chowned doesn't affect it)

Copy link
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM, thanks a lot @giuseppe!

@mheon PTAL

@mheon
Copy link
Member

mheon commented Jun 24, 2020

I'm still convinced this makes more sense as part of the volume mount operation - keeping the separate bool makes sense, but we should put it in the same place that copy-up currently happens.

@giuseppe
Copy link
Member Author

I'm still convinced this makes more sense as part of the volume mount operation - keeping the separate bool makes sense, but we should put it in the same place that copy-up currently happens.

the mount currently happens before the spec is generated (the UID/GID are not known)

@mheon
Copy link
Member

mheon commented Jun 24, 2020

That shouldn't be true - mount + copy up of volumes only happens as part of prepare() which is called as part of Start() (or Init()) once the container is created

@giuseppe
Copy link
Member Author

That shouldn't be true - mount + copy up of volumes only happens as part of prepare() which is called as part of Start() (or Init()) once the container is created

yes volumes are mounted with mountStorage as part of prepare() while generateSpec is called later as part of init()

@mheon
Copy link
Member

mheon commented Jun 24, 2020

Ah, I think I see now - you want to do the chown later, so we don't need a duplicate lookup up UID/GID. OK.

@giuseppe
Copy link
Member Author

Ah, I think I see now - you want to do the chown later, so we don't need a duplicate lookup up UID/GID. OK.

does it look good for you?

@mheon
Copy link
Member

mheon commented Jun 29, 2020

Sorry for the delay. Few issues with the volume functions, otherwise LGTM.

giuseppe and others added 3 commits June 29, 2020 17:51
move the chown for newly created volumes after the spec generation so
the correct UID/GID are known.

Closes: containers#5698

Signed-off-by: Giuseppe Scrivano <[email protected]>
@disaster123
Copy link

Does this one also affects v1.9 ? I'm always getting "permission denied" messages for containers running in rootless mode using volumes.

@mheon
Copy link
Member

mheon commented Jun 30, 2020

Yes, this affects every Podman version, I believe.

@disaster123
Copy link

OK i'll try to backport your branch to v1.9 and check whether it fixes my problems.

@giuseppe
Copy link
Member Author

/retest

@disaster123
Copy link

I backported this to v1.9 (which was trivial just two missing imports). But it still fails:

/home/podman/.local/share/containers/storage/volumes/maria_cs19-mariadb-data/_data is the source path for the volume which is owned by user podman shouldn't this be owned by the user running mysqld inside the container?

Output / log from Container:

2020-06-30 14:21:14 0 [Note] mysqld (mysqld 10.3.22-MariaDB-1:10.3.22+maria~bionic) starting as process 32 ...
2020-06-30 14:21:15 0 [ERROR] mysqld: Can't create/write to file '/var/lib/mysql/aria_log_control' (Errcode: 13 "Permission denied")
2020-06-30 14:21:15 0 [ERROR] mysqld: Got error 'Can't create file' when trying to use aria control file '/var/lib/mysql/aria_log_control'

The volume was created by podman-compose

@giuseppe
Copy link
Member Author

tests are green again

@disaster123
Copy link

The output of podman-compose looks like this:

podman pod create --name=maria --share net
a5ccf3e089fb2cac498d807982b5e21c4b54f153c9ff4270d318c2f187a65f98
0
podman volume inspect maria_cs19-mariadb-data || podman volume create maria_cs19-mariadb-data
Error: no volume with name "maria_cs19-mariadb-data" found: no such volume
podman volume inspect maria_cs19-mariadb-logs || podman volume create maria_cs19-mariadb-logs
Error: no volume with name "maria_cs19-mariadb-logs" found: no such volume
podman run --name=cs20-mariadb -d --pod=maria --label io.podman.compose.config-hash=123 --label io.podman.compose.project=maria --label io.podman.compose.version=0.0.1 --label com.docker.compose.container-number=1 --label com.docker.compose.service=mariadb -e zabbixServer=172.24.0.7 -e enableZabbixMonitoring=yes -e innodb_read_io_threads=4 -e innodb_write_io_threads=8 -e innodb_buffer_pool_size=8192M --mount type=bind,source=/home/podman/.local/share/containers/storage/volumes/maria_cs19-mariadb-data/_data,destination=/var/lib/mysql,bind-propagation=z --mount type=bind,source=/home/podman/.local/share/containers/storage/volumes/maria_cs19-mariadb-logs/_data,destination=/var/log/mysql,bind-propagation=z --add-host mariadb:127.0.0.1 --add-host cs20-mariadb:127.0.0.1 --hostname cs20-mariadb --tty docker.contentserv.com/cs-saas-prod/mariadbprod:stable

@giuseppe
Copy link
Member Author

I don't think the --mount type=bind is translated to a volume. That looks like a plain bind mount

@mheon
Copy link
Member

mheon commented Jun 30, 2020

It's a bind mount of a Libpod-managed named volume. That's honestly bizarre, and not a good idea.

Also, there's no --user directive, so I question whether this patch would help - it looks like mysql is started as root, then drops caps and becomes an unprivileged user

@rhatdan
Copy link
Member

rhatdan commented Jun 30, 2020

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 30, 2020
@openshift-merge-robot openshift-merge-robot merged commit c2a0ccd into containers:master Jun 30, 2020
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 24, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

named volume created when running with userns=keep-id has wrong ownership
8 participants