Skip to content

Commit d58db8d

Browse files
committed
add option to relax socket_vmnet validation
1 parent 291cbd6 commit d58db8d

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

pkg/networks/networks.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ type YAML struct {
99
}
1010

1111
type Paths struct {
12-
SocketVMNet string `yaml:"socketVMNet"`
13-
VarRun string `yaml:"varRun"`
14-
Sudoers string `yaml:"sudoers,omitempty"`
12+
SocketVMNet string `yaml:"socketVMNet"`
13+
VarRun string `yaml:"varRun"`
14+
Sudoers string `yaml:"sudoers,omitempty"`
15+
RelaxedVerification bool `yaml:"relaxedVerification,omitempty"`
1516
}
1617

1718
const (

pkg/networks/validate.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,20 @@ func (config *YAML) Validate() error {
2020
paths := reflect.ValueOf(&config.Paths).Elem()
2121
pathsMap := make(map[string]string, paths.NumField())
2222
var socketVMNetNotFound bool
23+
var relaxedVerification = config.Paths.RelaxedVerification
2324
for i := 0; i < paths.NumField(); i++ {
2425
// extract YAML name from struct tag; strip options like "omitempty"
2526
name := paths.Type().Field(i).Tag.Get("yaml")
2627
if i := strings.IndexRune(name, ','); i > -1 {
2728
name = name[:i]
2829
}
29-
path := paths.Field(i).Interface().(string)
30-
pathsMap[name] = path
30+
var path string
31+
if path, ok := paths.Field(i).Interface().(string); ok {
32+
pathsMap[name] = path
33+
} else {
34+
// we only validate strings from the config.Paths
35+
continue
36+
}
3137
// varPath will be created securely, but any existing parent directories must already be secure
3238
if name == "varRun" {
3339
path = findBaseDirectory(path)
@@ -44,11 +50,19 @@ func (config *YAML) Validate() error {
4450
continue
4551
}
4652
}
47-
return fmt.Errorf("networks.yaml field `paths.%s` error: %w", name, err)
53+
if relaxedVerification {
54+
fmt.Printf("networks.yaml field `paths.%s` error: %v\n", name, err)
55+
} else {
56+
return fmt.Errorf("networks.yaml field `paths.%s` error: %w", name, err)
57+
}
4858
}
4959
}
5060
if socketVMNetNotFound {
51-
return fmt.Errorf("networks.yaml: %q (`paths.socketVMNet`) has to be installed", pathsMap["socketVMNet"])
61+
if relaxedVerification {
62+
fmt.Printf("networks.yaml: %q (`paths.socketVMNet`) has to be installed\n", pathsMap["socketVMNet"])
63+
} else {
64+
return fmt.Errorf("networks.yaml: %q (`paths.socketVMNet`) has to be installed", pathsMap["socketVMNet"])
65+
}
5266
}
5367
// TODO(jandubois): validate network definitions
5468
return nil
@@ -126,7 +140,7 @@ func validatePath(path string, allowDaemonGroupWritable bool) error {
126140
}
127141
}
128142
if !ownerIsAdmin {
129-
return fmt.Errorf(`%s %q owner %dis not an admin`, file, path, stat.Uid)
143+
return fmt.Errorf(`%s %q owner %d is not an admin`, file, path, stat.Uid)
130144
}
131145
if allowDaemonGroupWritable {
132146
daemon, err := osutil.LookupUser("daemon")

0 commit comments

Comments
 (0)