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
6e83d88b
Commit
6e83d88b
authored
Nov 08, 2017
by
hzxuzhonghu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
audit support wildcard matching subresources
parent
291b56d0
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
18 deletions
+54
-18
types.go
staging/src/k8s.io/apiserver/pkg/apis/audit/types.go
+13
-4
types.go
...ing/src/k8s.io/apiserver/pkg/apis/audit/v1alpha1/types.go
+13
-4
types.go
staging/src/k8s.io/apiserver/pkg/apis/audit/v1beta1/types.go
+13
-4
checker.go
staging/src/k8s.io/apiserver/pkg/audit/policy/checker.go
+15
-6
No files found.
staging/src/k8s.io/apiserver/pkg/apis/audit/types.go
View file @
6e83d88b
...
@@ -226,10 +226,19 @@ type GroupResources struct {
...
@@ -226,10 +226,19 @@ type GroupResources struct {
// The empty string represents the core API group.
// The empty string represents the core API group.
// +optional
// +optional
Group
string
Group
string
// Resources is a list of resources within the API group. Subresources are
// Resources is a list of resources this rule applies to.
// matched using a "/" to indicate the subresource. For example, "pods/log"
//
// would match request to the log subresource of pods. The top level resource
// For example:
// does not match subresources, "pods" doesn't match "pods/log".
// 'pods' matches pods.
// 'pods/log' matches the log subresource of pods.
// '*' matches all resources and their subresources.
// 'pods/*' matches all subresources of pods.
// '*/scale' matches all scale subresources.
//
// If wildcard is present, the validation rule will ensure resources do not
// overlap with each other.
//
// An empty list implies all resources and subresources in this API groups apply.
// +optional
// +optional
Resources
[]
string
Resources
[]
string
// ResourceNames is a list of resource instance names that the policy matches.
// ResourceNames is a list of resource instance names that the policy matches.
...
...
staging/src/k8s.io/apiserver/pkg/apis/audit/v1alpha1/types.go
View file @
6e83d88b
...
@@ -233,10 +233,19 @@ type GroupResources struct {
...
@@ -233,10 +233,19 @@ type GroupResources struct {
// The empty string represents the core API group.
// The empty string represents the core API group.
// +optional
// +optional
Group
string
`json:"group,omitempty" protobuf:"bytes,1,opt,name=group"`
Group
string
`json:"group,omitempty" protobuf:"bytes,1,opt,name=group"`
// Resources is a list of resources within the API group. Subresources are
// Resources is a list of resources this rule applies to.
// matched using a "/" to indicate the subresource. For example, "pods/logs"
//
// would match request to the logs subresource of pods. The top level resource
// For example:
// does not match subresources, "pods" doesn't match "pods/logs".
// 'pods' matches pods.
// 'pods/log' matches the log subresource of pods.
// '*' matches all resources and their subresources.
// 'pods/*' matches all subresources of pods.
// '*/scale' matches all scale subresources.
//
// If wildcard is present, the validation rule will ensure resources do not
// overlap with each other.
//
// An empty list implies all resources and subresources in this API groups apply.
// +optional
// +optional
Resources
[]
string
`json:"resources,omitempty" protobuf:"bytes,2,rep,name=resources"`
Resources
[]
string
`json:"resources,omitempty" protobuf:"bytes,2,rep,name=resources"`
// ResourceNames is a list of resource instance names that the policy matches.
// ResourceNames is a list of resource instance names that the policy matches.
...
...
staging/src/k8s.io/apiserver/pkg/apis/audit/v1beta1/types.go
View file @
6e83d88b
...
@@ -229,10 +229,19 @@ type GroupResources struct {
...
@@ -229,10 +229,19 @@ type GroupResources struct {
// The empty string represents the core API group.
// The empty string represents the core API group.
// +optional
// +optional
Group
string
`json:"group,omitempty" protobuf:"bytes,1,opt,name=group"`
Group
string
`json:"group,omitempty" protobuf:"bytes,1,opt,name=group"`
// Resources is a list of resources within the API group. Subresources are
// Resources is a list of resources this rule applies to.
// matched using a "/" to indicate the subresource. For example, "pods/log"
//
// would match request to the log subresource of pods. The top level resource
// For example:
// does not match subresources, "pods" doesn't match "pods/log".
// 'pods' matches pods.
// 'pods/log' matches the log subresource of pods.
// '*' matches all resources and their subresources.
// 'pods/*' matches all subresources of pods.
// '*/scale' matches all scale subresources.
//
// If wildcard is present, the validation rule will ensure resources do not
// overlap with each other.
//
// An empty list implies all resources and subresources in this API groups apply.
// +optional
// +optional
Resources
[]
string
`json:"resources,omitempty" protobuf:"bytes,2,rep,name=resources"`
Resources
[]
string
`json:"resources,omitempty" protobuf:"bytes,2,rep,name=resources"`
// ResourceNames is a list of resource instance names that the policy matches.
// ResourceNames is a list of resource instance names that the policy matches.
...
...
staging/src/k8s.io/apiserver/pkg/audit/policy/checker.go
View file @
6e83d88b
...
@@ -160,11 +160,11 @@ func ruleMatchesResource(r *audit.PolicyRule, attrs authorizer.Attributes) bool
...
@@ -160,11 +160,11 @@ func ruleMatchesResource(r *audit.PolicyRule, attrs authorizer.Attributes) bool
apiGroup
:=
attrs
.
GetAPIGroup
()
apiGroup
:=
attrs
.
GetAPIGroup
()
resource
:=
attrs
.
GetResource
()
resource
:=
attrs
.
GetResource
()
subresource
:=
attrs
.
GetSubresource
()
combinedResource
:=
resource
// If subresource, the resource in the policy must match "(resource)/(subresource)"
// If subresource, the resource in the policy must match "(resource)/(subresource)"
//
if
subresource
!=
""
{
// TODO: consider adding options like "pods/*" to match all subresources.
combinedResource
=
resource
+
"/"
+
subresource
if
sr
:=
attrs
.
GetSubresource
();
sr
!=
""
{
resource
=
resource
+
"/"
+
sr
}
}
name
:=
attrs
.
GetName
()
name
:=
attrs
.
GetName
()
...
@@ -175,8 +175,17 @@ func ruleMatchesResource(r *audit.PolicyRule, attrs authorizer.Attributes) bool
...
@@ -175,8 +175,17 @@ func ruleMatchesResource(r *audit.PolicyRule, attrs authorizer.Attributes) bool
return
true
return
true
}
}
for
_
,
res
:=
range
gr
.
Resources
{
for
_
,
res
:=
range
gr
.
Resources
{
if
res
==
resource
{
if
len
(
gr
.
ResourceNames
)
==
0
||
hasString
(
gr
.
ResourceNames
,
name
)
{
if
len
(
gr
.
ResourceNames
)
==
0
||
hasString
(
gr
.
ResourceNames
,
name
)
{
// match "*"
if
res
==
combinedResource
||
res
==
"*"
{
return
true
}
// match "*/subresource"
if
len
(
subresource
)
>
0
&&
strings
.
HasPrefix
(
res
,
"*/"
)
&&
subresource
==
strings
.
TrimLeft
(
res
,
"*/"
)
{
return
true
}
// match "resource/*"
if
strings
.
HasSuffix
(
res
,
"/*"
)
&&
resource
==
strings
.
TrimRight
(
res
,
"/*"
)
{
return
true
return
true
}
}
}
}
...
...
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