Repository navigation
Allow burning of TP tokens - #20197
Conversation
ewdurbin
left a comment
There was a problem hiding this comment.
i'm +1 to this feature and fairly happy with this implementation being limited to only valid trusted publishing issued macaroons.
while reporting to sentry is a good signal of misuse, i would like to see failures recorded as a metric as well to watch for broader patterns over time.
calling this a "provisional" approval as i'd like input from other admins, specifically @miketheman before merge.
miketheman
left a comment
There was a problem hiding this comment.
Interesting idea, plenty of comments inline.
I like the 202 response for anything, yay!
There's no rate limit protections I can see, that's probably something good to add - and since we expect it to be TP-centric, not by IP, rather by token identity? Not sure about that yet, but there's nothing protecting from a DoS run on this endpoint right now. The integration one has verification of the submitter identity before we hit the DB for token lookups.
There's no Event emitted for the token removal, which there would be for a regular token. I realize that our "automatic reaper" doesn't emit those, rather relies on the created time to emit "Expired" vs actually knowing that it's gone. That's an oddball case that we may want to add into this scope, since we're not relying on the passage of time and a task to run successfully, we're taking an actual action.
But generally moving in a positive direction!
| metrics.increment("warehouse.oidc.burn_oidc_issued_token.attempt") | ||
|
|
||
| try: | ||
| payload = BurnPayload.model_validate_json(request.body) |
There was a problem hiding this comment.
If I understand this correctly, this is creating a pydantic model to verify that the inbound is a str? Is this machinery worth it to validate? The single test doesn't help me understand what an invalid str would be.
There was a problem hiding this comment.
Yep, exactly. We already do that for TokenPayload above, which happens to have the exact same shape (I'm not reusing it because that's just a coincidence, although we could reuse it until they diverge).
(My 0.02c is that this is worth it, since the open-coded version of pulling the JSON body, checking for a key, checking that it's a string, etc. would be longer. I can certainly add some tests demonstrating the value of StrictStr though.)
There was a problem hiding this comment.
Were any tests added to demonstrate the value of StrictStr?
There was a problem hiding this comment.
I'll add some.
(We already demonstrate the value in test_mint_token_from_oidc_invalid_payload and elsewhere, but no harm I guess in showing it in other endpoints.)
Hmm, are you imagining something like a ratelimit key that's
Yeah, this is kind of subtle: I think there's a chance this will be pretty noisy, since (in the happy case) there's a direct 1-1 correspondence between a TP token being issued and being "burned" before it would naturally expire. So we'd effectively double the number of TP-associated events in a user's security feed for something that's already happening in the background implicitly. My weak preference would be for deferring that, but I'm curious what you (and @ewdurbin) think. I think a cool longer-term thing we could do is "group" events properly to reduce the visual noise, which would allow us to emit these without spamming users. |
Since this is a new type of interaction/event, I think I am actually in the camp of emitting rather than suppressing. We have a lot of control over how events are surfaced to users which means that improvements that allow for filtering//suppressing serverside or clientside are probably preferable over dropping a potentially interesting event on the floor. |
|
Sounds good, I'll work on adding the appropriate event for it. |
| {% elif event.tag == EventTag.Project.ShortLivedAPITokenRevoked %} | ||
| <strong>{% trans %}Short-lived API token revoked{% endtrans %}</strong> |
There was a problem hiding this comment.
NB: It might make sense to just not render this event at the moment, since it's kind of confusing in the current layout: it corresponds to an automatic action (e.g. gh-action-pypi-publish proactively revoking a credential instead of letting it passively expire) and doesn't currently contain a lot of useful end-user context.
In the future, we could refactor the security history a bit to make this more interesting: for example we could allow events to be nested, so that the user would see something like:
+------------------------------------+
| Short-lived token added |
| Expires at: ... |
| Proactively revoked at: ... |
+------------------------------------+
...but this would (1) require us to track the macaroon IDs in token events (we don't currently) and (2) would require us to join/aggregate individual events together 🙂
75ff4e4 to
9f47279
Compare
9f47279 to
7697864
Compare
miketheman
left a comment
There was a problem hiding this comment.
Thanks- many of the previous reviews have been addressed, but there's some new things that should be resolved first.
Let me know if you disagree!
| metrics.increment("warehouse.oidc.burn_oidc_issued_token.attempt") | ||
|
|
||
| try: | ||
| payload = BurnPayload.model_validate_json(request.body) |
There was a problem hiding this comment.
Were any tests added to demonstrate the value of StrictStr?
| @view_config( | ||
| route_name="oidc.burn_token", | ||
| require_methods=["POST"], | ||
| renderer="json", | ||
| require_csrf=False, | ||
| ) |
There was a problem hiding this comment.
At the very least, should we add accept="application/json" here to prevent any other weird submissions?
There was a problem hiding this comment.
Mind if we fast-follow for that? I think we should do this consistently for all of the OIDC API routes, in which case it'd sprawl the diff a bit to do it here.
Signed-off-by: William Woodruff <william@yossarian.net> Tests for OIDC burning Signed-off-by: William Woodruff <william@yossarian.net> Feedback Signed-off-by: William Woodruff <william@yossarian.net> Use HTTPStatus Signed-off-by: William Woodruff <william@yossarian.net> Use request.metrics directly Signed-off-by: William Woodruff <william@yossarian.net> Lintage Signed-off-by: William Woodruff <william@yossarian.net> Simplify metrics Signed-off-by: William Woodruff <william@yossarian.net>
Signed-off-by: William Woodruff <william@yossarian.net>
9f01ae8 to
530ee07
Compare
Signed-off-by: William Woodruff <william@yossarian.net>
Signed-off-by: William Woodruff <william@yossarian.net>
Signed-off-by: William Woodruff <william@yossarian.net>
Signed-off-by: William Woodruff <william@yossarian.net>
miketheman
left a comment
There was a problem hiding this comment.
There's still opportunities here like a functional test for the happy path.
@woodruffw please keep a close eye on this as it rolls out.
This implements the (hopefully) uncontroversial part of #20125: we don't expose a general-purpose revocation API for now, just one that's specific to Trusted Publishing flows.
The basic idea: clients (like twine and uv) that implement Trusted Publishing can choose to explicitly "burn" their temporary token immediately after it's used. This adds a layer of protection atop TP tokens already being short-lived, since the publishing client can proactively invalidate them before they'd otherwise expire.
For prior art: crates.io's implementation of Trusted Publishing supports this, and their default integration (
rust-lang/crates-io-auth-action) performs it by default as a post-hook when invoked:https://github.com/rust-lang/crates-io-auth-action/blob/a1c979fa8eec9cf00f2c01904184fe133deb0ce9/src/post.ts#L29-L47
Signed-off-by: William Woodruff william@yossarian.net