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

Improve role config jwt bound constraint check #49

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion path_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,8 @@ func (b *jwtAuthBackend) pathRoleCreateUpdate(ctx context.Context, req *logical.
if roleType != "oidc" {
if len(role.BoundAudiences) == 0 &&
len(role.BoundCIDRs) == 0 &&
role.BoundSubject == "" {
role.BoundSubject == "" &&
len(role.BoundClaims) == 0 {
return logical.ErrorResponse("must have at least one bound constraint when creating/updating a role"), nil
}
}
Expand Down
97 changes: 96 additions & 1 deletion path_role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func TestPath_Create(t *testing.T) {

req = &logical.Request{
Operation: logical.CreateOperation,
Path: "role/test2",
Path: "role/test3",
Storage: storage,
Data: data,
}
Expand All @@ -140,6 +140,101 @@ func TestPath_Create(t *testing.T) {
if !strings.HasPrefix(resp.Error().Error(), "must have at least one bound constraint") {
t.Fatalf("unexpected err: %v", resp)
}

// Test has bound subject
data = map[string]interface{}{
"role_type": "jwt",
"user_claim": "user",
"policies": "test",
"bound_subject": "testsub",
}

req = &logical.Request{
Operation: logical.CreateOperation,
Path: "role/test4",
Storage: storage,
Data: data,
}

resp, err = b.HandleRequest(context.Background(), req)
if err != nil {
t.Fatal(err)
}
if resp != nil && resp.IsError() {
t.Fatalf("did not expect error")
}

// Test has audience
data = map[string]interface{}{
"role_type": "jwt",
"user_claim": "user",
"policies": "test",
"bound_audiences": "vault",
}

req = &logical.Request{
Operation: logical.CreateOperation,
Path: "role/test5",
Storage: storage,
Data: data,
}

resp, err = b.HandleRequest(context.Background(), req)
if err != nil {
t.Fatal(err)
}
if resp != nil && resp.IsError() {
t.Fatalf("did not expect error")
}

// Test has cidr
data = map[string]interface{}{
"role_type": "jwt",
"user_claim": "user",
"policies": "test",
"bound_cidrs": "127.0.0.1/8",
}

req = &logical.Request{
Operation: logical.CreateOperation,
Path: "role/test6",
Storage: storage,
Data: data,
}

resp, err = b.HandleRequest(context.Background(), req)
if err != nil {
t.Fatal(err)
}
if resp != nil && resp.IsError() {
t.Fatalf("did not expect error")
}

// Test has bound claims
data = map[string]interface{}{
"role_type": "jwt",
"user_claim": "user",
"policies": "test",
"bound_claims": map[string]interface{}{
"foo": 10,
"bar": "baz",
},
}

req = &logical.Request{
Operation: logical.CreateOperation,
Path: "role/test7",
Storage: storage,
Data: data,
}

resp, err = b.HandleRequest(context.Background(), req)
if err != nil {
t.Fatal(err)
}
if resp != nil && resp.IsError() {
t.Fatalf("did not expect error")
}
}

func TestPath_OIDCCreate(t *testing.T) {
Expand Down