Skip to content

Commit e20eb47

Browse files
committed
Add support for disabling network on workload
Previously a workload could only have its network disabled when that was aligned with the Profile. This change enables the workload to be more restrictive than the Profile. Signed-off-by: Paulo Gomes <[email protected]>
1 parent 95786b8 commit e20eb47

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

internal/types/workload.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (w Workload) ApplyProfile(p *Profile) EffectiveWorkload {
9797

9898
// If profile sets a network, that is enforced on all workloads.
9999
// If a profile does not set a network, workloads can only set "none" as a network.
100-
if p.Network != "" {
100+
if p.Network != "" && w.HostAccess.Network != "none" {
101101
e.Workload.HostAccess.Network = p.Network
102102
} else if w.HostAccess.Network != "" && w.HostAccess.Network != "none" {
103103
e.Workload.HostAccess.Network = ""

internal/types/workload_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,24 @@ func Test_ApplyProfile(t *testing.T) {
690690
},
691691
},
692692
},
693+
{
694+
name: "Network none: workload foo + profile none",
695+
workload: Workload{
696+
HostAccess: HostAccess{Network: "none"},
697+
},
698+
profile: &Profile{
699+
HostAccess: HostAccess{Network: "foo"},
700+
},
701+
want: EffectiveWorkload{
702+
Name: "-",
703+
Workload: Workload{
704+
HostAccess: HostAccess{Network: "none"},
705+
},
706+
Profile: &Profile{
707+
HostAccess: HostAccess{Network: "foo"},
708+
},
709+
},
710+
},
693711
{
694712
name: "Paths empty: workload /foo + profile empty",
695713
workload: Workload{

0 commit comments

Comments
 (0)