Skip to content

Commit fdc0257

Browse files
committed
Add krbPrincipalName to sssd.conf user attributes
The principal name provides a consistent username for creating user records since sssd supports logins with email or the username from the authentication system (freeipa). Using this consistent principal name prevents creating duplicate users created from both the free ipa username and from the configured email address. Related: ManageIQ/manageiq#23723 ManageIQ/manageiq-appliance#401
1 parent b8b4468 commit fdc0257

File tree

2 files changed

+77
-5
lines changed

2 files changed

+77
-5
lines changed

lib/manageiq/appliance_console/external_httpd_authentication/external_httpd_configuration.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ module ExternalHttpdConfiguration
3131
TIMESTAMP_FORMAT = "%Y%m%d_%H%M%S".freeze
3232

3333
LDAP_ATTRS = {
34-
"mail" => "REMOTE_USER_EMAIL",
35-
"givenname" => "REMOTE_USER_FIRSTNAME",
36-
"sn" => "REMOTE_USER_LASTNAME",
37-
"displayname" => "REMOTE_USER_FULLNAME",
38-
"domainname" => "REMOTE_USER_DOMAIN"
34+
"mail" => "REMOTE_USER_EMAIL",
35+
"givenname" => "REMOTE_USER_FIRSTNAME",
36+
"sn" => "REMOTE_USER_LASTNAME",
37+
"displayname" => "REMOTE_USER_FULLNAME",
38+
"domainname" => "REMOTE_USER_DOMAIN",
39+
"krbPrincipalName" => "REMOTE_USER_PRINCIPAL"
3940
}.freeze
4041

4142
def template_directory

spec/external_httpd_authentication_spec.rb

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,75 @@
204204
expect(described_class.config_status).to eq("External Auth SAML")
205205
end
206206
end
207+
208+
context "#configure_sssd_domain" do
209+
let(:domain) { "example.com" }
210+
let(:base_config) do
211+
<<~CONFIG
212+
[sssd]
213+
services = nss, pam
214+
215+
[domain/example.com]
216+
id_provider = ipa
217+
ipa_server = ipa.example.com
218+
CONFIG
219+
end
220+
221+
it "adds ldap_user_extra_attrs when not present" do
222+
config = base_config.dup
223+
subject.send(:configure_sssd_domain, config, domain)
224+
expect(config).to include("ldap_user_extra_attrs = mail, givenname, sn, displayname, domainname, krbPrincipalName")
225+
end
226+
227+
it "updates existing ldap_user_extra_attrs" do
228+
config = base_config + "ldap_user_extra_attrs = mail\n"
229+
subject.send(:configure_sssd_domain, config, domain)
230+
231+
# Verify the line contains all expected attributes
232+
expect(config).to include("ldap_user_extra_attrs = mail, givenname, sn, displayname, domainname, krbPrincipalName")
233+
234+
# Verify there's only one ldap_user_extra_attrs line
235+
expect(config.scan(/ldap_user_extra_attrs/).length).to eq(1)
236+
237+
# Verify the original "mail" only value was replaced, not just appended
238+
expect(config).not_to include("ldap_user_extra_attrs = mail\n")
239+
end
240+
241+
it "preserves existing configuration while adding attributes" do
242+
config = base_config.dup
243+
subject.send(:configure_sssd_domain, config, domain)
244+
expect(config).to include("id_provider = ipa")
245+
expect(config).to include("ipa_server = ipa.example.com")
246+
end
247+
end
248+
249+
context "#configure_sssd_ifp" do
250+
let(:base_config) do
251+
<<~CONFIG
252+
[sssd]
253+
services = nss, pam
254+
CONFIG
255+
end
256+
257+
it "adds [ifp] section when not present" do
258+
config = base_config.dup
259+
subject.send(:configure_sssd_ifp, config)
260+
expect(config).to include("[ifp]")
261+
expect(config).to include("allowed_uids = apache, root, manageiq")
262+
expect(config).to include("user_attributes = +mail, +givenname, +sn, +displayname, +domainname, +krbPrincipalName")
263+
end
264+
265+
it "updates user_attributes in existing [ifp] section" do
266+
config = base_config + "\n[ifp]\nallowed_uids = apache\nuser_attributes = +mail\n"
267+
subject.send(:configure_sssd_ifp, config)
268+
expect(config).to include("user_attributes = +mail, +givenname, +sn, +displayname, +domainname, +krbPrincipalName")
269+
expect(config.scan(/user_attributes/).length).to eq(1)
270+
end
271+
272+
it "adds user_attributes when [ifp] exists but user_attributes doesn't" do
273+
config = base_config + "\n[ifp]\nallowed_uids = apache\n"
274+
subject.send(:configure_sssd_ifp, config)
275+
expect(config).to include("user_attributes = +mail, +givenname, +sn, +displayname, +domainname, +krbPrincipalName")
276+
end
277+
end
207278
end

0 commit comments

Comments
 (0)