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
fed30040
Unverified
Commit
fed30040
authored
May 27, 2017
by
Jordan Liggitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make NodeRestriction admission require identifiable nodes
parent
d278a80a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
14 deletions
+7
-14
admission.go
plugin/pkg/admission/noderestriction/admission.go
+5
-11
admission_test.go
plugin/pkg/admission/noderestriction/admission_test.go
+2
-3
No files found.
plugin/pkg/admission/noderestriction/admission.go
View file @
fed30040
...
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
...
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
*/
*/
package
node
package
node
restriction
import
(
import
(
"fmt"
"fmt"
...
@@ -37,24 +37,22 @@ const (
...
@@ -37,24 +37,22 @@ const (
// Register registers a plugin
// Register registers a plugin
func
Register
(
plugins
*
admission
.
Plugins
)
{
func
Register
(
plugins
*
admission
.
Plugins
)
{
plugins
.
Register
(
PluginName
,
func
(
config
io
.
Reader
)
(
admission
.
Interface
,
error
)
{
plugins
.
Register
(
PluginName
,
func
(
config
io
.
Reader
)
(
admission
.
Interface
,
error
)
{
return
NewPlugin
(
nodeidentifier
.
NewDefaultNodeIdentifier
()
,
false
),
nil
return
NewPlugin
(
nodeidentifier
.
NewDefaultNodeIdentifier
()),
nil
})
})
}
}
// NewPlugin creates a new NodeRestriction admission plugin.
// NewPlugin creates a new NodeRestriction admission plugin.
// This plugin identifies requests from nodes
// This plugin identifies requests from nodes
func
NewPlugin
(
nodeIdentifier
nodeidentifier
.
NodeIdentifier
,
strict
bool
)
*
nodePlugin
{
func
NewPlugin
(
nodeIdentifier
nodeidentifier
.
NodeIdentifier
)
*
nodePlugin
{
return
&
nodePlugin
{
return
&
nodePlugin
{
Handler
:
admission
.
NewHandler
(
admission
.
Create
,
admission
.
Update
,
admission
.
Delete
),
Handler
:
admission
.
NewHandler
(
admission
.
Create
,
admission
.
Update
,
admission
.
Delete
),
nodeIdentifier
:
nodeIdentifier
,
nodeIdentifier
:
nodeIdentifier
,
strict
:
strict
,
}
}
}
}
// nodePlugin holds state for and implements the admission plugin.
// nodePlugin holds state for and implements the admission plugin.
type
nodePlugin
struct
{
type
nodePlugin
struct
{
*
admission
.
Handler
*
admission
.
Handler
strict
bool
nodeIdentifier
nodeidentifier
.
NodeIdentifier
nodeIdentifier
nodeidentifier
.
NodeIdentifier
podsGetter
coreinternalversion
.
PodsGetter
podsGetter
coreinternalversion
.
PodsGetter
}
}
...
@@ -92,12 +90,8 @@ func (c *nodePlugin) Admit(a admission.Attributes) error {
...
@@ -92,12 +90,8 @@ func (c *nodePlugin) Admit(a admission.Attributes) error {
}
}
if
len
(
nodeName
)
==
0
{
if
len
(
nodeName
)
==
0
{
if
c
.
strict
{
// disallow requests we cannot match to a particular node
// In strict mode, disallow requests from nodes 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 identity from user"
))
}
// Our job is just to restrict identifiable nodes
return
nil
}
}
switch
a
.
GetResource
()
.
GroupResource
()
{
switch
a
.
GetResource
()
.
GroupResource
()
{
...
...
plugin/pkg/admission/noderestriction/admission_test.go
View file @
fed30040
...
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
...
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
*/
*/
package
node
package
node
restriction
import
(
import
(
"strings"
"strings"
...
@@ -82,7 +82,6 @@ func Test_nodePlugin_Admit(t *testing.T) {
...
@@ -82,7 +82,6 @@ func Test_nodePlugin_Admit(t *testing.T) {
tests
:=
[]
struct
{
tests
:=
[]
struct
{
name
string
name
string
strict
bool
podsGetter
coreinternalversion
.
PodsGetter
podsGetter
coreinternalversion
.
PodsGetter
attributes
admission
.
Attributes
attributes
admission
.
Attributes
err
string
err
string
...
@@ -473,7 +472,7 @@ func Test_nodePlugin_Admit(t *testing.T) {
...
@@ -473,7 +472,7 @@ func Test_nodePlugin_Admit(t *testing.T) {
}
}
for
_
,
tt
:=
range
tests
{
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
c
:=
NewPlugin
(
nodeidentifier
.
NewDefaultNodeIdentifier
()
,
tt
.
strict
)
c
:=
NewPlugin
(
nodeidentifier
.
NewDefaultNodeIdentifier
())
c
.
podsGetter
=
tt
.
podsGetter
c
.
podsGetter
=
tt
.
podsGetter
err
:=
c
.
Admit
(
tt
.
attributes
)
err
:=
c
.
Admit
(
tt
.
attributes
)
if
(
err
==
nil
)
!=
(
len
(
tt
.
err
)
==
0
)
{
if
(
err
==
nil
)
!=
(
len
(
tt
.
err
)
==
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