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
1e7adaa5
Commit
1e7adaa5
authored
Aug 03, 2016
by
deads2k
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow restricting subresource access
parent
8805bbba
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
17 deletions
+52
-17
rbac.go
plugin/pkg/auth/authorizer/rbac/rbac.go
+5
-1
rbac_test.go
plugin/pkg/auth/authorizer/rbac/rbac_test.go
+47
-16
No files found.
plugin/pkg/auth/authorizer/rbac/rbac.go
View file @
1e7adaa5
...
...
@@ -44,10 +44,14 @@ func (r *RBACAuthorizer) Authorize(attr authorizer.Attributes) (bool, string, er
// Frame the authorization request as a privilege escalation check.
var
requestedRule
rbac
.
PolicyRule
if
attr
.
IsResourceRequest
()
{
resource
:=
attr
.
GetResource
()
if
len
(
attr
.
GetSubresource
())
>
0
{
resource
=
attr
.
GetResource
()
+
"/"
+
attr
.
GetSubresource
()
}
requestedRule
=
rbac
.
PolicyRule
{
Verbs
:
[]
string
{
attr
.
GetVerb
()},
APIGroups
:
[]
string
{
attr
.
GetAPIGroup
()},
// TODO(ericchiang): add api version here too?
Resources
:
[]
string
{
attr
.
GetResource
()
},
Resources
:
[]
string
{
resource
},
ResourceNames
:
[]
string
{
attr
.
GetName
()},
}
}
else
{
...
...
plugin/pkg/auth/authorizer/rbac/rbac_test.go
View file @
1e7adaa5
...
...
@@ -86,12 +86,13 @@ func newRoleBinding(namespace, roleName string, bindType uint16, subjects ...str
}
type
defaultAttributes
struct
{
user
string
groups
string
verb
string
resource
string
namespace
string
apiGroup
string
user
string
groups
string
verb
string
resource
string
subresource
string
namespace
string
apiGroup
string
}
func
(
d
*
defaultAttributes
)
String
()
string
{
...
...
@@ -106,7 +107,7 @@ func (d *defaultAttributes) GetVerb() string { return d.verb }
func
(
d
*
defaultAttributes
)
IsReadOnly
()
bool
{
return
d
.
verb
==
"get"
||
d
.
verb
==
"watch"
}
func
(
d
*
defaultAttributes
)
GetNamespace
()
string
{
return
d
.
namespace
}
func
(
d
*
defaultAttributes
)
GetResource
()
string
{
return
d
.
resource
}
func
(
d
*
defaultAttributes
)
GetSubresource
()
string
{
return
""
}
func
(
d
*
defaultAttributes
)
GetSubresource
()
string
{
return
d
.
subresource
}
func
(
d
*
defaultAttributes
)
GetName
()
string
{
return
""
}
func
(
d
*
defaultAttributes
)
GetAPIGroup
()
string
{
return
d
.
apiGroup
}
func
(
d
*
defaultAttributes
)
GetAPIVersion
()
string
{
return
""
}
...
...
@@ -133,17 +134,17 @@ func TestAuthorizer(t *testing.T) {
newRoleBinding
(
"ns1"
,
"admin"
,
bindToClusterRole
,
"User:admin"
,
"Group:admins"
),
},
shouldPass
:
[]
authorizer
.
Attributes
{
&
defaultAttributes
{
"admin"
,
""
,
"get"
,
"Pods"
,
"ns1"
,
""
},
&
defaultAttributes
{
"admin"
,
""
,
"watch"
,
"Pods"
,
"ns1"
,
""
},
&
defaultAttributes
{
"admin"
,
"group1"
,
"watch"
,
"Foobar"
,
"ns1"
,
""
},
&
defaultAttributes
{
"joe"
,
"admins"
,
"watch"
,
"Foobar"
,
"ns1"
,
""
},
&
defaultAttributes
{
"joe"
,
"group1,admins"
,
"watch"
,
"Foobar"
,
"ns1"
,
""
},
&
defaultAttributes
{
"admin"
,
""
,
"get"
,
"Pods"
,
"
"
,
"
ns1"
,
""
},
&
defaultAttributes
{
"admin"
,
""
,
"watch"
,
"Pods"
,
"
"
,
"
ns1"
,
""
},
&
defaultAttributes
{
"admin"
,
"group1"
,
"watch"
,
"Foobar"
,
"
"
,
"
ns1"
,
""
},
&
defaultAttributes
{
"joe"
,
"admins"
,
"watch"
,
"Foobar"
,
"
"
,
"
ns1"
,
""
},
&
defaultAttributes
{
"joe"
,
"group1,admins"
,
"watch"
,
"Foobar"
,
"
"
,
"
ns1"
,
""
},
},
shouldFail
:
[]
authorizer
.
Attributes
{
&
defaultAttributes
{
"admin"
,
""
,
"GET"
,
"Pods"
,
"ns2"
,
""
},
&
defaultAttributes
{
"admin"
,
""
,
"GET"
,
"Nodes"
,
""
,
""
},
&
defaultAttributes
{
"admin"
,
"admins"
,
"GET"
,
"Pods"
,
"ns2"
,
""
},
&
defaultAttributes
{
"admin"
,
"admins"
,
"GET"
,
"Nodes"
,
""
,
""
},
&
defaultAttributes
{
"admin"
,
""
,
"GET"
,
"Pods"
,
"
"
,
"
ns2"
,
""
},
&
defaultAttributes
{
"admin"
,
""
,
"GET"
,
"Nodes"
,
""
,
""
,
""
},
&
defaultAttributes
{
"admin"
,
"admins"
,
"GET"
,
"Pods"
,
"
"
,
"
ns2"
,
""
},
&
defaultAttributes
{
"admin"
,
"admins"
,
"GET"
,
"Nodes"
,
""
,
""
,
""
},
},
},
{
...
...
@@ -187,6 +188,36 @@ func TestAuthorizer(t *testing.T) {
authorizer
.
AttributesRecord
{
User
:
&
user
.
DefaultInfo
{
Groups
:
[]
string
{
"prefixed"
}},
Verb
:
"get"
,
Path
:
"/api/v1"
},
},
},
{
// test subresource resolution
clusterRoles
:
[]
rbac
.
ClusterRole
{
newClusterRole
(
"admin"
,
newRule
(
"*"
,
"*"
,
"pods"
,
"*"
)),
},
roleBindings
:
[]
rbac
.
RoleBinding
{
newRoleBinding
(
"ns1"
,
"admin"
,
bindToClusterRole
,
"User:admin"
,
"Group:admins"
),
},
shouldPass
:
[]
authorizer
.
Attributes
{
&
defaultAttributes
{
"admin"
,
""
,
"get"
,
"pods"
,
""
,
"ns1"
,
""
},
},
shouldFail
:
[]
authorizer
.
Attributes
{
&
defaultAttributes
{
"admin"
,
""
,
"get"
,
"pods"
,
"status"
,
"ns1"
,
""
},
},
},
{
// test subresource resolution
clusterRoles
:
[]
rbac
.
ClusterRole
{
newClusterRole
(
"admin"
,
newRule
(
"*"
,
"*"
,
"pods/status"
,
"*"
)),
},
roleBindings
:
[]
rbac
.
RoleBinding
{
newRoleBinding
(
"ns1"
,
"admin"
,
bindToClusterRole
,
"User:admin"
,
"Group:admins"
),
},
shouldPass
:
[]
authorizer
.
Attributes
{
&
defaultAttributes
{
"admin"
,
""
,
"get"
,
"pods"
,
"status"
,
"ns1"
,
""
},
},
shouldFail
:
[]
authorizer
.
Attributes
{
&
defaultAttributes
{
"admin"
,
""
,
"get"
,
"pods"
,
""
,
"ns1"
,
""
},
},
},
}
for
i
,
tt
:=
range
tests
{
ruleResolver
:=
validation
.
NewTestRuleResolver
(
tt
.
roles
,
tt
.
roleBindings
,
tt
.
clusterRoles
,
tt
.
clusterRoleBindings
)
...
...
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