aboutsummaryrefslogtreecommitdiffhomepage
path: root/hst
diff options
context:
space:
mode:
Diffstat (limited to 'hst')
-rw-r--r--hst/config.go47
-rw-r--r--hst/config_test.go76
2 files changed, 96 insertions, 27 deletions
diff --git a/hst/config.go b/hst/config.go
index 6b7e26f4..927f60ab 100644
--- a/hst/config.go
+++ b/hst/config.go
@@ -140,21 +140,29 @@ var (
ErrInsecure = errors.New("configuration is insecure")
)
+const (
+ // VAllowInsecure allows use of compatibility options considered insecure
+ // under any configuration, to work around ecosystem-wide flaws.
+ VAllowInsecure = 1 << iota
+)
+
// Validate checks [Config] and returns [AppError] if an invalid value is encountered.
-func (config *Config) Validate() error {
+func (config *Config) Validate(flags int) error {
+ const step = "validate configuration"
+
if config == nil {
- return &AppError{Step: "validate configuration", Err: ErrConfigNull,
+ return &AppError{Step: step, Err: ErrConfigNull,
Msg: "invalid configuration"}
}
// this is checked again in hsu
if config.Identity < IdentityStart || config.Identity > IdentityEnd {
- return &AppError{Step: "validate configuration", Err: ErrIdentityBounds,
+ return &AppError{Step: step, Err: ErrIdentityBounds,
Msg: "identity " + strconv.Itoa(config.Identity) + " out of range"}
}
if config.SchedPolicy < 0 || config.SchedPolicy > ext.SCHED_LAST {
- return &AppError{Step: "validate configuration", Err: ErrSchedPolicyBounds,
+ return &AppError{Step: step, Err: ErrSchedPolicyBounds,
Msg: "scheduling policy " +
strconv.Itoa(int(config.SchedPolicy)) +
" out of range"}
@@ -168,34 +176,51 @@ func (config *Config) Validate() error {
}
if config.Container == nil {
- return &AppError{Step: "validate configuration", Err: ErrConfigNull,
+ return &AppError{Step: step, Err: ErrConfigNull,
Msg: "configuration missing container state"}
}
if config.Container.Home == nil {
- return &AppError{Step: "validate configuration", Err: ErrConfigNull,
+ return &AppError{Step: step, Err: ErrConfigNull,
Msg: "container configuration missing path to home directory"}
}
if config.Container.Shell == nil {
- return &AppError{Step: "validate configuration", Err: ErrConfigNull,
+ return &AppError{Step: step, Err: ErrConfigNull,
Msg: "container configuration missing path to shell"}
}
if config.Container.Path == nil {
- return &AppError{Step: "validate configuration", Err: ErrConfigNull,
+ return &AppError{Step: step, Err: ErrConfigNull,
Msg: "container configuration missing path to initial program"}
}
for key := range config.Container.Env {
if strings.IndexByte(key, '=') != -1 || strings.IndexByte(key, 0) != -1 {
- return &AppError{Step: "validate configuration", Err: ErrEnviron,
+ return &AppError{Step: step, Err: ErrEnviron,
Msg: "invalid environment variable " + strconv.Quote(key)}
}
}
- if et := config.Enablements.Unwrap(); !config.DirectPulse && et&EPulse != 0 {
- return &AppError{Step: "validate configuration", Err: ErrInsecure,
+ et := config.Enablements.Unwrap()
+ if !config.DirectPulse && et&EPulse != 0 {
+ return &AppError{Step: step, Err: ErrInsecure,
Msg: "enablement PulseAudio is insecure and no longer supported"}
}
+ if flags&VAllowInsecure == 0 {
+ switch {
+ case et&EWayland != 0 && config.DirectWayland:
+ return &AppError{Step: step, Err: ErrInsecure,
+ Msg: "direct_wayland is insecure and no longer supported"}
+
+ case et&EPipeWire != 0 && config.DirectPipeWire:
+ return &AppError{Step: step, Err: ErrInsecure,
+ Msg: "direct_pipewire is insecure and no longer supported"}
+
+ case et&EPulse != 0 && config.DirectPulse:
+ return &AppError{Step: step, Err: ErrInsecure,
+ Msg: "direct_pulse is insecure and no longer supported"}
+ }
+ }
+
return nil
}
diff --git a/hst/config_test.go b/hst/config_test.go
index b9e44d8b..22d764b5 100644
--- a/hst/config_test.go
+++ b/hst/config_test.go
@@ -14,65 +14,109 @@ func TestConfigValidate(t *testing.T) {
testCases := []struct {
name string
config *hst.Config
+ flags int
wantErr error
}{
- {"nil", nil, &hst.AppError{Step: "validate configuration", Err: hst.ErrConfigNull,
+ {"nil", nil, 0, &hst.AppError{Step: "validate configuration", Err: hst.ErrConfigNull,
Msg: "invalid configuration"}},
- {"identity lower", &hst.Config{Identity: -1}, &hst.AppError{Step: "validate configuration", Err: hst.ErrIdentityBounds,
+
+ {"identity lower", &hst.Config{Identity: -1}, 0, &hst.AppError{Step: "validate configuration", Err: hst.ErrIdentityBounds,
Msg: "identity -1 out of range"}},
- {"identity upper", &hst.Config{Identity: 10000}, &hst.AppError{Step: "validate configuration", Err: hst.ErrIdentityBounds,
+ {"identity upper", &hst.Config{Identity: 10000}, 0, &hst.AppError{Step: "validate configuration", Err: hst.ErrIdentityBounds,
Msg: "identity 10000 out of range"}},
- {"sched lower", &hst.Config{SchedPolicy: -1}, &hst.AppError{Step: "validate configuration", Err: hst.ErrSchedPolicyBounds,
+
+ {"sched lower", &hst.Config{SchedPolicy: -1}, 0, &hst.AppError{Step: "validate configuration", Err: hst.ErrSchedPolicyBounds,
Msg: "scheduling policy -1 out of range"}},
- {"sched upper", &hst.Config{SchedPolicy: 0xcafe}, &hst.AppError{Step: "validate configuration", Err: hst.ErrSchedPolicyBounds,
+ {"sched upper", &hst.Config{SchedPolicy: 0xcafe}, 0, &hst.AppError{Step: "validate configuration", Err: hst.ErrSchedPolicyBounds,
Msg: "scheduling policy 51966 out of range"}},
- {"dbus session", &hst.Config{SessionBus: &hst.BusConfig{See: []string{""}}},
+
+ {"dbus session", &hst.Config{SessionBus: &hst.BusConfig{See: []string{""}}}, 0,
&hst.BadInterfaceError{Interface: "", Segment: "session"}},
- {"dbus system", &hst.Config{SystemBus: &hst.BusConfig{See: []string{""}}},
+ {"dbus system", &hst.Config{SystemBus: &hst.BusConfig{See: []string{""}}}, 0,
&hst.BadInterfaceError{Interface: "", Segment: "system"}},
- {"container", &hst.Config{}, &hst.AppError{Step: "validate configuration", Err: hst.ErrConfigNull,
+
+ {"container", &hst.Config{}, 0, &hst.AppError{Step: "validate configuration", Err: hst.ErrConfigNull,
Msg: "configuration missing container state"}},
- {"home", &hst.Config{Container: &hst.ContainerConfig{}}, &hst.AppError{Step: "validate configuration", Err: hst.ErrConfigNull,
+ {"home", &hst.Config{Container: &hst.ContainerConfig{}}, 0, &hst.AppError{Step: "validate configuration", Err: hst.ErrConfigNull,
Msg: "container configuration missing path to home directory"}},
{"shell", &hst.Config{Container: &hst.ContainerConfig{
Home: fhs.AbsTmp,
- }}, &hst.AppError{Step: "validate configuration", Err: hst.ErrConfigNull,
+ }}, 0, &hst.AppError{Step: "validate configuration", Err: hst.ErrConfigNull,
Msg: "container configuration missing path to shell"}},
{"path", &hst.Config{Container: &hst.ContainerConfig{
Home: fhs.AbsTmp,
Shell: fhs.AbsTmp,
- }}, &hst.AppError{Step: "validate configuration", Err: hst.ErrConfigNull,
+ }}, 0, &hst.AppError{Step: "validate configuration", Err: hst.ErrConfigNull,
Msg: "container configuration missing path to initial program"}},
+
{"env equals", &hst.Config{Container: &hst.ContainerConfig{
Home: fhs.AbsTmp,
Shell: fhs.AbsTmp,
Path: fhs.AbsTmp,
Env: map[string]string{"TERM=": ""},
- }}, &hst.AppError{Step: "validate configuration", Err: hst.ErrEnviron,
+ }}, 0, &hst.AppError{Step: "validate configuration", Err: hst.ErrEnviron,
Msg: `invalid environment variable "TERM="`}},
{"env NUL", &hst.Config{Container: &hst.ContainerConfig{
Home: fhs.AbsTmp,
Shell: fhs.AbsTmp,
Path: fhs.AbsTmp,
Env: map[string]string{"TERM\x00": ""},
- }}, &hst.AppError{Step: "validate configuration", Err: hst.ErrEnviron,
+ }}, 0, &hst.AppError{Step: "validate configuration", Err: hst.ErrEnviron,
Msg: `invalid environment variable "TERM\x00"`}},
+
{"insecure pulse", &hst.Config{Enablements: hst.NewEnablements(hst.EPulse), Container: &hst.ContainerConfig{
Home: fhs.AbsTmp,
Shell: fhs.AbsTmp,
Path: fhs.AbsTmp,
- }}, &hst.AppError{Step: "validate configuration", Err: hst.ErrInsecure,
+ }}, 0, &hst.AppError{Step: "validate configuration", Err: hst.ErrInsecure,
Msg: "enablement PulseAudio is insecure and no longer supported"}},
+
+ {"direct wayland", &hst.Config{Enablements: hst.NewEnablements(hst.EWayland), DirectWayland: true, Container: &hst.ContainerConfig{
+ Home: fhs.AbsTmp,
+ Shell: fhs.AbsTmp,
+ Path: fhs.AbsTmp,
+ }}, 0, &hst.AppError{Step: "validate configuration", Err: hst.ErrInsecure,
+ Msg: "direct_wayland is insecure and no longer supported"}},
+ {"direct wayland allow", &hst.Config{Enablements: hst.NewEnablements(hst.EWayland), DirectWayland: true, Container: &hst.ContainerConfig{
+ Home: fhs.AbsTmp,
+ Shell: fhs.AbsTmp,
+ Path: fhs.AbsTmp,
+ }}, hst.VAllowInsecure, nil},
+
+ {"direct pipewire", &hst.Config{Enablements: hst.NewEnablements(hst.EPipeWire), DirectPipeWire: true, Container: &hst.ContainerConfig{
+ Home: fhs.AbsTmp,
+ Shell: fhs.AbsTmp,
+ Path: fhs.AbsTmp,
+ }}, 0, &hst.AppError{Step: "validate configuration", Err: hst.ErrInsecure,
+ Msg: "direct_pipewire is insecure and no longer supported"}},
+ {"direct pipewire allow", &hst.Config{Enablements: hst.NewEnablements(hst.EPipeWire), DirectPipeWire: true, Container: &hst.ContainerConfig{
+ Home: fhs.AbsTmp,
+ Shell: fhs.AbsTmp,
+ Path: fhs.AbsTmp,
+ }}, hst.VAllowInsecure, nil},
+
+ {"direct pulse", &hst.Config{Enablements: hst.NewEnablements(hst.EPulse), DirectPulse: true, Container: &hst.ContainerConfig{
+ Home: fhs.AbsTmp,
+ Shell: fhs.AbsTmp,
+ Path: fhs.AbsTmp,
+ }}, 0, &hst.AppError{Step: "validate configuration", Err: hst.ErrInsecure,
+ Msg: "direct_pulse is insecure and no longer supported"}},
+ {"direct pulse allow", &hst.Config{Enablements: hst.NewEnablements(hst.EPulse), DirectPulse: true, Container: &hst.ContainerConfig{
+ Home: fhs.AbsTmp,
+ Shell: fhs.AbsTmp,
+ Path: fhs.AbsTmp,
+ }}, hst.VAllowInsecure, nil},
+
{"valid", &hst.Config{Container: &hst.ContainerConfig{
Home: fhs.AbsTmp,
Shell: fhs.AbsTmp,
Path: fhs.AbsTmp,
- }}, nil},
+ }}, 0, nil},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
- if err := tc.config.Validate(); !reflect.DeepEqual(err, tc.wantErr) {
+ if err := tc.config.Validate(tc.flags); !reflect.DeepEqual(err, tc.wantErr) {
t.Errorf("Validate: error = %#v, want %#v", err, tc.wantErr)
}
})