GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Implements Cloudsmith OIDC by joniumGit · Pull Request #47 · dependabot/proxy Conversation
Contributor
Implements support for OIDC authentication to the private registry service Cloudsmith The implementation is based on the information available in the official documentation and in the vendor provided GitHub Action. The code is mostly copied from the existing JFrog OIDC implementation and adapted to work with Cloudsmith as I am not a Go developer and not that familiar with it. Notes:
I appreciate and welcome all feedback on the PR.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pull request overviewAdds Cloudsmith as an additional OIDC-backed token provider in the Dependabot proxy’s OIDC subsystem, enabling the proxy to exchange a GitHub Actions OIDC token for a Cloudsmith API token and then use it for authenticated registry access (e.g., via existing OIDC-aware handlers like the npm registry handler). Changes:
Reviewed changesCopilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsUh oh!
There was an error while loading. Please reload this page. Uh oh!
There was an error while loading. Please reload this page. Uh oh!
There was an error while loading. Please reload this page. Uh oh!
There was an error while loading. Please reload this page.
Comment on lines
+596
to
+600
|
|
Added missing oidc url authentication handling tests for the Cloudsmith provider. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR! Overall it looks great and exactly what I'd hope it would look like. The only feedback (specific comments at their appropriate locations) is that the environment variable GITHUB_REPOSITORY_OWNER won't be available to the proxy at runtime so you'll have to make the audience parameter required.
Once this is all done there will be some internal PRs required to update the dependabot.yml schema to allow these additional values as well as some documentation updates, but I'll take care of that when the time comes.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Regarding your comment about testing it locally, it's difficult. You can build this image by running |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thank you for reviewing this. I have made the audience parameter mandatory and named it the same as in the Cloudsmith OIDC Github Action. Also, it is cool to see the Dependabot internals being open sourced. I will look into the CLI more and how to set up local testing for future contributions. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| return nil, fmt.Errorf("failed to read cloudsmith token response body: %w", err) | ||
| } | ||
|
|
||
| if resp.StatusCode != http.StatusOK { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Could you expand this check to also allow http.StatusCreated? The GitHub actions implementation accepts both 200 and 201 and .StatusCreated is what corresponds to that.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
That's a good catch, I missed that detail. I will update it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
|
|
||
| req.Header.Set("Content-Type", "application/json") | ||
| req.Header.Set("Accept", "application/json") |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I add an extra header here compared to the CLI, but I don't think it should cause issues. The CLI implementation assumes the response to be JSON.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if tokenResp.Token == "" { | ||
| return nil, fmt.Errorf("cloudsmith token response does not contain a token") | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The cli seems to be more defensive in this validation, should I add more?
!token || typeof token !== "string" || token.trim() === ""
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The current check against an empty string should suffice. The deserialization specified in the struct ensures it's a string and if we're getting tokens with leading or trailing whitespace that seems like an issue with their endpoint.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I went through the implementation again side by side with the CLI and docs after your comment. I only found a couple minor details I commented on. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thank you again for all your work. If you'll give me a few days I'll see if I can get a trial Cloudsmith account set up to test against just to make sure we didn't miss anything. In the meantime I'll start talking with my team and work on the internal PRs necessary to support this. On a related note if you need to catch my attention on this and I haven't responded yet, you can email me directly at |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Hello, following up on this. Did any required changes come up in the testing with the actual Cloudsmith instance? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@joniumGit I was finally able to get access to a Cloudsmith account and with only a few minor changes get this to work! The other OIDC providers use a bearer token but Cloudsmith uses a different request header. Could you modify your copy of --- a/internal/oidc/oidc_credential.go +++ b/internal/oidc/oidc_credential.go @@ -225,8 +225,15 @@ func TryAuthOIDCRequestWithPrefix(mutex *sync.RWMutex, oidcCredentials map[strin if err != nil { logging.RequestLogf(ctx, "* failed to get %s token via OIDC for %s: %v", matchedCred.Provider(), req.URL.Hostname(), err) } else { - logging.RequestLogf(ctx, "* authenticating request with OIDC token (host: %s)", req.URL.Hostname()) - req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token)) + switch matchedCred.parameters.(type) { + case *CloudsmithOIDCParameters: + logging.RequestLogf(ctx, "* authenticating request with OIDC API key (host: %s)", req.URL.Hostname()) + req.Header.Set("X-Api-Key", token) + default: + logging.RequestLogf(ctx, "* authenticating request with OIDC token (host: %s)", req.URL.Hostname()) + req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token)) + } + return true } } Similarly update --- a/internal/handlers/npm_registry.go +++ b/internal/handlers/npm_registry.go @@ -96,8 +96,13 @@ func (h *NPMRegistryHandler) HandleRequest(req *http.Request, ctx *goproxy.Proxy logging.RequestLogf(ctx, "* failed to get token via OIDC for %s: %v", reqHost, err) // Fall through to try static credentials } else { - logging.RequestLogf(ctx, "* authenticating npm registry request with OIDC token (host: %s)", reqHost) - req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token)) + if oidcCred.Provider() == "cloudsmith" { + logging.RequestLogf(ctx, "* authenticating npm registry request with OIDC API key (host: %s)", reqHost) + req.Header.Set("X-Api-Key", token) + } else { + logging.RequestLogf(ctx, "* authenticating npm registry request with OIDC token (host: %s)", reqHost) + req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token)) + } return req, nil } } And finally update --- a/internal/handlers/oidc_handling_test.go +++ b/internal/handlers/oidc_handling_test.go @@ -1380,7 +1380,12 @@ func TestOIDCURLsAreAuthenticated(t *testing.T) { for _, urlToAuth := range tc.urlsToAuthenticate { req := httptest.NewRequest("GET", urlToAuth, nil) req = handleRequestAndClose(handler, req, nil) - assertHasTokenAuth(t, req, "Bearer", "__test_token__", "package url: "+urlToAuth) + if tc.provider == "cloudsmith" { + assert.Equal(t, "__test_token__", req.Header.Get("X-Api-Key"), "package url: "+urlToAuth+" should include Cloudsmith API key") + assert.Equal(t, "", req.Header.Get("Authorization"), "package url: "+urlToAuth+" should not include Authorization header for Cloudsmith") + } else { + assertHasTokenAuth(t, req, "Bearer", "__test_token__", "package url: "+urlToAuth) + } } }) } Once these changes are in I'll still need to update the internal code to allow the additional Cloudsmith values in Thanks again for your work on this! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Hey, awesome news @brettfo! I applied the changes in the latest commit. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Signed-off-by: joniumGit <[email protected]>
Signed-off-by: joniumGit <[email protected]>
Signed-off-by: joniumGit <[email protected]>
Signed-off-by: joniumGit <[email protected]>
Signed-off-by: joniumGit <[email protected]>
Signed-off-by: joniumGit <[email protected]>
… oidc Signed-off-by: joniumGit <[email protected]>
Signed-off-by: joniumGit <[email protected]>
Signed-off-by: joniumGit <[email protected]>
Implements requested changes from PR. Signed-off-by: joniumGit <[email protected]>
40c83b1 to
841745d
Compare
|
Looks great! I just rebased it since it was so far out of date (that's entirely my bad) and approved it. Assuming CI passes I'll merge this Monday morning; it's near the end of the day here and I'm not interested in spending my Friday evening potentially tracking down some obscure dependabot proxy issue that might have crept in :) Also on Monday I'll work on getting the two internal PRs done. I'll reply here as those are completed. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Just merged this and it'll take a day or two to find its way to updater runs so in the meantime I'll work on finishing the internal PRs. I'll reply here as I have updates. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Hey, great to hear! I'll stay on the lookout for new releases. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@joniumGit I've deployed the internal changes to allow the new properties in Eventually I'll update this documentation with something like this: CloudsmithCloudsmith requires the values registries: my-cloudsmith-feed: type: npm-registry url: https://dl.cloudsmith.io/MY-NAMESPACE/MY-REPOSITORY/npm/ oidc-namespace: MY-NAMESPACE oidc-service-slug: MY-SERVICE-SLUG oidc-audience: MY-AUDIENCE api-host: api.cloudsmith.io # if required by your feed |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Hello, I tested it this morning with python packages and was able to successfully use the OIDC auth to get a Dependabot PR to pop up for a private package. The config I used was pretty much like this. The audience I set to match the example in the OIDC Github docs for actions so that I can use the same OIDC provider config in Cloudsmith for both. version: 2 registries: cloudsmith-python: replaces-base: true type: python-index # https://docs.cloudsmith.com/formats/python-repository#download--install-a-package url: https://dl.cloudsmith.io/public/OWNER/REPOSITORY/python/simple/ oidc-audience: https://github.com/GITHUB-ORG oidc-namespace: OWNER oidc-service-slug: ${{ secrets.CLOUDSMITH_USERNAME }} updates: - package-ecosystem: pip # One package needs this insecure-external-code-execution: allow registries: '*' directory: / schedule: interval: weekly |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Also tested NPM, Docker, and Maven to be working. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@joniumGit Thank you for checking! I'll work on getting the documentation published with a note that the audience should look like you specified. It might take a bit to get the docs up since there will likely be a blog post to go along with it, but in the meantime enjoy your secure package feeds. Thanks again for all your work, we really appreciate it! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thank you! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@joniumGit (and anybody else following along): We're doing a refactor of the proxy and we're renaming the values for Cloudsmith to remove the
We've made a sneaky change on the back end to auto-rename the When you get a chance could you update your |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Hi, thanks for the info. I will begin migrating all the repos that already use it. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.