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

Fix permission denied issue introduced in v4.2.0 #820

Merged
merged 2 commits into from
Apr 14, 2022

Conversation

chelnak
Copy link
Contributor

@chelnak chelnak commented Apr 12, 2022

Context

This PR fixes #819

What has changed?

This PR reverts the modification of the TMPDIR environment variable from the previous release. This change was made to fix a bug in docker compose where some processes would fail if the noexec bit had been set on /tmp. However this change caused unexpected failures in certain environments.

@chelnak chelnak added the bugfix label Apr 12, 2022
@chelnak chelnak self-assigned this Apr 12, 2022
@chelnak chelnak force-pushed the GH-819-permission_denied_from_mkdir branch 3 times, most recently from bf47696 to 038c575 Compare April 12, 2022 15:03
@@ -14,8 +14,7 @@
end

has_command(:docker_compose, command(:dockercompose)) do
Dir.mkdir('/tmp_docker') unless Dir.exist?('/tmp_docker')
ENV.store('TMPDIR', '/tmp_docker')
environment(HOME: '/root')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Overriding $HOME unconditionally is probably a bad idea. This is still a draft so probably needed for some tests, but flag it so that we don't forget about it by mistake.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seems to be true for other command definitions. It's a temporary override but I do see your point.

Choose a reason for hiding this comment

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

Please please please do not create new directories in /.
Please pick some other place (for example under /usr/local/share, /opt, /var/cache, or anywhere else but /).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @bjvrielink, I think you may have misinterpreted the proposed change here.

This PR removes the directory creation.

Choose a reason for hiding this comment

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

Yeah, now I noticed. I've spent a little too much time right now trying to figure out what was/is broken in the current release.

Copy link
Contributor

@canihavethisone canihavethisone Apr 13, 2022

Choose a reason for hiding this comment

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

I did some runtime tests with the new changes, and line 27 of lib/puppet/provider/docker_compose/ruby.rb was failing as it wasn't getting the new tmpdir param.

I got it to work by changing line 27 of lib/puppet/provider/docker_compose/ruby.rb to

compose_output = YAML.safe_load(exec_dockercompose(args))

however, it is not idempotent as the TMPDIR var gets set every time the resource runs. I can't find a way to silence it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good spot!

Interesting regarding the idempotency. I wouldn't have expected it to have an impact.

It's also highly possible that my suggested implementation is not the right fit here.

Maybe we shouldn't be overridden TMPDIR at all given that it it isn't actually a docker setting.

Could this boil down to a simple documentation update where we advise that impacted users may want to override TMPDIR with another puppet resource?

@smortex @kenyon what are your thoughts?

Copy link
Contributor

@canihavethisone canihavethisone Apr 13, 2022

Choose a reason for hiding this comment

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

I tried setting the TMPDIR env var previously using another puppet resource. However without a reboot the docker_compose resource wasn't seeing/respecting it. I like your draft approach as it takes care of it close to the compose resource, it just needs to occur silently if the param is declared - interestingly the existing (breaking) approach did that, however my testing with a hybrid method wasn't reading the resource[:tmpdir] if set earlier.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed so the resource hash is not available inside the has_command block so we can't use the environment method inside it.

That's why I ended up wrapping the command exec. Maybe Env.store isn't the right way to go about it 🧐.

The environment method did not seem to be available outside of that scope either (at least from inside a pry session).. could be wrong about that though.

I'm not by a computer right now so can't do any testing until later on.

Copy link
Contributor

@canihavethisone canihavethisone Apr 13, 2022

Choose a reason for hiding this comment

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

An alternative approach may be to precede the docker-compose command with 'TMPDIR=resource[:tmpdir]' so that it occurs as part of the command if the tmpdir param is declared. That way ruby isn't doing it, the shell is. Just a thought.

Setting the env var within the resource (and it subsequently being ephemeral) also avoids setting it globally on the system.

smortex referenced this pull request Apr 13, 2022
This commit reverts the modification of the TMPDIR environment variable
from the previous release. This change was made to fix a bug in
docker compose where some processes would fail if the noexec bit had
been set on /tmp. However this change caused unexpected failures in
certain environments.
@chelnak chelnak force-pushed the GH-819-permission_denied_from_mkdir branch from 038c575 to a34a1e2 Compare April 14, 2022 07:16
@chelnak chelnak marked this pull request as ready for review April 14, 2022 07:18
@chelnak chelnak requested a review from a team as a code owner April 14, 2022 07:18
@david22swan david22swan merged commit 8167cd5 into main Apr 14, 2022
@david22swan david22swan deleted the GH-819-permission_denied_from_mkdir branch April 14, 2022 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Permission denied from mkdir /tmp_docker in v4.2.0
5 participants