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

Return HTTP 400 status for inactive OIDC auth methods #5048

Merged
merged 1 commit into from
Aug 30, 2024

Conversation

davidsbond
Copy link
Member

@davidsbond davidsbond commented Aug 27, 2024

This commit modifies the OIDC authentication start method to return a 400 (Bad Request) error if a client attempts to start the authentication flow against an OIDC auth method that is set to inactive. This is something we noticed in our error logs in HCP Boundary that is impacting our SLOs.

Previously this returned its own error code which is mapped to a 500 response. Tests have been updated to catch this new scenario.

Copy link
Collaborator

@johanbrandhorst johanbrandhorst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing! My only question is if using 412 has precedent for auth methods. Why did we choose that status code specifically?

@johanbrandhorst johanbrandhorst added this to the 0.18.x milestone Aug 27, 2024
@davidsbond
Copy link
Member Author

davidsbond commented Aug 27, 2024

@johanbrandhorst I went with failed precondition as the situation we're in seems to line up with the grpc definition:

The operation was rejected because the system is not in a state required for the operation’s execution.

In this case, the state of the system (i.e the status of the OIDC auth method) is not in a state where we can start the auth flow. So the OIDC auth method being public feels like a precondition to its use.

Ultimately for HCP's purposes any 4xx status code is fine.

@johanbrandhorst
Copy link
Collaborator

@johanbrandhorst I went with failed precondition as the situation we're in seems to line up with the grpc definition:

The operation was rejected because the system is not in a state required for the operation’s execution.

In this case, the state of the system (i.e the status of the OIDC auth method) is not in a state where we can start the auth flow. So the OIDC auth method being public feels like a precondition to its use.

Ultimately for HCP's purposes any 4xx status code is fine.

I agree that the error code makes sense, but generally in Boundary we care more about using the correct HTTP status code than the correct gRPC status code. I just want to make sure that we're not going against some existing pattern. I did a search and it seems we already use this code for various errors, so I think this is fine :)

if err != nil {
switch {
case errors.Match(errors.T(errors.AuthMethodInactive), err):
return nil, handlers.ApiErrorWithCodeAndMessage(codes.FailedPrecondition, "Cannot start authentication against an inactive OIDC auth method")
Copy link
Contributor

@uruemu uruemu Aug 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this returns an HTTP 400 error and not a 412 from the GRPC gateway. I assume this would still make sense since it is on the client to activate the OIDC auth method. Does that sound correct?

Copy link
Contributor

@uruemu uruemu Aug 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, could the GRPC Aborted error could be more suitable here? It maps to the HTTP.StatusConflict, which is more descriptive to the case but not sure Aborted is more suitable than FailedPrecondition here

https://github.com/grpc-ecosystem/grpc-gateway/blob/93189d015a3e23872723445862dc6fe1c4502913/runtime/errors.go#L61-L62

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just saw that @johanbrandhorst was having a relevant discussion. This might be useful context, not sure if 400 is suitable here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh that's interesting, I wasn't aware that was the mapping behaviour. I'm personally fine with a regular 400.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the mapping is 400, I think that's fine here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the commit & PR title/description to reflect this is a 400 not a 412.

This commit modifies the OIDC authentication start method to return a 400 (Bad Request) error
if a client attempts to start the authentication flow against an OIDC auth method that is set to
inactive. This is something we noticed in our error logs in HCP Boundary that is impacting our
SLOs.

Previously this returned its own error code which is mapped to a 500 response. Tests have been updated
to catch this new scenario.

Signed-off-by: David Bond <davidsbond93@gmail.com>
@davidsbond davidsbond changed the title Return HTTP 412 status for inactive OIDC auth methods Return HTTP 400 status for inactive OIDC auth methods Aug 29, 2024
@davidsbond
Copy link
Member Author

Going to merge, the tests that are failing seem unrelated and they are failing across all other PRs

@davidsbond davidsbond merged commit 660e206 into main Aug 30, 2024
63 of 65 checks passed
@davidsbond davidsbond deleted the 4xx-for-inactive-auth branch August 30, 2024 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants