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
8553a8b8
Unverified
Commit
8553a8b8
authored
Nov 09, 2016
by
Jordan Liggitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check in YAML versions of bootstrap roles/rolebindings
parent
de55e68a
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
909 additions
and
5 deletions
+909
-5
BUILD
pkg/apis/rbac/BUILD
+1
-0
helpers.go
pkg/apis/rbac/helpers.go
+12
-5
BUILD
plugin/pkg/auth/authorizer/rbac/bootstrappolicy/BUILD
+8
-0
policy_test.go
...n/pkg/auth/authorizer/rbac/bootstrappolicy/policy_test.go
+97
-0
cluster-roles.yaml
...thorizer/rbac/bootstrappolicy/testdata/cluster-roles.yaml
+592
-0
controller-role-bindings.yaml
...ac/bootstrappolicy/testdata/controller-role-bindings.yaml
+199
-0
controller-roles.yaml
...rizer/rbac/bootstrappolicy/testdata/controller-roles.yaml
+0
-0
No files found.
pkg/apis/rbac/BUILD
View file @
8553a8b8
...
...
@@ -26,6 +26,7 @@ go_library(
"//pkg/conversion:go_default_library",
"//pkg/runtime:go_default_library",
"//pkg/runtime/schema:go_default_library",
"//pkg/util/sets:go_default_library",
"//pkg/watch/versioned:go_default_library",
],
)
pkg/apis/rbac/helpers.go
View file @
8553a8b8
...
...
@@ -22,6 +22,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/runtime/schema"
"k8s.io/kubernetes/pkg/util/sets"
)
func
RoleRefGroupKind
(
roleRef
RoleRef
)
schema
.
GroupKind
{
...
...
@@ -133,27 +134,27 @@ type PolicyRuleBuilder struct {
func
NewRule
(
verbs
...
string
)
*
PolicyRuleBuilder
{
return
&
PolicyRuleBuilder
{
PolicyRule
:
PolicyRule
{
Verbs
:
verbs
},
PolicyRule
:
PolicyRule
{
Verbs
:
sets
.
NewString
(
verbs
...
)
.
List
()
},
}
}
func
(
r
*
PolicyRuleBuilder
)
Groups
(
groups
...
string
)
*
PolicyRuleBuilder
{
r
.
PolicyRule
.
APIGroups
=
append
(
r
.
PolicyRule
.
APIGroups
,
groups
...
)
r
.
PolicyRule
.
APIGroups
=
combine
(
r
.
PolicyRule
.
APIGroups
,
groups
)
return
r
}
func
(
r
*
PolicyRuleBuilder
)
Resources
(
resources
...
string
)
*
PolicyRuleBuilder
{
r
.
PolicyRule
.
Resources
=
append
(
r
.
PolicyRule
.
Resources
,
resources
...
)
r
.
PolicyRule
.
Resources
=
combine
(
r
.
PolicyRule
.
Resources
,
resources
)
return
r
}
func
(
r
*
PolicyRuleBuilder
)
Names
(
names
...
string
)
*
PolicyRuleBuilder
{
r
.
PolicyRule
.
ResourceNames
=
append
(
r
.
PolicyRule
.
ResourceNames
,
names
...
)
r
.
PolicyRule
.
ResourceNames
=
combine
(
r
.
PolicyRule
.
ResourceNames
,
names
)
return
r
}
func
(
r
*
PolicyRuleBuilder
)
URLs
(
urls
...
string
)
*
PolicyRuleBuilder
{
r
.
PolicyRule
.
NonResourceURLs
=
append
(
r
.
PolicyRule
.
NonResourceURLs
,
urls
...
)
r
.
PolicyRule
.
NonResourceURLs
=
combine
(
r
.
PolicyRule
.
NonResourceURLs
,
urls
)
return
r
}
...
...
@@ -165,6 +166,12 @@ func (r *PolicyRuleBuilder) RuleOrDie() PolicyRule {
return
ret
}
func
combine
(
s1
,
s2
[]
string
)
[]
string
{
s
:=
sets
.
NewString
(
s1
...
)
s
.
Insert
(
s2
...
)
return
s
.
List
()
}
func
(
r
*
PolicyRuleBuilder
)
Rule
()
(
PolicyRule
,
error
)
{
if
len
(
r
.
PolicyRule
.
Verbs
)
==
0
{
return
PolicyRule
{},
fmt
.
Errorf
(
"verbs are required: %#v"
,
r
.
PolicyRule
)
...
...
plugin/pkg/auth/authorizer/rbac/bootstrappolicy/BUILD
View file @
8553a8b8
...
...
@@ -30,10 +30,18 @@ go_test(
srcs = ["policy_test.go"],
tags = ["automanaged"],
deps = [
"//pkg/api:go_default_library",
"//pkg/api/install:go_default_library",
"//pkg/api/v1:go_default_library",
"//pkg/apis/rbac:go_default_library",
"//pkg/apis/rbac/install:go_default_library",
"//pkg/apis/rbac/v1alpha1:go_default_library",
"//pkg/apis/rbac/validation:go_default_library",
"//pkg/runtime:go_default_library",
"//pkg/util/diff:go_default_library",
"//pkg/util/sets:go_default_library",
"//plugin/pkg/auth/authorizer/rbac/bootstrappolicy:go_default_library",
"//vendor:github.com/ghodss/yaml",
],
)
...
...
plugin/pkg/auth/authorizer/rbac/bootstrappolicy/policy_test.go
View file @
8553a8b8
...
...
@@ -17,10 +17,22 @@ limitations under the License.
package
bootstrappolicy_test
import
(
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/ghodss/yaml"
"k8s.io/kubernetes/pkg/api"
_
"k8s.io/kubernetes/pkg/api/install"
"k8s.io/kubernetes/pkg/api/v1"
rbac
"k8s.io/kubernetes/pkg/apis/rbac"
_
"k8s.io/kubernetes/pkg/apis/rbac/install"
rbacv1alpha1
"k8s.io/kubernetes/pkg/apis/rbac/v1alpha1"
rbacvalidation
"k8s.io/kubernetes/pkg/apis/rbac/validation"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util/diff"
"k8s.io/kubernetes/pkg/util/sets"
"k8s.io/kubernetes/plugin/pkg/auth/authorizer/rbac/bootstrappolicy"
)
...
...
@@ -136,3 +148,88 @@ func TestEditViewRelationship(t *testing.T) {
t
.
Errorf
(
"view is missing rules for: %#v
\n
If these are escalating powers, add them to the list. Otherwise, add them to the view role."
,
miss
)
}
}
func
TestBootstrapClusterRoles
(
t
*
testing
.
T
)
{
list
:=
&
api
.
List
{}
names
:=
sets
.
NewString
()
roles
:=
map
[
string
]
runtime
.
Object
{}
bootstrapRoles
:=
bootstrappolicy
.
ClusterRoles
()
for
i
:=
range
bootstrapRoles
{
role
:=
bootstrapRoles
[
i
]
names
.
Insert
(
role
.
Name
)
roles
[
role
.
Name
]
=
&
role
}
for
_
,
name
:=
range
names
.
List
()
{
list
.
Items
=
append
(
list
.
Items
,
roles
[
name
])
}
testObjects
(
t
,
list
,
"cluster-roles.yaml"
)
}
func
TestBootstrapControllerRoles
(
t
*
testing
.
T
)
{
list
:=
&
api
.
List
{}
names
:=
sets
.
NewString
()
roles
:=
map
[
string
]
runtime
.
Object
{}
bootstrapRoles
:=
bootstrappolicy
.
ControllerRoles
()
for
i
:=
range
bootstrapRoles
{
role
:=
bootstrapRoles
[
i
]
names
.
Insert
(
role
.
Name
)
roles
[
role
.
Name
]
=
&
role
}
for
_
,
name
:=
range
names
.
List
()
{
list
.
Items
=
append
(
list
.
Items
,
roles
[
name
])
}
testObjects
(
t
,
list
,
"controller-roles.yaml"
)
}
func
TestBootstrapControllerRoleBindings
(
t
*
testing
.
T
)
{
list
:=
&
api
.
List
{}
names
:=
sets
.
NewString
()
roleBindings
:=
map
[
string
]
runtime
.
Object
{}
bootstrapRoleBindings
:=
bootstrappolicy
.
ControllerRoleBindings
()
for
i
:=
range
bootstrapRoleBindings
{
roleBinding
:=
bootstrapRoleBindings
[
i
]
names
.
Insert
(
roleBinding
.
Name
)
roleBindings
[
roleBinding
.
Name
]
=
&
roleBinding
}
for
_
,
name
:=
range
names
.
List
()
{
list
.
Items
=
append
(
list
.
Items
,
roleBindings
[
name
])
}
testObjects
(
t
,
list
,
"controller-role-bindings.yaml"
)
}
func
testObjects
(
t
*
testing
.
T
,
list
*
api
.
List
,
fixtureFilename
string
)
{
filename
:=
filepath
.
Join
(
"testdata"
,
fixtureFilename
)
expectedYAML
,
err
:=
ioutil
.
ReadFile
(
filename
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
err
:=
runtime
.
EncodeList
(
api
.
Codecs
.
LegacyCodec
(
v1
.
SchemeGroupVersion
,
rbacv1alpha1
.
SchemeGroupVersion
),
list
.
Items
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
jsonData
,
err
:=
runtime
.
Encode
(
api
.
Codecs
.
LegacyCodec
(
v1
.
SchemeGroupVersion
,
rbacv1alpha1
.
SchemeGroupVersion
),
list
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
yamlData
,
err
:=
yaml
.
JSONToYAML
(
jsonData
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
string
(
yamlData
)
!=
string
(
expectedYAML
)
{
t
.
Errorf
(
"Bootstrap policy data does not match the test fixture in %s"
,
filename
)
const
updateEnvVar
=
"UPDATE_BOOTSTRAP_POLICY_FIXTURE_DATA"
if
os
.
Getenv
(
updateEnvVar
)
==
"true"
{
if
err
:=
ioutil
.
WriteFile
(
filename
,
[]
byte
(
yamlData
),
os
.
FileMode
(
0755
));
err
==
nil
{
t
.
Logf
(
"Updated data in %s"
,
filename
)
t
.
Logf
(
"Verify the diff, commit changes, and rerun the tests"
)
}
else
{
t
.
Logf
(
"Could not update data in %s: %v"
,
filename
,
err
)
}
}
else
{
t
.
Logf
(
"Diff between bootstrap data and fixture data in %s:
\n
-------------
\n
%s"
,
filename
,
diff
.
StringDiff
(
string
(
yamlData
),
string
(
expectedYAML
)))
t
.
Logf
(
"If the change is expected, re-run with %s=true to update the fixtures"
,
updateEnvVar
)
}
}
}
plugin/pkg/auth/authorizer/rbac/bootstrappolicy/testdata/cluster-roles.yaml
0 → 100644
View file @
8553a8b8
This diff is collapsed.
Click to expand it.
plugin/pkg/auth/authorizer/rbac/bootstrappolicy/testdata/controller-role-bindings.yaml
0 → 100644
View file @
8553a8b8
apiVersion
:
v1
items
:
-
apiVersion
:
rbac.authorization.k8s.io/v1alpha1
kind
:
ClusterRoleBinding
metadata
:
creationTimestamp
:
null
name
:
system:controller:attachdetach-controller
roleRef
:
apiGroup
:
rbac.authorization.k8s.io
kind
:
ClusterRole
name
:
system:controller:attachdetach-controller
subjects
:
-
kind
:
ServiceAccount
name
:
attachdetach-controller
namespace
:
kube-system
-
apiVersion
:
rbac.authorization.k8s.io/v1alpha1
kind
:
ClusterRoleBinding
metadata
:
creationTimestamp
:
null
name
:
system:controller:cronjob-controller
roleRef
:
apiGroup
:
rbac.authorization.k8s.io
kind
:
ClusterRole
name
:
system:controller:cronjob-controller
subjects
:
-
kind
:
ServiceAccount
name
:
cronjob-controller
namespace
:
kube-system
-
apiVersion
:
rbac.authorization.k8s.io/v1alpha1
kind
:
ClusterRoleBinding
metadata
:
creationTimestamp
:
null
name
:
system:controller:daemon-set-controller
roleRef
:
apiGroup
:
rbac.authorization.k8s.io
kind
:
ClusterRole
name
:
system:controller:daemon-set-controller
subjects
:
-
kind
:
ServiceAccount
name
:
daemon-set-controller
namespace
:
kube-system
-
apiVersion
:
rbac.authorization.k8s.io/v1alpha1
kind
:
ClusterRoleBinding
metadata
:
creationTimestamp
:
null
name
:
system:controller:deployment-controller
roleRef
:
apiGroup
:
rbac.authorization.k8s.io
kind
:
ClusterRole
name
:
system:controller:deployment-controller
subjects
:
-
kind
:
ServiceAccount
name
:
deployment-controller
namespace
:
kube-system
-
apiVersion
:
rbac.authorization.k8s.io/v1alpha1
kind
:
ClusterRoleBinding
metadata
:
creationTimestamp
:
null
name
:
system:controller:disruption-controller
roleRef
:
apiGroup
:
rbac.authorization.k8s.io
kind
:
ClusterRole
name
:
system:controller:disruption-controller
subjects
:
-
kind
:
ServiceAccount
name
:
disruption-controller
namespace
:
kube-system
-
apiVersion
:
rbac.authorization.k8s.io/v1alpha1
kind
:
ClusterRoleBinding
metadata
:
creationTimestamp
:
null
name
:
system:controller:endpoint-controller
roleRef
:
apiGroup
:
rbac.authorization.k8s.io
kind
:
ClusterRole
name
:
system:controller:endpoint-controller
subjects
:
-
kind
:
ServiceAccount
name
:
endpoint-controller
namespace
:
kube-system
-
apiVersion
:
rbac.authorization.k8s.io/v1alpha1
kind
:
ClusterRoleBinding
metadata
:
creationTimestamp
:
null
name
:
system:controller:horizontal-pod-autoscaler
roleRef
:
apiGroup
:
rbac.authorization.k8s.io
kind
:
ClusterRole
name
:
system:controller:horizontal-pod-autoscaler
subjects
:
-
kind
:
ServiceAccount
name
:
horizontal-pod-autoscaler
namespace
:
kube-system
-
apiVersion
:
rbac.authorization.k8s.io/v1alpha1
kind
:
ClusterRoleBinding
metadata
:
creationTimestamp
:
null
name
:
system:controller:job-controller
roleRef
:
apiGroup
:
rbac.authorization.k8s.io
kind
:
ClusterRole
name
:
system:controller:job-controller
subjects
:
-
kind
:
ServiceAccount
name
:
job-controller
namespace
:
kube-system
-
apiVersion
:
rbac.authorization.k8s.io/v1alpha1
kind
:
ClusterRoleBinding
metadata
:
creationTimestamp
:
null
name
:
system:controller:namespace-controller
roleRef
:
apiGroup
:
rbac.authorization.k8s.io
kind
:
ClusterRole
name
:
system:controller:namespace-controller
subjects
:
-
kind
:
ServiceAccount
name
:
namespace-controller
namespace
:
kube-system
-
apiVersion
:
rbac.authorization.k8s.io/v1alpha1
kind
:
ClusterRoleBinding
metadata
:
creationTimestamp
:
null
name
:
system:controller:persistent-volume-binder
roleRef
:
apiGroup
:
rbac.authorization.k8s.io
kind
:
ClusterRole
name
:
system:controller:persistent-volume-binder
subjects
:
-
kind
:
ServiceAccount
name
:
persistent-volume-binder
namespace
:
kube-system
-
apiVersion
:
rbac.authorization.k8s.io/v1alpha1
kind
:
ClusterRoleBinding
metadata
:
creationTimestamp
:
null
name
:
system:controller:pod-garbage-controller
roleRef
:
apiGroup
:
rbac.authorization.k8s.io
kind
:
ClusterRole
name
:
system:controller:pod-garbage-controller
subjects
:
-
kind
:
ServiceAccount
name
:
pod-garbage-controller
namespace
:
kube-system
-
apiVersion
:
rbac.authorization.k8s.io/v1alpha1
kind
:
ClusterRoleBinding
metadata
:
creationTimestamp
:
null
name
:
system:controller:replicaset-controller
roleRef
:
apiGroup
:
rbac.authorization.k8s.io
kind
:
ClusterRole
name
:
system:controller:replicaset-controller
subjects
:
-
kind
:
ServiceAccount
name
:
replicaset-controller
namespace
:
kube-system
-
apiVersion
:
rbac.authorization.k8s.io/v1alpha1
kind
:
ClusterRoleBinding
metadata
:
creationTimestamp
:
null
name
:
system:controller:replication-controller
roleRef
:
apiGroup
:
rbac.authorization.k8s.io
kind
:
ClusterRole
name
:
system:controller:replication-controller
subjects
:
-
kind
:
ServiceAccount
name
:
replication-controller
namespace
:
kube-system
-
apiVersion
:
rbac.authorization.k8s.io/v1alpha1
kind
:
ClusterRoleBinding
metadata
:
creationTimestamp
:
null
name
:
system:controller:service-controller
roleRef
:
apiGroup
:
rbac.authorization.k8s.io
kind
:
ClusterRole
name
:
system:controller:service-controller
subjects
:
-
kind
:
ServiceAccount
name
:
service-controller
namespace
:
kube-system
-
apiVersion
:
rbac.authorization.k8s.io/v1alpha1
kind
:
ClusterRoleBinding
metadata
:
creationTimestamp
:
null
name
:
system:controller:statefulset-controller
roleRef
:
apiGroup
:
rbac.authorization.k8s.io
kind
:
ClusterRole
name
:
system:controller:statefulset-controller
subjects
:
-
kind
:
ServiceAccount
name
:
statefulset-controller
namespace
:
kube-system
kind
:
List
metadata
:
{}
plugin/pkg/auth/authorizer/rbac/bootstrappolicy/testdata/controller-roles.yaml
0 → 100644
View file @
8553a8b8
This diff is collapsed.
Click to expand it.
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