Skip to content

New system test creating an API Key Role for Buildkite #5434

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

Merged
merged 2 commits into from
Feb 17, 2025

Conversation

yob
Copy link
Contributor

@yob yob commented Feb 5, 2025

Note: depends on #5416. Once that merges, I can rebase this and the first commit will fall away

At the moment creating an API Key Role for Buildkite on rubygems.org results in an Access Policy that requires a GitHub Actions principal: https://token.actions.githubusercontent.com. To fix it, I have to inspect the DOM on the new form and make the principal input visible, then change it to https://agent.buildkite.com.

This PR has two commits:

  1. Add a failing system test that demonstrates the issue
  2. The fix

When a gem has a source doe URI for GitHub, add_default_params defaults the form to common settings for GitHub OIDC tokens.

That's a reasonable thing to do. However, that includes setting the principal to a Github Actions shaped value. That value is rendered on the form in hidden elements so the user doesn't have a chance to edit it. After saving the created role has a provider of Buildkite with an expected principal for GitHub Actions.

Its safe to remove the statement.principal assignment completely. It's not required - when the form is submitted the
OIDC::ApiKeyRole#set_statement_principals callback will set the correct principal for both GitHub Actions and Buildkite.

Fixes #5376

@@ -134,7 +134,7 @@ def add_default_params(rubygem, statement, condition)

return unless rubygem
return unless (gh = helpers.link_to_github(rubygem)).presence
return unless (@api_key_role.provider = OIDC::Provider.github_actions)
return unless (@api_key_role.provider == OIDC::Provider.github_actions)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is the conditional with assignment instead of equality intentional or accidental? 🤔

Copy link
Member

Choose a reason for hiding this comment

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

it intentionally was an assignment, this is where the provider would get assigned (as a default, I think)

@@ -134,7 +134,7 @@ def add_default_params(rubygem, statement, condition)

return unless rubygem
return unless (gh = helpers.link_to_github(rubygem)).presence
return unless (@api_key_role.provider = OIDC::Provider.github_actions)
return unless (@api_key_role.provider == OIDC::Provider.github_actions)
Copy link
Member

Choose a reason for hiding this comment

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

it intentionally was an assignment, this is where the provider would get assigned (as a default, I think)

@yob
Copy link
Contributor Author

yob commented Feb 13, 2025

ah, fair enough then! From the outside it looked like the expression would never fail so might not have been intentional.

Would you prefer the alternative, where we just remove the hard coded principal assignment, and let than happen on form submit instead?

@yob yob force-pushed the non-github-actions-api-key-role branch from 62605db to d810930 Compare February 13, 2025 02:55
@yob
Copy link
Contributor Author

yob commented Feb 13, 2025

I've rebased onto master and force pushed, to remove the commit from #5416

@segiddins
Copy link
Member

Would you prefer the alternative, where we just remove the hard coded principal assignment, and let than happen on form submit instead?

I think that's also OK!

Copy link

codecov bot commented Feb 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.26%. Comparing base (968beaf) to head (d92a7bc).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5434      +/-   ##
==========================================
- Coverage   97.06%   94.26%   -2.80%     
==========================================
  Files         451      451              
  Lines        9392     9450      +58     
==========================================
- Hits         9116     8908     -208     
- Misses        276      542     +266     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@yob yob force-pushed the non-github-actions-api-key-role branch from d810930 to 22cbccc Compare February 17, 2025 12:08
James Healy added 2 commits February 17, 2025 23:18
The form and POSTing to create works, but the resulting API Key Role has
a condition that expects a principal of "https://token.actions.githubusercontent.com"
When a gem has a source doe URI for GitHub, `add_default_params`
defaults the form to common settings for GitHub OIDC tokens.

That's a reasonable thing to do. However, that includes setting the
principal to a Github Actions shaped value. That value is rendered on
the form in hidden elements so the user doesn't have a chance to
edit it. After saving the created role has a provider of Buildkite
with an expected principal for GitHub Actions.

Its safe to remove the statement.principal assignment completely. It's
not required - when the form is submitted the
OIDC::ApiKeyRole#set_statement_principals callback will set the correct
principal for both GitHub Actions *and* Buildkite.
@yob yob force-pushed the non-github-actions-api-key-role branch from 22cbccc to d92a7bc Compare February 17, 2025 12:18
@yob
Copy link
Contributor Author

yob commented Feb 17, 2025

I think this is ready for another look @segiddins. I decided to go with the alternate fix, removing the statement.principal default from the controller, and letting the model set the default on save (when we have more information from the user on what they want)

@segiddins segiddins merged commit 8ed4d35 into rubygems:master Feb 17, 2025
20 of 21 checks passed
yob pushed a commit to yob/rubygems.org that referenced this pull request Feb 19, 2025
While working on rubygems#5434 I found the other system tests in this file were
flakey on my local laptop.

Adding this assertion to force the test to wait for the sign in to
finish before proceeding makes them pass reliabily.
yob pushed a commit to yob/rubygems.org that referenced this pull request Feb 23, 2025
While working on rubygems#5434 I found the other system tests in this file were
flakey on my local laptop.

Adding this assertion to force the test to wait for the sign in to
finish before proceeding makes them pass reliabily.
segiddins pushed a commit that referenced this pull request Feb 24, 2025
While working on #5434 I found the other system tests in this file were
flakey on my local laptop.

Adding this assertion to force the test to wait for the sign in to
finish before proceeding makes them pass reliabily.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

Creating an API Key Role for Buildkite results in an access policy that requires Github Actions
2 participants