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
0c516c3a
Unverified
Commit
0c516c3a
authored
May 16, 2017
by
Jordan Liggitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add NodeIdentifier interface and default implementation
parent
d609f4eb
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
204 additions
and
0 deletions
+204
-0
.linted_packages
hack/.linted_packages
+1
-0
BUILD
pkg/BUILD
+1
-0
BUILD
pkg/auth/nodeidentifier/BUILD
+40
-0
default.go
pkg/auth/nodeidentifier/default.go
+64
-0
default_test.go
pkg/auth/nodeidentifier/default_test.go
+68
-0
interfaces.go
pkg/auth/nodeidentifier/interfaces.go
+30
-0
No files found.
hack/.linted_packages
View file @
0c516c3a
...
...
@@ -86,6 +86,7 @@ pkg/apis/settings/install
pkg/apis/settings/validation
pkg/apis/storage/install
pkg/apis/storage/validation
pkg/auth/nodeidentifier
pkg/bootstrap/api
pkg/client/conditions
pkg/client/informers/informers_generated/externalversions
...
...
pkg/BUILD
View file @
0c516c3a
...
...
@@ -31,6 +31,7 @@ filegroup(
"//pkg/apis/settings:all-srcs",
"//pkg/apis/storage:all-srcs",
"//pkg/auth/authorizer/abac:all-srcs",
"//pkg/auth/nodeidentifier:all-srcs",
"//pkg/auth/user:all-srcs",
"//pkg/bootstrap/api:all-srcs",
"//pkg/capabilities:all-srcs",
...
...
pkg/auth/nodeidentifier/BUILD
0 → 100644
View file @
0c516c3a
package(default_visibility = ["//visibility:public"])
licenses(["notice"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = [
"default.go",
"interfaces.go",
],
tags = ["automanaged"],
deps = ["//vendor/k8s.io/apiserver/pkg/authentication/user:go_default_library"],
)
go_test(
name = "go_default_test",
srcs = ["default_test.go"],
library = ":go_default_library",
tags = ["automanaged"],
deps = ["//vendor/k8s.io/apiserver/pkg/authentication/user:go_default_library"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
)
pkg/auth/nodeidentifier/default.go
0 → 100644
View file @
0c516c3a
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
nodeidentifier
import
(
"strings"
"k8s.io/apiserver/pkg/authentication/user"
)
// 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>
func
NewDefaultNodeIdentifier
()
NodeIdentifier
{
return
defaultNodeIdentifier
{}
}
// defaultNodeIdentifier implements NodeIdentifier
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>
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
}
isNode
:=
false
for
_
,
g
:=
range
u
.
GetGroups
()
{
if
g
==
user
.
NodesGroup
{
isNode
=
true
break
}
}
if
!
isNode
{
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
0 → 100644
View file @
0c516c3a
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
nodeidentifier
import
(
"testing"
"k8s.io/apiserver/pkg/authentication/user"
)
func
TestDefaultNodeIdentifier_NodeIdentity
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
user
user
.
Info
expectNodeName
string
expectIsNode
bool
}{
{
name
:
"nil user"
,
user
:
nil
,
expectNodeName
:
""
,
expectIsNode
:
false
,
},
{
name
:
"node username without group"
,
user
:
&
user
.
DefaultInfo
{
Name
:
"system:node:foo"
},
expectNodeName
:
""
,
expectIsNode
:
false
,
},
{
name
:
"node group without username"
,
user
:
&
user
.
DefaultInfo
{
Name
:
"foo"
,
Groups
:
[]
string
{
"system:nodes"
}},
expectNodeName
:
""
,
expectIsNode
:
true
,
},
{
name
:
"node group and username"
,
user
:
&
user
.
DefaultInfo
{
Name
:
"system:node:foo"
,
Groups
:
[]
string
{
"system:nodes"
}},
expectNodeName
:
"foo"
,
expectIsNode
:
true
,
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
nodeName
,
isNode
:=
NewDefaultNodeIdentifier
()
.
NodeIdentity
(
tt
.
user
)
if
nodeName
!=
tt
.
expectNodeName
{
t
.
Errorf
(
"DefaultNodeIdentifier.NodeIdentity() got = %v, want %v"
,
nodeName
,
tt
.
expectNodeName
)
}
if
isNode
!=
tt
.
expectIsNode
{
t
.
Errorf
(
"DefaultNodeIdentifier.NodeIdentity() got1 = %v, want %v"
,
isNode
,
tt
.
expectIsNode
)
}
})
}
}
pkg/auth/nodeidentifier/interfaces.go
0 → 100644
View file @
0c516c3a
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
nodeidentifier
import
(
"k8s.io/apiserver/pkg/authentication/user"
)
// NodeIdentifier determines node information from a given user
type
NodeIdentifier
interface
{
// IdentifyNode determines node information from the given user.Info.
// nodeName is the name of the Node API object associated with the user.Info,
// and may be empty if a specific node cannot be determined.
// isNode is true if the user.Info represents an identity issued to a node.
NodeIdentity
(
user
.
Info
)
(
nodeName
string
,
isNode
bool
)
}
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