Commit 2b840279 authored by Jordan Liggitt's avatar Jordan Liggitt

Validate service account name in pod spec

parent 9f60f3ce
...@@ -963,6 +963,11 @@ func ValidatePodSpec(spec *api.PodSpec) errs.ValidationErrorList { ...@@ -963,6 +963,11 @@ func ValidatePodSpec(spec *api.PodSpec) errs.ValidationErrorList {
allErrs = append(allErrs, ValidateLabels(spec.NodeSelector, "nodeSelector")...) allErrs = append(allErrs, ValidateLabels(spec.NodeSelector, "nodeSelector")...)
allErrs = append(allErrs, validateHostNetwork(spec.HostNetwork, spec.Containers).Prefix("hostNetwork")...) allErrs = append(allErrs, validateHostNetwork(spec.HostNetwork, spec.Containers).Prefix("hostNetwork")...)
allErrs = append(allErrs, validateImagePullSecrets(spec.ImagePullSecrets).Prefix("imagePullSecrets")...) allErrs = append(allErrs, validateImagePullSecrets(spec.ImagePullSecrets).Prefix("imagePullSecrets")...)
if len(spec.ServiceAccount) > 0 {
if ok, msg := ValidateServiceAccountName(spec.ServiceAccount, false); !ok {
allErrs = append(allErrs, errs.NewFieldInvalid("serviceAccount", spec.ServiceAccount, msg))
}
}
if spec.ActiveDeadlineSeconds != nil { if spec.ActiveDeadlineSeconds != nil {
if *spec.ActiveDeadlineSeconds <= 0 { if *spec.ActiveDeadlineSeconds <= 0 {
......
...@@ -1052,6 +1052,7 @@ func TestValidatePodSpec(t *testing.T) { ...@@ -1052,6 +1052,7 @@ func TestValidatePodSpec(t *testing.T) {
NodeName: "foobar", NodeName: "foobar",
DNSPolicy: api.DNSClusterFirst, DNSPolicy: api.DNSClusterFirst,
ActiveDeadlineSeconds: &activeDeadlineSeconds, ActiveDeadlineSeconds: &activeDeadlineSeconds,
ServiceAccount: "acct",
}, },
{ // Populate HostNetwork. { // Populate HostNetwork.
Containers: []api.Container{ Containers: []api.Container{
...@@ -1092,6 +1093,12 @@ func TestValidatePodSpec(t *testing.T) { ...@@ -1092,6 +1093,12 @@ func TestValidatePodSpec(t *testing.T) {
RestartPolicy: api.RestartPolicyAlways, RestartPolicy: api.RestartPolicyAlways,
Containers: []api.Container{{Name: "ctr", Image: "image", ImagePullPolicy: "IfNotPresent"}}, Containers: []api.Container{{Name: "ctr", Image: "image", ImagePullPolicy: "IfNotPresent"}},
}, },
"bad service account name": {
Containers: []api.Container{{Name: "ctr", Image: "image", ImagePullPolicy: "IfNotPresent"}},
RestartPolicy: api.RestartPolicyAlways,
DNSPolicy: api.DNSClusterFirst,
ServiceAccount: "invalidName",
},
"bad restart policy": { "bad restart policy": {
RestartPolicy: "UnknowPolicy", RestartPolicy: "UnknowPolicy",
DNSPolicy: api.DNSClusterFirst, DNSPolicy: api.DNSClusterFirst,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment