-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Compare groups case-insensitively at login time #3240
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package okta | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/hashicorp/vault/helper/policyutil" | ||
"github.com/hashicorp/vault/logical" | ||
"github.com/hashicorp/vault/logical/framework" | ||
|
@@ -45,34 +47,59 @@ func pathGroups(b *backend) *framework.Path { | |
} | ||
} | ||
|
||
func (b *backend) Group(s logical.Storage, n string) (*GroupEntry, error) { | ||
// We look up groups in a case-insensitive manner since Okta is case-preserving | ||
// but case-insensitive for comparisons | ||
func (b *backend) Group(s logical.Storage, n string) (*GroupEntry, string, error) { | ||
canonicalName := n | ||
entry, err := s.Get("group/" + n) | ||
if err != nil { | ||
return nil, err | ||
return nil, "", err | ||
} | ||
if entry == nil { | ||
return nil, nil | ||
entries, err := s.List("group/") | ||
if err != nil { | ||
return nil, "", err | ||
} | ||
for _, groupName := range entries { | ||
if strings.ToLower(groupName) == strings.ToLower(n) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't we just look at There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That will only get us one possible capitalization. So if you have written "GroupFoo" before and now try to write "Groupfoo", you won't find it. With the current logic, you will. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, got it! |
||
entry, err = s.Get("group/" + groupName) | ||
if err != nil { | ||
return nil, "", err | ||
} | ||
canonicalName = groupName | ||
break | ||
} | ||
} | ||
} | ||
if entry == nil { | ||
return nil, "", nil | ||
} | ||
|
||
var result GroupEntry | ||
if err := entry.DecodeJSON(&result); err != nil { | ||
return nil, err | ||
return nil, "", err | ||
} | ||
|
||
return &result, nil | ||
return &result, canonicalName, nil | ||
} | ||
|
||
func (b *backend) pathGroupDelete( | ||
req *logical.Request, d *framework.FieldData) (*logical.Response, error) { | ||
name := d.Get("name").(string) | ||
if len(name) == 0 { | ||
return logical.ErrorResponse("Error empty name"), nil | ||
return logical.ErrorResponse("'name' must be supplied"), nil | ||
} | ||
|
||
err := req.Storage.Delete("group/" + name) | ||
entry, canonicalName, err := b.Group(req.Storage, name) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if entry != nil { | ||
err := req.Storage.Delete("group/" + canonicalName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
return nil, nil | ||
} | ||
|
@@ -81,10 +108,10 @@ func (b *backend) pathGroupRead( | |
req *logical.Request, d *framework.FieldData) (*logical.Response, error) { | ||
name := d.Get("name").(string) | ||
if len(name) == 0 { | ||
return logical.ErrorResponse("Error empty name"), nil | ||
return logical.ErrorResponse("'name' must be supplied"), nil | ||
} | ||
|
||
group, err := b.Group(req.Storage, name) | ||
group, _, err := b.Group(req.Storage, name) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -103,7 +130,19 @@ func (b *backend) pathGroupWrite( | |
req *logical.Request, d *framework.FieldData) (*logical.Response, error) { | ||
name := d.Get("name").(string) | ||
if len(name) == 0 { | ||
return logical.ErrorResponse("Error empty name"), nil | ||
return logical.ErrorResponse("'name' must be supplied"), nil | ||
} | ||
|
||
// Check for an existing group, possibly lowercased so that we keep using | ||
// existing user set values | ||
_, canonicalName, err := b.Group(req.Storage, name) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if canonicalName != "" { | ||
name = canonicalName | ||
} else { | ||
name = strings.ToLower(name) | ||
} | ||
|
||
entry, err := logical.StorageEntryJSON("group/"+name, &GroupEntry{ | ||
|
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.
Sort of unrelated, but why do we need to check the logger's level? Does it not respect the level set with
SetLevel()
so thatlogger.Debug()
doesn't print if the logger is set at a higher level?