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
73e47f65
Unverified
Commit
73e47f65
authored
Jun 01, 2017
by
Mike Danese
Committed by
Jordan Liggitt
Jun 08, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nodeidentifier: require nodes to have wellformed usernames
parent
5404948e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
11 deletions
+14
-11
default.go
pkg/auth/nodeidentifier/default.go
+13
-10
default_test.go
pkg/auth/nodeidentifier/default_test.go
+1
-1
No files found.
pkg/auth/nodeidentifier/default.go
View file @
73e47f65
...
...
@@ -23,8 +23,9 @@ import (
)
// NewDefaultNodeIdentifier returns a default NodeIdentifier implementation,
// which returns isNode=true if the user groups contain the system:nodes group,
// and populates nodeName if isNode is true, and the user name is in the format system:node:<nodeName>
// which returns isNode=true if the user groups contain the system:nodes group
// and the user name matches the format system:node:<nodeName>, and populates
// nodeName if isNode is true
func
NewDefaultNodeIdentifier
()
NodeIdentifier
{
return
defaultNodeIdentifier
{}
}
...
...
@@ -35,14 +36,22 @@ type defaultNodeIdentifier struct{}
// nodeUserNamePrefix is the prefix for usernames in the form `system:node:<nodeName>`
const
nodeUserNamePrefix
=
"system:node:"
// NodeIdentity returns isNode=true if the user groups contain the system:nodes group,
// and populates nodeName if isNode is true, and the user name is in the format system:node:<nodeName>
// NodeIdentity returns isNode=true if the user groups contain the system:nodes
// group and the user name matches the format system:node:<nodeName>, and
// populates nodeName if isNode is true
func
(
defaultNodeIdentifier
)
NodeIdentity
(
u
user
.
Info
)
(
string
,
bool
)
{
// Make sure we're a node, and can parse the node name
if
u
==
nil
{
return
""
,
false
}
userName
:=
u
.
GetName
()
if
!
strings
.
HasPrefix
(
userName
,
nodeUserNamePrefix
)
{
return
""
,
false
}
nodeName
:=
strings
.
TrimPrefix
(
userName
,
nodeUserNamePrefix
)
isNode
:=
false
for
_
,
g
:=
range
u
.
GetGroups
()
{
if
g
==
user
.
NodesGroup
{
...
...
@@ -54,11 +63,5 @@ func (defaultNodeIdentifier) NodeIdentity(u user.Info) (string, bool) {
return
""
,
false
}
userName
:=
u
.
GetName
()
nodeName
:=
""
if
strings
.
HasPrefix
(
userName
,
nodeUserNamePrefix
)
{
nodeName
=
strings
.
TrimPrefix
(
userName
,
nodeUserNamePrefix
)
}
return
nodeName
,
isNode
}
pkg/auth/nodeidentifier/default_test.go
View file @
73e47f65
...
...
@@ -45,7 +45,7 @@ func TestDefaultNodeIdentifier_NodeIdentity(t *testing.T) {
name
:
"node group without username"
,
user
:
&
user
.
DefaultInfo
{
Name
:
"foo"
,
Groups
:
[]
string
{
"system:nodes"
}},
expectNodeName
:
""
,
expectIsNode
:
tru
e
,
expectIsNode
:
fals
e
,
},
{
name
:
"node group and username"
,
...
...
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