refuse serviceaccount projection volume request when pod has no serviceaccount bounded

This commit is contained in:
WanLinghao
2018-07-27 10:52:36 +08:00
parent 6764a79586
commit 5a27ee9282
2 changed files with 43 additions and 0 deletions

View File

@@ -7670,6 +7670,35 @@ func TestValidatePod(t *testing.T) {
},
},
},
"serviceaccount token projected volume with no serviceaccount name specified": {
expectedError: "must not be specified when serviceAccountName is not set",
spec: core.Pod{
ObjectMeta: metav1.ObjectMeta{Name: "123", Namespace: "ns"},
Spec: core.PodSpec{
Containers: []core.Container{{Name: "ctr", Image: "image", ImagePullPolicy: "IfNotPresent", TerminationMessagePolicy: "File"}},
RestartPolicy: core.RestartPolicyAlways,
DNSPolicy: core.DNSClusterFirst,
Volumes: []core.Volume{
{
Name: "projected-volume",
VolumeSource: core.VolumeSource{
Projected: &core.ProjectedVolumeSource{
Sources: []core.VolumeProjection{
{
ServiceAccountToken: &core.ServiceAccountTokenProjection{
Audience: "foo-audience",
ExpirationSeconds: 6000,
Path: "foo-path",
},
},
},
},
},
},
},
},
},
},
}
for k, v := range errorCases {
if errs := ValidatePod(&v.spec); len(errs) == 0 {