Skip to content

Commit 7590cb7

Browse files
authored
Merge pull request kubernetes#125257 from vinayakankugoyal/armor
KEP-24: Update AppArmor feature gates to GA stage.
2 parents d7194eb + bc06071 commit 7590cb7

File tree

12 files changed

+35
-94
lines changed

12 files changed

+35
-94
lines changed

pkg/api/pod/util.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -628,25 +628,6 @@ func dropDisabledFields(
628628
podSpec = &api.PodSpec{}
629629
}
630630

631-
if !utilfeature.DefaultFeatureGate.Enabled(features.AppArmor) && !appArmorAnnotationsInUse(oldPodAnnotations) {
632-
for k := range podAnnotations {
633-
if strings.HasPrefix(k, api.DeprecatedAppArmorAnnotationKeyPrefix) {
634-
delete(podAnnotations, k)
635-
}
636-
}
637-
}
638-
if (!utilfeature.DefaultFeatureGate.Enabled(features.AppArmor) || !utilfeature.DefaultFeatureGate.Enabled(features.AppArmorFields)) && !appArmorFieldsInUse(oldPodSpec) {
639-
if podSpec.SecurityContext != nil {
640-
podSpec.SecurityContext.AppArmorProfile = nil
641-
}
642-
VisitContainers(podSpec, AllContainers, func(c *api.Container, _ ContainerType) bool {
643-
if c.SecurityContext != nil {
644-
c.SecurityContext.AppArmorProfile = nil
645-
}
646-
return true
647-
})
648-
}
649-
650631
// If the feature is disabled and not in use, drop the hostUsers field.
651632
if !utilfeature.DefaultFeatureGate.Enabled(features.UserNamespacesSupport) && !hostUsersInUse(oldPodSpec) {
652633
// Drop the field in podSpec only if SecurityContext is not nil.

pkg/api/pod/util_test.go

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -769,45 +769,36 @@ func TestDropAppArmor(t *testing.T) {
769769
}}
770770

771771
for _, test := range tests {
772-
for _, enabled := range []bool{true, false} {
773-
for _, fieldsEnabled := range []bool{true, false} {
774-
t.Run(fmt.Sprintf("%v/enabled=%v/fields=%v", test.description, enabled, fieldsEnabled), func(t *testing.T) {
775-
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.AppArmor, enabled)
776-
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.AppArmorFields, fieldsEnabled)
777772

778-
newPod := test.pod.DeepCopy()
773+
t.Run(fmt.Sprintf("%v", test.description), func(t *testing.T) {
774+
newPod := test.pod.DeepCopy()
779775

780-
if hasAnnotations := appArmorAnnotationsInUse(newPod.Annotations); hasAnnotations != test.hasAnnotations {
781-
t.Errorf("appArmorAnnotationsInUse does not match expectation: %t != %t", hasAnnotations, test.hasAnnotations)
782-
}
783-
if hasFields := appArmorFieldsInUse(&newPod.Spec); hasFields != test.hasFields {
784-
t.Errorf("appArmorFieldsInUse does not match expectation: %t != %t", hasFields, test.hasFields)
785-
}
786-
787-
DropDisabledPodFields(newPod, newPod)
788-
require.Equal(t, &test.pod, newPod, "unchanged pod should never be mutated")
776+
if hasAnnotations := appArmorAnnotationsInUse(newPod.Annotations); hasAnnotations != test.hasAnnotations {
777+
t.Errorf("appArmorAnnotationsInUse does not match expectation: %t != %t", hasAnnotations, test.hasAnnotations)
778+
}
779+
if hasFields := appArmorFieldsInUse(&newPod.Spec); hasFields != test.hasFields {
780+
t.Errorf("appArmorFieldsInUse does not match expectation: %t != %t", hasFields, test.hasFields)
781+
}
789782

790-
DropDisabledPodFields(newPod, nil)
783+
DropDisabledPodFields(newPod, newPod)
784+
require.Equal(t, &test.pod, newPod, "unchanged pod should never be mutated")
791785

792-
if enabled && fieldsEnabled {
793-
assert.Equal(t, &test.pod, newPod, "pod should not be mutated when both feature gates are enabled")
794-
return
795-
}
786+
DropDisabledPodFields(newPod, nil)
787+
assert.Equal(t, &test.pod, newPod, "pod should not be mutated when both feature gates are enabled")
796788

797-
expectAnnotations := test.hasAnnotations && enabled
798-
assert.Equal(t, expectAnnotations, appArmorAnnotationsInUse(newPod.Annotations), "AppArmor annotations expectation")
799-
if expectAnnotations == test.hasAnnotations {
800-
assert.Equal(t, test.pod.Annotations, newPod.Annotations, "annotations should not be mutated")
801-
}
789+
expectAnnotations := test.hasAnnotations
790+
assert.Equal(t, expectAnnotations, appArmorAnnotationsInUse(newPod.Annotations), "AppArmor annotations expectation")
791+
if expectAnnotations == test.hasAnnotations {
792+
assert.Equal(t, test.pod.Annotations, newPod.Annotations, "annotations should not be mutated")
793+
}
802794

803-
expectFields := test.hasFields && enabled && fieldsEnabled
804-
assert.Equal(t, expectFields, appArmorFieldsInUse(&newPod.Spec), "AppArmor fields expectation")
805-
if expectFields == test.hasFields {
806-
assert.Equal(t, &test.pod.Spec, &newPod.Spec, "PodSpec should not be mutated")
807-
}
808-
})
795+
expectFields := test.hasFields
796+
assert.Equal(t, expectFields, appArmorFieldsInUse(&newPod.Spec), "AppArmor fields expectation")
797+
if expectFields == test.hasFields {
798+
assert.Equal(t, &test.pod.Spec, &newPod.Spec, "PodSpec should not be mutated")
809799
}
810-
}
800+
})
801+
811802
}
812803
}
813804

pkg/api/pod/warnings.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@ import (
2424
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2525
"k8s.io/apimachinery/pkg/util/sets"
2626
"k8s.io/apimachinery/pkg/util/validation/field"
27-
utilfeature "k8s.io/apiserver/pkg/util/feature"
2827
nodeapi "k8s.io/kubernetes/pkg/api/node"
2928
pvcutil "k8s.io/kubernetes/pkg/api/persistentvolumeclaim"
3029
api "k8s.io/kubernetes/pkg/apis/core"
3130
"k8s.io/kubernetes/pkg/apis/core/pods"
32-
"k8s.io/kubernetes/pkg/features"
3331
)
3432

3533
func GetWarningsForPod(ctx context.Context, pod, oldPod *api.Pod) []string {
@@ -225,14 +223,13 @@ func warningsForPodSpecAndMeta(fieldPath *field.Path, podSpec *api.PodSpec, meta
225223
}
226224

227225
// use of container AppArmor annotation without accompanying field
228-
if utilfeature.DefaultFeatureGate.Enabled(features.AppArmorFields) {
229-
isPodTemplate := fieldPath != nil // Pod warnings are emitted through applyAppArmorVersionSkew instead.
230-
hasAppArmorField := hasPodAppArmorProfile || (c.SecurityContext != nil && c.SecurityContext.AppArmorProfile != nil)
231-
if isPodTemplate && !hasAppArmorField {
232-
key := api.DeprecatedAppArmorAnnotationKeyPrefix + c.Name
233-
if _, exists := meta.Annotations[key]; exists {
234-
warnings = append(warnings, fmt.Sprintf(`%s: deprecated since v1.30; use the "appArmorProfile" field instead`, fieldPath.Child("metadata", "annotations").Key(key)))
235-
}
226+
227+
isPodTemplate := fieldPath != nil // Pod warnings are emitted through applyAppArmorVersionSkew instead.
228+
hasAppArmorField := hasPodAppArmorProfile || (c.SecurityContext != nil && c.SecurityContext.AppArmorProfile != nil)
229+
if isPodTemplate && !hasAppArmorField {
230+
key := api.DeprecatedAppArmorAnnotationKeyPrefix + c.Name
231+
if _, exists := meta.Annotations[key]; exists {
232+
warnings = append(warnings, fmt.Sprintf(`%s: deprecated since v1.30; use the "appArmorProfile" field instead`, fieldPath.Child("metadata", "annotations").Key(key)))
236233
}
237234
}
238235

pkg/apis/core/validation/validation.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4793,9 +4793,6 @@ func ValidateAppArmorProfileFormat(profile string) error {
47934793

47944794
// validateAppArmorAnnotationsAndFieldsMatchOnCreate validates that AppArmor fields and annotations are consistent.
47954795
func validateAppArmorAnnotationsAndFieldsMatchOnCreate(objectMeta metav1.ObjectMeta, podSpec *core.PodSpec, specPath *field.Path) field.ErrorList {
4796-
if !utilfeature.DefaultFeatureGate.Enabled(features.AppArmorFields) {
4797-
return nil
4798-
}
47994796
if podSpec.OS != nil && podSpec.OS.Name == core.Windows {
48004797
// Skip consistency check for windows pods.
48014798
return nil

pkg/features/kube_features.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@ const (
6868

6969
// owner: @tallclair
7070
// beta: v1.4
71+
// GA: v1.31
7172
AppArmor featuregate.Feature = "AppArmor"
7273

7374
// owner: @tallclair
7475
// beta: v1.30
76+
// GA: v1.31
7577
AppArmorFields featuregate.Feature = "AppArmorFields"
7678

7779
// owner: @liggitt
@@ -995,9 +997,9 @@ var defaultKubernetesFeatureGates = map[featuregate.Feature]featuregate.FeatureS
995997

996998
AnyVolumeDataSource: {Default: true, PreRelease: featuregate.Beta}, // on by default in 1.24
997999

998-
AppArmor: {Default: true, PreRelease: featuregate.Beta},
1000+
AppArmor: {Default: true, PreRelease: featuregate.GA, LockToDefault: true}, // remove in 1.33
9991001

1000-
AppArmorFields: {Default: true, PreRelease: featuregate.Beta},
1002+
AppArmorFields: {Default: true, PreRelease: featuregate.GA, LockToDefault: true}, // remove in 1.33
10011003

10021004
AuthorizeNodeWithSelectors: {Default: false, PreRelease: featuregate.Alpha},
10031005

pkg/registry/core/pod/strategy.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -765,10 +765,6 @@ func applySchedulingGatedCondition(pod *api.Pod) {
765765
// applyAppArmorVersionSkew implements the version skew behavior described in:
766766
// https://github.com/kubernetes/enhancements/tree/master/keps/sig-node/24-apparmor#version-skew-strategy
767767
func applyAppArmorVersionSkew(ctx context.Context, pod *api.Pod) {
768-
if !utilfeature.DefaultFeatureGate.Enabled(features.AppArmorFields) {
769-
return
770-
}
771-
772768
if pod.Spec.OS != nil && pod.Spec.OS.Name == api.Windows {
773769
return
774770
}

pkg/security/apparmor/helpers.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ import (
2020
"strings"
2121

2222
v1 "k8s.io/api/core/v1"
23-
utilfeature "k8s.io/apiserver/pkg/util/feature"
2423
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
25-
"k8s.io/kubernetes/pkg/features"
2624
)
2725

2826
// Checks whether app armor is required for the pod to run. AppArmor is considered required if any
@@ -54,10 +52,6 @@ func isRequired(pod *v1.Pod) bool {
5452

5553
// GetProfileName returns the name of the profile to use with the container.
5654
func GetProfile(pod *v1.Pod, container *v1.Container) *v1.AppArmorProfile {
57-
if !utilfeature.DefaultFeatureGate.Enabled(features.AppArmorFields) {
58-
return getProfileFromPodAnnotations(pod.Annotations, container.Name)
59-
}
60-
6155
if container.SecurityContext != nil && container.SecurityContext.AppArmorProfile != nil {
6256
return container.SecurityContext.AppArmorProfile
6357
}

pkg/security/apparmor/validate.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ import (
2323

2424
"github.com/opencontainers/runc/libcontainer/apparmor"
2525
v1 "k8s.io/api/core/v1"
26-
utilfeature "k8s.io/apiserver/pkg/util/feature"
2726
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
28-
"k8s.io/kubernetes/pkg/features"
2927
)
3028

3129
// Whether AppArmor should be disabled by default.
@@ -89,11 +87,6 @@ func (v *validator) ValidateHost() error {
8987

9088
// validateHost verifies that the host and runtime is capable of enforcing AppArmor profiles.
9189
func validateHost() error {
92-
// Check feature-gates
93-
if !utilfeature.DefaultFeatureGate.Enabled(features.AppArmor) {
94-
return errors.New("AppArmor disabled by feature-gate")
95-
}
96-
9790
// Check build support.
9891
if isDisabledBuild {
9992
return errors.New("binary not compiled for linux")

test/e2e/feature/feature.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ var (
2828
// TODO: document the feature (owning SIG, when to use this feature for a test)
2929
APIServerIdentity = framework.WithFeature(framework.ValidFeatures.Add("APIServerIdentity"))
3030

31-
// TODO: document the feature (owning SIG, when to use this feature for a test)
32-
AppArmor = framework.WithFeature(framework.ValidFeatures.Add("AppArmor"))
33-
3431
// TODO: document the feature (owning SIG, when to use this feature for a test)
3532
BootstrapTokens = framework.WithFeature(framework.ValidFeatures.Add("BootstrapTokens"))
3633

test/e2e/nodefeature/nodefeature.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ import (
2525
var (
2626
// Please keep the list in alphabetical order.
2727

28-
// TODO: document the feature (owning SIG, when to use this feature for a test)
29-
AppArmor = framework.WithNodeFeature(framework.ValidNodeFeatures.Add("AppArmor"))
30-
3128
// TODO: document the feature (owning SIG, when to use this feature for a test)
3229
CheckpointContainer = framework.WithNodeFeature(framework.ValidNodeFeatures.Add("CheckpointContainer"))
3330

0 commit comments

Comments
 (0)