Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
5a27ee92
Commit
5a27ee92
authored
Jul 27, 2018
by
WanLinghao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refuse serviceaccount projection volume request when pod has no serviceaccount bounded
parent
6764a795
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
0 deletions
+43
-0
validation.go
pkg/apis/core/validation/validation.go
+14
-0
validation_test.go
pkg/apis/core/validation/validation_test.go
+29
-0
No files found.
pkg/apis/core/validation/validation.go
View file @
5a27ee92
...
@@ -2913,6 +2913,20 @@ func ValidatePod(pod *core.Pod) field.ErrorList {
...
@@ -2913,6 +2913,20 @@ func ValidatePod(pod *core.Pod) field.ErrorList {
// this was done to preserve backwards compatibility
// this was done to preserve backwards compatibility
specPath
:=
field
.
NewPath
(
"spec"
)
specPath
:=
field
.
NewPath
(
"spec"
)
if
pod
.
Spec
.
ServiceAccountName
==
""
{
for
vi
,
volume
:=
range
pod
.
Spec
.
Volumes
{
path
:=
specPath
.
Child
(
"volumes"
)
.
Index
(
vi
)
.
Child
(
"projected"
)
if
volume
.
Projected
!=
nil
{
for
si
,
source
:=
range
volume
.
Projected
.
Sources
{
saPath
:=
path
.
Child
(
"sources"
)
.
Index
(
si
)
.
Child
(
"serviceAccountToken"
)
if
source
.
ServiceAccountToken
!=
nil
{
allErrs
=
append
(
allErrs
,
field
.
Forbidden
(
saPath
,
"must not be specified when serviceAccountName is not set"
))
}
}
}
}
}
allErrs
=
append
(
allErrs
,
validateContainersOnlyForPod
(
pod
.
Spec
.
Containers
,
specPath
.
Child
(
"containers"
))
...
)
allErrs
=
append
(
allErrs
,
validateContainersOnlyForPod
(
pod
.
Spec
.
Containers
,
specPath
.
Child
(
"containers"
))
...
)
allErrs
=
append
(
allErrs
,
validateContainersOnlyForPod
(
pod
.
Spec
.
InitContainers
,
specPath
.
Child
(
"initContainers"
))
...
)
allErrs
=
append
(
allErrs
,
validateContainersOnlyForPod
(
pod
.
Spec
.
InitContainers
,
specPath
.
Child
(
"initContainers"
))
...
)
...
...
pkg/apis/core/validation/validation_test.go
View file @
5a27ee92
...
@@ -7670,6 +7670,35 @@ func TestValidatePod(t *testing.T) {
...
@@ -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
{
for
k
,
v
:=
range
errorCases
{
if
errs
:=
ValidatePod
(
&
v
.
spec
);
len
(
errs
)
==
0
{
if
errs
:=
ValidatePod
(
&
v
.
spec
);
len
(
errs
)
==
0
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment