Skip to content

Commit a2cff80

Browse files
committed
restrict ssh option to default and return error
1 parent 267b5ab commit a2cff80

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

pkg/build/buildopts.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,20 @@ func NewBuildOpts(ctx context.Context, basePath string, contextMap map[string][]
241241
return args, nil
242242
}
243243

244-
sshExtract := func(key string) []sshprovider.AgentConfig {
244+
sshExtract := func(key string) ([]sshprovider.AgentConfig, error) {
245245
values, ok := contextMap[key]
246246
if !ok {
247-
return nil
247+
return nil, nil
248248
}
249+
if len(values) != 1 {
250+
return nil, ErrInvalidSSH
251+
}
252+
253+
value := strings.TrimSpace(values[0])
254+
if value != "default" {
255+
return nil, ErrInvalidSSH
256+
}
257+
249258
agentConfigs := make([]sshprovider.AgentConfig, 0, len(values))
250259
for _, value := range values {
251260
id, path, hasPath := strings.Cut(value, "=")
@@ -267,7 +276,7 @@ func NewBuildOpts(ctx context.Context, basePath string, contextMap map[string][]
267276
}
268277
agentConfigs = append(agentConfigs, config)
269278
}
270-
return agentConfigs
279+
return agentConfigs, nil
271280
}
272281

273282
labels := mapExtract(KeyLabels)
@@ -276,7 +285,10 @@ func NewBuildOpts(ctx context.Context, basePath string, contextMap map[string][]
276285
if err != nil {
277286
return nil, err
278287
}
279-
ssh := sshExtract(KeySSH)
288+
ssh, err := sshExtract(KeySSH)
289+
if err != nil {
290+
return nil, err
291+
}
280292
cacheIn := contextMap[KeyCacheIn]
281293
cacheOut := contextMap[KeyCacheOut]
282294
outputs := contextMap[KeyOutput]

pkg/build/errors.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ var (
2828
ErrNoBuildDirectives = fmt.Errorf("no build directives")
2929
ErrInvalidImageContextFormat = fmt.Errorf("image resolver: image name format is invalid")
3030
ErrInvalidProgress = fmt.Errorf("build arg progress value is invalid")
31+
ErrInvalidSSH = fmt.Errorf("build arg ssh value is invalid")
3132
)

0 commit comments

Comments
 (0)