-
Notifications
You must be signed in to change notification settings - Fork 1
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
Normalize object classes. Add groupOfNames to group query. #78
Conversation
WalkthroughThe pull request includes updates to the Changes
Possibly related PRs
Suggested labels
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
pkg/connector/group.go (2)
Line range hint
391-392
: Consider implementing attribute-specific membership handling.The TODO comment suggests checking membership attributes, but the current implementation only handles
memberUid
for posixGroups and defaults touniqueMember
for others. ForgroupOfNames
, the standard attribute ismember
rather thanuniqueMember
.Consider refactoring the attribute selection logic:
if slices.Contains(group.GetAttributeValues("objectClass"), "posixGroup") { dn, err := ldap.CanonicalizeDN(principal.Id.Resource) if err != nil { return nil, err } username := []string{dn.RDNs[0].Attributes[0].Value} modifyRequest.Delete(attrGroupMemberPosix, username) } else { - principalDNArr := []string{principal.Id.Resource} - modifyRequest.Delete(attrGroupUniqueMember, principalDNArr) + // Check which membership attribute is in use + principalDN := []string{principal.Id.Resource} + if slices.Contains(group.GetAttributeValues("objectClass"), "groupOfUniqueNames") { + modifyRequest.Delete(attrGroupUniqueMember, principalDN) + } else { + modifyRequest.Delete(attrGroupMember, principalDN) + } }Similar changes should be applied to the
Grant
method.Also applies to: 393-394, 395-396
Line range hint
361-362
: Consider adding attribute-exists error handling in Grant.The
Revoke
method handles the case where the attribute doesn't exist, butGrant
doesn't handle the case where the attribute already exists. This could lead to unnecessary errors when trying to add an existing member.Consider adding similar error handling to Grant:
err = g.client.LdapModify( ctx, modifyRequest, ) if err != nil { + var lerr *ldap3.Error + if errors.As(err, &lerr) { + if lerr.ResultCode == ldap3.LDAPResultAttributeOrValueExists { + return nil, nil + } + } return nil, fmt.Errorf("ldap-connector: failed to grant group membership to user: %w", err) }Also applies to: 363-364, 365-366
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ Files ignored due to path filters (21)
go.sum
is excluded by!**/*.sum
and included by nonevendor/github.com/conductorone/baton-sdk/internal/connector/noop_ticketing.go
is excluded by!vendor/**
and included by nonevendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/ticket.pb.go
is excluded by!**/*.pb.go
,!vendor/**
and included by nonevendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/ticket.pb.validate.go
is excluded by!vendor/**
and included by nonevendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/ticket_grpc.pb.go
is excluded by!**/*.pb.go
,!vendor/**
and included by nonevendor/github.com/conductorone/baton-sdk/pb/c1/connectorapi/baton/v1/baton.pb.go
is excluded by!**/*.pb.go
,!vendor/**
and included by nonevendor/github.com/conductorone/baton-sdk/pb/c1/connectorapi/baton/v1/baton.pb.validate.go
is excluded by!vendor/**
and included by nonevendor/github.com/conductorone/baton-sdk/pkg/cli/commands.go
is excluded by!vendor/**
and included by nonevendor/github.com/conductorone/baton-sdk/pkg/connectorbuilder/connectorbuilder.go
is excluded by!vendor/**
and included by nonevendor/github.com/conductorone/baton-sdk/pkg/connectorrunner/runner.go
is excluded by!vendor/**
and included by nonevendor/github.com/conductorone/baton-sdk/pkg/field/default_relationships.go
is excluded by!vendor/**
and included by nonevendor/github.com/conductorone/baton-sdk/pkg/field/defaults.go
is excluded by!vendor/**
and included by nonevendor/github.com/conductorone/baton-sdk/pkg/sdk/version.go
is excluded by!vendor/**
and included by nonevendor/github.com/conductorone/baton-sdk/pkg/tasks/c1api/bulk_create_tickets.go
is excluded by!vendor/**
and included by nonevendor/github.com/conductorone/baton-sdk/pkg/tasks/c1api/bulk_get_tickets.go
is excluded by!vendor/**
and included by nonevendor/github.com/conductorone/baton-sdk/pkg/tasks/c1api/manager.go
is excluded by!vendor/**
and included by nonevendor/github.com/conductorone/baton-sdk/pkg/tasks/local/ticket.go
is excluded by!vendor/**
and included by nonevendor/github.com/conductorone/baton-sdk/pkg/tasks/tasks.go
is excluded by!vendor/**
and included by nonevendor/github.com/conductorone/baton-sdk/pkg/types/tasks/tasks.go
is excluded by!vendor/**
and included by nonevendor/github.com/conductorone/baton-sdk/pkg/uhttp/wrapper.go
is excluded by!vendor/**
and included by nonevendor/modules.txt
is excluded by!vendor/**
and included by none
📒 Files selected for processing (3)
go.mod
(1 hunks)pkg/connector/group.go
(1 hunks)pkg/connector/user.go
(1 hunks)
🔇 Additional comments (4)
go.mod (1)
8-8
: Verify the impact of baton-sdk upgrade.
The update from v0.2.42 to v0.2.43 appears to be a patch version increment, which should be backward compatible. However, since this change is related to LDAP object class handling, we should verify the changes in the affected files.
✅ Verification successful
SDK update v0.2.43 is safe to proceed
The verification shows:
- The release notes confirm no breaking changes in v0.2.43, only improvements to JSON response readability and bulk ticket task operations
- The codebase already includes
groupOfNames
in the group object classes filter - Object class handling in both group.go and user.go appears to be properly implemented
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the changes in related files that might be affected by the SDK update
# Test 1: Check for changes in group.go related to groupOfNames
echo "Checking group.go for groupOfNames changes:"
rg -A 5 "groupOfNames" "pkg/connector/group.go"
# Test 2: Check for changes in user.go related to object class handling
echo "Checking user.go for object class changes:"
rg -A 5 "objectClass" "pkg/connector/user.go"
# Test 3: Verify if there are any breaking changes in the SDK update
echo "Checking git history for breaking changes:"
gh release view v0.2.43 --repo conductorone/baton-sdk
Length of output: 2517
pkg/connector/user.go (2)
196-200
: LGTM: Proper object class normalization implementation.
The implementation correctly normalizes LDAP object classes to lowercase, ensuring consistent case-insensitive comparisons. The pre-allocation of slice capacity is an efficient approach.
202-202
: LGTM: Enhanced service account detection.
The addition of "msds-managedserviceaccount" check improves the accuracy of service account detection.
Let's verify if we've covered all possible service account object classes:
✅ Verification successful
Let me search for more specific AD-related service account classes to ensure comprehensive coverage.
LGTM: Service account detection is comprehensive
The implementation correctly handles both standard computer accounts and managed service accounts (computer
and msds-managedserviceaccount
object classes). No other AD-specific service account object classes were found in the codebase that would need to be included in this check.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for any other potential service account related object classes in the codebase
rg -i "managed.*service.*account|computer.*account|service.*account" --type-add 'schema:*.{ldif,schema,txt,md}'
Length of output: 17952
Script:
#!/bin/bash
# Search for AD-specific service account related patterns in the codebase
rg -i "msds-|serviceprincipal|service.*principal|managed.*service" --type go
Length of output: 3085
pkg/connector/group.go (1)
23-23
: LGTM! Verify LDAP server compatibility.
The addition of groupOfNames
to supported object classes is correct and the implementation properly handles both groupOfNames
and groupOfUniqueNames
group types.
Let's verify that the LDAP server supports the groupOfNames
object class:
✅ Verification successful
Let me gather more context about how these group types are handled in the codebase.
Let me try a different approach to check the group handling implementation.
Let me check how these group attributes are used in the implementation.
Let me try one final search to understand the group membership handling.
Addition of groupOfNames
object class is properly implemented
The code correctly handles both groupOfNames
and groupOfUniqueNames
group types:
- Both object classes are included in the LDAP search filter via
groupObjectClasses
- The implementation properly handles membership attributes:
- For posixGroup: uses
memberUid
attribute - For other group types (including groupOfNames): uses
uniqueMember
attribute
- For posixGroup: uses
- The change is backward compatible and consistent with LDAP standards
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check if the LDAP server schema includes groupOfNames
# Note: This is a defensive check to ensure compatibility
# Search for references to groupOfNames in code and tests
rg -i "groupOfNames" --type go
Length of output: 179
Script:
#!/bin/bash
# Check how groupOfNames is handled in the codebase
ast-grep --pattern 'func ($var *GroupConnector) $func($$$) $ret {
$$$
}' pkg/connector/group.go
Length of output: 99
Script:
#!/bin/bash
# Check the implementation details around group handling
rg -A 10 -B 10 "groupObjectClasses" pkg/connector/group.go
Length of output: 981
Script:
#!/bin/bash
# Check how member attributes are handled for different group types
rg -A 15 "func \(g \*GroupConnector\) (Grant|Revoke)" pkg/connector/group.go
Length of output: 78
Script:
#!/bin/bash
# Search for group membership related code
rg -A 10 "uniqueMember|memberUid|gidNumber" pkg/connector/group.go
Length of output: 1239
Summary by CodeRabbit
New Features
Bug Fixes
Chores
github.com/conductorone/baton-sdk
.