Skip to content

fix: credentials: don't store creds for local credential tools #239

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

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -340,9 +341,18 @@ func (r *Runner) handleCredentials(callCtx engine.Context, monitor Monitor, env
}

for _, credToolName := range callCtx.Tool.Credentials {
cred, exists, err := store.Get(credToolName)
if err != nil {
return nil, fmt.Errorf("failed to get credentials for tool %s: %w", credToolName, err)
var (
cred *credentials.Credential
exists bool
err error
)

// Only try to look up the cred if the tool is on GitHub.
if isGitHubTool(credToolName) {
cred, exists, err = store.Get(credToolName)
if err != nil {
return nil, fmt.Errorf("failed to get credentials for tool %s: %w", credToolName, err)
}
}

// If the credential doesn't already exist in the store, run the credential tool in order to get the value,
Expand Down Expand Up @@ -375,7 +385,7 @@ func (r *Runner) handleCredentials(callCtx engine.Context, monitor Monitor, env
}

// Only store the credential if the tool is on GitHub.
if callCtx.Program.ToolSet[credToolID].Source.Repo != nil {
if isGitHubTool(credToolName) && callCtx.Program.ToolSet[credToolID].Source.Repo != nil {
if err := store.Add(*cred); err != nil {
return nil, fmt.Errorf("failed to add credential for tool %s: %w", credToolName, err)
}
Expand All @@ -391,3 +401,7 @@ func (r *Runner) handleCredentials(callCtx engine.Context, monitor Monitor, env

return env, nil
}

func isGitHubTool(toolName string) bool {
return strings.HasPrefix(toolName, "github.com")
}