@@ -1062,6 +1062,11 @@ type ServiceAccount struct {
...
@@ -1062,6 +1062,11 @@ type ServiceAccount struct {
// Secrets is the list of secrets allowed to be used by pods running using this ServiceAccount
// Secrets is the list of secrets allowed to be used by pods running using this ServiceAccount
Secrets[]ObjectReference`json:"secrets"`
Secrets[]ObjectReference`json:"secrets"`
// ImagePullSecrets is a list of references to secrets in the same namespace to use for pulling any images
// in pods that reference this ServiceAccount. ImagePullSecrets are distinct from Secrets because Secrets
// can be mounted in the pod, but ImagePullSecrets are only accessed by the kubelet.
ImagePullSecrets[]LocalObjectReference`json:"imagePullSecrets,omitempty" description:"list of references to secrets in the same namespace available for pulling container images"`
}
}
// ServiceAccountList is a list of ServiceAccount objects
// ServiceAccountList is a list of ServiceAccount objects
@@ -1053,6 +1053,11 @@ type ServiceAccount struct {
...
@@ -1053,6 +1053,11 @@ type ServiceAccount struct {
// Secrets is the list of secrets allowed to be used by pods running using this ServiceAccount
// Secrets is the list of secrets allowed to be used by pods running using this ServiceAccount
Secrets[]ObjectReference`json:"secrets,omitempty" description:"list of secrets that can be used by pods running as this service account" patchStrategy:"merge" patchMergeKey:"name"`
Secrets[]ObjectReference`json:"secrets,omitempty" description:"list of secrets that can be used by pods running as this service account" patchStrategy:"merge" patchMergeKey:"name"`
// ImagePullSecrets is a list of references to secrets in the same namespace to use for pulling any images
// in pods that reference this ServiceAccount. ImagePullSecrets are distinct from Secrets because Secrets
// can be mounted in the pod, but ImagePullSecrets are only accessed by the kubelet.
ImagePullSecrets[]LocalObjectReference`json:"imagePullSecrets,omitempty" description:"list of references to secrets in the same namespace available for pulling container images"`
}
}
// ServiceAccountList is a list of ServiceAccount objects
// ServiceAccountList is a list of ServiceAccount objects
// Secrets is the list of secrets allowed to be used by pods running using this ServiceAccount
// Secrets is the list of secrets allowed to be used by pods running using this ServiceAccount
Secrets[]ObjectReference`json:"secrets" description:"list of secrets that can be used by pods running as this service account" patchStrategy:"merge" patchMergeKey:"name"`
Secrets[]ObjectReference`json:"secrets" description:"list of secrets that can be used by pods running as this service account" patchStrategy:"merge" patchMergeKey:"name"`
// ImagePullSecrets is a list of references to secrets in the same namespace to use for pulling any images
// in pods that reference this ServiceAccount. ImagePullSecrets are distinct from Secrets because Secrets
// can be mounted in the pod, but ImagePullSecrets are only accessed by the kubelet.
ImagePullSecrets[]LocalObjectReference`json:"imagePullSecrets,omitempty" description:"list of references to secrets in the same namespace available for pulling container images"`
}
}
// ServiceAccountList is a list of ServiceAccount objects
// ServiceAccountList is a list of ServiceAccount objects
// Secrets is the list of secrets allowed to be used by pods running using this ServiceAccount
// Secrets is the list of secrets allowed to be used by pods running using this ServiceAccount
Secrets[]ObjectReference`json:"secrets" description:"list of secrets that can be used by pods running as this service account" patchStrategy:"merge" patchMergeKey:"name"`
Secrets[]ObjectReference`json:"secrets" description:"list of secrets that can be used by pods running as this service account" patchStrategy:"merge" patchMergeKey:"name"`
// ImagePullSecrets is a list of references to secrets in the same namespace to use for pulling any images
// in pods that reference this ServiceAccount. ImagePullSecrets are distinct from Secrets because Secrets
// can be mounted in the pod, but ImagePullSecrets are only accessed by the kubelet.
ImagePullSecrets[]LocalObjectReference`json:"imagePullSecrets,omitempty" description:"list of references to secrets in the same namespace available for pulling container images"`
}
}
// ServiceAccountList is a list of ServiceAccount objects
// ServiceAccountList is a list of ServiceAccount objects
@@ -1057,6 +1057,11 @@ type ServiceAccount struct {
...
@@ -1057,6 +1057,11 @@ type ServiceAccount struct {
// Secrets is the list of secrets allowed to be used by pods running using this ServiceAccount
// Secrets is the list of secrets allowed to be used by pods running using this ServiceAccount
Secrets[]ObjectReference`json:"secrets,omitempty" description:"list of secrets that can be used by pods running as this service account" patchStrategy:"merge" patchMergeKey:"name"`
Secrets[]ObjectReference`json:"secrets,omitempty" description:"list of secrets that can be used by pods running as this service account" patchStrategy:"merge" patchMergeKey:"name"`
// ImagePullSecrets is a list of references to secrets in the same namespace to use for pulling any images
// in pods that reference this ServiceAccount. ImagePullSecrets are distinct from Secrets because Secrets
// can be mounted in the pod, but ImagePullSecrets are only accessed by the kubelet.
ImagePullSecrets[]LocalObjectReference`json:"imagePullSecrets,omitempty" description:"list of references to secrets in the same namespace available for pulling container images"`
}
}
// ServiceAccountList is a list of ServiceAccount objects
// ServiceAccountList is a list of ServiceAccount objects
// Ensure all secrets the pod references are allowed by the service account
// Ensure all secrets the pod references are allowed by the service account
referencedSecrets:=util.NewStringSet()
mountableSecrets:=util.NewStringSet()
for_,s:=rangeserviceAccount.Secrets{
for_,s:=rangeserviceAccount.Secrets{
referencedSecrets.Insert(s.Name)
mountableSecrets.Insert(s.Name)
}
}
for_,volume:=rangepod.Spec.Volumes{
for_,volume:=rangepod.Spec.Volumes{
source:=volume.VolumeSource
source:=volume.VolumeSource
...
@@ -292,10 +298,21 @@ func (s *serviceAccount) limitSecretReferences(serviceAccount *api.ServiceAccoun
...
@@ -292,10 +298,21 @@ func (s *serviceAccount) limitSecretReferences(serviceAccount *api.ServiceAccoun
continue
continue
}
}
secretName:=source.Secret.SecretName
secretName:=source.Secret.SecretName
if!referencedSecrets.Has(secretName){
if!mountableSecrets.Has(secretName){
returnfmt.Errorf("Volume with secret.secretName=\"%s\" is not allowed because service account %s does not reference that secret",secretName,serviceAccount.Name)
returnfmt.Errorf("Volume with secret.secretName=\"%s\" is not allowed because service account %s does not reference that secret",secretName,serviceAccount.Name)
returnfmt.Errorf(`imagePullSecrets[%d].name="%s" is not allowed because service account %s does not reference that imagePullSecret`,i,pullSecretRef.Name,serviceAccount.Name)