Skip to content

ipa: improve handling of external group memberships#8094

Closed
sumit-bose wants to merge 3 commits intoSSSD:masterfrom
sumit-bose:ipa_add_group_member_fix
Closed

ipa: improve handling of external group memberships#8094
sumit-bose wants to merge 3 commits intoSSSD:masterfrom
sumit-bose:ipa_add_group_member_fix

Conversation

@sumit-bose
Copy link
Contributor

Recently add_ad_user_to_cached_groups() was modified to better handle
adding and removing group memberships of users from trusted domains in
groups of the local IPA domain. Before the change group members were only
added and with the change a removal was possible as well. This caused an
issues with an in-out parameter which contains the full list of IPA group
memberships at input and the list of group missing in the cache as output.
Since add_ad_user_to_cached_groups() is called twice, the second time after
the missing groups were read from the IPA server, this caused and
unexpected removal of group memberships since the second call to
add_ad_user_to_cached_groups() was done with the list of missing groups and
not with the full list.

With this patch a dedicated list is used for the missing groups to avoid
the described issues.

Additionally this PR contains a second patch which filters some objects SSSD
currently does not handle.

Resolves: #7921

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively refactors the handling of external group memberships to resolve an issue with an in-out parameter, by introducing a dedicated list for missing groups. This correctly prevents unintended group membership removals. Additionally, it introduces filtering for objects that SSSD does not handle. However, I've found a critical use-after-free vulnerability in the new helper function get_rdn_name_from_dn_string which must be addressed.

@sumit-bose sumit-bose force-pushed the ipa_add_group_member_fix branch from 0eda138 to 77ae7dc Compare September 11, 2025 17:09
@sumit-bose
Copy link
Contributor Author

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly refactors the handling of external group memberships to prevent incorrect group removals by using a dedicated list for missing groups. It also introduces filtering to avoid lookups for non-group objects. The logic seems sound, but I've identified a memory leak in the new filtering function that should be addressed.

@sumit-bose sumit-bose force-pushed the ipa_add_group_member_fix branch from 77ae7dc to 4b9dce6 Compare September 12, 2025 07:12
@pbrezina
Copy link
Member

Hi, would you mind adding test for the original issue? It should be fairly simple.

Once SSSD/sssd-test-framework#190 is merged, we can add also test for the sudo case.

@sumit-bose
Copy link
Contributor Author

Hi, would you mind adding test for the original issue? It should be fairly simple.

Once SSSD/sssd-test-framework#190 is merged, we can add also test for the sudo case.

Hi,

you mean a test to check that a group membership is properly removed? For the "sudo case" Shridhar has already opened #8074 for the underlying issue.

bye,
Sumit

@pbrezina
Copy link
Member

Hi, would you mind adding test for the original issue? It should be fairly simple.
Once SSSD/sssd-test-framework#190 is merged, we can add also test for the sudo case.

Hi,

you mean a test to check that a group membership is properly removed?

yes

@sumit-bose sumit-bose force-pushed the ipa_add_group_member_fix branch from 4b9dce6 to dc0301b Compare September 15, 2025 10:47
@sumit-bose
Copy link
Contributor Author

Hi, would you mind adding test for the original issue? It should be fairly simple.
Once SSSD/sssd-test-framework#190 is merged, we can add also test for the sudo case.

Hi,
you mean a test to check that a group membership is properly removed?

yes

added

@sumit-bose sumit-bose force-pushed the ipa_add_group_member_fix branch 2 times, most recently from 96f3a1d to 54f2dc1 Compare September 15, 2025 10:53
@alexey-tikhonov alexey-tikhonov added the coverity Trigger a coverity scan label Sep 15, 2025
Copy link
Member

@pbrezina pbrezina left a comment

Choose a reason for hiding this comment

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

Hi, there is a typo in the second commita message "removall". The third commit also contains some test bits that should be moved to the second commit.

Otherwise ack, thank you.

:customerscenario: True
"""
ipa.sssd.subdom('ipa.test', trusted.domain)['ldap_use_tokengroups'] = use_token_groups
ipa.sssd.config_apply(check_config=False)
Copy link
Member

Choose a reason for hiding this comment

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

Why disable check_config?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi,

currently the config check does not like ldap_use_tokengroups in the sub-domain section. I didn't want to add it to the allowed options en passant because it might need some more careful testing when using the AD provider. Since token groups are not used in the IPA provider it might be possible to set ldap_use_tokengroups in the IPA domain section and inherit it, if you prefer.

bye,
Sumit

Copy link
Member

Choose a reason for hiding this comment

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

Thank you for the explanation, maybe add a comment then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi,

I switched to the inherit variant and removed check_config=False.

bye,
Sumit

ipa.group("posix-group").add().add_member(external)

ipa.sssd.clear(db=True, memcache=True, logs=True)
ipa.host.conn.exec(["systemctl", "restart", "sssd.service"])
Copy link
Member

Choose a reason for hiding this comment

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

Why don't you use ipa.sssd.restart? And isn't it sufficient to restart it only once, since you are clearing the cache anyway?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi,

this is the work-around for SSSD/sssd-test-framework#203. If ipa.sssd.restart() is used there will be no valid Kerberos ticket anymore for the second ipa .... command.

bye,
Sumit

Copy link
Member

@pbrezina pbrezina Sep 16, 2025

Choose a reason for hiding this comment

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

No need for workaround, I wrote a fix: SSSD/sssd-test-framework#205

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi,

the test is now using ipa.sssd.restart()

bye,
Sumit

@alexey-tikhonov
Copy link
Member

Note: Covscan is green.

@alexey-tikhonov alexey-tikhonov removed the coverity Trigger a coverity scan label Sep 19, 2025
return NULL;
}

tmp_str = ldb_dn_get_rdn_name(dn);
Copy link
Member

Choose a reason for hiding this comment

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

Since ldb_dn_get_rdn_name() returns name of 1st component only anyway:

dn->components[0].name

would it work to simply strchr('=')? Can '=' be escaped in a DN?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi,

using strchr() was my first implementation, but what I found that ldb functions were used for similar task I wanted to be consistent and switch to the current implementation.

Since LDAP attribute names (or short names or descriptors as they are called in the RFCs) cannot contain a =, only "ALPHA / DIGIT / HYPHEN" are allowed (https://www.rfc-editor.org/rfc/rfc4512#section-1.4) the strchr() variant would work as well. So, if you prefer I can change the implementation.

bye,
Sumit

Copy link
Member

@alexey-tikhonov alexey-tikhonov Sep 22, 2025

Choose a reason for hiding this comment

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

So, if you prefer I can change the implementation.

It depends if this is a hot path.

Cache performance is already a huge pain point, especially for AD/IPA-AD cases.
If this is a hot path (and imo it can be) then I'd vote to not introduce additional overhead here (this includes my other perf related comments).

@sumit-bose sumit-bose force-pushed the ipa_add_group_member_fix branch from 5562c52 to 8514b49 Compare September 23, 2025 08:05
@sumit-bose
Copy link
Contributor Author

Hi,

I removed the third patch with the filtering from this PR to be able to move more swiftly with the actual fix. I will add a now PR with the filtering including Alexey's suggestion once this here is finished.

bye,
Sumit

In a IPA-AD trust environment, AD-user has membership of a
external-ipa group. This external-ipa-group is member of IPA-posix
group. When a HBAC rule is added and is the ipa-posix member is
added as member for that rule, AD-user misses that IPA-group-membership
@alexey-tikhonov
Copy link
Member

ACK, thank you.

Copy link
Contributor

@justin-stephenson justin-stephenson left a comment

Choose a reason for hiding this comment

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

Ack.

@alexey-tikhonov alexey-tikhonov added Accepted coverity Trigger a coverity scan labels Sep 23, 2025
@alexey-tikhonov
Copy link
Member

Note: Covscan is still green.

@alexey-tikhonov
Copy link
Member

Pushed PR: #8094

  • master
    • 80ccb59 - Test: HBAC affecting AD-users ipa-group membership
    • 2a388e7 - tests: test removal of external group membership
    • 9f72fcd - ipa: improve handling of external group memberships
  • sssd-2-11
    • 96b4251 - Test: HBAC affecting AD-users ipa-group membership
    • 146b251 - tests: test removal of external group membership
    • 5afeec3 - ipa: improve handling of external group memberships
  • sssd-2-9
    • 0a26516 - Test: HBAC affecting AD-users ipa-group membership
    • 46f7101 - tests: test removal of external group membership
    • de347b2 - ipa: improve handling of external group memberships

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AD user in external group is not cleared when expiring the cache

5 participants