Skip to content

feat: add CLI commands#20

Merged
ericnorris merged 1 commit into
mainfrom
feat-add-cli
May 6, 2026
Merged

feat: add CLI commands#20
ericnorris merged 1 commit into
mainfrom
feat-add-cli

Conversation

@ericnorris
Copy link
Copy Markdown
Collaborator

This commit adds two CLI commands to make it possible for users to do the token exchange outside of a GitHub Action.

github-app-sts-client is a CLI command that performs a token exchange given an OIDC token (like AWS_WEB_IDENTITY_TOKEN_FILE) or a token source (like gcp, which fetches a token using Google's application default credentials pattern).

git-credential-github-app-sts is a git credential helper that will perform a token exchange using the same arguments, but will output the token in a way that is compatible with git's credential helper protocol.

In the future, we could add more token sources like doing a user-triggered OIDC flow using a local browser.

Comment thread internal/client/tokensource/gcp.go Outdated
// Credentials. This works on GCE, Cloud Run, GKE, and anywhere a service
// account key or workload identity federation is configured.
func FromGCP(ctx context.Context, audience string) (string, error) {
ts, err := idtoken.NewTokenSource(ctx, audience)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

When --token-source=gcp is used on a dev VM that has gcloud auth application-default login configured, idtoken.NewTokenSource walks the standard ADC chain (1. env var, 2. ~/.config/gcloud/application_default_credentials.json, 3. metadata server). Step 2 hits the user's gcloud login first; idtoken rejects it because user credentials can't mint audience-restricted ID tokens and the chain doesn't fall through to the metadata server.

I was able to work around it by renaming ~/.config/gcloud/application_default_credentials.json but that's a bit unintuitive.

IMO, we should do something like:

import "cloud.google.com/go/compute/metadata"
tok, err := metadata.GetWithContext(ctx, instance/service-accounts/default/identity?audience="+url.QueryEscape(audience))

To me, this more clearly aligns with the flag's purpose.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We chatted about this outside of the PR - we're going to leave this as-is, since we'd like this to work transparently with the Application Default Credentials pattern where possible. Unfortunately that does mean that if a user runs gcloud auth application-default login, it would cause this flow to stop working, but it would also break anything else that was meant to use the system's service account (e.g. on a VM).

This commit adds two CLI commands to make it possible for users to do
the token exchange outside of a GitHub Action.

`github-app-sts-client` is a CLI command that performs a token exchange
given an OIDC token (like `AWS_WEB_IDENTITY_TOKEN_FILE`) or a token
source (like `gcp`, which fetches a token using Google's application
default credentials pattern).

`git-credential-github-app-sts` is a git credential helper that will
perform a token exchange using the same arguments, but will output the
token in a way that is compatible with git's credential helper protocol.

In the future, we could add more token sources like doing a
user-triggered OIDC flow using a local browser.
@ericnorris ericnorris marked this pull request as ready for review May 5, 2026 19:16
@ericnorris ericnorris requested a review from a team as a code owner May 5, 2026 19:16
Copy link
Copy Markdown

@DakotaNelson DakotaNelson left a comment

Choose a reason for hiding this comment

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

rubber stamped, did not look that hard since it looks like you and simpsonw have been over it

@ericnorris ericnorris merged commit 16b454e into main May 6, 2026
2 checks passed
@ericnorris ericnorris deleted the feat-add-cli branch May 6, 2026 13:36
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.

3 participants