-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -19,7 +19,15 @@ module Puppet | |||||||||||||
provided in the `gid` attribute) or any group listed in the `groups` | ||||||||||||||
attribute then the user resource will autorequire that group. If Puppet | ||||||||||||||
is managing any role accounts corresponding to the user's roles, the | ||||||||||||||
user resource will autorequire those role accounts." | ||||||||||||||
user resource will autorequire those role accounts. | ||||||||||||||
Only when the resource is ensured to be present. | ||||||||||||||
|
||||||||||||||
**Autobefores:** If Puppet is managing the user's primary group (as | ||||||||||||||
provided in the `gid` attribute) or any group listed in the `groups` | ||||||||||||||
attribute then the user resource will autobefore that group. If Puppet | ||||||||||||||
is managing any role accounts corresponding to the user's roles, the | ||||||||||||||
user resource will autorequire those role accounts. | ||||||||||||||
Only when the resource is ensured to be absent." | ||||||||||||||
|
||||||||||||||
feature :allows_duplicates, | ||||||||||||||
"The provider supports duplicate users with the same UID." | ||||||||||||||
|
@@ -459,40 +467,47 @@ def insync?(current) | |||||||||||||
end | ||||||||||||||
end | ||||||||||||||
|
||||||||||||||
# Autorequire the group, if it's around | ||||||||||||||
# Autorequire groups, if they're around | ||||||||||||||
autorequire(:group) do | ||||||||||||||
autos = [] | ||||||||||||||
|
||||||||||||||
# autorequire primary group, if managed | ||||||||||||||
obj = @parameters[:gid] | ||||||||||||||
groups = obj.shouldorig if obj | ||||||||||||||
if groups | ||||||||||||||
groups = groups.collect { |group| | ||||||||||||||
if group.is_a?(String) && group =~/^\d+$/ | ||||||||||||||
Integer(group) | ||||||||||||||
else | ||||||||||||||
group | ||||||||||||||
end | ||||||||||||||
} | ||||||||||||||
groups.each { |group| | ||||||||||||||
case group | ||||||||||||||
when Integer | ||||||||||||||
resource = catalog.resources.find { |r| r.is_a?(Puppet::Type.type(:group)) && r.should(:gid) == group } | ||||||||||||||
if resource | ||||||||||||||
autos << resource | ||||||||||||||
if self[:ensure] != :absent | ||||||||||||||
if @parameters[:gid]&.shouldorig | ||||||||||||||
groups_in_catalog = catalog.resources.filter { |r| r.is_a?(Puppet::Type.type(:group)) } | ||||||||||||||
autos += @parameters[:gid].shouldorig.filter_map do |group| | ||||||||||||||
if (group.is_a?(String) && group.match?(/^\d+$/)) || group.is_a?(Integer) | ||||||||||||||
gid = Integer(group) | ||||||||||||||
groups_in_catalog.find { |r| r.should(:gid) == gid } | ||||||||||||||
else | ||||||||||||||
group | ||||||||||||||
end | ||||||||||||||
else | ||||||||||||||
autos << group | ||||||||||||||
end | ||||||||||||||
} | ||||||||||||||
end | ||||||||||||||
|
||||||||||||||
if @parameters[:groups]&.should | ||||||||||||||
autos += @parameters[:groups].should.split(",") | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Internally puppet stores the desired values as an array (both However, the Lines 531 to 535 in 7ca202b
The behavior is determined based on the puppet/lib/puppet/type/group.rb Line 84 in 7ca202b
|
||||||||||||||
end | ||||||||||||||
end | ||||||||||||||
|
||||||||||||||
# autorequire groups, excluding primary group, if managed | ||||||||||||||
obj = @parameters[:groups] | ||||||||||||||
if obj | ||||||||||||||
groups = obj.should | ||||||||||||||
if groups | ||||||||||||||
autos += groups.split(",") | ||||||||||||||
autos | ||||||||||||||
end | ||||||||||||||
|
||||||||||||||
# 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 commentThe 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 commentThe 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. |
||||||||||||||
autos = [] | ||||||||||||||
|
||||||||||||||
if self[:ensure] == :absent | ||||||||||||||
if @parameters[:gid]&.shouldorig | ||||||||||||||
groups_in_catalog = catalog.resources.filter { |r| r.is_a?(Puppet::Type.type(:group)) } | ||||||||||||||
autos += @parameters[:gid].shouldorig.filter_map do |group| | ||||||||||||||
if (group.is_a?(String) && group.match?(/^\d+$/)) || group.is_a?(Integer) | ||||||||||||||
gid = Integer(group) | ||||||||||||||
groups_in_catalog.find { |r| r.should(:gid) == gid } | ||||||||||||||
else | ||||||||||||||
group | ||||||||||||||
end | ||||||||||||||
end | ||||||||||||||
end | ||||||||||||||
end | ||||||||||||||
|
||||||||||||||
|
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'smunge
method. Whereas.shouldorig
is the desired value before munging:puppet/lib/puppet/property.rb
Line 549 in 7ca202b