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
e3e25df5
Unverified
Commit
e3e25df5
authored
Jul 10, 2017
by
Jordan Liggitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve node restriction message
parent
5ca03d67
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
17 deletions
+17
-17
admission.go
plugin/pkg/admission/noderestriction/admission.go
+13
-13
node_authorizer.go
plugin/pkg/auth/authorizer/node/node_authorizer.go
+4
-4
No files found.
plugin/pkg/admission/noderestriction/admission.go
View file @
e3e25df5
...
@@ -92,7 +92,7 @@ func (c *nodePlugin) Admit(a admission.Attributes) error {
...
@@ -92,7 +92,7 @@ func (c *nodePlugin) Admit(a admission.Attributes) error {
if
len
(
nodeName
)
==
0
{
if
len
(
nodeName
)
==
0
{
// disallow requests we cannot match to a particular node
// disallow requests we cannot match to a particular node
return
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"could not determine node from user %
s
"
,
a
.
GetUserInfo
()
.
GetName
()))
return
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"could not determine node from user %
q
"
,
a
.
GetUserInfo
()
.
GetName
()))
}
}
switch
a
.
GetResource
()
.
GroupResource
()
{
switch
a
.
GetResource
()
.
GroupResource
()
{
...
@@ -103,7 +103,7 @@ func (c *nodePlugin) Admit(a admission.Attributes) error {
...
@@ -103,7 +103,7 @@ func (c *nodePlugin) Admit(a admission.Attributes) error {
case
"status"
:
case
"status"
:
return
c
.
admitPodStatus
(
nodeName
,
a
)
return
c
.
admitPodStatus
(
nodeName
,
a
)
default
:
default
:
return
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"unexpected pod subresource %
s
"
,
a
.
GetSubresource
()))
return
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"unexpected pod subresource %
q
"
,
a
.
GetSubresource
()))
}
}
case
nodeResource
:
case
nodeResource
:
...
@@ -125,31 +125,31 @@ func (c *nodePlugin) admitPod(nodeName string, a admission.Attributes) error {
...
@@ -125,31 +125,31 @@ func (c *nodePlugin) admitPod(nodeName string, a admission.Attributes) error {
// only allow nodes to create mirror pods
// only allow nodes to create mirror pods
if
_
,
isMirrorPod
:=
pod
.
Annotations
[
api
.
MirrorPodAnnotationKey
];
!
isMirrorPod
{
if
_
,
isMirrorPod
:=
pod
.
Annotations
[
api
.
MirrorPodAnnotationKey
];
!
isMirrorPod
{
return
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"pod does not have %q annotation, node %
s
can only create mirror pods"
,
api
.
MirrorPodAnnotationKey
,
nodeName
))
return
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"pod does not have %q annotation, node %
q
can only create mirror pods"
,
api
.
MirrorPodAnnotationKey
,
nodeName
))
}
}
// only allow nodes to create a pod bound to itself
// only allow nodes to create a pod bound to itself
if
pod
.
Spec
.
NodeName
!=
nodeName
{
if
pod
.
Spec
.
NodeName
!=
nodeName
{
return
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"node %
s
can only create pods with spec.nodeName set to itself"
,
nodeName
))
return
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"node %
q
can only create pods with spec.nodeName set to itself"
,
nodeName
))
}
}
// don't allow a node to create a pod that references any other API objects
// don't allow a node to create a pod that references any other API objects
if
pod
.
Spec
.
ServiceAccountName
!=
""
{
if
pod
.
Spec
.
ServiceAccountName
!=
""
{
return
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"node %
s
can not create pods that reference a service account"
,
nodeName
))
return
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"node %
q
can not create pods that reference a service account"
,
nodeName
))
}
}
hasSecrets
:=
false
hasSecrets
:=
false
podutil
.
VisitPodSecretNames
(
pod
,
func
(
name
string
)
(
shouldContinue
bool
)
{
hasSecrets
=
true
;
return
false
})
podutil
.
VisitPodSecretNames
(
pod
,
func
(
name
string
)
(
shouldContinue
bool
)
{
hasSecrets
=
true
;
return
false
})
if
hasSecrets
{
if
hasSecrets
{
return
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"node %
s
can not create pods that reference secrets"
,
nodeName
))
return
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"node %
q
can not create pods that reference secrets"
,
nodeName
))
}
}
hasConfigMaps
:=
false
hasConfigMaps
:=
false
podutil
.
VisitPodConfigmapNames
(
pod
,
func
(
name
string
)
(
shouldContinue
bool
)
{
hasConfigMaps
=
true
;
return
false
})
podutil
.
VisitPodConfigmapNames
(
pod
,
func
(
name
string
)
(
shouldContinue
bool
)
{
hasConfigMaps
=
true
;
return
false
})
if
hasConfigMaps
{
if
hasConfigMaps
{
return
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"node %
s
can not create pods that reference configmaps"
,
nodeName
))
return
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"node %
q
can not create pods that reference configmaps"
,
nodeName
))
}
}
for
_
,
v
:=
range
pod
.
Spec
.
Volumes
{
for
_
,
v
:=
range
pod
.
Spec
.
Volumes
{
if
v
.
PersistentVolumeClaim
!=
nil
{
if
v
.
PersistentVolumeClaim
!=
nil
{
return
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"node %
s
can not create pods that reference persistentvolumeclaims"
,
nodeName
))
return
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"node %
q
can not create pods that reference persistentvolumeclaims"
,
nodeName
))
}
}
}
}
...
@@ -167,12 +167,12 @@ func (c *nodePlugin) admitPod(nodeName string, a admission.Attributes) error {
...
@@ -167,12 +167,12 @@ func (c *nodePlugin) admitPod(nodeName string, a admission.Attributes) error {
}
}
// only allow a node to delete a pod bound to itself
// only allow a node to delete a pod bound to itself
if
existingPod
.
Spec
.
NodeName
!=
nodeName
{
if
existingPod
.
Spec
.
NodeName
!=
nodeName
{
return
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"node %
s
can only delete pods with spec.nodeName set to itself"
,
nodeName
))
return
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"node %
q
can only delete pods with spec.nodeName set to itself"
,
nodeName
))
}
}
return
nil
return
nil
default
:
default
:
return
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"unexpected operation %
s
"
,
a
.
GetOperation
()))
return
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"unexpected operation %
q
"
,
a
.
GetOperation
()))
}
}
}
}
...
@@ -186,12 +186,12 @@ func (c *nodePlugin) admitPodStatus(nodeName string, a admission.Attributes) err
...
@@ -186,12 +186,12 @@ func (c *nodePlugin) admitPodStatus(nodeName string, a admission.Attributes) err
}
}
// only allow a node to update status of a pod bound to itself
// only allow a node to update status of a pod bound to itself
if
pod
.
Spec
.
NodeName
!=
nodeName
{
if
pod
.
Spec
.
NodeName
!=
nodeName
{
return
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"node %
s
can only update pod status for pods with spec.nodeName set to itself"
,
nodeName
))
return
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"node %
q
can only update pod status for pods with spec.nodeName set to itself"
,
nodeName
))
}
}
return
nil
return
nil
default
:
default
:
return
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"unexpected operation %
s
"
,
a
.
GetOperation
()))
return
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"unexpected operation %
q
"
,
a
.
GetOperation
()))
}
}
}
}
...
@@ -208,7 +208,7 @@ func (c *nodePlugin) admitNode(nodeName string, a admission.Attributes) error {
...
@@ -208,7 +208,7 @@ func (c *nodePlugin) admitNode(nodeName string, a admission.Attributes) error {
}
}
if
requestedName
!=
nodeName
{
if
requestedName
!=
nodeName
{
return
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"node %
s cannot modify node %s
"
,
nodeName
,
requestedName
))
return
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"node %
q cannot modify node %q
"
,
nodeName
,
requestedName
))
}
}
return
nil
return
nil
}
}
plugin/pkg/auth/authorizer/node/node_authorizer.go
View file @
e3e25df5
...
@@ -113,7 +113,7 @@ func (r *NodeAuthorizer) authorizeGet(nodeName string, startingType vertexType,
...
@@ -113,7 +113,7 @@ func (r *NodeAuthorizer) authorizeGet(nodeName string, startingType vertexType,
return
false
,
"no path found to object"
,
nil
return
false
,
"no path found to object"
,
nil
}
}
if
!
ok
{
if
!
ok
{
glog
.
V
(
2
)
.
Infof
(
"NODE DENY: %
s
%#v"
,
nodeName
,
attrs
)
glog
.
V
(
2
)
.
Infof
(
"NODE DENY: %
q
%#v"
,
nodeName
,
attrs
)
return
false
,
"no path found to object"
,
nil
return
false
,
"no path found to object"
,
nil
}
}
return
ok
,
""
,
nil
return
ok
,
""
,
nil
...
@@ -126,12 +126,12 @@ func (r *NodeAuthorizer) hasPathFrom(nodeName string, startingType vertexType, s
...
@@ -126,12 +126,12 @@ func (r *NodeAuthorizer) hasPathFrom(nodeName string, startingType vertexType, s
nodeVertex
,
exists
:=
r
.
graph
.
getVertex_rlocked
(
nodeVertexType
,
""
,
nodeName
)
nodeVertex
,
exists
:=
r
.
graph
.
getVertex_rlocked
(
nodeVertexType
,
""
,
nodeName
)
if
!
exists
{
if
!
exists
{
return
false
,
fmt
.
Errorf
(
"unknown node %
s
cannot get %s %s/%s"
,
nodeName
,
vertexTypes
[
startingType
],
startingNamespace
,
startingName
)
return
false
,
fmt
.
Errorf
(
"unknown node %
q
cannot get %s %s/%s"
,
nodeName
,
vertexTypes
[
startingType
],
startingNamespace
,
startingName
)
}
}
startingVertex
,
exists
:=
r
.
graph
.
getVertex_rlocked
(
startingType
,
startingNamespace
,
startingName
)
startingVertex
,
exists
:=
r
.
graph
.
getVertex_rlocked
(
startingType
,
startingNamespace
,
startingName
)
if
!
exists
{
if
!
exists
{
return
false
,
fmt
.
Errorf
(
"node %
s
cannot get unknown %s %s/%s"
,
nodeName
,
vertexTypes
[
startingType
],
startingNamespace
,
startingName
)
return
false
,
fmt
.
Errorf
(
"node %
q
cannot get unknown %s %s/%s"
,
nodeName
,
vertexTypes
[
startingType
],
startingNamespace
,
startingName
)
}
}
found
:=
false
found
:=
false
...
@@ -158,7 +158,7 @@ func (r *NodeAuthorizer) hasPathFrom(nodeName string, startingType vertexType, s
...
@@ -158,7 +158,7 @@ func (r *NodeAuthorizer) hasPathFrom(nodeName string, startingType vertexType, s
return
found
return
found
})
})
if
!
found
{
if
!
found
{
return
false
,
fmt
.
Errorf
(
"node %
s
cannot get %s %s/%s, no path was found"
,
nodeName
,
vertexTypes
[
startingType
],
startingNamespace
,
startingName
)
return
false
,
fmt
.
Errorf
(
"node %
q
cannot get %s %s/%s, no path was found"
,
nodeName
,
vertexTypes
[
startingType
],
startingNamespace
,
startingName
)
}
}
return
true
,
nil
return
true
,
nil
}
}
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