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

Avoid using 'safefile' #4

Merged
merged 2 commits into from
May 12, 2020
Merged

Avoid using 'safefile' #4

merged 2 commits into from
May 12, 2020

Conversation

juan131
Copy link

@juan131 juan131 commented May 11, 2020

Signed-off-by: juan131 juan@bitnami.com

This PR fixes the issue described below when running ini-file with an unprivileged user:


When we have a “non-root” container run as 1001:root and we have a file with the permissions below:

-rw-rw-r-- 1 root root 22338 Apr  7 15:56 default.ini

The user can write in the file since it belongs to the root group. However, running the command below will fail:

./ini-file set --section section --key foo --value bar default.ini

The reason is how ini-file perform write operations. It's using safefile that create a temporal file, to replace the destination file with this temporal file later. This temporal file is created with -rw-r-r-- 1001:root permissions, which is wrong for two reasons:

  • It's not respecting the original ownership
  • It's not respecting the original permissions.

We tried to fix this by running some chown/chmod operations but it's not working since "chown" operations require privilege permissions.


Solution: stop using safefile and directly write in the destination.

Signed-off-by: juan131 <juan@bitnami.com>
Copy link
Contributor

@marcosbc marcosbc left a comment

Choose a reason for hiding this comment

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

LGTM

Signed-off-by: juan131 <juan@bitnami.com>
@juan131 juan131 merged commit 96d3a36 into master May 12, 2020
@juan131 juan131 deleted the ini-file-save-file branch May 12, 2020 07:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants