connector/saml: add 'FilterGroups' setting

This should make AllowedGroups equivalent to an LDAP group filter:

When set to true, only the groups from AllowedGroups will be included in the
user's identity.

Signed-off-by: Stephan Renatus <srenatus@chef.io>
This commit is contained in:
Stephan Renatus
2020-05-11 11:42:26 +02:00
parent d87cf1c924
commit 4a0feaf589
3 changed files with 34 additions and 0 deletions

View File

@@ -101,6 +101,7 @@ type Config struct {
// used split the groups string.
GroupsDelim string `json:"groupsDelim"`
AllowedGroups []string `json:"allowedGroups"`
FilterGroups bool `json:"filterGroups"`
RedirectURI string `json:"redirectURI"`
// Requested format of the NameID. The NameID value is is mapped to the ID Token
@@ -165,6 +166,7 @@ func (c *Config) openConnector(logger log.Logger) (*provider, error) {
groupsAttr: c.GroupsAttr,
groupsDelim: c.GroupsDelim,
allowedGroups: c.AllowedGroups,
filterGroups: c.FilterGroups,
redirectURI: c.RedirectURI,
logger: logger,
@@ -240,6 +242,7 @@ type provider struct {
groupsAttr string
groupsDelim string
allowedGroups []string
filterGroups bool
redirectURI string
@@ -430,6 +433,10 @@ func (p *provider) HandlePOST(s connector.Scopes, samlResponse, inResponseTo str
return ident, fmt.Errorf("user not a member of allowed groups")
}
if p.filterGroups {
ident.Groups = groupMatches
}
// Otherwise, we're good
return ident, nil
}