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

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

yob
Copy link

@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. A possible fix

Currently the fix is to change a conditional to use == instead of =. However, it's likely that will break some other tests. A possible alternative fix is:

diff --git a/app/controllers/oidc/api_key_roles_controller.rb b/app/controllers/oidc/api_key_roles_controller.rb
index 29d065b07..791b05fac 100644
--- a/app/controllers/oidc/api_key_roles_controller.rb
+++ b/app/controllers/oidc/api_key_roles_controller.rb
@@ -136,8 +136,6 @@ class OIDC::ApiKeyRolesController < ApplicationController
     return unless (gh = helpers.link_to_github(rubygem)).presence
     return unless (@api_key_role.provider == OIDC::Provider.github_actions)
 
-    statement.principal = { oidc: @api_key_role.provider.issuer }
-
     repo_condition = OIDC::AccessPolicy::Statement::Condition.new(
       claim: "repository",
       operator: "string_equals",

The principal input is hidden on the form anyway, and will be set to a default value in the OIDC::ApiKeyRole#set_statement_principals model callback

Fixes #5376

yob added 3 commits February 3, 2025 10:03
…IDC token

Until recently, Buildkite OIDC tokens did not contain a `jti` claim. At
some point in early 2024 it was possible to assume an API Key Role using
Buildkite OIDC tokens, but when testing in January 2025 we found the
assume role request was failing with an error:

> Missing/invalid jti

Buildkite has addressed that by adding a `jti` claim to tokens - it's a
good claim to include. However, to reduce the risk of regressions in the
future, this proposes adding an integration test with a Buildkite-shaped
OIDC token.

The trait added to the OIDC::Provider factory is based on a real token
that I generated then anonymized. I only test the happy path with this
token - there's a buncha existing tests for various unhappy paths
(expired token, etc) using the Github Actions shaped OIDC token and
there's little value in replicating them.

Most of the added test is copy-pasted from the happy-path Github Actions
test further up the file.

Fixes rubygems#5412
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"
The conditional in add_default_params is always try (it's a single =) so
statement.principal is set to the GitHub Actions principal
(https://token.actions.githubusercontent.com) every time the new API Key
Role form is loaded.

That field is hidden on the form so the user doesn't have a chance to
edit it, and after saving the created role has a provider of Buildkite
with an expected principal for GitHub Actions.

An alternative solution would be 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 Actionas *and* Buildkite.
@@ -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
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? 🤔

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
1 participant