@@ -19,7 +19,7 @@ limitations under the License.
19
19
//
20
20
// The markers take the form:
21
21
//
22
- // +kubebuilder:rbac:groups=<groups>,resources=<resources>,verbs=<verbs>,urls=<non resource urls>
22
+ // +kubebuilder:rbac:groups=<groups>,resources=<resources>,resourceNames=<resource names>, verbs=<verbs>,urls=<non resource urls>
23
23
package rbac
24
24
25
25
import (
@@ -48,6 +48,11 @@ type Rule struct {
48
48
Groups []string `marker:",optional"`
49
49
// Resources specifies the API resources that this rule encompasses.
50
50
Resources []string `marker:",optional"`
51
+ // ResourceNames specifies the names of the API resources that this rule encompasses.
52
+ //
53
+ // Create requests cannot be restricted by resourcename, as the object's name
54
+ // is not known at authorization time.
55
+ ResourceNames []string `marker:",optional"`
51
56
// Verbs specifies the (lowercase) kubernetes API verbs that this rule encompasses.
52
57
Verbs []string
53
58
// URL specifies the non-resource URLs that this rule encompasses.
@@ -60,13 +65,14 @@ type Rule struct {
60
65
61
66
// ruleKey represents the resources and non-resources a Rule applies.
62
67
type ruleKey struct {
63
- Groups string
64
- Resources string
65
- URLs string
68
+ Groups string
69
+ Resources string
70
+ ResourceNames string
71
+ URLs string
66
72
}
67
73
68
74
func (key ruleKey ) String () string {
69
- return fmt .Sprintf ("%s + %s + %s" , key .Groups , key .Resources , key .URLs )
75
+ return fmt .Sprintf ("%s + %s + %s + %s " , key .Groups , key .Resources , key . ResourceNames , key .URLs )
70
76
}
71
77
72
78
// ruleKeys implements sort.Interface
@@ -80,9 +86,10 @@ func (keys ruleKeys) Less(i, j int) bool { return keys[i].String() < keys[j].Str
80
86
func (r * Rule ) key () ruleKey {
81
87
r .normalize ()
82
88
return ruleKey {
83
- Groups : strings .Join (r .Groups , "&" ),
84
- Resources : strings .Join (r .Resources , "&" ),
85
- URLs : strings .Join (r .URLs , "&" ),
89
+ Groups : strings .Join (r .Groups , "&" ),
90
+ Resources : strings .Join (r .Resources , "&" ),
91
+ ResourceNames : strings .Join (r .ResourceNames , "&" ),
92
+ URLs : strings .Join (r .URLs , "&" ),
86
93
}
87
94
}
88
95
@@ -96,6 +103,7 @@ func (r *Rule) addVerbs(verbs []string) {
96
103
func (r * Rule ) normalize () {
97
104
r .Groups = removeDupAndSort (r .Groups )
98
105
r .Resources = removeDupAndSort (r .Resources )
106
+ r .ResourceNames = removeDupAndSort (r .ResourceNames )
99
107
r .Verbs = removeDupAndSort (r .Verbs )
100
108
r .URLs = removeDupAndSort (r .URLs )
101
109
}
@@ -130,6 +138,7 @@ func (r *Rule) ToRule() rbacv1.PolicyRule {
130
138
APIGroups : r .Groups ,
131
139
Verbs : r .Verbs ,
132
140
Resources : r .Resources ,
141
+ ResourceNames : r .ResourceNames ,
133
142
NonResourceURLs : r .URLs ,
134
143
}
135
144
}
0 commit comments