@@ -82,37 +82,64 @@ var _ = framework.KubeDescribe("AppArmor", func() {
82
82
})
83
83
84
84
It ("should fail with an unloaded profile" , func () {
85
- profile := apparmorProfileNamePrefix + "non-existent-profile"
85
+ profile := & runtimeapi.LinuxContainerSecurityContext {
86
+ ApparmorProfile : apparmorProfileNamePrefix + "non-existent-profile" ,
87
+ }
86
88
containerID := createContainerWithAppArmor (rc , ic , sandboxID , sandboxConfig , profile , false )
87
89
Expect (containerID ).To (BeEmpty ())
88
90
})
89
91
90
92
It ("should enforce a profile blocking writes" , func () {
91
- profile := apparmorProfileNamePrefix + "cri-validate-apparmor-test-deny-write"
93
+ profile := & runtimeapi.LinuxContainerSecurityContext {
94
+ ApparmorProfile : apparmorProfileNamePrefix + "cri-validate-apparmor-test-deny-write" ,
95
+ }
92
96
containerID := createContainerWithAppArmor (rc , ic , sandboxID , sandboxConfig , profile , true )
93
97
checkContainerApparmor (rc , containerID , false )
94
98
})
95
99
96
100
It ("should enforce a permissive profile" , func () {
97
- profile := apparmorProfileNamePrefix + "cri-validate-apparmor-test-audit-write"
101
+ profile := & runtimeapi.LinuxContainerSecurityContext {
102
+ ApparmorProfile : apparmorProfileNamePrefix + "cri-validate-apparmor-test-audit-write" ,
103
+ }
98
104
containerID := createContainerWithAppArmor (rc , ic , sandboxID , sandboxConfig , profile , true )
99
105
checkContainerApparmor (rc , containerID , true )
100
106
})
107
+
108
+ It ("should work with another field" , func () {
109
+ profile := & runtimeapi.LinuxContainerSecurityContext {
110
+ Apparmor : & runtimeapi.SecurityProfile {
111
+ ProfileType : runtimeapi .SecurityProfile_Localhost ,
112
+ LocalhostRef : apparmorProfileNamePrefix + "cri-validate-apparmor-test-deny-write" ,
113
+ },
114
+ }
115
+ containerID := createContainerWithAppArmor (rc , ic , sandboxID , sandboxConfig , profile , true )
116
+ Expect (containerID ).To (BeEmpty ())
117
+ })
118
+
119
+ It ("should work with different fields" , func () {
120
+ profile := & runtimeapi.LinuxContainerSecurityContext {
121
+ ApparmorProfile : apparmorProfileNamePrefix + "non-existent-profile" ,
122
+ Apparmor : & runtimeapi.SecurityProfile {
123
+ ProfileType : runtimeapi .SecurityProfile_Localhost ,
124
+ LocalhostRef : apparmorProfileNamePrefix + "cri-validate-apparmor-test-deny-write" ,
125
+ },
126
+ }
127
+ containerID := createContainerWithAppArmor (rc , ic , sandboxID , sandboxConfig , profile , true )
128
+ Expect (containerID ).To (BeEmpty ())
129
+ })
101
130
})
102
131
}
103
132
})
104
133
105
- func createContainerWithAppArmor (rc internalapi.RuntimeService , ic internalapi.ImageManagerService , sandboxID string , sandboxConfig * runtimeapi.PodSandboxConfig , profile string , shouldSucceed bool ) string {
134
+ func createContainerWithAppArmor (rc internalapi.RuntimeService , ic internalapi.ImageManagerService , sandboxID string , sandboxConfig * runtimeapi.PodSandboxConfig , profile * runtimeapi. LinuxContainerSecurityContext , shouldSucceed bool ) string {
106
135
By ("create a container with apparmor" )
107
136
containerName := "apparmor-test-" + framework .NewUUID ()
108
137
containerConfig := & runtimeapi.ContainerConfig {
109
138
Metadata : framework .BuildContainerMetadata (containerName , framework .DefaultAttempt ),
110
139
Image : & runtimeapi.ImageSpec {Image : framework .TestContext .TestImageList .DefaultTestContainerImage },
111
140
Command : []string {"touch" , "/tmp/foo" },
112
141
Linux : & runtimeapi.LinuxContainerConfig {
113
- SecurityContext : & runtimeapi.LinuxContainerSecurityContext {
114
- ApparmorProfile : profile ,
115
- },
142
+ SecurityContext : profile ,
116
143
},
117
144
}
118
145
0 commit comments