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
aaeb1dad
Commit
aaeb1dad
authored
May 13, 2015
by
Paul Weil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
expose user info to admission controllers
parent
fe24da84
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
61 additions
and
48 deletions
+61
-48
attributes.go
pkg/admission/attributes.go
+8
-1
interfaces.go
pkg/admission/interfaces.go
+2
-0
resthandler.go
pkg/apiserver/resthandler.go
+11
-7
admission_test.go
plugin/pkg/admission/deny/admission_test.go
+1
-1
admission_test.go
...n/pkg/admission/namespace/autoprovision/admission_test.go
+4
-4
admission_test.go
plugin/pkg/admission/namespace/lifecycle/admission_test.go
+4
-4
admission_test.go
plugin/pkg/admission/resourcequota/admission_test.go
+15
-15
admission_test.go
...in/pkg/admission/securitycontext/scdeny/admission_test.go
+2
-2
admission_test.go
plugin/pkg/admission/serviceaccount/admission_test.go
+14
-14
No files found.
pkg/admission/attributes.go
View file @
aaeb1dad
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
admission
import
(
"github.com/GoogleCloudPlatform/kubernetes/pkg/auth/user"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
)
...
...
@@ -26,15 +27,17 @@ type attributesRecord struct {
resource
string
operation
string
object
runtime
.
Object
userInfo
user
.
Info
}
func
NewAttributesRecord
(
object
runtime
.
Object
,
kind
,
namespace
,
resource
,
operation
string
)
Attributes
{
func
NewAttributesRecord
(
object
runtime
.
Object
,
kind
,
namespace
,
resource
,
operation
string
,
userInfo
user
.
Info
)
Attributes
{
return
&
attributesRecord
{
kind
:
kind
,
namespace
:
namespace
,
resource
:
resource
,
operation
:
operation
,
object
:
object
,
userInfo
:
userInfo
,
}
}
...
...
@@ -57,3 +60,7 @@ func (record *attributesRecord) GetOperation() string {
func
(
record
*
attributesRecord
)
GetObject
()
runtime
.
Object
{
return
record
.
object
}
func
(
record
*
attributesRecord
)
GetUserInfo
()
user
.
Info
{
return
record
.
userInfo
}
pkg/admission/interfaces.go
View file @
aaeb1dad
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
admission
import
(
"github.com/GoogleCloudPlatform/kubernetes/pkg/auth/user"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
)
...
...
@@ -28,6 +29,7 @@ type Attributes interface {
GetOperation
()
string
GetObject
()
runtime
.
Object
GetKind
()
string
GetUserInfo
()
user
.
Info
}
// Interface is an abstract, pluggable interface for Admission Control decisions.
...
...
pkg/apiserver/resthandler.go
View file @
aaeb1dad
...
...
@@ -293,7 +293,8 @@ func createHandler(r rest.NamedCreater, scope RequestScope, typer runtime.Object
return
}
err
=
admit
.
Admit
(
admission
.
NewAttributesRecord
(
obj
,
scope
.
Kind
,
namespace
,
scope
.
Resource
,
"CREATE"
))
userInfo
,
_
:=
api
.
UserFrom
(
ctx
)
err
=
admit
.
Admit
(
admission
.
NewAttributesRecord
(
obj
,
scope
.
Kind
,
namespace
,
scope
.
Resource
,
"CREATE"
,
userInfo
))
if
err
!=
nil
{
errorJSON
(
err
,
scope
.
Codec
,
w
)
return
...
...
@@ -356,16 +357,17 @@ func PatchResource(r rest.Patcher, scope RequestScope, typer runtime.ObjectTyper
}
obj
:=
r
.
New
()
ctx
:=
scope
.
ContextFunc
(
req
)
ctx
=
api
.
WithNamespace
(
ctx
,
namespace
)
// PATCH requires same permission as UPDATE
err
=
admit
.
Admit
(
admission
.
NewAttributesRecord
(
obj
,
scope
.
Kind
,
namespace
,
scope
.
Resource
,
"UPDATE"
))
userInfo
,
_
:=
api
.
UserFrom
(
ctx
)
err
=
admit
.
Admit
(
admission
.
NewAttributesRecord
(
obj
,
scope
.
Kind
,
namespace
,
scope
.
Resource
,
"UPDATE"
,
userInfo
))
if
err
!=
nil
{
errorJSON
(
err
,
scope
.
Codec
,
w
)
return
}
ctx
:=
scope
.
ContextFunc
(
req
)
ctx
=
api
.
WithNamespace
(
ctx
,
namespace
)
versionedObj
,
err
:=
converter
.
ConvertToVersion
(
obj
,
scope
.
APIVersion
)
if
err
!=
nil
{
errorJSON
(
err
,
scope
.
Codec
,
w
)
...
...
@@ -457,7 +459,8 @@ func UpdateResource(r rest.Updater, scope RequestScope, typer runtime.ObjectType
return
}
err
=
admit
.
Admit
(
admission
.
NewAttributesRecord
(
obj
,
scope
.
Kind
,
namespace
,
scope
.
Resource
,
"UPDATE"
))
userInfo
,
_
:=
api
.
UserFrom
(
ctx
)
err
=
admit
.
Admit
(
admission
.
NewAttributesRecord
(
obj
,
scope
.
Kind
,
namespace
,
scope
.
Resource
,
"UPDATE"
,
userInfo
))
if
err
!=
nil
{
errorJSON
(
err
,
scope
.
Codec
,
w
)
return
...
...
@@ -518,7 +521,8 @@ func DeleteResource(r rest.GracefulDeleter, checkBody bool, scope RequestScope,
}
}
err
=
admit
.
Admit
(
admission
.
NewAttributesRecord
(
nil
,
scope
.
Kind
,
namespace
,
scope
.
Resource
,
"DELETE"
))
userInfo
,
_
:=
api
.
UserFrom
(
ctx
)
err
=
admit
.
Admit
(
admission
.
NewAttributesRecord
(
nil
,
scope
.
Kind
,
namespace
,
scope
.
Resource
,
"DELETE"
,
userInfo
))
if
err
!=
nil
{
errorJSON
(
err
,
scope
.
Codec
,
w
)
return
...
...
plugin/pkg/admission/deny/admission_test.go
View file @
aaeb1dad
...
...
@@ -24,7 +24,7 @@ import (
func
TestAdmission
(
t
*
testing
.
T
)
{
handler
:=
NewAlwaysDeny
()
err
:=
handler
.
Admit
(
admission
.
NewAttributesRecord
(
nil
,
"Pod"
,
"foo"
,
"Pod"
,
"ignored"
))
err
:=
handler
.
Admit
(
admission
.
NewAttributesRecord
(
nil
,
"Pod"
,
"foo"
,
"Pod"
,
"ignored"
,
nil
))
if
err
==
nil
{
t
.
Errorf
(
"Expected error returned from admission handler"
)
}
...
...
plugin/pkg/admission/namespace/autoprovision/admission_test.go
View file @
aaeb1dad
...
...
@@ -41,7 +41,7 @@ func TestAdmission(t *testing.T) {
Containers
:
[]
api
.
Container
{{
Name
:
"ctr"
,
Image
:
"image"
}},
},
}
err
:=
handler
.
Admit
(
admission
.
NewAttributesRecord
(
&
pod
,
"Pod"
,
namespace
,
"pods"
,
"CREATE"
))
err
:=
handler
.
Admit
(
admission
.
NewAttributesRecord
(
&
pod
,
"Pod"
,
namespace
,
"pods"
,
"CREATE"
,
nil
))
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error returned from admission handler"
)
}
...
...
@@ -72,7 +72,7 @@ func TestAdmissionNamespaceExists(t *testing.T) {
Containers
:
[]
api
.
Container
{{
Name
:
"ctr"
,
Image
:
"image"
}},
},
}
err
:=
handler
.
Admit
(
admission
.
NewAttributesRecord
(
&
pod
,
"Pod"
,
namespace
,
"pods"
,
"CREATE"
))
err
:=
handler
.
Admit
(
admission
.
NewAttributesRecord
(
&
pod
,
"Pod"
,
namespace
,
"pods"
,
"CREATE"
,
nil
))
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error returned from admission handler"
)
}
...
...
@@ -96,7 +96,7 @@ func TestIgnoreAdmission(t *testing.T) {
Containers
:
[]
api
.
Container
{{
Name
:
"ctr"
,
Image
:
"image"
}},
},
}
err
:=
handler
.
Admit
(
admission
.
NewAttributesRecord
(
&
pod
,
"Pod"
,
namespace
,
"pods"
,
"UPDATE"
))
err
:=
handler
.
Admit
(
admission
.
NewAttributesRecord
(
&
pod
,
"Pod"
,
namespace
,
"pods"
,
"UPDATE"
,
nil
))
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error returned from admission handler"
)
}
...
...
@@ -123,7 +123,7 @@ func TestAdmissionNamespaceExistsUnknownToHandler(t *testing.T) {
Containers
:
[]
api
.
Container
{{
Name
:
"ctr"
,
Image
:
"image"
}},
},
}
err
:=
handler
.
Admit
(
admission
.
NewAttributesRecord
(
&
pod
,
"Pod"
,
namespace
,
"pods"
,
"CREATE"
))
err
:=
handler
.
Admit
(
admission
.
NewAttributesRecord
(
&
pod
,
"Pod"
,
namespace
,
"pods"
,
"CREATE"
,
nil
))
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error returned from admission handler"
)
}
...
...
plugin/pkg/admission/namespace/lifecycle/admission_test.go
View file @
aaeb1dad
...
...
@@ -50,7 +50,7 @@ func TestAdmission(t *testing.T) {
Containers
:
[]
api
.
Container
{{
Name
:
"ctr"
,
Image
:
"image"
}},
},
}
err
:=
handler
.
Admit
(
admission
.
NewAttributesRecord
(
&
pod
,
"Pod"
,
namespaceObj
.
Namespace
,
"pods"
,
"CREATE"
))
err
:=
handler
.
Admit
(
admission
.
NewAttributesRecord
(
&
pod
,
"Pod"
,
namespaceObj
.
Namespace
,
"pods"
,
"CREATE"
,
nil
))
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error returned from admission handler: %v"
,
err
)
}
...
...
@@ -60,19 +60,19 @@ func TestAdmission(t *testing.T) {
store
.
Add
(
namespaceObj
)
// verify create operations in the namespace cause an error
err
=
handler
.
Admit
(
admission
.
NewAttributesRecord
(
&
pod
,
"Pod"
,
namespaceObj
.
Namespace
,
"pods"
,
"CREATE"
))
err
=
handler
.
Admit
(
admission
.
NewAttributesRecord
(
&
pod
,
"Pod"
,
namespaceObj
.
Namespace
,
"pods"
,
"CREATE"
,
nil
))
if
err
==
nil
{
t
.
Errorf
(
"Expected error rejecting creates in a namespace when it is terminating"
)
}
// verify update operations in the namespace can proceed
err
=
handler
.
Admit
(
admission
.
NewAttributesRecord
(
&
pod
,
"Pod"
,
namespaceObj
.
Namespace
,
"pods"
,
"UPDATE"
))
err
=
handler
.
Admit
(
admission
.
NewAttributesRecord
(
&
pod
,
"Pod"
,
namespaceObj
.
Namespace
,
"pods"
,
"UPDATE"
,
nil
))
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error returned from admission handler: %v"
,
err
)
}
// verify delete operations in the namespace can proceed
err
=
handler
.
Admit
(
admission
.
NewAttributesRecord
(
nil
,
"Pod"
,
namespaceObj
.
Namespace
,
"pods"
,
"DELETE"
))
err
=
handler
.
Admit
(
admission
.
NewAttributesRecord
(
nil
,
"Pod"
,
namespaceObj
.
Namespace
,
"pods"
,
"DELETE"
,
nil
))
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error returned from admission handler: %v"
,
err
)
}
...
...
plugin/pkg/admission/resourcequota/admission_test.go
View file @
aaeb1dad
...
...
@@ -41,7 +41,7 @@ func getResourceRequirements(cpu, memory string) api.ResourceRequirements {
func
TestAdmissionIgnoresDelete
(
t
*
testing
.
T
)
{
namespace
:=
"default"
handler
:=
NewResourceQuota
(
&
testclient
.
Fake
{})
err
:=
handler
.
Admit
(
admission
.
NewAttributesRecord
(
nil
,
"Pod"
,
namespace
,
"pods"
,
"DELETE"
))
err
:=
handler
.
Admit
(
admission
.
NewAttributesRecord
(
nil
,
"Pod"
,
namespace
,
"pods"
,
"DELETE"
,
nil
))
if
err
!=
nil
{
t
.
Errorf
(
"ResourceQuota should admit all deletes"
,
err
)
}
...
...
@@ -67,7 +67,7 @@ func TestIncrementUsagePods(t *testing.T) {
r
:=
api
.
ResourcePods
status
.
Hard
[
r
]
=
resource
.
MustParse
(
"2"
)
status
.
Used
[
r
]
=
resource
.
MustParse
(
"1"
)
dirty
,
err
:=
IncrementUsage
(
admission
.
NewAttributesRecord
(
&
api
.
Pod
{},
"Pod"
,
namespace
,
"pods"
,
"CREATE"
),
status
,
client
)
dirty
,
err
:=
IncrementUsage
(
admission
.
NewAttributesRecord
(
&
api
.
Pod
{},
"Pod"
,
namespace
,
"pods"
,
"CREATE"
,
nil
),
status
,
client
)
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error"
,
err
)
}
...
...
@@ -107,7 +107,7 @@ func TestIncrementUsageMemory(t *testing.T) {
Volumes
:
[]
api
.
Volume
{{
Name
:
"vol"
}},
Containers
:
[]
api
.
Container
{{
Name
:
"ctr"
,
Image
:
"image"
,
Resources
:
getResourceRequirements
(
"100m"
,
"1Gi"
)}},
}}
dirty
,
err
:=
IncrementUsage
(
admission
.
NewAttributesRecord
(
newPod
,
"Pod"
,
namespace
,
"pods"
,
"CREATE"
),
status
,
client
)
dirty
,
err
:=
IncrementUsage
(
admission
.
NewAttributesRecord
(
newPod
,
"Pod"
,
namespace
,
"pods"
,
"CREATE"
,
nil
),
status
,
client
)
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error"
,
err
)
}
...
...
@@ -148,7 +148,7 @@ func TestExceedUsageMemory(t *testing.T) {
Volumes
:
[]
api
.
Volume
{{
Name
:
"vol"
}},
Containers
:
[]
api
.
Container
{{
Name
:
"ctr"
,
Image
:
"image"
,
Resources
:
getResourceRequirements
(
"100m"
,
"3Gi"
)}},
}}
_
,
err
:=
IncrementUsage
(
admission
.
NewAttributesRecord
(
newPod
,
"Pod"
,
namespace
,
"pods"
,
"CREATE"
),
status
,
client
)
_
,
err
:=
IncrementUsage
(
admission
.
NewAttributesRecord
(
newPod
,
"Pod"
,
namespace
,
"pods"
,
"CREATE"
,
nil
),
status
,
client
)
if
err
==
nil
{
t
.
Errorf
(
"Expected memory usage exceeded error"
)
}
...
...
@@ -181,7 +181,7 @@ func TestIncrementUsageCPU(t *testing.T) {
Volumes
:
[]
api
.
Volume
{{
Name
:
"vol"
}},
Containers
:
[]
api
.
Container
{{
Name
:
"ctr"
,
Image
:
"image"
,
Resources
:
getResourceRequirements
(
"100m"
,
"1Gi"
)}},
}}
dirty
,
err
:=
IncrementUsage
(
admission
.
NewAttributesRecord
(
newPod
,
"Pod"
,
namespace
,
"pods"
,
"CREATE"
),
status
,
client
)
dirty
,
err
:=
IncrementUsage
(
admission
.
NewAttributesRecord
(
newPod
,
"Pod"
,
namespace
,
"pods"
,
"CREATE"
,
nil
),
status
,
client
)
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error"
,
err
)
}
...
...
@@ -222,7 +222,7 @@ func TestUnboundedCPU(t *testing.T) {
Volumes
:
[]
api
.
Volume
{{
Name
:
"vol"
}},
Containers
:
[]
api
.
Container
{{
Name
:
"ctr"
,
Image
:
"image"
,
Resources
:
getResourceRequirements
(
"0m"
,
"1Gi"
)}},
}}
_
,
err
:=
IncrementUsage
(
admission
.
NewAttributesRecord
(
newPod
,
"Pod"
,
namespace
,
"pods"
,
"CREATE"
),
status
,
client
)
_
,
err
:=
IncrementUsage
(
admission
.
NewAttributesRecord
(
newPod
,
"Pod"
,
namespace
,
"pods"
,
"CREATE"
,
nil
),
status
,
client
)
if
err
==
nil
{
t
.
Errorf
(
"Expected CPU unbounded usage error"
)
}
...
...
@@ -255,7 +255,7 @@ func TestUnboundedMemory(t *testing.T) {
Volumes
:
[]
api
.
Volume
{{
Name
:
"vol"
}},
Containers
:
[]
api
.
Container
{{
Name
:
"ctr"
,
Image
:
"image"
,
Resources
:
getResourceRequirements
(
"250m"
,
"0"
)}},
}}
_
,
err
:=
IncrementUsage
(
admission
.
NewAttributesRecord
(
newPod
,
"Pod"
,
namespace
,
"pods"
,
"CREATE"
),
status
,
client
)
_
,
err
:=
IncrementUsage
(
admission
.
NewAttributesRecord
(
newPod
,
"Pod"
,
namespace
,
"pods"
,
"CREATE"
,
nil
),
status
,
client
)
if
err
==
nil
{
t
.
Errorf
(
"Expected memory unbounded usage error"
)
}
...
...
@@ -288,7 +288,7 @@ func TestExceedUsageCPU(t *testing.T) {
Volumes
:
[]
api
.
Volume
{{
Name
:
"vol"
}},
Containers
:
[]
api
.
Container
{{
Name
:
"ctr"
,
Image
:
"image"
,
Resources
:
getResourceRequirements
(
"500m"
,
"1Gi"
)}},
}}
_
,
err
:=
IncrementUsage
(
admission
.
NewAttributesRecord
(
newPod
,
"Pod"
,
namespace
,
"pods"
,
"CREATE"
),
status
,
client
)
_
,
err
:=
IncrementUsage
(
admission
.
NewAttributesRecord
(
newPod
,
"Pod"
,
namespace
,
"pods"
,
"CREATE"
,
nil
),
status
,
client
)
if
err
==
nil
{
t
.
Errorf
(
"Expected CPU usage exceeded error"
)
}
...
...
@@ -314,7 +314,7 @@ func TestExceedUsagePods(t *testing.T) {
r
:=
api
.
ResourcePods
status
.
Hard
[
r
]
=
resource
.
MustParse
(
"1"
)
status
.
Used
[
r
]
=
resource
.
MustParse
(
"1"
)
_
,
err
:=
IncrementUsage
(
admission
.
NewAttributesRecord
(
&
api
.
Pod
{},
"Pod"
,
namespace
,
"pods"
,
"CREATE"
),
status
,
client
)
_
,
err
:=
IncrementUsage
(
admission
.
NewAttributesRecord
(
&
api
.
Pod
{},
"Pod"
,
namespace
,
"pods"
,
"CREATE"
,
nil
),
status
,
client
)
if
err
==
nil
{
t
.
Errorf
(
"Expected error because this would exceed your quota"
)
}
...
...
@@ -336,7 +336,7 @@ func TestIncrementUsageServices(t *testing.T) {
r
:=
api
.
ResourceServices
status
.
Hard
[
r
]
=
resource
.
MustParse
(
"2"
)
status
.
Used
[
r
]
=
resource
.
MustParse
(
"1"
)
dirty
,
err
:=
IncrementUsage
(
admission
.
NewAttributesRecord
(
&
api
.
Service
{},
"Service"
,
namespace
,
"services"
,
"CREATE"
),
status
,
client
)
dirty
,
err
:=
IncrementUsage
(
admission
.
NewAttributesRecord
(
&
api
.
Service
{},
"Service"
,
namespace
,
"services"
,
"CREATE"
,
nil
),
status
,
client
)
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error"
,
err
)
}
...
...
@@ -365,7 +365,7 @@ func TestExceedUsageServices(t *testing.T) {
r
:=
api
.
ResourceServices
status
.
Hard
[
r
]
=
resource
.
MustParse
(
"1"
)
status
.
Used
[
r
]
=
resource
.
MustParse
(
"1"
)
_
,
err
:=
IncrementUsage
(
admission
.
NewAttributesRecord
(
&
api
.
Service
{},
"Service"
,
namespace
,
"services"
,
"CREATE"
),
status
,
client
)
_
,
err
:=
IncrementUsage
(
admission
.
NewAttributesRecord
(
&
api
.
Service
{},
"Service"
,
namespace
,
"services"
,
"CREATE"
,
nil
),
status
,
client
)
if
err
==
nil
{
t
.
Errorf
(
"Expected error because this would exceed usage"
)
}
...
...
@@ -387,7 +387,7 @@ func TestIncrementUsageReplicationControllers(t *testing.T) {
r
:=
api
.
ResourceReplicationControllers
status
.
Hard
[
r
]
=
resource
.
MustParse
(
"2"
)
status
.
Used
[
r
]
=
resource
.
MustParse
(
"1"
)
dirty
,
err
:=
IncrementUsage
(
admission
.
NewAttributesRecord
(
&
api
.
ReplicationController
{},
"ReplicationController"
,
namespace
,
"replicationControllers"
,
"CREATE"
),
status
,
client
)
dirty
,
err
:=
IncrementUsage
(
admission
.
NewAttributesRecord
(
&
api
.
ReplicationController
{},
"ReplicationController"
,
namespace
,
"replicationControllers"
,
"CREATE"
,
nil
),
status
,
client
)
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error"
,
err
)
}
...
...
@@ -416,7 +416,7 @@ func TestExceedUsageReplicationControllers(t *testing.T) {
r
:=
api
.
ResourceReplicationControllers
status
.
Hard
[
r
]
=
resource
.
MustParse
(
"1"
)
status
.
Used
[
r
]
=
resource
.
MustParse
(
"1"
)
_
,
err
:=
IncrementUsage
(
admission
.
NewAttributesRecord
(
&
api
.
ReplicationController
{},
"ReplicationController"
,
namespace
,
"replicationControllers"
,
"CREATE"
),
status
,
client
)
_
,
err
:=
IncrementUsage
(
admission
.
NewAttributesRecord
(
&
api
.
ReplicationController
{},
"ReplicationController"
,
namespace
,
"replicationControllers"
,
"CREATE"
,
nil
),
status
,
client
)
if
err
==
nil
{
t
.
Errorf
(
"Expected error for exceeding hard limits"
)
}
...
...
@@ -438,7 +438,7 @@ func TestExceedUsageSecrets(t *testing.T) {
r
:=
api
.
ResourceSecrets
status
.
Hard
[
r
]
=
resource
.
MustParse
(
"1"
)
status
.
Used
[
r
]
=
resource
.
MustParse
(
"1"
)
_
,
err
:=
IncrementUsage
(
admission
.
NewAttributesRecord
(
&
api
.
Secret
{},
"Secret"
,
namespace
,
"secrets"
,
"CREATE"
),
status
,
client
)
_
,
err
:=
IncrementUsage
(
admission
.
NewAttributesRecord
(
&
api
.
Secret
{},
"Secret"
,
namespace
,
"secrets"
,
"CREATE"
,
nil
),
status
,
client
)
if
err
==
nil
{
t
.
Errorf
(
"Expected error for exceeding hard limits"
)
}
...
...
@@ -460,7 +460,7 @@ func TestExceedUsagePersistentVolumeClaims(t *testing.T) {
r
:=
api
.
ResourcePersistentVolumeClaims
status
.
Hard
[
r
]
=
resource
.
MustParse
(
"1"
)
status
.
Used
[
r
]
=
resource
.
MustParse
(
"1"
)
_
,
err
:=
IncrementUsage
(
admission
.
NewAttributesRecord
(
&
api
.
PersistentVolumeClaim
{},
"PersistentVolumeClaim"
,
namespace
,
"persistentVolumeClaims"
,
"CREATE"
),
status
,
client
)
_
,
err
:=
IncrementUsage
(
admission
.
NewAttributesRecord
(
&
api
.
PersistentVolumeClaim
{},
"PersistentVolumeClaim"
,
namespace
,
"persistentVolumeClaims"
,
"CREATE"
,
nil
),
status
,
client
)
if
err
==
nil
{
t
.
Errorf
(
"Expected error for exceeding hard limits"
)
}
...
...
plugin/pkg/admission/securitycontext/scdeny/admission_test.go
View file @
aaeb1dad
...
...
@@ -44,7 +44,7 @@ func TestAdmission(t *testing.T) {
}
for
k
,
v
:=
range
successCases
{
pod
.
Spec
.
Containers
[
0
]
.
SecurityContext
=
v
err
:=
handler
.
Admit
(
admission
.
NewAttributesRecord
(
&
pod
,
"Pod"
,
"foo"
,
string
(
api
.
ResourcePods
),
"ignored"
))
err
:=
handler
.
Admit
(
admission
.
NewAttributesRecord
(
&
pod
,
"Pod"
,
"foo"
,
string
(
api
.
ResourcePods
),
"ignored"
,
nil
))
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error returned from admission handler for case %s"
,
k
)
}
...
...
@@ -57,7 +57,7 @@ func TestAdmission(t *testing.T) {
}
for
k
,
v
:=
range
errorCases
{
pod
.
Spec
.
Containers
[
0
]
.
SecurityContext
=
v
err
:=
handler
.
Admit
(
admission
.
NewAttributesRecord
(
&
pod
,
"Pod"
,
"foo"
,
string
(
api
.
ResourcePods
),
"ignored"
))
err
:=
handler
.
Admit
(
admission
.
NewAttributesRecord
(
&
pod
,
"Pod"
,
"foo"
,
string
(
api
.
ResourcePods
),
"ignored"
,
nil
))
if
err
==
nil
{
t
.
Errorf
(
"Expected error returned from admission handler for case %s"
,
k
)
}
...
...
plugin/pkg/admission/serviceaccount/admission_test.go
View file @
aaeb1dad
...
...
@@ -30,7 +30,7 @@ import (
func
TestIgnoresNonCreate
(
t
*
testing
.
T
)
{
pod
:=
&
api
.
Pod
{}
for
_
,
op
:=
range
[]
string
{
"UPDATE"
,
"DELETE"
,
"CUSTOM"
}
{
attrs
:=
admission
.
NewAttributesRecord
(
pod
,
"Pod"
,
"myns"
,
string
(
api
.
ResourcePods
),
op
)
attrs
:=
admission
.
NewAttributesRecord
(
pod
,
"Pod"
,
"myns"
,
string
(
api
.
ResourcePods
),
op
,
nil
)
err
:=
NewServiceAccount
(
nil
)
.
Admit
(
attrs
)
if
err
!=
nil
{
t
.
Errorf
(
"Expected %s operation allowed, got err: %v"
,
op
,
err
)
...
...
@@ -40,7 +40,7 @@ func TestIgnoresNonCreate(t *testing.T) {
func
TestIgnoresNonPodResource
(
t
*
testing
.
T
)
{
pod
:=
&
api
.
Pod
{}
attrs
:=
admission
.
NewAttributesRecord
(
pod
,
"Pod"
,
"myns"
,
"CustomResource"
,
"CREATE"
)
attrs
:=
admission
.
NewAttributesRecord
(
pod
,
"Pod"
,
"myns"
,
"CustomResource"
,
"CREATE"
,
nil
)
err
:=
NewServiceAccount
(
nil
)
.
Admit
(
attrs
)
if
err
!=
nil
{
t
.
Errorf
(
"Expected non-pod resource allowed, got err: %v"
,
err
)
...
...
@@ -48,7 +48,7 @@ func TestIgnoresNonPodResource(t *testing.T) {
}
func
TestIgnoresNilObject
(
t
*
testing
.
T
)
{
attrs
:=
admission
.
NewAttributesRecord
(
nil
,
"Pod"
,
"myns"
,
string
(
api
.
ResourcePods
),
"CREATE"
)
attrs
:=
admission
.
NewAttributesRecord
(
nil
,
"Pod"
,
"myns"
,
string
(
api
.
ResourcePods
),
"CREATE"
,
nil
)
err
:=
NewServiceAccount
(
nil
)
.
Admit
(
attrs
)
if
err
!=
nil
{
t
.
Errorf
(
"Expected nil object allowed allowed, got err: %v"
,
err
)
...
...
@@ -57,7 +57,7 @@ func TestIgnoresNilObject(t *testing.T) {
func
TestIgnoresNonPodObject
(
t
*
testing
.
T
)
{
obj
:=
&
api
.
Namespace
{}
attrs
:=
admission
.
NewAttributesRecord
(
obj
,
"Pod"
,
"myns"
,
string
(
api
.
ResourcePods
),
"CREATE"
)
attrs
:=
admission
.
NewAttributesRecord
(
obj
,
"Pod"
,
"myns"
,
string
(
api
.
ResourcePods
),
"CREATE"
,
nil
)
err
:=
NewServiceAccount
(
nil
)
.
Admit
(
attrs
)
if
err
!=
nil
{
t
.
Errorf
(
"Expected non pod object allowed, got err: %v"
,
err
)
...
...
@@ -77,7 +77,7 @@ func TestIgnoresMirrorPod(t *testing.T) {
},
},
}
attrs
:=
admission
.
NewAttributesRecord
(
pod
,
"Pod"
,
"myns"
,
string
(
api
.
ResourcePods
),
"CREATE"
)
attrs
:=
admission
.
NewAttributesRecord
(
pod
,
"Pod"
,
"myns"
,
string
(
api
.
ResourcePods
),
"CREATE"
,
nil
)
err
:=
NewServiceAccount
(
nil
)
.
Admit
(
attrs
)
if
err
!=
nil
{
t
.
Errorf
(
"Expected mirror pod without service account or secrets allowed, got err: %v"
,
err
)
...
...
@@ -95,7 +95,7 @@ func TestRejectsMirrorPodWithServiceAccount(t *testing.T) {
ServiceAccount
:
"default"
,
},
}
attrs
:=
admission
.
NewAttributesRecord
(
pod
,
"Pod"
,
"myns"
,
string
(
api
.
ResourcePods
),
"CREATE"
)
attrs
:=
admission
.
NewAttributesRecord
(
pod
,
"Pod"
,
"myns"
,
string
(
api
.
ResourcePods
),
"CREATE"
,
nil
)
err
:=
NewServiceAccount
(
nil
)
.
Admit
(
attrs
)
if
err
==
nil
{
t
.
Errorf
(
"Expected a mirror pod to be prevented from referencing a service account"
)
...
...
@@ -115,7 +115,7 @@ func TestRejectsMirrorPodWithSecretVolumes(t *testing.T) {
},
},
}
attrs
:=
admission
.
NewAttributesRecord
(
pod
,
"Pod"
,
"myns"
,
string
(
api
.
ResourcePods
),
"CREATE"
)
attrs
:=
admission
.
NewAttributesRecord
(
pod
,
"Pod"
,
"myns"
,
string
(
api
.
ResourcePods
),
"CREATE"
,
nil
)
err
:=
NewServiceAccount
(
nil
)
.
Admit
(
attrs
)
if
err
==
nil
{
t
.
Errorf
(
"Expected a mirror pod to be prevented from referencing a secret volume"
)
...
...
@@ -137,7 +137,7 @@ func TestAssignsDefaultServiceAccountAndToleratesMissingAPIToken(t *testing.T) {
})
pod
:=
&
api
.
Pod
{}
attrs
:=
admission
.
NewAttributesRecord
(
pod
,
"Pod"
,
ns
,
string
(
api
.
ResourcePods
),
"CREATE"
)
attrs
:=
admission
.
NewAttributesRecord
(
pod
,
"Pod"
,
ns
,
string
(
api
.
ResourcePods
),
"CREATE"
,
nil
)
err
:=
admit
.
Admit
(
attrs
)
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
...
...
@@ -161,7 +161,7 @@ func TestFetchesUncachedServiceAccount(t *testing.T) {
admit
:=
NewServiceAccount
(
client
)
pod
:=
&
api
.
Pod
{}
attrs
:=
admission
.
NewAttributesRecord
(
pod
,
"Pod"
,
ns
,
string
(
api
.
ResourcePods
),
"CREATE"
)
attrs
:=
admission
.
NewAttributesRecord
(
pod
,
"Pod"
,
ns
,
string
(
api
.
ResourcePods
),
"CREATE"
,
nil
)
err
:=
admit
.
Admit
(
attrs
)
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
...
...
@@ -180,7 +180,7 @@ func TestDeniesInvalidServiceAccount(t *testing.T) {
admit
:=
NewServiceAccount
(
client
)
pod
:=
&
api
.
Pod
{}
attrs
:=
admission
.
NewAttributesRecord
(
pod
,
"Pod"
,
ns
,
string
(
api
.
ResourcePods
),
"CREATE"
)
attrs
:=
admission
.
NewAttributesRecord
(
pod
,
"Pod"
,
ns
,
string
(
api
.
ResourcePods
),
"CREATE"
,
nil
)
err
:=
admit
.
Admit
(
attrs
)
if
err
==
nil
{
t
.
Errorf
(
"Expected error for missing service account, got none"
)
...
...
@@ -242,7 +242,7 @@ func TestAutomountsAPIToken(t *testing.T) {
},
},
}
attrs
:=
admission
.
NewAttributesRecord
(
pod
,
"Pod"
,
ns
,
string
(
api
.
ResourcePods
),
"CREATE"
)
attrs
:=
admission
.
NewAttributesRecord
(
pod
,
"Pod"
,
ns
,
string
(
api
.
ResourcePods
),
"CREATE"
,
nil
)
err
:=
admit
.
Admit
(
attrs
)
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
...
...
@@ -320,7 +320,7 @@ func TestRespectsExistingMount(t *testing.T) {
},
},
}
attrs
:=
admission
.
NewAttributesRecord
(
pod
,
"Pod"
,
ns
,
string
(
api
.
ResourcePods
),
"CREATE"
)
attrs
:=
admission
.
NewAttributesRecord
(
pod
,
"Pod"
,
ns
,
string
(
api
.
ResourcePods
),
"CREATE"
,
nil
)
err
:=
admit
.
Admit
(
attrs
)
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
...
...
@@ -363,7 +363,7 @@ func TestAllowsReferencedSecretVolumes(t *testing.T) {
},
},
}
attrs
:=
admission
.
NewAttributesRecord
(
pod
,
"Pod"
,
ns
,
string
(
api
.
ResourcePods
),
"CREATE"
)
attrs
:=
admission
.
NewAttributesRecord
(
pod
,
"Pod"
,
ns
,
string
(
api
.
ResourcePods
),
"CREATE"
,
nil
)
err
:=
admit
.
Admit
(
attrs
)
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
...
...
@@ -391,7 +391,7 @@ func TestRejectsUnreferencedSecretVolumes(t *testing.T) {
},
},
}
attrs
:=
admission
.
NewAttributesRecord
(
pod
,
"Pod"
,
ns
,
string
(
api
.
ResourcePods
),
"CREATE"
)
attrs
:=
admission
.
NewAttributesRecord
(
pod
,
"Pod"
,
ns
,
string
(
api
.
ResourcePods
),
"CREATE"
,
nil
)
err
:=
admit
.
Admit
(
attrs
)
if
err
==
nil
{
t
.
Errorf
(
"Expected rejection for using a secret the service account does not reference"
)
...
...
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