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

Add timeout to JWKs refresh #28

Merged
merged 1 commit into from
Jun 14, 2022
Merged

Add timeout to JWKs refresh #28

merged 1 commit into from
Jun 14, 2022

Conversation

JAORMX
Copy link
Collaborator

@JAORMX JAORMX commented Jun 7, 2022

We were explicitly not passing a context to the JWKs URI refresh call;
this is problematic as calls may hang indefinitely.

To better deal with these scenario, a new configuration option was
added:

  • The oidc-jwks-remote-timeout flag.

or

  • oidc.jwksremotetimeout configuration entry.

this is passed to a context.WithTimeout so we now get a timeout as
expected.

If a timeout is not given context.Background() is used (as was the case before).

Closes #21

Signed-off-by: Juan Antonio Osorio juan.osoriorobles@eu.equinix.com

We were explicitly not passing a context to the JWKs URI refresh call;
this is problematic as calls may hang indefinitely.

To better deal with these scenario, a new configuration option was
added:

* The `oidc-jwks-remote-timeout` flag.

or

* `oidc.jwksremotetimeout` configuration entry.

this is passed to a `context.WithTimeout` so we now get a timeout as
expected.

Signed-off-by: Juan Antonio Osorio <juan.osoriorobles@eu.equinix.com>
@JAORMX JAORMX requested a review from a team as a code owner June 7, 2022 09:04
Copy link
Contributor

@fishnix fishnix left a comment

Choose a reason for hiding this comment

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

I only have the one question, otherwise looks good!

defer cancel()
} else {
ctx = context.Background()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This works and makes sense to me if we were passing this context up and down the stack, but did you give thought to creating a non-default http client and setting a timeout there?

client := http.Client{
    Timeout: 5 * time.Second,
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did think about it, but I tend to prefer using contexts as opposed to the direct client timeout; It's more idiomatic. That was basically the extent of my reasoning.

Copy link
Contributor

@fishnix fishnix left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@JAORMX JAORMX merged commit 400d4a2 into main Jun 14, 2022
@JAORMX JAORMX deleted the timeout branch June 14, 2022 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Calls to external http service should have a timeout
3 participants