Skip to content

Commit 781886f

Browse files
committed
feat: Allow multiple sshkey entries with scim
1 parent 5ff5a77 commit 781886f

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

nss_cache/sources/scimsource.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,18 @@ def _ExtractShell(self, user_data):
571571
return default_shell
572572

573573

574+
class UniqueSshkeyMapEntry(sshkey.SshkeyMapEntry):
575+
"""SSH key map entry that uses composite key to allow multiple keys per user."""
576+
577+
def Key(self):
578+
"""Return a composite key that includes both username and SSH key.
579+
580+
This allows multiple SSH keys for the same user to coexist in the map.
581+
"""
582+
# Use a composite key of username + ssh key to make each entry unique
583+
return f"{self.name}:{self.sshkey}"
584+
585+
574586
class ScimSshkeyMapParser(ScimMapParser):
575587
"""Class for parsing SCIM Users into sshkey cache."""
576588

@@ -579,7 +591,7 @@ def __init__(self, source=None):
579591
super().__init__(source)
580592

581593
def _ReadEntry(self, user_data):
582-
"""Return SshkeyMapEntry instances from a SCIM user resource."""
594+
"""Return UniqueSshkeyMapEntry instances from a SCIM user resource."""
583595
entries = []
584596

585597
# Extract username using configurable path
@@ -604,10 +616,10 @@ def _ReadEntry(self, user_data):
604616
elif not isinstance(ssh_keys, list):
605617
ssh_keys = []
606618

607-
# Create an entry for each SSH key
619+
# Create an entry for each SSH key using our custom entry class
608620
for ssh_key in ssh_keys:
609621
if ssh_key and ssh_key.strip():
610-
map_entry = sshkey.SshkeyMapEntry()
622+
map_entry = UniqueSshkeyMapEntry()
611623
map_entry.name = username
612624
map_entry.sshkey = ssh_key.strip()
613625
entries.append(map_entry)

0 commit comments

Comments
 (0)