Skip to content

Commit 1e28cf6

Browse files
committed
default-validator: implement finer-grained validation.
Implement role based overrides for authenticated plugins. This allows setting a restrictive default configuration and override it with more liberal configuration for some plugins/roles. Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
1 parent 70e9848 commit 1e28cf6

File tree

5 files changed

+203
-82
lines changed

5 files changed

+203
-82
lines changed

pkg/adaptation/adaptation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func WithBuiltinPlugins(plugins ...*builtin.BuiltinPlugin) Option {
137137
}
138138

139139
// WithDefaultValidator sets up builtin validator plugin if it is configured.
140-
func WithDefaultValidator(cfg *validator.DefaultValidatorConfig) Option {
140+
func WithDefaultValidator(cfg *validator.DefaultConfig) Option {
141141
return func(r *Adaptation) error {
142142
if plugin := validator.GetDefaultValidator(cfg); plugin != nil {
143143
r.builtin = append([]*builtin.BuiltinPlugin{plugin}, r.builtin...)

pkg/adaptation/adaptation_suite_test.go

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,9 +1110,11 @@ var _ = Describe("Plugin container creation adjustments", func() {
11101110
&mockRuntime{
11111111
options: []nri.Option{
11121112
nri.WithDefaultValidator(
1113-
&validator.DefaultValidatorConfig{
1114-
Enable: true,
1115-
RejectOCIHookAdjustment: true,
1113+
&validator.DefaultConfig{
1114+
Enable: true,
1115+
Config: &validator.Config{
1116+
RejectOCIHookAdjustment: boolptr(true),
1117+
},
11161118
},
11171119
),
11181120
},
@@ -1203,9 +1205,11 @@ var _ = Describe("Plugin container creation adjustments", func() {
12031205
&mockRuntime{
12041206
options: []nri.Option{
12051207
nri.WithDefaultValidator(
1206-
&validator.DefaultValidatorConfig{
1207-
Enable: true,
1208-
RejectRuntimeDefaultSeccompAdjustment: true,
1208+
&validator.DefaultConfig{
1209+
Enable: true,
1210+
Config: &validator.Config{
1211+
RejectRuntimeDefaultSeccompAdjustment: boolptr(true),
1212+
},
12091213
},
12101214
),
12111215
},
@@ -1306,9 +1310,11 @@ var _ = Describe("Plugin container creation adjustments", func() {
13061310
&mockRuntime{
13071311
options: []nri.Option{
13081312
nri.WithDefaultValidator(
1309-
&validator.DefaultValidatorConfig{
1310-
Enable: true,
1311-
RejectRuntimeDefaultSeccompAdjustment: false,
1313+
&validator.DefaultConfig{
1314+
Enable: true,
1315+
Config: &validator.Config{
1316+
RejectRuntimeDefaultSeccompAdjustment: boolptr(false),
1317+
},
13121318
},
13131319
),
13141320
},
@@ -1409,9 +1415,11 @@ var _ = Describe("Plugin container creation adjustments", func() {
14091415
&mockRuntime{
14101416
options: []nri.Option{
14111417
nri.WithDefaultValidator(
1412-
&validator.DefaultValidatorConfig{
1413-
Enable: true,
1414-
RejectCustomSeccompAdjustment: true,
1418+
&validator.DefaultConfig{
1419+
Enable: true,
1420+
Config: &validator.Config{
1421+
RejectCustomSeccompAdjustment: boolptr(true),
1422+
},
14151423
},
14161424
),
14171425
},
@@ -1513,9 +1521,11 @@ var _ = Describe("Plugin container creation adjustments", func() {
15131521
&mockRuntime{
15141522
options: []nri.Option{
15151523
nri.WithDefaultValidator(
1516-
&validator.DefaultValidatorConfig{
1517-
Enable: true,
1518-
RejectCustomSeccompAdjustment: false,
1524+
&validator.DefaultConfig{
1525+
Enable: true,
1526+
Config: &validator.Config{
1527+
RejectCustomSeccompAdjustment: boolptr(false),
1528+
},
15191529
},
15201530
),
15211531
},
@@ -1617,9 +1627,11 @@ var _ = Describe("Plugin container creation adjustments", func() {
16171627
&mockRuntime{
16181628
options: []nri.Option{
16191629
nri.WithDefaultValidator(
1620-
&validator.DefaultValidatorConfig{
1621-
Enable: true,
1622-
RejectUnconfinedSeccompAdjustment: true,
1630+
&validator.DefaultConfig{
1631+
Enable: true,
1632+
Config: &validator.Config{
1633+
RejectUnconfinedSeccompAdjustment: boolptr(true),
1634+
},
16231635
},
16241636
),
16251637
},
@@ -1720,9 +1732,11 @@ var _ = Describe("Plugin container creation adjustments", func() {
17201732
&mockRuntime{
17211733
options: []nri.Option{
17221734
nri.WithDefaultValidator(
1723-
&validator.DefaultValidatorConfig{
1724-
Enable: true,
1725-
RejectUnconfinedSeccompAdjustment: false,
1735+
&validator.DefaultConfig{
1736+
Enable: true,
1737+
Config: &validator.Config{
1738+
RejectUnconfinedSeccompAdjustment: boolptr(false),
1739+
},
17261740
},
17271741
),
17281742
},
@@ -1823,9 +1837,11 @@ var _ = Describe("Plugin container creation adjustments", func() {
18231837
&mockRuntime{
18241838
options: []nri.Option{
18251839
nri.WithDefaultValidator(
1826-
&validator.DefaultValidatorConfig{
1827-
Enable: true,
1828-
RejectNamespaceAdjustment: true,
1840+
&validator.DefaultConfig{
1841+
Enable: true,
1842+
Config: &validator.Config{
1843+
RejectNamespaceAdjustment: boolptr(true),
1844+
},
18291845
},
18301846
),
18311847
},
@@ -1912,7 +1928,7 @@ var _ = Describe("Plugin container creation adjustments", func() {
19121928
&mockRuntime{
19131929
options: []nri.Option{
19141930
nri.WithDefaultValidator(
1915-
&validator.DefaultValidatorConfig{
1931+
&validator.DefaultConfig{
19161932
Enable: true,
19171933
RequiredPlugins: []string{
19181934
"foo",
@@ -3157,3 +3173,7 @@ func protoDiff(a, b proto.Message) string {
31573173
func protoEqual(a, b proto.Message) bool {
31583174
return cmp.Equal(a, b, cmpopts.EquateEmpty(), protocmp.Transform())
31593175
}
3176+
3177+
func boolptr(v bool) *bool {
3178+
return &v
3179+
}

plugins/default-validator/builtin/plugin.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ import (
2626
)
2727

2828
type (
29-
DefaultValidatorConfig = validator.DefaultValidatorConfig
29+
Config = validator.Config
30+
DefaultConfig = validator.DefaultConfig
3031
)
3132

3233
// GetDefaultValidator returns a configured instance of the default validator.
3334
// If default validation is disabled nil is returned.
34-
func GetDefaultValidator(cfg *DefaultValidatorConfig) *builtin.BuiltinPlugin {
35+
func GetDefaultValidator(cfg *DefaultConfig) *builtin.BuiltinPlugin {
3536
if cfg == nil || !cfg.Enable {
3637
log.Infof(context.TODO(), "built-in NRI default validator is disabled")
3738
return nil

0 commit comments

Comments
 (0)