Skip to content

Fix execute chown and chgrp for symlink #8

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

Merged
merged 1 commit into from
Nov 18, 2021
Merged

Fix execute chown and chgrp for symlink #8

merged 1 commit into from
Nov 18, 2021

Conversation

npwalker
Copy link
Owner

Description

Used resource:

recursive_file_permissions { '/usr/lib/one/sunstone':
    file_mode => '0644',
    dir_mode  => '0755',
    owner     => 'root',
    group     => 'oneadmin',
}

exec:

find /usr/lib/one/sunstone "(" -type f '!' -perm 0644 ")" \
-o "(" -type d '!' -perm 0755 ")" \
-o "(" '!' -user root ")" \
-o "(" '!' -group oneadmin ")" | grep '.*'

result:

/usr/lib/one/sunstone/public/dist/main.js

this is symlink:

ls -la main.js
lrwxrwxrwx 1 oneadmin oneadmin 29 Apr  7 15:21 main.js -> /var/lib/one/sunstone/main.js

The next step is to run the chown command for the file /usr/lib/one/sunstone/public/dist/main.js, which modifies /var/lib/one/sunstone/main.js. But next time the puppet will find the given file again. (recursive loop).

The resource should change the symlink, not the file that she points to.

Fixes

Use the -h option for chown and chgrp. This option is supported by all operating systems for which support for this module is claimed.

--dereference
affect the referent of each symbolic link (this is the default),
rather than the symbolic link itself

-h, --no-dereference
affect each symbolic link instead of any referenced file
(useful only on systems that can change the ownership/group of a symlink)

@npwalker
Copy link
Owner Author

@tryfunc I recreated this as #6 was closed when I removed the master branch.

@npwalker npwalker requested a review from reidmv April 15, 2021 19:38
@reidmv
Copy link
Collaborator

reidmv commented Apr 15, 2021

Looks good to me conceptually. Maybe a little over-engineered? I'd suggest just hard-coding in "-h" to the two relevant places. There is no known variance for this flag on any platform, making setting and using $h unneeded.

Signed-off-by: Vadim Chernyshev <tryfunc@gmail.com>
@tryfunc
Copy link
Contributor

tryfunc commented Apr 18, 2021

This is logical, I agree. Updated the commit.

Copy link
Collaborator

@reidmv reidmv left a comment

Choose a reason for hiding this comment

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

LGTM! 👍

@reidmv reidmv merged commit e2d8bce into npwalker:main Nov 18, 2021
npwalker added a commit that referenced this pull request Nov 30, 2021
includes #8
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.

3 participants