Exclude Service Groups and outside members in Azure AD Dynamic Groups - azure-active-directory

Would like to create a dynamic group in Azure AD that has the following criteria:
Only include individual user accounts (no service accounts) who are actually employees of our company.
I think there should be a way to accomplish the first criteria, but a bit unsure about the second.
Also would be great if the group could be alphabetical.
Any assistance would be greatly appreciated.

The rule or rules will depend on how you have your employee users organized. Only users can be assigned dynamically.
Below you will find some samples:
If employees are all members (not guests):
(user.userType -eq "member")
If employees are all members (not guests) who have the Exchange Online (Plan 2) service plan assigned and enabled:
(user.userType -eq "member") and (user.assignedPlans -any (assignedPlan.servicePlanId -eq "efb87545-963c-4e0d-99df-69c6916d9eb0" -and assignedPlan.capabilityStatus -eq "Enabled"))
Etc.
For more information, please take a look to Dynamic membership rules for groups in Azure Active Directory.

Related

Ldap query to get users of a group in Active Directory

I'm trying to write a filter to get all the users of a given group in Active Directory.
To that end I have the following query
LDAPSearch("DC=test,DC=myorg,DC=com", "(objectClass=user)", 1, "name")
I'm a bit confused as to where I should give the name of the group on which to base the search on. As far as I know you cannot have two groups in AD with the same name.
In general, user objects have an attribute called memberOf that lists DNs of groups that a user is member of. Therefore you can search with a filter like (&(objectClass=user)(memberOf=<DN of requested group>)).
Please note that due to AD design, user's primary group is not included in memberOf attribute. For most users that group would be Domain Users (unless explicitly changed), but if changed, that group will no longer list in memberOf and this query will not find such user.

Active Directory group lists a member user, user's entry does not mention the group

I have group G and user U. The entry for G includes U as a "member" record. The entry for U does not include G as a "memberOf" record. (I am querying the entries programmatically, in C#, and viewing them in Softerra LDAP Browser). Can anybody explain this paradox?
The memberOf attribute is not authoritative. Whether a group is listed there depends on the "Scope" of the group. It will only include:
Universal groups in the same AD forest
Global groups from the same domain as the user
Domain Local groups on the same domain as the server you are reading from (which may or may not be the same domain as the user)
I describe this in a little more detail in an article I wrote, under the heading "Beware of memberOf".
If you need to find groups that memberOf doesn't list, I also wrote an article called Finding all of a user's groups with code samples.

ADFS not returning domain groups (Also odd issues with get-aduser)

I am trying to help someone troubleshoot an extremely odd AD\ADFS issue and am about out of ideas.
We are using ADFS to return the security groups (among other things) that a user belongs to. If that user has a specific group, then we grant them access. This is something that works on several other systems\environments. In this case, ADFS is not returning any domain groups for the user (and I have checked a few users).
If I use
Get-aduser username -properties memberof | select -expandproperty memberof
nothing gets displayed. If I do
get-aduser username -properties memberof | measureobject
it does give me a count of one.
Here's where things get really interesting.
If I check the user in ADUC, I see that it is a member of domain users, but that's it. If I go look at the group in question in ADUC, it shows this user is also a member of that group (but does NOT show this group under memberof for that user.)
If I check get-adgroupmember it shows that this user is a member of the group that I truly need returned. The SID is the same for the user that it shows as belonging to the group as it is for when I use get-aduser to check the user in question (where this group doesn't show up).
Now, all of that aside - if I go and query ADFS - I don't get any domain groups returned for the user in question (neither Domain Users nor the other one that it SHOULD be in)
I assume this is LIKELY something security related, but am at a loss.
This same exact configuration for ADFS works absolutely perfect in several of my test environments.
Any advice\suggestions?
A few things:
memberOf shows you only:
Groups in your AD forest with a group scope of Universal
Groups on the same domain with a group scope of Global
It does not show:
Groups with a scope of Domain Local on any domain
Groups on other domains in your forest with a scope of Global
There's more: the Domain Users group is a bit odd. Members of that group are not usually in the members attribute of that group. User objects have an attribute called primaryGroupID, which contains the RID of that user's "primary group". The RID is the last portion of the SID. That's what makes them a "member" of that group.
All this means that you can't rely on memberOf. You can search the member attribute of groups for the user (using the user's distinguishedName):
Get-ADGroup -Filter { member -eq "distinguishedName" }
And if you need the primary group, find that separately too.
But there is a PowerShell cmdlet that does all this for you: Get-ADPrincipalGroupMembership
It returns group objects, so if you just want the name, then pipe it into Select:
Get-ADPrincipalGroupMembership username | Select -ExpandProperty Name

Generic ldap nested group implementation

I need to implement nested group membership for generic AD services.
Previously, i was using a specific search-filter ("member:1.2.840.113556.1.4.1941:=") through which using a single search request, i was able to get hold of all group membership through which that user was part of. However, it looks like that search-filter seems to work only for MS AD servers and not for generic AD servers.
So, is anybody aware of any specific search filter which we can send in a search request (applicable to All AD servers), through which i can derive nested group membership via a single search query.
Thanks in advance for your help on this.
"member:1.2.840.113556.1.4.1941" is LDAP_MATCHING_RULE_IN_CHAIN and might very well not be implemented by other LDAP vendors. LDAP Wiki
Edit:
You could do something like this if you want to reurse the groups:
Use the filter:
(&(objectCategory=organizationalPerson)(objectClass=User)(sAMAccountName=YOURUSER)
get "distinguishedName" (this is the user's distinguishedName)
get "memberOf" (this is a collection of distinguishedNames of the groups the user is a member of (minus the primary group in MS Active Directory, which should be "Domain Users"))
Foreach memberOf in the collection: (This is the first level, so there is no need to check if he is there, because he is.)
(&(objectCategory=group)(distinguishedName=THISMEMBEROF))
get "member" (this is a collection of distinguishedNames of group members)
Foreach memberOf in the collection:
This is the second level (the groups within the groups), so first check if the users distinguishedName is present.
(&(objectCategory=group)(distinguishedName=THISMEMBEROF))
get "member" (this is a collection of distinguishedNames of group members)
Foreach memberOf in the collection:
This is the third level (the groups within the groups), so first check if the users distinguishedName is present.
(&(objectCategory=group)(distinguishedName=THISMEMBEROF))
get "member" (this is a collection of distinguishedNames of group members)
etc.

Active Directory memberof property doesn't contain nested security groups

An AD setup I'm using has users that are stored as members of (multiple) security groups.
I am using software that reads the memberof property of a user to work out access permissions.
In AD Explorer I can see the memberof property of the user shows the immediate security groups they belong to say 'Course - English'. It does not show the parents groups, nested up to say 'ALL Students'.
Is there a reason for this or a way of ensuring all nested groups are shown in the memberof property?
If you're on .NET 3.5 and up, you should check out the System.DirectoryServices.AccountManagement (S.DS.AM) namespace. Read all about it here:
Managing Directory Security Principals in the .NET Framework 3.5
MSDN docs on System.DirectoryServices.AccountManagement
Basically, you can define a domain context and easily find users and/or groups in AD:
// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
// find a user
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "SomeUserName");
if(user != null)
{
var groups = user.GetAuthorizationGroups();
// enumerate over groups
foreach(GroupPrincipal gp in groups)
{
// do something here....
}
}
The new S.DS.AM makes it really easy to play around with users and groups in AD!
The .GetAuthorizationGroups() method is the only one around that I know of that will do recursive searches, e.g. find groups that a user is member of by virtue of another group. The pre-.NET 3.5 DirectoryServices stuff doesn't do this - you would have to totally roll your own if you need that.
The probable reason that the memberOf attribute does not contain all the nested group information is that the value is computed when the attribute is loaded, as noted in this link:
Be aware that this attribute lists the groups that contain the user in their member attribute—it does not contain the recursive list of nested predecessors. For example, if user O is a member of group C and group B and group B were nested in group A, the memberOf attribute of user O would list group C and group B, but not group A.
This attribute is not stored—it is a computed back-link attribute.
Hence, to support this, your DC would be forced to load all nested groups every time a LDAP query returned the memberOf attribute, which could be a lot of excess work.
Depending on the technology you are using, there are almost certainly better ways to check group membership than loading all groups and listing them all. For example, ADSI has a pre-built function to check if a user is a member of the group.
However, for a pure LDAP solution, you could use the LDAP_MATCHING_RULE_IN_CHAIN as shown in this answer (assuming you have the DN for the user), e.g.,
(member:1.2.840.113556.1.4.1941:=CN=Administrator,OU=Users,DC=fabrikam,DC=com)
Which will get all the groups which Administrator is a member of. Note, however, that this query can be extremely slow. To speed up performance, consider paging results or restricting the search base to only the group you are interested in checking.

Resources