Skip to content

Commit d29ccef

Browse files
committed
feat: adding --oidc-audience (aud) claim configuration options
Signed-off-by: SequeI <asiek@redhat.com>
1 parent d4295dc commit d29ccef

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ All versions prior to 0.9.0 are untracked.
1212

1313
* Added support for ed25519 keys.
1414
[#1377](https://github.com/sigstore/sigstore-python/pull/1377)
15+
* Added --oidc-audience for using a custom oidc clients aud claim. helps if a user has a custom client id and needs to match this aud.
16+
[#1402](https://github.com/sigstore/sigstore-python/pull/1402)
17+
1518

1619
### Fixed
1720

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ OpenID Connect options:
126126
--oauth-force-oob Force an out-of-band OAuth flow and do not
127127
automatically start the default web browser (default:
128128
False)
129+
--oidc-audience Expected audience (`aud`) claim in the token to
130+
validate against (default: None)
129131
130132
Output options:
131133
--no-default-files Don't emit the default output files

sigstore/_cli.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,13 @@ def _add_shared_oidc_options(
238238
default=_boolify_env("SIGSTORE_OAUTH_FORCE_OOB"),
239239
help="Force an out-of-band OAuth flow and do not automatically start the default web browser",
240240
)
241+
group.add_argument(
242+
"--oidc-audience",
243+
metavar="AUDIENCE",
244+
type=str,
245+
default=os.getenv("SIGSTORE_OIDC_AUDIENCE"),
246+
help="Expected audience (`aud`) claim in the token to validate against",
247+
)
241248

242249

243250
def _parser() -> argparse.ArgumentParser:
@@ -1190,6 +1197,7 @@ def _get_identity(args: argparse.Namespace) -> Optional[IdentityToken]:
11901197
client_id=args.oidc_client_id,
11911198
client_secret=args.oidc_client_secret,
11921199
force_oob=args.oauth_force_oob,
1200+
audience=args.oidc_audience,
11931201
)
11941202

11951203
return token

sigstore/oidc.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
"https://oauth2.sigstage.dev/auth": "email",
4545
"https://token.actions.githubusercontent.com": "sub",
4646
}
47-
_DEFAULT_AUDIENCE = "sigstore"
4847

48+
_DEFAULT_AUDIENCE = "sigstore"
4949

5050
class _OpenIDConfiguration(BaseModel):
5151
"""
@@ -69,13 +69,16 @@ class IdentityToken:
6969
a sensible subject, issuer, and audience for Sigstore purposes.
7070
"""
7171

72-
def __init__(self, raw_token: str) -> None:
72+
def __init__(self, raw_token: str, client_id: str, audience: Optional[str] = None) -> None:
7373
"""
7474
Create a new `IdentityToken` from the given OIDC token.
7575
"""
7676

7777
self._raw_token = raw_token
7878

79+
# Determine the correct audience to use
80+
resolved_audience = audience or client_id or _DEFAULT_AUDIENCE
81+
7982
# NOTE: The lack of verification here is intentional, and is part of
8083
# Sigstore's verification model: clients like sigstore-python are
8184
# responsible only for forwarding the OIDC identity to Fulcio for
@@ -93,7 +96,7 @@ def __init__(self, raw_token: str) -> None:
9396
# See: https://openid.net/specs/openid-connect-basic-1_0.html#IDToken
9497
"require": ["aud", "sub", "iat", "exp", "iss"],
9598
},
96-
audience=_DEFAULT_AUDIENCE,
99+
audience=resolved_audience,
97100
# NOTE: This leeway shouldn't be strictly necessary, but is
98101
# included to preempt any (small) skew between the host
99102
# and the originating IdP.
@@ -290,6 +293,7 @@ def identity_token( # nosec: B107
290293
client_id: str = "sigstore",
291294
client_secret: str = "",
292295
force_oob: bool = False,
296+
audience: Optional[str] = None
293297
) -> IdentityToken:
294298
"""
295299
Retrieves and returns an `IdentityToken` from the current `Issuer`, via OAuth.
@@ -367,7 +371,7 @@ def identity_token( # nosec: B107
367371
if token_error is not None:
368372
raise IdentityError(f"Error response from token endpoint: {token_error}")
369373

370-
return IdentityToken(token_json["access_token"])
374+
return IdentityToken(token_json["access_token"], client_id, audience)
371375

372376

373377
class IdentityError(Error):

0 commit comments

Comments
 (0)