Skip to content

Commit

Permalink
Merge pull request #269 from depot/debug-oidc
Browse files Browse the repository at this point in the history
Add debug env var for OIDC exchange
  • Loading branch information
jacobwgillespie authored Apr 11, 2024
2 parents c6e9eca + 7e68923 commit 6b365f6
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 2 deletions.
14 changes: 13 additions & 1 deletion pkg/helpers/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,20 @@ func ResolveToken(ctx context.Context, token string) (string, error) {
}

if token == "" {
var err error
debug := os.Getenv("DEPOT_DEBUG_OIDC") != ""

for _, provider := range oidc.Providers {
token, _ = provider.RetrieveToken(ctx)
if debug {
fmt.Printf("Trying OIDC provider %s\n", provider.Name())
}

token, err = provider.RetrieveToken(ctx)

if err != nil && debug {
fmt.Printf("OIDC provider %s failed: %v\n", provider.Name(), err)
}

if token != "" {
return token, nil
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/oidc/actionspublic.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ func NewActionsPublicProvider() *ActionsPublicProvider {
return &ActionsPublicProvider{}
}

func (p *ActionsPublicProvider) Name() string {
return "actions-public"
}

func (p *ActionsPublicProvider) RetrieveToken(ctx context.Context) (string, error) {
token, err := actionspublic.RetrieveToken(ctx, "https://depot.dev")
return token, err
Expand Down
6 changes: 5 additions & 1 deletion pkg/oidc/buildkite.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ func NewBuildkiteOIDCProvider() *BuildkiteOIDCProvider {
return &BuildkiteOIDCProvider{}
}

func (p *BuildkiteOIDCProvider) Name() string {
return "buildkite"
}

func (p *BuildkiteOIDCProvider) RetrieveToken(ctx context.Context) (string, error) {
agentToken := os.Getenv("BUILDKITE_AGENT_ACCESS_TOKEN")
if agentToken == "" {
return "", nil
return "", fmt.Errorf("Not running in a Buildkite agent environment")
}

endpoint := os.Getenv("BUILDKITE_AGENT_ENDPOINT")
Expand Down
4 changes: 4 additions & 0 deletions pkg/oidc/circleci.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ func NewCircleCIOIDCProvider() *CircleCIOIDCProvider {
return &CircleCIOIDCProvider{}
}

func (p *CircleCIOIDCProvider) Name() string {
return "circleci"
}

func (p *CircleCIOIDCProvider) RetrieveToken(ctx context.Context) (string, error) {
token := os.Getenv("CIRCLE_OIDC_TOKEN_V2")
return token, nil
Expand Down
4 changes: 4 additions & 0 deletions pkg/oidc/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ func NewGitHubOIDCProvider() *GitHubOIDCProvider {
return &GitHubOIDCProvider{}
}

func (p *GitHubOIDCProvider) Name() string {
return "github"
}

func (p *GitHubOIDCProvider) RetrieveToken(ctx context.Context) (string, error) {
requestToken := os.Getenv("ACTIONS_ID_TOKEN_REQUEST_TOKEN")
if requestToken == "" {
Expand Down
1 change: 1 addition & 0 deletions pkg/oidc/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "context"
const audience = "https://depot.dev"

type OIDCProvider interface {
Name() string
RetrieveToken(ctx context.Context) (string, error)
}

Expand Down

0 comments on commit 6b365f6

Please sign in to comment.