-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Correct user <-> group relationship on removal #9114
base: main
Are you sure you want to change the base?
Conversation
This refactors the code using safe navigators and modern Ruby functions.
When a group needs to be removed, it can't be the primary group of a user. So if a user is ensured absent, it needs to happen before the group is removed.
Can one of the admins verify this patch? |
} | ||
end | ||
|
||
if @parameters[:groups]&.should |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is .should
doing? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's mostly based on what was already there. I'm just refactoring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The .should
is the desired value specified in the catalog, which has been canonicalized by the property's munge
method. Whereas .shouldorig
is the desired value before munging:
Line 549 in 7ca202b
@shouldorig = values |
end | ||
|
||
if @parameters[:groups]&.should | ||
autos += @parameters[:groups].should.split(",") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can multiple groups be passed as comma separated string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question, was just refactoring. Now I question why it was there. I did notice in the other example that shouldorig
was an array while should
wasn't. So perhaps that's the problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Internally puppet stores the desired values as an array (both should
and shouldorig
) for example https://github.com/puppetlabs/puppet/blob/7ca202bd2faf876e1904a8a2e891c10c2cee6ffc/lib/puppet/property.rb#L552C1-L552C1
However, the should
reader will either return a single value (default case) or an array depending on whether the property is single or multi-valued:
Lines 531 to 535 in 7ca202b
if match_all? | |
return @should.collect { |val| self.unmunge(val) } | |
else | |
return self.unmunge(@should[0]) | |
end |
The behavior is determined based on the array_matching
value specified when the property is defined using newproperty
. For example, members
of the group is multi-valued:
puppet/lib/puppet/type/group.rb
Line 84 in 7ca202b
newproperty(:members, :array_matching => :all, :required_features => :manages_members) do |
|
||
# Autobefore the primary group, if it's around. Otherwise group removal | ||
# fails when that group is also ensured absent. | ||
autobefore(:group) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a long standing bug in puppet that auto* relationships and ensure => absent don't work well together. I filed a redmine ticket a long time ago, which was exported to https://puppet.atlassian.net/browse/PUP-2451. Ideally I think puppet would know to reverse the direction for any auto* relationship when ensuring absent. Worse, if you try to set an explicit relationship, it will create a cycle due to the auto relationship.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have written Puppet code where I had a lot of conditionals based on absent/present. I'd love for Puppet to be smarter here. But reading https://github.com/voxpupuli/puppet-systemd/blob/dbaa56f690e36f9f164fee464bf7b0e8a9a6d37c/manifests/unit_file.pp#L131-L142 I really don't know how it could be designed in a way that's not more confusing than the status quo.
Overall few people write modules with (full) support to ensure things are absent.
When a group needs to be removed, it can't be the primary group of a user. So if a user is ensured absent, it needs to happen before the group is removed.
This PR first adds tests to the existing code, before refactoring it. Then in the last commit it adds autobefore and makes sure autorequires is empty when ensure is absent.