Use appropriate gRPC error codes for OIDC (#4877)

This commit makes modifications to the OIDC request handlers to return appropriate gRPC
status codes on errors. Before this change, boundary presents the internal error codes to
clients. This causes problems for reverse proxies, as these status codes are mapped to
non-standard HTTP response codes which are ultimately all turned into 500 responses when
4xx status codes are more appropriate and descriptive of the error returned.

Some modifications in this commit include calls to `event.WriteError` so that the
internal error is written to the controller log for visibility. Comments about
potential duplicate logs are now removed as `event.WriteError` is not called when using
functions from the `handlers` package.

Signed-off-by: David Bond <davidsbond93@gmail.com>
This commit is contained in:
David Bond authored and GitHub committed 2024-06-06 14:59:43 +01:00
1 parent 84ae33994a
commit 0c25dbad13
3 files changed
+26 -31

No files matched your search

@@ -1423,19 +1423,19 @@ func (s Service) ConvertInternalAuthTokenToApiAuthToken(ctx context.Context, tok
func (s Service) convertToAuthenticateResponse(ctx context.Context, req *pbs.AuthenticateRequest, authResults *requestauth.VerifyResults, tok *pba.AuthToken) (*pbs.AuthenticateResponse, error) {
const op = "authmethod.convertToAuthenticateResponse"
if req == nil {
return nil, errors.New(ctx, errors.InvalidParameter, op, "Missing request.")
return nil, handlers.InvalidArgumentErrorf("Nil request.", nil)
}
if authResults == nil {
return nil, errors.New(ctx, errors.InvalidParameter, op, "Missing auth results.")
return nil, handlers.InvalidArgumentErrorf("Nil auth results.", nil)
}
if authResults.Scope == nil {
return nil, errors.New(ctx, errors.InvalidParameter, op, "Missing auth results scope.")
return nil, handlers.InvalidArgumentErrorf("Missing auth results scope.", nil)
}
if authResults.Scope.Id == "" {
return nil, errors.New(ctx, errors.InvalidParameter, op, "Missing auth results scope ID.")
return nil, handlers.InvalidArgumentErrorf("Missing auth results scope ID.", nil)
}
if tok == nil {
return nil, errors.New(ctx, errors.InvalidParameter, op, "Missing auth token.")
return nil, handlers.InvalidArgumentErrorf("Missing auth token", nil)
}
res := &perms.Resource{
ScopeId: authResults.Scope.Id,