-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(idtoken-auth): add auth validator using google idtoken (#349)
* feat(idtoken-auth): add auth validator using google idtoken * docs: add idtoken validation on sample config.yaml * feat: add auth config to replace idtoken validator config, and refactor default auth header key * refactor: move auth interceptor to pkg/auth * chore: delete idtoken validator mock * feat: keep config.AuthenticatedUserHeaderKey for backward-compatibility * chore: re-order import * refactor: change sample config.yaml for auth config * chore: make auth user header key sample and default config consistent * chore: re-order import on oidc test * fix: change oidc initialism * fix: oidc validator mocks renaming * fix: avoid using params with pointer, as it will lead to panic if params is nil * fix: detect old auth user header key using empty string instead of default tag * refactor: move OIDCAuth to pkg/auth * refactor: move oidc validator mocks into pkg/auth/mocks * chore: add deprecation notes on AuthenticatedUserHeaderKey * refactor: make default auth email context key back to unexported, use different context key for oidc email * refactor: do not use default header key on oidc auth, use its own header (it's only used for logrus) * refactor: move logrus context custom fields to new interceptor and retrieve its value from context * refactor: auth email context key mapping for default and oidc used for grpc server * test: change ways of getting user email from request header to context * refactor: use auth.OIDCAuth instead of OIDCValidatorParams
- Loading branch information
1 parent
575dfc7
commit a4b0c5d
Showing
12 changed files
with
448 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,11 +128,7 @@ func (s *GrpcHandlersSuite) TestListUserAppeals() { | |
ResourceUrns: []string{"test-resource-urn"}, | ||
OrderBy: []string{"test-order"}, | ||
} | ||
ctx := context.Background() | ||
md := metadata.New(map[string]string{ | ||
s.authenticatedUserHeaderKey: expectedUser, | ||
}) | ||
ctx = metadata.NewIncomingContext(ctx, md) | ||
ctx := context.WithValue(context.Background(), authEmailTestContextKey{}, expectedUser) | ||
res, err := s.grpcServer.ListUserAppeals(ctx, req) | ||
|
||
s.NoError(err) | ||
|
@@ -162,11 +158,7 @@ func (s *GrpcHandlersSuite) TestListUserAppeals() { | |
Return(nil, expectedError).Once() | ||
|
||
req := &guardianv1beta1.ListUserAppealsRequest{} | ||
ctx := context.Background() | ||
md := metadata.New(map[string]string{ | ||
s.authenticatedUserHeaderKey: "test-user", | ||
}) | ||
ctx = metadata.NewIncomingContext(ctx, md) | ||
ctx := context.WithValue(context.Background(), authEmailTestContextKey{}, "test-user") | ||
res, err := s.grpcServer.ListUserAppeals(ctx, req) | ||
|
||
s.Equal(codes.Internal, status.Code(err)) | ||
|
@@ -188,11 +180,7 @@ func (s *GrpcHandlersSuite) TestListUserAppeals() { | |
Return(invalidAppeals, nil).Once() | ||
|
||
req := &guardianv1beta1.ListUserAppealsRequest{} | ||
ctx := context.Background() | ||
md := metadata.New(map[string]string{ | ||
s.authenticatedUserHeaderKey: "test-user", | ||
}) | ||
ctx = metadata.NewIncomingContext(ctx, md) | ||
ctx := context.WithValue(context.Background(), authEmailTestContextKey{}, "test-user") | ||
res, err := s.grpcServer.ListUserAppeals(ctx, req) | ||
|
||
s.Equal(codes.Internal, status.Code(err)) | ||
|
@@ -484,11 +472,7 @@ func (s *GrpcHandlersSuite) TestCreateAppeal() { | |
}, | ||
Description: "The answer is 42", | ||
} | ||
ctx := context.Background() | ||
md := metadata.New(map[string]string{ | ||
s.authenticatedUserHeaderKey: expectedUser, | ||
}) | ||
ctx = metadata.NewIncomingContext(ctx, md) | ||
ctx := context.WithValue(context.Background(), authEmailTestContextKey{}, expectedUser) | ||
res, err := s.grpcServer.CreateAppeal(ctx, req) | ||
|
||
s.NoError(err) | ||
|
@@ -520,11 +504,7 @@ func (s *GrpcHandlersSuite) TestCreateAppeal() { | |
s.appealService.EXPECT().Create(mock.AnythingOfType("*context.valueCtx"), mock.Anything).Return(appeal.ErrAppealDuplicate).Once() | ||
|
||
req := &guardianv1beta1.CreateAppealRequest{} | ||
ctx := context.Background() | ||
md := metadata.New(map[string]string{ | ||
s.authenticatedUserHeaderKey: "[email protected]", | ||
}) | ||
ctx = metadata.NewIncomingContext(ctx, md) | ||
ctx := context.WithValue(context.Background(), authEmailTestContextKey{}, "[email protected]") | ||
res, err := s.grpcServer.CreateAppeal(ctx, req) | ||
|
||
s.Equal(codes.AlreadyExists, status.Code(err)) | ||
|
@@ -539,11 +519,7 @@ func (s *GrpcHandlersSuite) TestCreateAppeal() { | |
s.appealService.EXPECT().Create(mock.AnythingOfType("*context.valueCtx"), mock.Anything).Return(expectedError).Once() | ||
|
||
req := &guardianv1beta1.CreateAppealRequest{} | ||
ctx := context.Background() | ||
md := metadata.New(map[string]string{ | ||
s.authenticatedUserHeaderKey: "[email protected]", | ||
}) | ||
ctx = metadata.NewIncomingContext(ctx, md) | ||
ctx := context.WithValue(context.Background(), authEmailTestContextKey{}, "[email protected]") | ||
res, err := s.grpcServer.CreateAppeal(ctx, req) | ||
|
||
s.Equal(codes.Internal, status.Code(err)) | ||
|
@@ -567,11 +543,7 @@ func (s *GrpcHandlersSuite) TestCreateAppeal() { | |
Return(nil).Once() | ||
|
||
req := &guardianv1beta1.CreateAppealRequest{Resources: make([]*guardianv1beta1.CreateAppealRequest_Resource, 1)} | ||
ctx := context.Background() | ||
md := metadata.New(map[string]string{ | ||
s.authenticatedUserHeaderKey: "[email protected]", | ||
}) | ||
ctx = metadata.NewIncomingContext(ctx, md) | ||
ctx := context.WithValue(context.Background(), authEmailTestContextKey{}, "[email protected]") | ||
res, err := s.grpcServer.CreateAppeal(ctx, req) | ||
|
||
s.Equal(codes.Internal, status.Code(err)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,11 +116,7 @@ func (s *GrpcHandlersSuite) TestListUserApprovals() { | |
Statuses: []string{"active", "pending"}, | ||
OrderBy: []string{"test-order"}, | ||
} | ||
ctx := context.Background() | ||
md := metadata.New(map[string]string{ | ||
s.authenticatedUserHeaderKey: expectedUser, | ||
}) | ||
ctx = metadata.NewIncomingContext(ctx, md) | ||
ctx := context.WithValue(context.Background(), authEmailTestContextKey{}, expectedUser) | ||
res, err := s.grpcServer.ListUserApprovals(ctx, req) | ||
|
||
s.NoError(err) | ||
|
@@ -150,11 +146,7 @@ func (s *GrpcHandlersSuite) TestListUserApprovals() { | |
Return(nil, expectedError).Once() | ||
|
||
req := &guardianv1beta1.ListUserApprovalsRequest{} | ||
ctx := context.Background() | ||
md := metadata.New(map[string]string{ | ||
s.authenticatedUserHeaderKey: "test-user", | ||
}) | ||
ctx = metadata.NewIncomingContext(ctx, md) | ||
ctx := context.WithValue(context.Background(), authEmailTestContextKey{}, "test-user") | ||
res, err := s.grpcServer.ListUserApprovals(ctx, req) | ||
|
||
s.Equal(codes.Internal, status.Code(err)) | ||
|
@@ -178,11 +170,7 @@ func (s *GrpcHandlersSuite) TestListUserApprovals() { | |
Return(invalidApprovals, nil).Once() | ||
|
||
req := &guardianv1beta1.ListUserApprovalsRequest{} | ||
ctx := context.Background() | ||
md := metadata.New(map[string]string{ | ||
s.authenticatedUserHeaderKey: "test-user", | ||
}) | ||
ctx = metadata.NewIncomingContext(ctx, md) | ||
ctx := context.WithValue(context.Background(), authEmailTestContextKey{}, "test-user") | ||
res, err := s.grpcServer.ListUserApprovals(ctx, req) | ||
|
||
s.Equal(codes.Internal, status.Code(err)) | ||
|
@@ -443,11 +431,7 @@ func (s *GrpcHandlersSuite) TestUpdateApproval() { | |
Reason: expectedReason, | ||
}, | ||
} | ||
ctx := context.Background() | ||
md := metadata.New(map[string]string{ | ||
s.authenticatedUserHeaderKey: expectedUser, | ||
}) | ||
ctx = metadata.NewIncomingContext(ctx, md) | ||
ctx := context.WithValue(context.Background(), authEmailTestContextKey{}, expectedUser) | ||
res, err := s.grpcServer.UpdateApproval(ctx, req) | ||
|
||
s.NoError(err) | ||
|
@@ -553,11 +537,7 @@ func (s *GrpcHandlersSuite) TestUpdateApproval() { | |
Return(nil, tc.expectedError).Once() | ||
|
||
req := &guardianv1beta1.UpdateApprovalRequest{} | ||
ctx := context.Background() | ||
md := metadata.New(map[string]string{ | ||
s.authenticatedUserHeaderKey: expectedUser, | ||
}) | ||
ctx = metadata.NewIncomingContext(ctx, md) | ||
ctx := context.WithValue(context.Background(), authEmailTestContextKey{}, expectedUser) | ||
res, err := s.grpcServer.UpdateApproval(ctx, req) | ||
|
||
s.Equal(tc.expectedStatusCode, status.Code(err)) | ||
|
@@ -579,11 +559,7 @@ func (s *GrpcHandlersSuite) TestUpdateApproval() { | |
Return(invalidAppeal, nil).Once() | ||
|
||
req := &guardianv1beta1.UpdateApprovalRequest{} | ||
ctx := context.Background() | ||
md := metadata.New(map[string]string{ | ||
s.authenticatedUserHeaderKey: "[email protected]", | ||
}) | ||
ctx = metadata.NewIncomingContext(ctx, md) | ||
ctx := context.WithValue(context.Background(), authEmailTestContextKey{}, "[email protected]") | ||
res, err := s.grpcServer.UpdateApproval(ctx, req) | ||
|
||
s.Equal(codes.Internal, status.Code(err)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.