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

feat: Add ability to use GitHub OIDC #161

Merged
merged 40 commits into from
Sep 9, 2024

Conversation

nicholas-codecov
Copy link
Collaborator

Description

This PR adds in support for using GitHub OIDC with the bundler plugins.

Closes codecov/engineering-team#2209

Notable Changes

  • Add new config options to enable OIDC
  • Add in @actions/core package
  • Add in logic in getPreSignedUrl to grab the token through GitHub OIDC

@codecov-notifications
Copy link

codecov-notifications bot commented Aug 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Components Coverage Δ
Plugin core 96.84% <100.00%> (+<0.01%) ⬆️
Rollup plugin 10.81% <ø> (ø)
Vite plugin 11.02% <ø> (ø)
Webpack plugin 50.11% <ø> (ø)

📢 Thoughts on this report? Let us know!

Copy link

codecov bot commented Aug 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 75.43%. Comparing base (be89828) to head (d3aa674).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files
Components Coverage Δ
Plugin core 96.84% <100.00%> (+<0.01%) ⬆️
Rollup plugin 10.81% <ø> (ø)
Vite plugin 11.02% <ø> (ø)
Webpack plugin 50.11% <ø> (ø)

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

Copy link

codecov bot commented Aug 28, 2024

Bundle Report

Changes will increase total bundle size by 183.02kB ⬆️

Bundle name Size Change
@codecov/bundler-plugin-core-cjs 46.59kB 1.16kB ⬆️
@codecov/bundler-plugin-core-esm 41.56kB 31.3kB ⬆️
@codecov/example-sveltekit-app-client-esm 714.98kB 2 bytes ⬆️
@codecov/example-oidc-app-esm 150.57kB 150.57kB ⬆️

@codecov-staging
Copy link

codecov-staging bot commented Aug 28, 2024

Bundle Report

Changes will increase total bundle size by 446.46kB ⬆️

Bundle name Size Change
@codecov/vite-plugin-cjs 2.8kB 2.8kB ⬆️
@codecov/vite-plugin-esm 1.24kB 1.24kB ⬆️
@codecov/nextjs-webpack-plugin-cjs 2.11kB 2.11kB ⬆️
@codecov/nuxt-plugin-cjs 1.41kB 1.41kB ⬆️
@codecov/nextjs-webpack-plugin-esm 1.88kB 1.88kB ⬆️
@codecov/example-next-15-app-server-cjs 359.11kB 359.11kB ⬆️
@codecov/rollup-plugin-esm 1.3kB 1.3kB ⬆️
@codecov/remix-vite-plugin-esm 1.1kB 1.1kB ⬆️
@codecov/remix-vite-plugin-cjs 1.32kB 1.32kB ⬆️
@codecov/solidstart-plugin-cjs 1.33kB 1.33kB ⬆️
@codecov/sveltekit-plugin-cjs 1.33kB 1.33kB ⬆️
@codecov/sveltekit-plugin-esm 1.1kB 1.1kB ⬆️
@codecov/solidstart-plugin-esm 949 bytes 949 bytes ⬆️
@codecov/webpack-plugin-cjs 4.35kB 4.35kB ⬆️
@codecov/nuxt-plugin-esm 830 bytes 830 bytes ⬆️
@codecov/webpack-plugin-esm 3.36kB 3.36kB ⬆️
@codecov/rollup-plugin-cjs 2.82kB 2.82kB ⬆️
@codecov/bundler-plugin-core-cjs 46.59kB 46.59kB ⬆️
@codecov/bundler-plugin-core-esm 12.24kB 12.24kB ⬆️
@codecov/example-next-app-edge-server-array-push (removed) 354 bytes ⬇️
@codecov/example-next-15-app-edge-server-array-push (removed) 356 bytes ⬇️

@nicholas-codecov nicholas-codecov force-pushed the gh-eng-2209-add-ability-to-use-github-oidc branch from 9d5df6b to 63ac370 Compare September 3, 2024 13:03
@nicholas-codecov nicholas-codecov marked this pull request as ready for review September 3, 2024 13:14
Copy link
Contributor

@suejung-sentry suejung-sentry left a comment

Choose a reason for hiding this comment

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

Awesome stuff!! 🚀
Sorry for the long comments - let me know what you think!

packages/bundler-plugin-core/src/errors/FailedOIDCFetch.ts Outdated Show resolved Hide resolved
packages/bundler-plugin-core/src/utils/Output.ts Outdated Show resolved Hide resolved
packages/bundler-plugin-core/src/utils/getPreSignedURL.ts Outdated Show resolved Hide resolved
url = output.oidc.OIDCEndpoint;
let token = "";
try {
token = await Core.getIDToken(output.oidc.OIDCEndpoint);
Copy link
Contributor

Choose a reason for hiding this comment

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

From the docs, it seems we need to pass to getIDToken() the audience to match that as we set in codecov-api here.
For example in prod that would be either settings.CODECOV_API_URL = https://api.codecov.io or settings.CODECOV_URL = https://codecov.io

Given that I think we should name that variable something like gitHubOIDCTokenAudience

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So the audience is the OIDC endpoint, which I can rename to your suggestion. To implement this I followed along with how we have this done up in our action

Copy link
Contributor

@suejung-sentry suejung-sentry Sep 5, 2024

Choose a reason for hiding this comment

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

Ah gotcha. I'd argue the variable over there is misnamed too 🙃 . And arguably relying on a (potentially changing) implementation detail of our codecov-api server.

As in re: "the audience is the OIDC endpoint" - that works as long as the server consuming the JWT token issued through GitHub OIDC validates the JWT expecting the audience to be the same string as the url host. Which may not always hold true, but happens to in our case. Other servers perhaps may be hosted at https://mysubdomain.myhost.com while the audience is expected to be https://*.myhost.com or https://myhost.com or other..

In any case I like what you've got here now - thank you for all this!

packages/bundler-plugin-core/src/types.ts Outdated Show resolved Hide resolved
packages/bundler-plugin-core/src/utils/getPreSignedURL.ts Outdated Show resolved Hide resolved
*
* Defaults to `https://codecov.io`
*/
OIDCEndpoint?: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

(See other PR comment re: this variable.)

Technically, something like below may be a little clearer:

/**
 * The expected audience in the GitHub OIDC JWT token to be validated by the apiUrl.
 *
 * Defaults to `https://codecov.io`
 */
gitHubOIDCTokenAudience?: string;

The value of this string needs to match that at codecov-api here.

We are never actually hitting this "endpoint" and technically the value of this doesn't need to be a url at all.

packages/bundler-plugin-core/src/utils/normalizeOptions.ts Outdated Show resolved Hide resolved
.github/workflows/ci.yml Outdated Show resolved Hide resolved
.github/workflows/ci.yml Outdated Show resolved Hide resolved
packages/bundler-plugin-core/src/utils/normalizeOptions.ts Outdated Show resolved Hide resolved
red(
`Failed to get OIDC token with url:\`${oidc.gitHubOIDCTokenAudience}\`. ${err.message}`,
);
throw new FailedOIDCFetchError(
Copy link
Collaborator

Choose a reason for hiding this comment

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

we should attach err as the error.cause of the FailedOIDCFetchError

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hrm, I'm getting type errors trying to add a second argument to Error, I see it in the MDN docs. I tried updating the @types/node however that didn't resolve the issue, any other ideas/guidance 👀

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm it might be because of the tsconfig here:

"lib": ["DOM", "DOM.Iterable", "ES2021"],

try setting it to be ES2022?

if that doesn't work feel free to ignore this and more forward.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ahh yea that did the trick

packages/bundler-plugin-core/src/utils/getPreSignedURL.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@suejung-sentry suejung-sentry left a comment

Choose a reason for hiding this comment

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

This is amazing, thank you so much for all this work!!

packages/bundler-plugin-core/src/utils/normalizeOptions.ts Outdated Show resolved Hide resolved
@nicholas-codecov nicholas-codecov merged commit 80dc4ee into main Sep 9, 2024
56 checks passed
@nicholas-codecov nicholas-codecov deleted the gh-eng-2209-add-ability-to-use-github-oidc branch September 9, 2024 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Tokenless][Plugin] Add support for GH OIDC
3 participants