Skip to content
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

add dynamic group mapping for AD provider #146

Merged

Conversation

rshlin
Copy link
Contributor

@rshlin rshlin commented Jan 12, 2021

Description

implemented dynamic group mapping for AD provider.

Related Issue

https://support.tyk.io/hc/requests/11700
https://tyktech.atlassian.net/browse/TT-2400

Motivation and Context

After deserializing ldap response with user info previous implementation of ADProvider was grabbing the first element from user attribute with type array and hence all valuable group membership information was cutted off.

  • fixed ADProvider
  • added handler for []string array of AD groups @ tyk_handler.go:groupStringer function
  • minor code style improvements

How This Has Been Tested

Ran TIB as standalone, AD, dashboard. Used the following profile for test:

[
  {
    "ActionType": "GenerateOrLoginUserProfile",
    "ID": "1",
    "OrgID": "5f48ae5f62a1be5a74f39377",
    "IdentityHandlerConfig": {
      "DashboardCredential": ""
    },
    "ProviderConfig": {
      "LDAPUseSSL": false,
      "FailureRedirect": "{{ failure redirect }}",
      "LDAPPort": "389",
      "LDAPServer": "{{ server address }}",
      "LDAPAdminUser": "{{ DN of admin user }}",
      "LDAPAdminPassword": "{{ admin password }}",
      "LDAPSearchScope": 2,
      "LDAPFilter": "(&(objectcategory=user)(sAMAccountName=*USERNAME*))",
      "LDAPEmailAttribute": "mail",
      "LDAPFirstNameAttribute": "givenName",
      "LDAPLastNameAttribute": "sn",
      "LDAPGroupMembershipAttribute": "memberOf",
      "LDAPUserDN": "{{ base directory }}"
    },
    "DefaultUserGroupID": "5f48b17462a1be7845a7a448",
    "CustomUserGroupField": "memberOf",
    "UserGroupMapping": {
      "{{ DN of group }}": "5f48b19262a1be7845a7a449"
    },
    "ProviderName": "ADProvider",
    "ReturnURL": "{{ return URL }}",
    "Type": "passthrough"
  }
]

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring or add test (improvements in base code or adds test coverage to functionality)

Checklist

  • Make sure you are requesting to pull a topic/feature/bugfix branch (right side). If pulling from your own
    fork, don't request your master!
  • Make sure you are making a pull request against the master branch (left side). Also, you should start
    your branch off our latest master.
  • My change requires a change to the documentation.
    • If you've changed APIs, describe what needs to be updated in the documentation.
    • If new config option added, ensure that it can be set via ENV variable
  • I have updated the documentation accordingly.
  • Modules and vendor dependencies have been updated; run go mod tidy && go mod vendor
  • When updating library version must provide reason/explanation for this update.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • Check your code additions will not fail linting checks:
    • go fmt -s
    • go vet

@letzya letzya requested a review from sredxny January 28, 2021 19:18
@sredxny sredxny requested a review from tbuchaillot August 3, 2021 16:02
Copy link
Contributor

@tbuchaillot tbuchaillot left a comment

Choose a reason for hiding this comment

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

@rshlin left some comments! otherwise, it looks good!

@@ -243,9 +244,13 @@ func (s *ADProvider) getUserData(username string, password string) (goth.User, e
if j.Name == s.config.LDAPLastNameAttribute {
thisUser.LastName = j.Values[0]
}
if j.Name == s.config.LDAPGroupMembershipAttribute {
Copy link
Contributor

Choose a reason for hiding this comment

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

@rshlin what do you think if here, instead of adding a new config field (s.config.LDAPGroupMembershipAttribute) we just use s.profile.CustomUserGroupField ?

Choose a reason for hiding this comment

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

@rshlin we are thinking of implementing this using the suggestion made by @tbuchaillot -- Any objections? Thanks a lot for this!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had concerns on using s.profile.CustomUserGroupField because this field had different semantics(see GetGroupId): providers collect relevant identity attributes into a single container and at the end SSOAccessData is uniformly assembled. I wanted to leave these layers(i.e. adapter & core logic) low coupled and introduce a minimum amount of changes(preferably incremental) to make AD mapping work.

Anyway, required design decisions produce insignificant effects at this stage, and I agree with @tbuchaillot suggestion.

@rshlin rshlin requested a review from tbuchaillot October 14, 2021 12:20
Copy link
Contributor

@sredxny sredxny left a comment

Choose a reason for hiding this comment

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

lgtm

@tbuchaillot tbuchaillot merged commit 96df97c into TykTechnologies:master Oct 14, 2021
@tbuchaillot
Copy link
Contributor

thanks a lot @rshlin for your contribution! We are going to notify you when this is released :)

@rshlin rshlin deleted the group-mapping-for-ldap-provider branch November 17, 2021 13:28
sredxny pushed a commit that referenced this pull request Jan 28, 2022
* add dynamic group mapping feature for AD provider

* reuse s.profile.CustomUserGroupField config key for groups retrievement

Co-authored-by: rsharifullin <rsharifullin@cinimex.ru>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants