Skip to content

Commit 7c08dc7

Browse files
committed
fcos/v1_6_exp: Add validations to SElinux
Adds a SElinux validations and add new errors.
1 parent 45af03c commit 7c08dc7

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

config/common/errors.go

+5
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ var (
9393

9494
// Kernel arguments
9595
ErrGeneralKernelArgumentSupport = errors.New("kernel argument customization is not supported in this spec version")
96+
97+
// SElinux
98+
ErrSelinuxInvalidModeValue = errors.New("Invalid Selinux mode value, it must be true(enforcing) or false(permissive)")
99+
ErrSelinuxInvalidStateValue = errors.New("Invalid Selinux state value, it must be true(enabled) or false(disabled)")
100+
ErrSelinuxModeRequiredWithStateTrue = errors.New("Invalid configuration. If Selinux is enabled, a mode should be defined.")
96101
)
97102

98103
type ErrUnmarshal struct {

config/fcos/v1_6_exp/validate.go

+14
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,17 @@ func (user GrubUser) Validate(c path.ContextPath) (r report.Report) {
7777
}
7878
return
7979
}
80+
81+
func (s *Selinux) ValidateSelinux(c path.ContextPath) (r report.Report) {
82+
if s.State != nil {
83+
if !(*s.State == true || *s.State == false) {
84+
r.AddOnError(c.Append("state"), common.ErrSelinuxInvalidStateValue)
85+
} else if *s.State == true && s.Mode == nil {
86+
r.AddOnError(c.Append("mode"), common.ErrSelinuxModeRequiredWithStateTrue)
87+
}
88+
}
89+
if s.Mode != nil && !(*s.Mode == true || *s.Mode == false) {
90+
r.AddOnError(c.Append("mode"), common.ErrSelinuxInvalidModeValue)
91+
}
92+
return
93+
}

0 commit comments

Comments
 (0)