@@ -14,11 +14,9 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
16
17
+ // Package abac authorizes Kubernetes API actions using an Attribute-based access control scheme.
17
18
package abac
18
19
19
- // Policy authorizes Kubernetes API actions using an Attribute-based access
20
- // control scheme.
21
-
22
20
import (
23
21
"bufio"
24
22
"fmt"
@@ -31,6 +29,8 @@ import (
31
29
"k8s.io/apiserver/pkg/authentication/user"
32
30
"k8s.io/apiserver/pkg/authorization/authorizer"
33
31
"k8s.io/kubernetes/pkg/apis/abac"
32
+
33
+ // Import latest API for init/side-effects
34
34
_ "k8s.io/kubernetes/pkg/apis/abac/latest"
35
35
"k8s.io/kubernetes/pkg/apis/abac/v0"
36
36
)
@@ -49,10 +49,13 @@ func (p policyLoadError) Error() string {
49
49
return fmt .Sprintf ("error reading policy file %s: %v" , p .path , p .err )
50
50
}
51
51
52
- type policyList []* abac.Policy
52
+ // PolicyList is simply a slice of Policy structs.
53
+ type PolicyList []* abac.Policy
53
54
55
+ // NewFromFile attempts to create a policy list from the given file.
56
+ //
54
57
// TODO: Have policies be created via an API call and stored in REST storage.
55
- func NewFromFile (path string ) (policyList , error ) {
58
+ func NewFromFile (path string ) (PolicyList , error ) {
56
59
// File format is one map per line. This allows easy concatenation of files,
57
60
// comments in files, and identification of errors by line number.
58
61
file , err := os .Open (path )
@@ -62,7 +65,7 @@ func NewFromFile(path string) (policyList, error) {
62
65
defer file .Close ()
63
66
64
67
scanner := bufio .NewScanner (file )
65
- pl := make (policyList , 0 )
68
+ pl := make (PolicyList , 0 )
66
69
67
70
decoder := abac .Codecs .UniversalDecoder ()
68
71
@@ -220,8 +223,8 @@ func resourceMatches(p abac.Policy, a authorizer.Attributes) bool {
220
223
return false
221
224
}
222
225
223
- // Authorizer implements authorizer.Authorize
224
- func (pl policyList ) Authorize (a authorizer.Attributes ) (authorizer.Decision , string , error ) {
226
+ // Authorize implements authorizer.Authorize
227
+ func (pl PolicyList ) Authorize (a authorizer.Attributes ) (authorizer.Decision , string , error ) {
225
228
for _ , p := range pl {
226
229
if matches (* p , a ) {
227
230
return authorizer .DecisionAllow , "" , nil
@@ -233,7 +236,8 @@ func (pl policyList) Authorize(a authorizer.Attributes) (authorizer.Decision, st
233
236
// Then, add Caching only if needed.
234
237
}
235
238
236
- func (pl policyList ) RulesFor (user user.Info , namespace string ) ([]authorizer.ResourceRuleInfo , []authorizer.NonResourceRuleInfo , bool , error ) {
239
+ // RulesFor returns rules for the given user and namespace.
240
+ func (pl PolicyList ) RulesFor (user user.Info , namespace string ) ([]authorizer.ResourceRuleInfo , []authorizer.NonResourceRuleInfo , bool , error ) {
237
241
var (
238
242
resourceRules []authorizer.ResourceRuleInfo
239
243
nonResourceRules []authorizer.NonResourceRuleInfo
0 commit comments