-
Notifications
You must be signed in to change notification settings - Fork 154
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
Cannot create a file in the sync volume root folder by non-root user #224
Comments
This workaround works: volumes:
sync-volume:
external: true
docker volume create --name="sync-volume"
docker run -it --rm -v "sync-volume:/data" busybox chmod 777 /data $ ls -al
total 2360
drwxrwxrwx 9 root root 4096 Aug 27 13:48 .
drwxr-xr-x 1 root root 4096 Aug 27 13:47 ..
... However, it is not so comfortable to manage a volume outside docker-compose. |
I think it's a common docker issue. You have to create the folder inside the image (with Dockerfile) and chown it (still in Dockerfile) with a user matching your host user id. Then, on volume creation, it will use this gid/uid. Fixuid may also be an option. |
This is a known Docker (and Compose) issue (see, e.g., docker/compose#3270, moby/moby#3124, and moby/moby#2372). It would really be more appropriate if there were a way to specify ownership of Compose-created volumes as part of the Compose I would recommend opening an issue on the Compose Spec repository and seeing if they're more receptive to it than the previous issues on the Compose repository itself. If that gets shot down, we can reopen this issue and see if maybe there's something that Mutagen can offer as a workaround (such as setting ownership from the sidecar). |
Hello @havoc-io, I fully agree, it is a common Docker issue. However, I do not have the issue as my container runs first and inits the volume with the proper ownership. Bringing mutagen + compose initiates the "magic" sidecar container that is running at the very first and inits the volume with the root ownership (and bring problems). And I have no control over that. The only way is initing the volume before |
Hey @sprymiker, thanks for the additional context. I see now how Mutagen would interfere with the existing workaround. I'll reopen and think about what makes the most sense here. There may be other workarounds for other problems that are also broken by the additional sidecar container starting first. |
@havoc-io is there a way for the sidecar container to chown the volume root directory to the configured |
@pjv There's not at the moment. I'd be hesitant to make such behavior automatic, though perhaps that would be acceptable if Mutagen detected that the volume was empty? This is such a common case that it might be worth doing. If we go this route, we'd still need to make sure the issues I mentioned here don't cause problems, but I don't think they will. I'm not sure exactly how to implement this... probably just some small executable in the sidecar container that Mutagen Compose will invoke as part of its Alternatively (or perhaps additionally), Mutagen could allow users to specify a custom sidecar image (based off of the standard image but using the same dynamic image building functionality of Compose) that could pre-create mountpoints and set their ownership/permissions. This would also solve the problem since volumes inherit the permissions of the first mountpoint to which they're attached (and the sidecar is always started first), and it might allow more flexibility in general. The mountpoints would have to be created using a certain scheme, but that could be documented. I just don't want to support whatever other stuff users might inject into this image, so I'd really only consider this as a last resort, or if it provided some significant additional value, though none comes to mind beyond this permissions problem. |
@havoc-io I looked at the sidecar repo over the weekend hoping to see if I could help out with a PR but I’m not a go coder and all the mutagen code is pretty greek to me. WRT making the Let me know if you need help testing the custom sidecar image idea. Edit: if this anecdotal data point means anything, I just brought up my little wp dev template project (described in #228) and shelled into the sidecar container and did So at least for the purposes of my particular use-case, executing a simple |
Yes, please. That sounds great. When I use
I get:
but when I use
I get
which is unexpected. It would be really nice to get the same behavior, even if it requires a bit of additional configuration, which I need to do anyway. I like the idea of using
Is it possible for mutagen to inspect the compose file and the image to evaluate which permissions should be used? Or would that be too complex? |
@pjv Thanks for testing the
@paneq Mutagen's actually already inspecting the Compose file to read configuration information, the issues are just (a) whether or not it should change volume root ownership by default (vs. as a configuration setting) and (b) what mechanism it should use to do that (i.e. should it be done by sync sessions or as something special to the sidecar container). I've been playing with adding a configuration option to the Instead, I'm leaning towards just enabling this default ownership setting as a heuristic in cases where (a) the synchronization root is empty, (b) it exists under So I'll try to prototype up this default behavior and see how it looks. I expect I'll have a chance to tackle it on Sunday evening and Monday. |
@havoc-io have you had any time to look at this? |
@pjv Sorry I've been silent on this; I ended up having less time than anticipated. I started prototyping the changes, but there was some edge case behavior that needed further consideration. For example, at the moment, the Mutagen sessions defined in Beyond that, it wasn't immediately clear where in the synchronization code/process the ownership setting should be handled and whether or not it should be re-handled on subsequent synchronization cycles. I'm also wondering if it makes more sense to implement this in the context of a more general permission propagation setting. I'm still working on it and thinking about it. I'm hoping to have a solution in the next few days. Thanks for following up though! |
@havoc-io I’m ignorant of the specifics of what the sidecar is doing altogether, but just imagining creating mountpoints from the linux command line, I’d think that the time to set the owner and group would be right after creating the mountpoint.
I think you could document that the order of the sessions is not defined and then it’s up to the user to make sure that they are specifying the same owner:group for the mount point in all sessions (which I imagine is going to cover 99.5% of use-cases) or know that the owner:group will be undefined due to the undefined ordering. I guess I think that it should definitely be set per the config on the original creation of the mountpoint and then whether to re-handle on subsequent sync sessions seems to me to be a push; I could see an argument for it either way but I have a slight preference for not re-doing it later on in case someone at some point finds a reason for shelling into the sidecar and manually changing it themselves. Again that seems like an extreme edge case and something that can be documented and ignored (for now). |
Hi. Same problem here, and I don't understand how to fix the problem. In the Still in the In
But in the container, if I tried to add this to
I also tried only with And if I replace I'm lost, and have no idea to what to try know... |
i have been able to work around the problem that we've been discussing here (and @ByScripts just repeated) in an impossibly kludgy way by executing something like this once all the containers are up and running:
This needs to be repeated every time the container is recreated (i.e. after a Until you come up with a better way to work this all out, can we get an extension to the x-mutagen configurationBeta permissions, e.g.:
...that would effectively do the same thing as my docker exec one-liner once the sidecar container is up rather than our having to remember to do this manually? |
@pjv I tried your solution. It worked until I edited a file, its owner/group was set back to I surrender. Another thing I don't understand, is that Mutagen was then included in Docker Edge, then removed in favor of gRPC FUSE. This option is activated is my Docker settings, but I don't see any change about the performances. Without Mutagen, |
Hello, I have just run into this issue, is there any progress? Thank you |
I am setting right owner of root in my Dockerfile, but it gets changed after |
@TomasLudvik this is currently how I am getting around the issue by using the afterCreate lifecycle hook in the mutagen.yml project file which works well for my local environment. |
@newtondev thanks for suggestion. I have tried it, but mutagen.yml config seems to be not working with mutagen compose. |
Any update regarding this? I'm stuck also with this permissions problem as |
Docker is inconsistent about the initial ownership of a volume. You'll likely have to add a way to chown to the user that you're running the container as. For example, ddev has to chown the volume like this: func SetMutagenVolumeOwnership(app *DdevApp) error {
// Make sure that if we have a volume mount it's got proper ownership
uidStr, gidStr, _ := util.GetContainerUIDGid()
util.Debug("chowning mutagen docker volume for user %s", uidStr)
_, _, err := app.Exec(
&ExecOpts{
Dir: "/tmp",
Cmd: fmt.Sprintf("sudo chown -R %s:%s /var/www", uidStr, gidStr),
})
util.Debug("done chowning mutagen docker volume, result=%v", err)
return err
} |
Indeed, there's just a lot of inconsistency with regard to volume ownership, so setting it explicitly through some mechanism is the best option for now. Unfortunately neither the Docker CLI nor Compose provides a mechanism for this at the moment. This is something that will need to be considered as Mutagen moves to supporting Compose V2, probably as some sort of Mutagen-specific hack/heuristic. However, the issue with not being able to find the user |
@xenoscopic sorry for late response. We have custom user named On Linux, Windows with WSL and MacOS with Docker-sync rights are working as intended, but when mounting volume using mutagen compose, the files in project root directory are owned by Parameter |
@xenoscopic I can't say for sure this would work for all use-cases, but I don't see why it wouldn't. Try it and let's see. Change the sidecar behavior so that after that container comes up, and before the other containers defined in the compose file come up, the sidecar |
@pjv I also think that's the right approach (but probably conditioned on the volume being empty). I think this will probably just get punted to the Mutagen Compose V2 implementation though, as the V1 implementation is super crufty at the moment. I'll take a look though and see if it's easy enough to do this robustly. It's mostly an agent change anyway. I've been deep-diving into the |
Two updates to close out this issue: First, Mutagen now implements a heuristic to support this in Mutagen v0.13.0-beta2. Specifically, if a Mutagen Compose synchronization session targets an empty volume root, and a non-default owner, group, or directory mode setting has been specified for that session, then Mutagen will set the permissions of the volume root to match. I think this should offer users enough control to set permissions as desired in most cases. If you need different permissions for different directories, the solution is just to use multiple volumes and synchronization sessions (both of which are cheap). Second, this new behavior was really implemented to support the Compose-V2-based Mutagen Compose, which will very soon be replacing Mutagen's Compose V1 integration. This is now available to try if you'd like and more information can be found here. If this new heuristic isn't sufficient, isn't working properly, or needs a bit of tweaking, feel free to comment on this issue or drop by the Mutagen Community Slack Workspace and we can definitely continue the discussion. |
Which version of Mutagen are you using (
mutagen version
)?0.12.0-beta1
Which operating system (platform/version/architecture) are you using?
MacOS 10.14.6 (18G6020)
What is the issue that you're experiencing?
A terminating sync session is stuck forever.
What are the steps to reproduce the issue?
brew install mutagen-io/mutagen/mutagen-beta
cd /tmp
git clone https://github.com/mutagen-io/example-voting-app.git ./voting
cd ./voting
mutagen compose up -d
docker exec -it -u 1000:1000 mutagen_result_1 mkdir somedir
What is the expected result of these steps in the absence of the issue?
Folder is created
docker exec -it -u 1000:1000 mutagen_result_1 ls -al somedir
What is the actual result?
Is there any other information that might be helpful?
Docker set the owner for named volume root folder at the first initialization.
The sidecar image has root owner set for
/volumes
, therefor volume root folder hasroot
owner and 755 permission that disallow to write into it by a non-root user.Possible solutions
The sidecar's entry point:
find /volumes -maxdepth 1 -type d -exec chmod 777 "{}" \;
The text was updated successfully, but these errors were encountered: