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
e024e55e
Commit
e024e55e
authored
Sep 28, 2015
by
Jordan Liggitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add verb to authorizer attributes
parent
719cf561
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
28 deletions
+37
-28
handlers.go
pkg/apiserver/handlers.go
+4
-3
abac_test.go
pkg/auth/authorizer/abac/abac_test.go
+23
-23
interfaces.go
pkg/auth/authorizer/interfaces.go
+10
-2
No files found.
pkg/apiserver/handlers.go
View file @
e024e55e
...
@@ -362,11 +362,10 @@ func (r *requestAttributeGetter) GetAttribs(req *http.Request) authorizer.Attrib
...
@@ -362,11 +362,10 @@ func (r *requestAttributeGetter) GetAttribs(req *http.Request) authorizer.Attrib
}
}
}
}
attribs
.
ReadOnly
=
IsReadOnlyReq
(
*
req
)
apiRequestInfo
,
_
:=
r
.
apiRequestInfoResolver
.
GetAPIRequestInfo
(
req
)
apiRequestInfo
,
_
:=
r
.
apiRequestInfoResolver
.
GetAPIRequestInfo
(
req
)
attribs
.
APIGroup
=
apiRequestInfo
.
APIGroup
attribs
.
APIGroup
=
apiRequestInfo
.
APIGroup
attribs
.
Verb
=
apiRequestInfo
.
Verb
// If a path follows the conventions of the REST object store, then
// If a path follows the conventions of the REST object store, then
// we can extract the resource. Otherwise, not.
// we can extract the resource. Otherwise, not.
...
@@ -442,6 +441,7 @@ type APIRequestInfoResolver struct {
...
@@ -442,6 +441,7 @@ type APIRequestInfoResolver struct {
func
(
r
*
APIRequestInfoResolver
)
GetAPIRequestInfo
(
req
*
http
.
Request
)
(
APIRequestInfo
,
error
)
{
func
(
r
*
APIRequestInfoResolver
)
GetAPIRequestInfo
(
req
*
http
.
Request
)
(
APIRequestInfo
,
error
)
{
requestInfo
:=
APIRequestInfo
{
requestInfo
:=
APIRequestInfo
{
Raw
:
splitPath
(
req
.
URL
.
Path
),
Raw
:
splitPath
(
req
.
URL
.
Path
),
Verb
:
strings
.
ToLower
(
req
.
Method
),
}
}
currentParts
:=
requestInfo
.
Raw
currentParts
:=
requestInfo
.
Raw
...
@@ -489,8 +489,9 @@ func (r *APIRequestInfoResolver) GetAPIRequestInfo(req *http.Request) (APIReques
...
@@ -489,8 +489,9 @@ func (r *APIRequestInfoResolver) GetAPIRequestInfo(req *http.Request) (APIReques
requestInfo
.
Verb
=
"patch"
requestInfo
.
Verb
=
"patch"
case
"DELETE"
:
case
"DELETE"
:
requestInfo
.
Verb
=
"delete"
requestInfo
.
Verb
=
"delete"
default
:
requestInfo
.
Verb
=
""
}
}
}
}
// URL forms: /namespaces/{namespace}/{kind}/*, where parts are adjusted to be relative to kind
// URL forms: /namespaces/{namespace}/{kind}/*, where parts are adjusted to be relative to kind
...
...
pkg/auth/authorizer/abac/abac_test.go
View file @
e024e55e
...
@@ -75,49 +75,49 @@ func TestNotAuthorized(t *testing.T) {
...
@@ -75,49 +75,49 @@ func TestNotAuthorized(t *testing.T) {
testCases
:=
[]
struct
{
testCases
:=
[]
struct
{
User
user
.
DefaultInfo
User
user
.
DefaultInfo
RO
bool
Verb
string
Resource
string
Resource
string
NS
string
NS
string
ExpectAllow
bool
ExpectAllow
bool
}{
}{
// Scheduler can read pods
// Scheduler can read pods
{
User
:
uScheduler
,
RO
:
true
,
Resource
:
"pods"
,
NS
:
"ns1"
,
ExpectAllow
:
true
},
{
User
:
uScheduler
,
Verb
:
"list"
,
Resource
:
"pods"
,
NS
:
"ns1"
,
ExpectAllow
:
true
},
{
User
:
uScheduler
,
RO
:
true
,
Resource
:
"pods"
,
NS
:
""
,
ExpectAllow
:
true
},
{
User
:
uScheduler
,
Verb
:
"list"
,
Resource
:
"pods"
,
NS
:
""
,
ExpectAllow
:
true
},
// Scheduler cannot write pods
// Scheduler cannot write pods
{
User
:
uScheduler
,
RO
:
false
,
Resource
:
"pods"
,
NS
:
"ns1"
,
ExpectAllow
:
false
},
{
User
:
uScheduler
,
Verb
:
"create"
,
Resource
:
"pods"
,
NS
:
"ns1"
,
ExpectAllow
:
false
},
{
User
:
uScheduler
,
RO
:
false
,
Resource
:
"pods"
,
NS
:
""
,
ExpectAllow
:
false
},
{
User
:
uScheduler
,
Verb
:
"create"
,
Resource
:
"pods"
,
NS
:
""
,
ExpectAllow
:
false
},
// Scheduler can write bindings
// Scheduler can write bindings
{
User
:
uScheduler
,
RO
:
true
,
Resource
:
"bindings"
,
NS
:
"ns1"
,
ExpectAllow
:
true
},
{
User
:
uScheduler
,
Verb
:
"get"
,
Resource
:
"bindings"
,
NS
:
"ns1"
,
ExpectAllow
:
true
},
{
User
:
uScheduler
,
RO
:
true
,
Resource
:
"bindings"
,
NS
:
""
,
ExpectAllow
:
true
},
{
User
:
uScheduler
,
Verb
:
"get"
,
Resource
:
"bindings"
,
NS
:
""
,
ExpectAllow
:
true
},
// Alice can read and write anything in the right namespace.
// Alice can read and write anything in the right namespace.
{
User
:
uAlice
,
RO
:
true
,
Resource
:
"pods"
,
NS
:
"projectCaribou"
,
ExpectAllow
:
true
},
{
User
:
uAlice
,
Verb
:
"get"
,
Resource
:
"pods"
,
NS
:
"projectCaribou"
,
ExpectAllow
:
true
},
{
User
:
uAlice
,
RO
:
true
,
Resource
:
"widgets"
,
NS
:
"projectCaribou"
,
ExpectAllow
:
true
},
{
User
:
uAlice
,
Verb
:
"get"
,
Resource
:
"widgets"
,
NS
:
"projectCaribou"
,
ExpectAllow
:
true
},
{
User
:
uAlice
,
RO
:
true
,
Resource
:
""
,
NS
:
"projectCaribou"
,
ExpectAllow
:
true
},
{
User
:
uAlice
,
Verb
:
"get"
,
Resource
:
""
,
NS
:
"projectCaribou"
,
ExpectAllow
:
true
},
{
User
:
uAlice
,
RO
:
false
,
Resource
:
"pods"
,
NS
:
"projectCaribou"
,
ExpectAllow
:
true
},
{
User
:
uAlice
,
Verb
:
"update"
,
Resource
:
"pods"
,
NS
:
"projectCaribou"
,
ExpectAllow
:
true
},
{
User
:
uAlice
,
RO
:
false
,
Resource
:
"widgets"
,
NS
:
"projectCaribou"
,
ExpectAllow
:
true
},
{
User
:
uAlice
,
Verb
:
"update"
,
Resource
:
"widgets"
,
NS
:
"projectCaribou"
,
ExpectAllow
:
true
},
{
User
:
uAlice
,
RO
:
false
,
Resource
:
""
,
NS
:
"projectCaribou"
,
ExpectAllow
:
true
},
{
User
:
uAlice
,
Verb
:
"update"
,
Resource
:
""
,
NS
:
"projectCaribou"
,
ExpectAllow
:
true
},
// .. but not the wrong namespace.
// .. but not the wrong namespace.
{
User
:
uAlice
,
RO
:
true
,
Resource
:
"pods"
,
NS
:
"ns1"
,
ExpectAllow
:
false
},
{
User
:
uAlice
,
Verb
:
"get"
,
Resource
:
"pods"
,
NS
:
"ns1"
,
ExpectAllow
:
false
},
{
User
:
uAlice
,
RO
:
true
,
Resource
:
"widgets"
,
NS
:
"ns1"
,
ExpectAllow
:
false
},
{
User
:
uAlice
,
Verb
:
"get"
,
Resource
:
"widgets"
,
NS
:
"ns1"
,
ExpectAllow
:
false
},
{
User
:
uAlice
,
RO
:
true
,
Resource
:
""
,
NS
:
"ns1"
,
ExpectAllow
:
false
},
{
User
:
uAlice
,
Verb
:
"get"
,
Resource
:
""
,
NS
:
"ns1"
,
ExpectAllow
:
false
},
// Chuck can read events, since anyone can.
// Chuck can read events, since anyone can.
{
User
:
uChuck
,
RO
:
true
,
Resource
:
"events"
,
NS
:
"ns1"
,
ExpectAllow
:
true
},
{
User
:
uChuck
,
Verb
:
"get"
,
Resource
:
"events"
,
NS
:
"ns1"
,
ExpectAllow
:
true
},
{
User
:
uChuck
,
RO
:
true
,
Resource
:
"events"
,
NS
:
""
,
ExpectAllow
:
true
},
{
User
:
uChuck
,
Verb
:
"get"
,
Resource
:
"events"
,
NS
:
""
,
ExpectAllow
:
true
},
// Chuck can't do other things.
// Chuck can't do other things.
{
User
:
uChuck
,
RO
:
false
,
Resource
:
"events"
,
NS
:
"ns1"
,
ExpectAllow
:
false
},
{
User
:
uChuck
,
Verb
:
"update"
,
Resource
:
"events"
,
NS
:
"ns1"
,
ExpectAllow
:
false
},
{
User
:
uChuck
,
RO
:
true
,
Resource
:
"pods"
,
NS
:
"ns1"
,
ExpectAllow
:
false
},
{
User
:
uChuck
,
Verb
:
"get"
,
Resource
:
"pods"
,
NS
:
"ns1"
,
ExpectAllow
:
false
},
{
User
:
uChuck
,
RO
:
true
,
Resource
:
"floop"
,
NS
:
"ns1"
,
ExpectAllow
:
false
},
{
User
:
uChuck
,
Verb
:
"get"
,
Resource
:
"floop"
,
NS
:
"ns1"
,
ExpectAllow
:
false
},
// Chunk can't access things with no kind or namespace
// Chunk can't access things with no kind or namespace
// TODO: find a way to give someone access to miscellaneous endpoints, such as
// TODO: find a way to give someone access to miscellaneous endpoints, such as
// /healthz, /version, etc.
// /healthz, /version, etc.
{
User
:
uChuck
,
RO
:
true
,
Resource
:
""
,
NS
:
""
,
ExpectAllow
:
false
},
{
User
:
uChuck
,
Verb
:
"get"
,
Resource
:
""
,
NS
:
""
,
ExpectAllow
:
false
},
}
}
for
i
,
tc
:=
range
testCases
{
for
i
,
tc
:=
range
testCases
{
attr
:=
authorizer
.
AttributesRecord
{
attr
:=
authorizer
.
AttributesRecord
{
User
:
&
tc
.
User
,
User
:
&
tc
.
User
,
ReadOnly
:
tc
.
RO
,
Verb
:
tc
.
Verb
,
Resource
:
tc
.
Resource
,
Resource
:
tc
.
Resource
,
Namespace
:
tc
.
NS
,
Namespace
:
tc
.
NS
,
}
}
...
...
pkg/auth/authorizer/interfaces.go
View file @
e024e55e
...
@@ -32,6 +32,10 @@ type Attributes interface {
...
@@ -32,6 +32,10 @@ type Attributes interface {
// authentication occurred.
// authentication occurred.
GetGroups
()
[]
string
GetGroups
()
[]
string
// GetVerb returns the kube verb associated with API requests (this includes get, list, watch, create, update, patch, delete, and proxy),
// or the lowercased HTTP verb associated with non-API requests (this includes get, put, post, patch, and delete)
GetVerb
()
string
// When IsReadOnly() == true, the request has no side effects, other than
// When IsReadOnly() == true, the request has no side effects, other than
// caching, logging, and other incidentals.
// caching, logging, and other incidentals.
IsReadOnly
()
bool
IsReadOnly
()
bool
...
@@ -62,7 +66,7 @@ func (f AuthorizerFunc) Authorize(a Attributes) error {
...
@@ -62,7 +66,7 @@ func (f AuthorizerFunc) Authorize(a Attributes) error {
// AttributesRecord implements Attributes interface.
// AttributesRecord implements Attributes interface.
type
AttributesRecord
struct
{
type
AttributesRecord
struct
{
User
user
.
Info
User
user
.
Info
ReadOnly
bool
Verb
string
Namespace
string
Namespace
string
APIGroup
string
APIGroup
string
Resource
string
Resource
string
...
@@ -76,8 +80,12 @@ func (a AttributesRecord) GetGroups() []string {
...
@@ -76,8 +80,12 @@ func (a AttributesRecord) GetGroups() []string {
return
a
.
User
.
GetGroups
()
return
a
.
User
.
GetGroups
()
}
}
func
(
a
AttributesRecord
)
GetVerb
()
string
{
return
a
.
Verb
}
func
(
a
AttributesRecord
)
IsReadOnly
()
bool
{
func
(
a
AttributesRecord
)
IsReadOnly
()
bool
{
return
a
.
ReadOnly
return
a
.
Verb
==
"get"
||
a
.
Verb
==
"list"
||
a
.
Verb
==
"watch"
}
}
func
(
a
AttributesRecord
)
GetNamespace
()
string
{
func
(
a
AttributesRecord
)
GetNamespace
()
string
{
...
...
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