Skip to content
This repository was archived by the owner on Oct 12, 2023. It is now read-only.

Commit 11c0c11

Browse files
aramasekkmsft
authored andcommitted
update immutable identity check + tests (#452)
1 parent b64f812 commit 11c0c11

File tree

8 files changed

+11
-15
lines changed

8 files changed

+11
-15
lines changed

charts/aad-pod-identity/templates/mic-deployment.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ spec:
6363
- --clientQps={{ .Values.mic.clientQps }}
6464
{{- end }}
6565
{{- if .Values.mic.immutableUserMSIs }}
66-
- "--immutableUserMSIs={{- join "," .Values.mic.immutableUserMSIs}}"
66+
- "--immutable-user-msis={{- join "," .Values.mic.immutableUserMSIs}}"
6767
{{- end }}
6868
env:
6969
- name: FORCENAMESPACED

cmd/mic/main.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func main() {
7070
flag.Float64Var(&clientQPS, "clientQps", 5, "Client QPS used for throttling of calls to kube-api server")
7171

7272
//Identities that should be never removed from Azure AD (used defined managed identities)
73-
flag.StringVar(&immutableUserMSIs, "immutableUserMSIs", "", "prevent deletion of these IDs from the underlying VM/VMSS")
73+
flag.StringVar(&immutableUserMSIs, "immutable-user-msis", "", "prevent deletion of these IDs from the underlying VM/VMSS")
7474

7575
flag.Parse()
7676
if versionInfo {
@@ -112,7 +112,6 @@ func main() {
112112
if immutableUserMSIs != "" {
113113
immutableUserMSIsList = strings.Split(immutableUserMSIs, ",")
114114
}
115-
glog.Infof("immutable identities are %v", immutableUserMSIsList)
116115

117116
micClient, err := mic.NewMICClient(cloudconfig, config, forceNamespaced, syncRetryDuration, &leaderElectionCfg, enableScaleFeatures, createDeleteBatch, immutableUserMSIsList)
118117
if err != nil {

docs/readmes/README.featureflags.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ their use cases.
4646
## ImmutableUserMSIs flag
4747
> Available from 1.5.4 release
4848
49-
Aad-pod-identity has a new flag `immutableUserMSIs` which can be used to prevent deletion of specified identities from VM/VMSS.
49+
Aad-pod-identity has a new flag `immutable-user-msis` which can be used to prevent deletion of specified identities from VM/VMSS.
5050
The list is comma separated. Example: 00000000-0000-0000-0000-000000000000,11111111-1111-1111-1111-111111111111

pkg/mic/mic.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ func (c *Client) getListOfIdsToDelete(deleteList map[string]aadpodid.AzureAssign
490490

491491
id := delID.Spec.AzureIdentityRef
492492
isUserAssignedMSI := c.checkIfUserAssignedMSI(id)
493-
isImmutableIdentity := c.checkIfIdentityImmutable(id.Spec.ResourceID)
493+
isImmutableIdentity := c.checkIfIdentityImmutable(id.Spec.ClientID)
494494

495495
// this case includes Assigned state and empty state to ensure backward compatability
496496
if delID.Status.Status == aadpodid.AssignedIDAssigned || delID.Status.Status == "" {

pkg/mic/mic_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1440,8 +1440,8 @@ func TestMicAddDelVMSSwithImmutableIdentities(t *testing.T) {
14401440
evtRecorder.lastEvent = new(LastEvent)
14411441
evtRecorder.eventChannel = make(chan bool, 100)
14421442
var immutableUserMSIs = map[string]bool{
1443-
"zero-test": true,
1444-
"test-user-msi-resourceid": true,
1443+
"zero-test": true,
1444+
"test-user-msi-clientid": true,
14451445
}
14461446

14471447
micClient := NewMICTestClient(eventCh, cloudClient, crdClient, podClient, nodeClient, &evtRecorder, false, 4, immutableUserMSIs)

test/e2e/aadpodidentity_test.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -1288,15 +1288,13 @@ func validateAzureAssignedIdentity(azureAssignedIdentity aadpodid.AzureAssignedI
12881288
Expect(azureAssignedIdentity.Spec.AzureIdentityRef.ObjectMeta.Name).To(Equal(identityName))
12891289
Expect(azureAssignedIdentity.Spec.AzureIdentityRef.ObjectMeta.Namespace).To(Equal("default"))
12901290

1291-
if strings.HasPrefix(identityName, keyvaultIdentity) {
1292-
cmdOutput, err := validateUserAssignedIdentityOnPod(podName, identityClientID)
1293-
Expect(errors.Wrap(err, string(cmdOutput))).NotTo(HaveOccurred())
1294-
} else if strings.HasPrefix(identityName, clusterIdentity) {
1291+
if strings.HasPrefix(identityName, clusterIdentity) {
12951292
cmdOutput, err := validateClusterWideUserAssignedIdentity(podName, identityClientID)
12961293
Expect(errors.Wrap(err, string(cmdOutput))).NotTo(HaveOccurred())
12971294
} else {
1298-
err := errors.Errorf("Invalid identity name: %s", identityName)
1299-
Expect(err).NotTo(HaveOccurred())
1295+
// validates user assigned identity - this includes keyvault identities and immutable identities
1296+
cmdOutput, err := validateUserAssignedIdentityOnPod(podName, identityClientID)
1297+
Expect(errors.Wrap(err, string(cmdOutput))).NotTo(HaveOccurred())
13001298
}
13011299

13021300
fmt.Printf("# %s validated!\n", identityName)

test/e2e/template/deployment-rbac-old.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ spec:
191191
args:
192192
{{if .MICArg}}- mic {{ end }}
193193
- "--cloudconfig=/etc/kubernetes/azure.json"
194-
{{if .ImmutableUserMSIs}}- "--immutableUserMSIs={{.ImmutableUserMSIs}}" {{end}}
195194
- "--logtostderr"
196195
volumeMounts:
197196
- name: k8s-azure-file

test/e2e/template/deployment-rbac.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ spec:
222222
args:
223223
{{if .MICArg}}- mic {{ end }}
224224
- "--cloudconfig=/etc/kubernetes/azure.json"
225-
{{if .ImmutableUserMSIs}}- "--immutableUserMSIs={{.ImmutableUserMSIs}}" {{end}}
225+
{{if .ImmutableUserMSIs}}- "--immutable-user-msis={{.ImmutableUserMSIs}}" {{end}}
226226
- "--logtostderr"
227227
{{if .EnableScaleFeatures}}- "--enableScaleFeatures=true" {{end}}
228228
resources:

0 commit comments

Comments
 (0)