Check for existing Trusted Publishers before constraining existing one #17576
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR makes the following changes:
OIDCPublisherAdded
event, to make debugging easierMissing check
When a user uses a Trusted Publisher with no environment configured, from a CI running in a specific environment, we send them an email suggesting they constrain the TP to only accept the specific environment they just used (see #17281).
The email contains a magic link to constrain the existing TP. However, if the user manually creates a constrained TP after the warning email was sent, but before the magic link is clicked, we get an uncaught exception due to not checking for existing TPs.
Concretely, here's the sequence of events that would trigger the issue:
(owner, repo, workflow)
, but no environmentmy_env
(owner, repo, workflow, my_env)
(owner, repo, workflow, my_env)
We add a check in
constrain_environment()
that checks if the constrained publisher already exists before trying to add itExtra metadata in
OIDCPublisherAdded
We add two new additional fields to the
OIDCPublisherAdded
event:These should be self-explanatory. Additionally, we now add an event when reifying a pending trusted publisher, since before there were no events for it.
cc @di @woodruffw