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
de3db1ee
Commit
de3db1ee
authored
Apr 22, 2017
by
Cao Shufeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add subresource support to kube auth can-i
Eg: kubectl auth can-i get pods --subresource=log
parent
29f37fde
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
6 deletions
+25
-6
known-flags.txt
hack/verify-flags/known-flags.txt
+1
-0
cani.go
pkg/kubectl/cmd/auth/cani.go
+12
-6
cani_test.go
pkg/kubectl/cmd/auth/cani_test.go
+12
-0
No files found.
hack/verify-flags/known-flags.txt
View file @
de3db1ee
...
...
@@ -667,6 +667,7 @@ storage-media-type
storage-version
storage-versions
streaming-connection-idle-timeout
subresource
suicide-timeout
sync-frequency
system-cgroups
...
...
pkg/kubectl/cmd/auth/cani.go
View file @
de3db1ee
...
...
@@ -45,6 +45,7 @@ type CanIOptions struct {
Verb
string
Resource
schema
.
GroupVersionResource
Subresource
string
ResourceName
string
Out
io
.
Writer
...
...
@@ -70,7 +71,10 @@ var (
kubectl auth can-i '*' '*'
# Check to see if I can get the job named "bar" in namespace "foo"
kubectl auth can-i list jobs.batch/bar -n foo`
)
kubectl auth can-i list jobs.batch/bar -n foo
# check to see if I can read pod logs
kubectl auth can-i get pods --subresource=log`
)
)
func
NewCmdCanI
(
f
cmdutil
.
Factory
,
out
,
err
io
.
Writer
)
*
cobra
.
Command
{
...
...
@@ -101,6 +105,7 @@ func NewCmdCanI(f cmdutil.Factory, out, err io.Writer) *cobra.Command {
cmd
.
Flags
()
.
BoolVar
(
&
o
.
AllNamespaces
,
"all-namespaces"
,
o
.
AllNamespaces
,
"If true, check the specified action in all namespaces."
)
cmd
.
Flags
()
.
BoolVarP
(
&
o
.
Quiet
,
"quiet"
,
"q"
,
o
.
Quiet
,
"If true, suppress output and just return the exit code."
)
cmd
.
Flags
()
.
StringVar
(
&
o
.
Subresource
,
"subresource"
,
""
,
"SubResource such as pod/log or deployment/scale"
)
return
cmd
}
...
...
@@ -149,11 +154,12 @@ func (o *CanIOptions) RunAccessCheck() (bool, error) {
sar
:=
&
authorizationapi
.
SelfSubjectAccessReview
{
Spec
:
authorizationapi
.
SelfSubjectAccessReviewSpec
{
ResourceAttributes
:
&
authorizationapi
.
ResourceAttributes
{
Namespace
:
o
.
Namespace
,
Verb
:
o
.
Verb
,
Group
:
o
.
Resource
.
Group
,
Resource
:
o
.
Resource
.
Resource
,
Name
:
o
.
ResourceName
,
Namespace
:
o
.
Namespace
,
Verb
:
o
.
Verb
,
Group
:
o
.
Resource
.
Group
,
Resource
:
o
.
Resource
.
Resource
,
Subresource
:
o
.
Subresource
,
Name
:
o
.
ResourceName
,
},
},
}
...
...
pkg/kubectl/cmd/auth/cani_test.go
View file @
de3db1ee
...
...
@@ -92,6 +92,18 @@ func TestRunAccessCheck(t *testing.T) {
`{"resourceAttributes":{"verb":"get","group":"extensions","resource":"deployments","name":"foo"}}`
,
},
},
{
name
:
"sub resource"
,
o
:
&
CanIOptions
{
AllNamespaces
:
true
,
Subresource
:
"log"
,
},
args
:
[]
string
{
"get"
,
"pods"
},
allowed
:
true
,
expectedBodyStrings
:
[]
string
{
`{"resourceAttributes":{"verb":"get","resource":"pods","subresource":"log"}}`
,
},
},
}
for
_
,
test
:=
range
tests
{
...
...
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