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

solver: fix reading secrets from any session #5833

Merged
merged 1 commit into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
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
5 changes: 1 addition & 4 deletions frontend/gateway/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,11 @@ func (gwCtr *gatewayContainer) loadSecretEnv(ctx context.Context, secretEnv []*p
err = gwCtr.sm.Any(ctx, gwCtr.group, func(ctx context.Context, _ string, caller session.Caller) error {
dt, err = secrets.GetSecret(ctx, caller, id)
if err != nil {
if errors.Is(err, secrets.ErrNotFound) && sopt.Optional {
return nil
}
return err
}
return nil
})
if err != nil {
if err != nil && !(errors.Is(err, secrets.ErrNotFound) && sopt.Optional) {
return nil, err
}
out = append(out, fmt.Sprintf("%s=%s", sopt.Name, string(dt)))
Expand Down
5 changes: 1 addition & 4 deletions solver/llbsolver/ops/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,14 +559,11 @@ func (e *ExecOp) loadSecretEnv(ctx context.Context, g session.Group) ([]string,
err = e.sm.Any(ctx, g, func(ctx context.Context, _ string, caller session.Caller) error {
dt, err = secrets.GetSecret(ctx, caller, id)
if err != nil {
if errors.Is(err, secrets.ErrNotFound) && sopt.Optional {
return nil
}
return err
}
return nil
})
if err != nil {
if err != nil && !(errors.Is(err, secrets.ErrNotFound) && sopt.Optional) {
return nil, err
}
out = append(out, fmt.Sprintf("%s=%s", sopt.Name, string(dt)))
Expand Down
12 changes: 9 additions & 3 deletions source/git/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,11 @@ func (gs *gitSourceHandler) getAuthToken(ctx context.Context, g session.Group) e
if err != nil {
return err
}
return gs.sm.Any(ctx, g, func(ctx context.Context, _ string, caller session.Caller) error {
err = gs.sm.Any(ctx, g, func(ctx context.Context, _ string, caller session.Caller) error {
var err error
for _, s := range sec {
dt, err := secrets.GetSecret(ctx, caller, s.name)
var dt []byte
dt, err = secrets.GetSecret(ctx, caller, s.name)
if err != nil {
if errors.Is(err, secrets.ErrNotFound) {
continue
Expand All @@ -271,8 +273,12 @@ func (gs *gitSourceHandler) getAuthToken(ctx context.Context, g session.Group) e
gs.authArgs = []string{"-c", "http." + tokenScope(gs.src.Remote) + ".extraheader=Authorization: " + string(dt)}
break
}
return nil
return err
})
if errors.Is(err, secrets.ErrNotFound) {
err = nil
}
return err
}

func (gs *gitSourceHandler) mountSSHAuthSock(ctx context.Context, sshID string, g session.Group) (string, func() error, error) {
Expand Down