-
Notifications
You must be signed in to change notification settings - Fork 38.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add init containers to PSP admission #25830
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -324,6 +324,16 @@ func (s *serviceAccount) limitSecretReferences(serviceAccount *api.ServiceAccoun | |
} | ||
} | ||
|
||
for _, container := range pod.Spec.InitContainers { | ||
for _, env := range container.Env { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extract method? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Message would be different There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, agree it's not worth it here. |
||
if env.ValueFrom != nil && env.ValueFrom.SecretKeyRef != nil { | ||
if !mountableSecrets.Has(env.ValueFrom.SecretKeyRef.Name) { | ||
return fmt.Errorf("Init container %s with envVar %s referencing secret.secretName=\"%s\" is not allowed because service account %s does not reference that secret", container.Name, env.Name, env.ValueFrom.SecretKeyRef.Name, serviceAccount.Name) | ||
} | ||
} | ||
} | ||
} | ||
|
||
for _, container := range pod.Spec.Containers { | ||
for _, env := range container.Env { | ||
if env.ValueFrom != nil && env.ValueFrom.SecretKeyRef != nil { | ||
|
@@ -394,6 +404,20 @@ func (s *serviceAccount) mountServiceAccountToken(serviceAccount *api.ServiceAcc | |
|
||
// Ensure every container mounts the APISecret volume | ||
needsTokenVolume := false | ||
for i, container := range pod.Spec.InitContainers { | ||
existingContainerMount := false | ||
for _, volumeMount := range container.VolumeMounts { | ||
// Existing mounts at the default mount path prevent mounting of the API token | ||
if volumeMount.MountPath == DefaultAPITokenMountPath { | ||
existingContainerMount = true | ||
break | ||
} | ||
} | ||
if !existingContainerMount { | ||
pod.Spec.InitContainers[i].VolumeMounts = append(pod.Spec.InitContainers[i].VolumeMounts, volumeMount) | ||
needsTokenVolume = true | ||
} | ||
} | ||
for i, container := range pod.Spec.Containers { | ||
existingContainerMount := false | ||
for _, volumeMount := range container.VolumeMounts { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not extract a method here
denyContainerSecurityContext
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could do it here and technically save lines but it's not worth much.