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
9d22f8b5
Commit
9d22f8b5
authored
Mar 11, 2016
by
deads2k
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prevent disallowed secret refs from leaking via the downward API
parent
502d2457
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
9 deletions
+66
-9
admission.go
plugin/pkg/admission/serviceaccount/admission.go
+10
-0
admission_test.go
plugin/pkg/admission/serviceaccount/admission_test.go
+56
-9
No files found.
plugin/pkg/admission/serviceaccount/admission.go
View file @
9d22f8b5
...
...
@@ -324,6 +324,16 @@ func (s *serviceAccount) limitSecretReferences(serviceAccount *api.ServiceAccoun
}
}
for
_
,
container
:=
range
pod
.
Spec
.
Containers
{
for
_
,
env
:=
range
container
.
Env
{
if
env
.
ValueFrom
!=
nil
&&
env
.
ValueFrom
.
SecretKeyRef
!=
nil
{
if
!
mountableSecrets
.
Has
(
env
.
ValueFrom
.
SecretKeyRef
.
Name
)
{
return
fmt
.
Errorf
(
"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
)
}
}
}
}
// limit pull secret references as well
pullSecrets
:=
sets
.
NewString
()
for
_
,
s
:=
range
serviceAccount
.
ImagePullSecrets
{
...
...
plugin/pkg/admission/serviceaccount/admission_test.go
View file @
9d22f8b5
...
...
@@ -18,6 +18,7 @@ package serviceaccount
import
(
"reflect"
"strings"
"testing"
"k8s.io/kubernetes/pkg/admission"
...
...
@@ -367,7 +368,7 @@ func TestRespectsExistingMount(t *testing.T) {
}
}
func
TestAllowsReferencedSecret
Volumes
(
t
*
testing
.
T
)
{
func
TestAllowsReferencedSecret
(
t
*
testing
.
T
)
{
ns
:=
"myns"
admit
:=
NewServiceAccount
(
nil
)
...
...
@@ -385,16 +386,39 @@ func TestAllowsReferencedSecretVolumes(t *testing.T) {
},
})
pod
:=
&
api
.
Pod
{
pod
1
:=
&
api
.
Pod
{
Spec
:
api
.
PodSpec
{
Volumes
:
[]
api
.
Volume
{
{
VolumeSource
:
api
.
VolumeSource
{
Secret
:
&
api
.
SecretVolumeSource
{
SecretName
:
"foo"
}}},
},
},
}
attrs
:=
admission
.
NewAttributesRecord
(
pod
,
api
.
Kind
(
"Pod"
),
ns
,
"myname"
,
api
.
Resource
(
"pods"
),
""
,
admission
.
Create
,
nil
)
err
:=
admit
.
Admit
(
attrs
)
if
err
!=
nil
{
attrs
:=
admission
.
NewAttributesRecord
(
pod1
,
api
.
Kind
(
"Pod"
),
ns
,
"myname"
,
api
.
Resource
(
"pods"
),
""
,
admission
.
Create
,
nil
)
if
err
:=
admit
.
Admit
(
attrs
);
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
}
pod2
:=
&
api
.
Pod
{
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Name
:
"container-1"
,
Env
:
[]
api
.
EnvVar
{
{
Name
:
"env-1"
,
ValueFrom
:
&
api
.
EnvVarSource
{
SecretKeyRef
:
&
api
.
SecretKeySelector
{
LocalObjectReference
:
api
.
LocalObjectReference
{
Name
:
"foo"
},
},
},
},
},
},
},
},
}
attrs
=
admission
.
NewAttributesRecord
(
pod2
,
api
.
Kind
(
"Pod"
),
ns
,
"myname"
,
api
.
Resource
(
"pods"
),
""
,
admission
.
Create
,
nil
)
if
err
:=
admit
.
Admit
(
attrs
);
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
}
}
...
...
@@ -414,18 +438,41 @@ func TestRejectsUnreferencedSecretVolumes(t *testing.T) {
},
})
pod
:=
&
api
.
Pod
{
pod
1
:=
&
api
.
Pod
{
Spec
:
api
.
PodSpec
{
Volumes
:
[]
api
.
Volume
{
{
VolumeSource
:
api
.
VolumeSource
{
Secret
:
&
api
.
SecretVolumeSource
{
SecretName
:
"foo"
}}},
},
},
}
attrs
:=
admission
.
NewAttributesRecord
(
pod
,
api
.
Kind
(
"Pod"
),
ns
,
"myname"
,
api
.
Resource
(
"pods"
),
""
,
admission
.
Create
,
nil
)
err
:=
admit
.
Admit
(
attrs
)
if
err
==
nil
{
attrs
:=
admission
.
NewAttributesRecord
(
pod1
,
api
.
Kind
(
"Pod"
),
ns
,
"myname"
,
api
.
Resource
(
"pods"
),
""
,
admission
.
Create
,
nil
)
if
err
:=
admit
.
Admit
(
attrs
);
err
==
nil
{
t
.
Errorf
(
"Expected rejection for using a secret the service account does not reference"
)
}
pod2
:=
&
api
.
Pod
{
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Name
:
"container-1"
,
Env
:
[]
api
.
EnvVar
{
{
Name
:
"env-1"
,
ValueFrom
:
&
api
.
EnvVarSource
{
SecretKeyRef
:
&
api
.
SecretKeySelector
{
LocalObjectReference
:
api
.
LocalObjectReference
{
Name
:
"foo"
},
},
},
},
},
},
},
},
}
attrs
=
admission
.
NewAttributesRecord
(
pod2
,
api
.
Kind
(
"Pod"
),
ns
,
"myname"
,
api
.
Resource
(
"pods"
),
""
,
admission
.
Create
,
nil
)
if
err
:=
admit
.
Admit
(
attrs
);
err
==
nil
||
!
strings
.
Contains
(
err
.
Error
(),
"with envVar"
)
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
}
}
func
TestAllowUnreferencedSecretVolumesForPermissiveSAs
(
t
*
testing
.
T
)
{
...
...
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