@@ -252,17 +252,24 @@ func parseMount(val string, expander SingleWordExpander) (*Mount, error) {
252
252
}
253
253
}
254
254
255
+ if err = validateMount (m , roAuto ); err != nil {
256
+ return nil , err
257
+ }
258
+ return m , nil
259
+ }
260
+
261
+ func validateMount (m * Mount , roAuto bool ) error {
255
262
fileInfoAllowed := m .Type == MountTypeSecret || m .Type == MountTypeSSH || m .Type == MountTypeCache
256
263
257
264
if ! fileInfoAllowed {
258
265
if m .Mode != nil {
259
- return nil , errors .Errorf ("mode not allowed for %q type mounts" , m .Type )
266
+ return errors .Errorf ("mode not allowed for %q type mounts" , m .Type )
260
267
}
261
268
if m .UID != nil {
262
- return nil , errors .Errorf ("uid not allowed for %q type mounts" , m .Type )
269
+ return errors .Errorf ("uid not allowed for %q type mounts" , m .Type )
263
270
}
264
271
if m .GID != nil {
265
- return nil , errors .Errorf ("gid not allowed for %q type mounts" , m .Type )
272
+ return errors .Errorf ("gid not allowed for %q type mounts" , m .Type )
266
273
}
267
274
}
268
275
@@ -276,22 +283,22 @@ func parseMount(val string, expander SingleWordExpander) (*Mount, error) {
276
283
277
284
if m .Type == MountTypeSecret {
278
285
if m .From != "" {
279
- return nil , errors .Errorf ("secret mount should not have a from" )
286
+ return errors .Errorf ("secret mount should not have a from" )
280
287
}
281
288
if m .CacheSharing != "" {
282
- return nil , errors .Errorf ("secret mount should not define sharing" )
289
+ return errors .Errorf ("secret mount should not define sharing" )
283
290
}
284
291
if m .Source == "" && m .Target == "" && m .CacheID == "" {
285
- return nil , errors .Errorf ("invalid secret mount. one of source, target required" )
292
+ return errors .Errorf ("invalid secret mount. one of source, target required" )
286
293
}
287
294
if m .Source != "" && m .CacheID != "" {
288
- return nil , errors .Errorf ("both source and id can't be set" )
295
+ return errors .Errorf ("both source and id can't be set" )
289
296
}
290
297
}
291
298
292
299
if m .CacheSharing != "" && m .Type != MountTypeCache {
293
- return nil , errors .Errorf ("invalid cache sharing set for %v mount" , m .Type )
300
+ return errors .Errorf ("invalid cache sharing set for %v mount" , m .Type )
294
301
}
295
302
296
- return m , nil
303
+ return nil
297
304
}
0 commit comments