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

oidc: configure timeouts for requests #541

Merged
merged 2 commits into from
Mar 11, 2023
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
16 changes: 15 additions & 1 deletion sigstore/_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,24 @@ class NetworkError(Error):

def diagnostics(self) -> str:
"""Returns diagnostics for the error."""
return """A network issue occurred.

cause_ctx = (
f"""
Additional context:

{self.__cause__}
"""
if self.__cause__
else ""
)

return (
"""A network issue occurred.

Check your internet connection and try again.
"""
+ cause_ctx
)


class TUFError(Error):
Expand Down
22 changes: 16 additions & 6 deletions sigstore/oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
from id import IdentityError
from pydantic import BaseModel, StrictStr

from sigstore._errors import NetworkError

DEFAULT_OAUTH_ISSUER_URL = "https://oauth2.sigstore.dev/auth"
STAGING_OAUTH_ISSUER_URL = "https://oauth2.sigstage.dev/auth"

Expand Down Expand Up @@ -69,7 +71,11 @@ def __init__(self, base_url: str) -> None:
f"{base_url}/", ".well-known/openid-configuration"
)

resp: requests.Response = requests.get(oidc_config_url)
try:
resp: requests.Response = requests.get(oidc_config_url, timeout=30)
except (requests.ConnectionError, requests.Timeout) as exc:
raise NetworkError from exc

try:
resp.raise_for_status()
except requests.HTTPError as http_error:
Expand Down Expand Up @@ -152,11 +158,15 @@ def identity_token( # nosec: B107
client_secret,
)
logging.debug(f"PAYLOAD: data={data}")
resp: requests.Response = requests.post(
self.oidc_config.token_endpoint,
data=data,
auth=auth,
)
try:
resp: requests.Response = requests.post(
self.oidc_config.token_endpoint,
data=data,
auth=auth,
timeout=30,
)
except (requests.ConnectionError, requests.Timeout) as exc:
raise NetworkError from exc

try:
resp.raise_for_status()
Expand Down