123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269 |
- /*
- Copyright 2014 The Kubernetes Authors.
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
- package abac
- import (
- "io/ioutil"
- "os"
- "reflect"
- "testing"
- "k8s.io/apimachinery/pkg/runtime"
- "k8s.io/apiserver/pkg/authentication/user"
- "k8s.io/apiserver/pkg/authorization/authorizer"
- "k8s.io/kubernetes/pkg/apis/abac"
- "k8s.io/kubernetes/pkg/apis/abac/v0"
- "k8s.io/kubernetes/pkg/apis/abac/v1beta1"
- )
- func TestEmptyFile(t *testing.T) {
- _, err := newWithContents(t, "")
- if err != nil {
- t.Errorf("unable to read policy file: %v", err)
- }
- }
- func TestOneLineFileNoNewLine(t *testing.T) {
- _, err := newWithContents(t, `{"user":"scheduler", "readonly": true, "resource": "pods", "namespace":"ns1"}`)
- if err != nil {
- t.Errorf("unable to read policy file: %v", err)
- }
- }
- func TestTwoLineFile(t *testing.T) {
- _, err := newWithContents(t, `{"user":"scheduler", "readonly": true, "resource": "pods"}
- {"user":"scheduler", "readonly": true, "resource": "services"}
- `)
- if err != nil {
- t.Errorf("unable to read policy file: %v", err)
- }
- }
- // Test the file that we will point users at as an example.
- func TestExampleFile(t *testing.T) {
- _, err := NewFromFile("./example_policy_file.jsonl")
- if err != nil {
- t.Errorf("unable to read policy file: %v", err)
- }
- }
- func TestAuthorizeV0(t *testing.T) {
- a, err := newWithContents(t, `{ "readonly": true, "resource": "events" }
- {"user":"scheduler", "readonly": true, "resource": "pods" }
- {"user":"scheduler", "resource": "bindings" }
- {"user":"kubelet", "readonly": true, "resource": "bindings" }
- {"user":"kubelet", "resource": "events" }
- {"user":"alice", "namespace": "projectCaribou"}
- {"user":"bob", "readonly": true, "namespace": "projectCaribou"}
- `)
- if err != nil {
- t.Fatalf("unable to read policy file: %v", err)
- }
- authenticatedGroup := []string{user.AllAuthenticated}
- uScheduler := user.DefaultInfo{Name: "scheduler", UID: "uid1", Groups: authenticatedGroup}
- uAlice := user.DefaultInfo{Name: "alice", UID: "uid3", Groups: authenticatedGroup}
- uChuck := user.DefaultInfo{Name: "chuck", UID: "uid5", Groups: authenticatedGroup}
- testCases := []struct {
- User user.DefaultInfo
- Verb string
- Resource string
- NS string
- APIGroup string
- Path string
- ExpectDecision authorizer.Decision
- }{
- // Scheduler can read pods
- {User: uScheduler, Verb: "list", Resource: "pods", NS: "ns1", ExpectDecision: authorizer.DecisionAllow},
- {User: uScheduler, Verb: "list", Resource: "pods", NS: "", ExpectDecision: authorizer.DecisionAllow},
- // Scheduler cannot write pods
- {User: uScheduler, Verb: "create", Resource: "pods", NS: "ns1", ExpectDecision: authorizer.DecisionNoOpinion},
- {User: uScheduler, Verb: "create", Resource: "pods", NS: "", ExpectDecision: authorizer.DecisionNoOpinion},
- // Scheduler can write bindings
- {User: uScheduler, Verb: "get", Resource: "bindings", NS: "ns1", ExpectDecision: authorizer.DecisionAllow},
- {User: uScheduler, Verb: "get", Resource: "bindings", NS: "", ExpectDecision: authorizer.DecisionAllow},
- // Alice can read and write anything in the right namespace.
- {User: uAlice, Verb: "get", Resource: "pods", NS: "projectCaribou", ExpectDecision: authorizer.DecisionAllow},
- {User: uAlice, Verb: "get", Resource: "widgets", NS: "projectCaribou", ExpectDecision: authorizer.DecisionAllow},
- {User: uAlice, Verb: "get", Resource: "", NS: "projectCaribou", ExpectDecision: authorizer.DecisionAllow},
- {User: uAlice, Verb: "update", Resource: "pods", NS: "projectCaribou", ExpectDecision: authorizer.DecisionAllow},
- {User: uAlice, Verb: "update", Resource: "widgets", NS: "projectCaribou", ExpectDecision: authorizer.DecisionAllow},
- {User: uAlice, Verb: "update", Resource: "", NS: "projectCaribou", ExpectDecision: authorizer.DecisionAllow},
- {User: uAlice, Verb: "update", Resource: "foo", NS: "projectCaribou", APIGroup: "bar", ExpectDecision: authorizer.DecisionAllow},
- // .. but not the wrong namespace.
- {User: uAlice, Verb: "get", Resource: "pods", NS: "ns1", ExpectDecision: authorizer.DecisionNoOpinion},
- {User: uAlice, Verb: "get", Resource: "widgets", NS: "ns1", ExpectDecision: authorizer.DecisionNoOpinion},
- {User: uAlice, Verb: "get", Resource: "", NS: "ns1", ExpectDecision: authorizer.DecisionNoOpinion},
- // Chuck can read events, since anyone can.
- {User: uChuck, Verb: "get", Resource: "events", NS: "ns1", ExpectDecision: authorizer.DecisionAllow},
- {User: uChuck, Verb: "get", Resource: "events", NS: "", ExpectDecision: authorizer.DecisionAllow},
- // Chuck can't do other things.
- {User: uChuck, Verb: "update", Resource: "events", NS: "ns1", ExpectDecision: authorizer.DecisionNoOpinion},
- {User: uChuck, Verb: "get", Resource: "pods", NS: "ns1", ExpectDecision: authorizer.DecisionNoOpinion},
- {User: uChuck, Verb: "get", Resource: "floop", NS: "ns1", ExpectDecision: authorizer.DecisionNoOpinion},
- // Chunk can't access things with no kind or namespace
- {User: uChuck, Verb: "get", Path: "/", Resource: "", NS: "", ExpectDecision: authorizer.DecisionNoOpinion},
- }
- for i, tc := range testCases {
- attr := authorizer.AttributesRecord{
- User: &tc.User,
- Verb: tc.Verb,
- Resource: tc.Resource,
- Namespace: tc.NS,
- APIGroup: tc.APIGroup,
- Path: tc.Path,
- ResourceRequest: len(tc.NS) > 0 || len(tc.Resource) > 0,
- }
- decision, _, _ := a.Authorize(attr)
- if tc.ExpectDecision != decision {
- t.Logf("tc: %v -> attr %v", tc, attr)
- t.Errorf("%d: Expected allowed=%v but actually allowed=%v\n\t%v",
- i, tc.ExpectDecision, decision, tc)
- }
- }
- }
- func getResourceRules(infos []authorizer.ResourceRuleInfo) []authorizer.DefaultResourceRuleInfo {
- rules := make([]authorizer.DefaultResourceRuleInfo, len(infos))
- for i, info := range infos {
- rules[i] = authorizer.DefaultResourceRuleInfo{
- Verbs: info.GetVerbs(),
- APIGroups: info.GetAPIGroups(),
- Resources: info.GetResources(),
- ResourceNames: info.GetResourceNames(),
- }
- }
- return rules
- }
- func getNonResourceRules(infos []authorizer.NonResourceRuleInfo) []authorizer.DefaultNonResourceRuleInfo {
- rules := make([]authorizer.DefaultNonResourceRuleInfo, len(infos))
- for i, info := range infos {
- rules[i] = authorizer.DefaultNonResourceRuleInfo{
- Verbs: info.GetVerbs(),
- NonResourceURLs: info.GetNonResourceURLs(),
- }
- }
- return rules
- }
- func TestRulesFor(t *testing.T) {
- a, err := newWithContents(t, `
- { "readonly": true, "resource": "events" }
- {"user":"scheduler", "readonly": true, "resource": "pods" }
- {"user":"scheduler", "resource": "bindings" }
- {"user":"kubelet", "readonly": true, "resource": "pods" }
- {"user":"kubelet", "resource": "events" }
- {"user":"alice", "namespace": "projectCaribou"}
- {"user":"bob", "readonly": true, "namespace": "projectCaribou"}
- {"user":"bob", "readonly": true, "nonResourcePath": "*"}
- {"group":"a", "resource": "bindings" }
- {"group":"b", "readonly": true, "nonResourcePath": "*"}
- `)
- if err != nil {
- t.Fatalf("unable to read policy file: %v", err)
- }
- authenticatedGroup := []string{user.AllAuthenticated}
- uScheduler := user.DefaultInfo{Name: "scheduler", UID: "uid1", Groups: authenticatedGroup}
- uKubelet := user.DefaultInfo{Name: "kubelet", UID: "uid2", Groups: []string{"a", "b"}}
- uAlice := user.DefaultInfo{Name: "alice", UID: "uid3", Groups: authenticatedGroup}
- uBob := user.DefaultInfo{Name: "bob", UID: "uid4", Groups: authenticatedGroup}
- uChuck := user.DefaultInfo{Name: "chuck", UID: "uid5", Groups: []string{"a", "b"}}
- testCases := []struct {
- User user.DefaultInfo
- Namespace string
- ExpectResourceRules []authorizer.DefaultResourceRuleInfo
- ExpectNonResourceRules []authorizer.DefaultNonResourceRuleInfo
- }{
- {
- User: uScheduler,
- Namespace: "ns1",
- ExpectResourceRules: []authorizer.DefaultResourceRuleInfo{
- {
- Verbs: []string{"get", "list", "watch"},
- APIGroups: []string{"*"},
- Resources: []string{"events"},
- },
- {
- Verbs: []string{"get", "list", "watch"},
- APIGroups: []string{"*"},
- Resources: []string{"pods"},
- },
- {
- Verbs: []string{"*"},
- APIGroups: []string{"*"},
- Resources: []string{"bindings"},
- },
- },
- ExpectNonResourceRules: []authorizer.DefaultNonResourceRuleInfo{},
- },
- {
- User: uKubelet,
- Namespace: "ns1",
- ExpectResourceRules: []authorizer.DefaultResourceRuleInfo{
- {
- Verbs: []string{"get", "list", "watch"},
- APIGroups: []string{"*"},
- Resources: []string{"pods"},
- },
- {
- Verbs: []string{"*"},
- APIGroups: []string{"*"},
- Resources: []string{"events"},
- },
- {
- Verbs: []string{"*"},
- APIGroups: []string{"*"},
- Resources: []string{"bindings"},
- },
- {
- Verbs: []string{"get", "list", "watch"},
- APIGroups: []string{"*"},
- Resources: []string{"*"},
- },
- },
- ExpectNonResourceRules: []authorizer.DefaultNonResourceRuleInfo{
- {
- Verbs: []string{"get", "list", "watch"},
- NonResourceURLs: []string{"*"},
- },
- },
- },
- {
- User: uAlice,
- Namespace: "projectCaribou",
- ExpectResourceRules: []authorizer.DefaultResourceRuleInfo{
- {
- Verbs: []string{"get", "list", "watch"},
- APIGroups: []string{"*"},
- Resources: []string{"events"},
- },
- {
- Verbs: []string{"*"},
- APIGroups: []string{"*"},
- Resources: []string{"*"},
- },
- },
- ExpectNonResourceRules: []authorizer.DefaultNonResourceRuleInfo{},
- },
- {
- User: uBob,
- Namespace: "projectCaribou",
- ExpectResourceRules: []authorizer.DefaultResourceRuleInfo{
- {
- Verbs: []string{"get", "list", "watch"},
- APIGroups: []string{"*"},
- Resources: []string{"events"},
- },
- {
- Verbs: []string{"get", "list", "watch"},
- APIGroups: []string{"*"},
- Resources: []string{"*"},
- },
- {
- Verbs: []string{"get", "list", "watch"},
- APIGroups: []string{"*"},
- Resources: []string{"*"},
- },
- },
- ExpectNonResourceRules: []authorizer.DefaultNonResourceRuleInfo{
- {
- Verbs: []string{"get", "list", "watch"},
- NonResourceURLs: []string{"*"},
- },
- },
- },
- {
- User: uChuck,
- Namespace: "ns1",
- ExpectResourceRules: []authorizer.DefaultResourceRuleInfo{
- {
- Verbs: []string{"*"},
- APIGroups: []string{"*"},
- Resources: []string{"bindings"},
- },
- {
- Verbs: []string{"get", "list", "watch"},
- APIGroups: []string{"*"},
- Resources: []string{"*"},
- },
- },
- ExpectNonResourceRules: []authorizer.DefaultNonResourceRuleInfo{
- {
- Verbs: []string{"get", "list", "watch"},
- NonResourceURLs: []string{"*"},
- },
- },
- },
- }
- for i, tc := range testCases {
- attr := authorizer.AttributesRecord{
- User: &tc.User,
- Namespace: tc.Namespace,
- }
- resourceRules, nonResourceRules, _, _ := a.RulesFor(attr.GetUser(), attr.GetNamespace())
- actualResourceRules := getResourceRules(resourceRules)
- if !reflect.DeepEqual(tc.ExpectResourceRules, actualResourceRules) {
- t.Logf("tc: %v -> attr %v", tc, attr)
- t.Errorf("%d: Expected: \n%#v\n but actual: \n%#v\n",
- i, tc.ExpectResourceRules, actualResourceRules)
- }
- actualNonResourceRules := getNonResourceRules(nonResourceRules)
- if !reflect.DeepEqual(tc.ExpectNonResourceRules, actualNonResourceRules) {
- t.Logf("tc: %v -> attr %v", tc, attr)
- t.Errorf("%d: Expected: \n%#v\n but actual: \n%#v\n",
- i, tc.ExpectNonResourceRules, actualNonResourceRules)
- }
- }
- }
- func TestAuthorizeV1beta1(t *testing.T) {
- a, err := newWithContents(t,
- `
- # Comment line, after a blank line
- {"apiVersion":"abac.authorization.kubernetes.io/v1beta1","kind":"Policy","spec":{"user":"*", "readonly": true, "nonResourcePath": "/api"}}
- {"apiVersion":"abac.authorization.kubernetes.io/v1beta1","kind":"Policy","spec":{"user":"*", "nonResourcePath": "/custom"}}
- {"apiVersion":"abac.authorization.kubernetes.io/v1beta1","kind":"Policy","spec":{"user":"*", "nonResourcePath": "/root/*"}}
- {"apiVersion":"abac.authorization.kubernetes.io/v1beta1","kind":"Policy","spec":{"user":"noresource", "nonResourcePath": "*"}}
- {"apiVersion":"abac.authorization.kubernetes.io/v1beta1","kind":"Policy","spec":{"user":"*", "readonly": true, "resource": "events", "namespace": "*"}}
- {"apiVersion":"abac.authorization.kubernetes.io/v1beta1","kind":"Policy","spec":{"user":"scheduler", "readonly": true, "resource": "pods", "namespace": "*"}}
- {"apiVersion":"abac.authorization.kubernetes.io/v1beta1","kind":"Policy","spec":{"user":"scheduler", "resource": "bindings", "namespace": "*"}}
- {"apiVersion":"abac.authorization.kubernetes.io/v1beta1","kind":"Policy","spec":{"user":"kubelet", "readonly": true, "resource": "bindings", "namespace": "*"}}
- {"apiVersion":"abac.authorization.kubernetes.io/v1beta1","kind":"Policy","spec":{"user":"kubelet", "resource": "events", "namespace": "*"}}
- {"apiVersion":"abac.authorization.kubernetes.io/v1beta1","kind":"Policy","spec":{"user":"alice", "resource": "*", "namespace": "projectCaribou"}}
- {"apiVersion":"abac.authorization.kubernetes.io/v1beta1","kind":"Policy","spec":{"user":"bob", "readonly": true, "resource": "*", "namespace": "projectCaribou"}}
- {"apiVersion":"abac.authorization.kubernetes.io/v1beta1","kind":"Policy","spec":{"user":"debbie", "resource": "pods", "namespace": "projectCaribou"}}
- {"apiVersion":"abac.authorization.kubernetes.io/v1beta1","kind":"Policy","spec":{"user":"apigroupuser", "resource": "*", "namespace": "projectAnyGroup", "apiGroup": "*"}}
- {"apiVersion":"abac.authorization.kubernetes.io/v1beta1","kind":"Policy","spec":{"user":"apigroupuser", "resource": "*", "namespace": "projectEmptyGroup", "apiGroup": "" }}
- {"apiVersion":"abac.authorization.kubernetes.io/v1beta1","kind":"Policy","spec":{"user":"apigroupuser", "resource": "*", "namespace": "projectXGroup", "apiGroup": "x"}}`)
- if err != nil {
- t.Fatalf("unable to read policy file: %v", err)
- }
- authenticatedGroup := []string{user.AllAuthenticated}
- uScheduler := user.DefaultInfo{Name: "scheduler", UID: "uid1", Groups: authenticatedGroup}
- uAlice := user.DefaultInfo{Name: "alice", UID: "uid3", Groups: authenticatedGroup}
- uChuck := user.DefaultInfo{Name: "chuck", UID: "uid5", Groups: authenticatedGroup}
- uDebbie := user.DefaultInfo{Name: "debbie", UID: "uid6", Groups: authenticatedGroup}
- uNoResource := user.DefaultInfo{Name: "noresource", UID: "uid7", Groups: authenticatedGroup}
- uAPIGroup := user.DefaultInfo{Name: "apigroupuser", UID: "uid8", Groups: authenticatedGroup}
- testCases := []struct {
- User user.DefaultInfo
- Verb string
- Resource string
- APIGroup string
- NS string
- Path string
- ExpectDecision authorizer.Decision
- }{
- // Scheduler can read pods
- {User: uScheduler, Verb: "list", Resource: "pods", NS: "ns1", ExpectDecision: authorizer.DecisionAllow},
- {User: uScheduler, Verb: "list", Resource: "pods", NS: "", ExpectDecision: authorizer.DecisionAllow},
- // Scheduler cannot write pods
- {User: uScheduler, Verb: "create", Resource: "pods", NS: "ns1", ExpectDecision: authorizer.DecisionNoOpinion},
- {User: uScheduler, Verb: "create", Resource: "pods", NS: "", ExpectDecision: authorizer.DecisionNoOpinion},
- // Scheduler can write bindings
- {User: uScheduler, Verb: "get", Resource: "bindings", NS: "ns1", ExpectDecision: authorizer.DecisionAllow},
- {User: uScheduler, Verb: "get", Resource: "bindings", NS: "", ExpectDecision: authorizer.DecisionAllow},
- // Alice can read and write anything in the right namespace.
- {User: uAlice, Verb: "get", Resource: "pods", NS: "projectCaribou", ExpectDecision: authorizer.DecisionAllow},
- {User: uAlice, Verb: "get", Resource: "widgets", NS: "projectCaribou", ExpectDecision: authorizer.DecisionAllow},
- {User: uAlice, Verb: "get", Resource: "", NS: "projectCaribou", ExpectDecision: authorizer.DecisionAllow},
- {User: uAlice, Verb: "update", Resource: "pods", NS: "projectCaribou", ExpectDecision: authorizer.DecisionAllow},
- {User: uAlice, Verb: "update", Resource: "widgets", NS: "projectCaribou", ExpectDecision: authorizer.DecisionAllow},
- {User: uAlice, Verb: "update", Resource: "", NS: "projectCaribou", ExpectDecision: authorizer.DecisionAllow},
- // .. but not the wrong namespace.
- {User: uAlice, Verb: "get", Resource: "pods", NS: "ns1", ExpectDecision: authorizer.DecisionNoOpinion},
- {User: uAlice, Verb: "get", Resource: "widgets", NS: "ns1", ExpectDecision: authorizer.DecisionNoOpinion},
- {User: uAlice, Verb: "get", Resource: "", NS: "ns1", ExpectDecision: authorizer.DecisionNoOpinion},
- // Debbie can write to pods in the right namespace
- {User: uDebbie, Verb: "update", Resource: "pods", NS: "projectCaribou", ExpectDecision: authorizer.DecisionAllow},
- // Chuck can read events, since anyone can.
- {User: uChuck, Verb: "get", Resource: "events", NS: "ns1", ExpectDecision: authorizer.DecisionAllow},
- {User: uChuck, Verb: "get", Resource: "events", NS: "", ExpectDecision: authorizer.DecisionAllow},
- // Chuck can't do other things.
- {User: uChuck, Verb: "update", Resource: "events", NS: "ns1", ExpectDecision: authorizer.DecisionNoOpinion},
- {User: uChuck, Verb: "get", Resource: "pods", NS: "ns1", ExpectDecision: authorizer.DecisionNoOpinion},
- {User: uChuck, Verb: "get", Resource: "floop", NS: "ns1", ExpectDecision: authorizer.DecisionNoOpinion},
- // Chuck can't access things with no resource or namespace
- {User: uChuck, Verb: "get", Path: "/", Resource: "", NS: "", ExpectDecision: authorizer.DecisionNoOpinion},
- // but can access /api
- {User: uChuck, Verb: "get", Path: "/api", Resource: "", NS: "", ExpectDecision: authorizer.DecisionAllow},
- // though he cannot write to it
- {User: uChuck, Verb: "create", Path: "/api", Resource: "", NS: "", ExpectDecision: authorizer.DecisionNoOpinion},
- // while he can write to /custom
- {User: uChuck, Verb: "update", Path: "/custom", Resource: "", NS: "", ExpectDecision: authorizer.DecisionAllow},
- // he cannot get "/root"
- {User: uChuck, Verb: "get", Path: "/root", Resource: "", NS: "", ExpectDecision: authorizer.DecisionNoOpinion},
- // but can get any subpath
- {User: uChuck, Verb: "get", Path: "/root/", Resource: "", NS: "", ExpectDecision: authorizer.DecisionAllow},
- {User: uChuck, Verb: "get", Path: "/root/test/1/2/3", Resource: "", NS: "", ExpectDecision: authorizer.DecisionAllow},
- // the user "noresource" can get any non-resource request
- {User: uNoResource, Verb: "get", Path: "", Resource: "", NS: "", ExpectDecision: authorizer.DecisionAllow},
- {User: uNoResource, Verb: "get", Path: "/", Resource: "", NS: "", ExpectDecision: authorizer.DecisionAllow},
- {User: uNoResource, Verb: "get", Path: "/foo/bar/baz", Resource: "", NS: "", ExpectDecision: authorizer.DecisionAllow},
- // but cannot get any request where IsResourceRequest() == true
- {User: uNoResource, Verb: "get", Path: "/", Resource: "", NS: "bar", ExpectDecision: authorizer.DecisionNoOpinion},
- {User: uNoResource, Verb: "get", Path: "/foo/bar/baz", Resource: "foo", NS: "bar", ExpectDecision: authorizer.DecisionNoOpinion},
- // Test APIGroup matching
- {User: uAPIGroup, Verb: "get", APIGroup: "x", Resource: "foo", NS: "projectAnyGroup", ExpectDecision: authorizer.DecisionAllow},
- {User: uAPIGroup, Verb: "get", APIGroup: "x", Resource: "foo", NS: "projectEmptyGroup", ExpectDecision: authorizer.DecisionNoOpinion},
- {User: uAPIGroup, Verb: "get", APIGroup: "x", Resource: "foo", NS: "projectXGroup", ExpectDecision: authorizer.DecisionAllow},
- }
- for i, tc := range testCases {
- attr := authorizer.AttributesRecord{
- User: &tc.User,
- Verb: tc.Verb,
- Resource: tc.Resource,
- APIGroup: tc.APIGroup,
- Namespace: tc.NS,
- ResourceRequest: len(tc.NS) > 0 || len(tc.Resource) > 0,
- Path: tc.Path,
- }
- // t.Logf("tc %2v: %v -> attr %v", i, tc, attr)
- decision, _, _ := a.Authorize(attr)
- if tc.ExpectDecision != decision {
- t.Errorf("%d: Expected allowed=%v but actually allowed=%v, for case %+v & %+v",
- i, tc.ExpectDecision, decision, tc, attr)
- }
- }
- }
- func TestSubjectMatches(t *testing.T) {
- testCases := map[string]struct {
- User user.DefaultInfo
- Policy runtime.Object
- ExpectMatch bool
- }{
- "v0 empty policy does not match unauthed user": {
- User: user.DefaultInfo{Name: "system:anonymous", Groups: []string{"system:unauthenticated"}},
- Policy: &v0.Policy{
- User: "",
- Group: "",
- },
- ExpectMatch: false,
- },
- "v0 * user policy does not match unauthed user": {
- User: user.DefaultInfo{Name: "system:anonymous", Groups: []string{"system:unauthenticated"}},
- Policy: &v0.Policy{
- User: "*",
- Group: "",
- },
- ExpectMatch: false,
- },
- "v0 * group policy does not match unauthed user": {
- User: user.DefaultInfo{Name: "system:anonymous", Groups: []string{"system:unauthenticated"}},
- Policy: &v0.Policy{
- User: "",
- Group: "*",
- },
- ExpectMatch: false,
- },
- "v0 empty policy matches authed user": {
- User: user.DefaultInfo{Name: "Foo", Groups: []string{user.AllAuthenticated}},
- Policy: &v0.Policy{
- User: "",
- Group: "",
- },
- ExpectMatch: true,
- },
- "v0 empty policy matches authed user with groups": {
- User: user.DefaultInfo{Name: "Foo", Groups: []string{"a", "b", user.AllAuthenticated}},
- Policy: &v0.Policy{
- User: "",
- Group: "",
- },
- ExpectMatch: true,
- },
- "v0 user policy does not match unauthed user": {
- User: user.DefaultInfo{Name: "system:anonymous", Groups: []string{"system:unauthenticated"}},
- Policy: &v0.Policy{
- User: "Foo",
- Group: "",
- },
- ExpectMatch: false,
- },
- "v0 user policy does not match different user": {
- User: user.DefaultInfo{Name: "Bar", Groups: []string{user.AllAuthenticated}},
- Policy: &v0.Policy{
- User: "Foo",
- Group: "",
- },
- ExpectMatch: false,
- },
- "v0 user policy is case-sensitive": {
- User: user.DefaultInfo{Name: "foo", Groups: []string{user.AllAuthenticated}},
- Policy: &v0.Policy{
- User: "Foo",
- Group: "",
- },
- ExpectMatch: false,
- },
- "v0 user policy does not match substring": {
- User: user.DefaultInfo{Name: "FooBar", Groups: []string{user.AllAuthenticated}},
- Policy: &v0.Policy{
- User: "Foo",
- Group: "",
- },
- ExpectMatch: false,
- },
- "v0 user policy matches username": {
- User: user.DefaultInfo{Name: "Foo", Groups: []string{user.AllAuthenticated}},
- Policy: &v0.Policy{
- User: "Foo",
- Group: "",
- },
- ExpectMatch: true,
- },
- "v0 group policy does not match unauthed user": {
- User: user.DefaultInfo{Name: "system:anonymous", Groups: []string{"system:unauthenticated"}},
- Policy: &v0.Policy{
- User: "",
- Group: "Foo",
- },
- ExpectMatch: false,
- },
- "v0 group policy does not match user in different group": {
- User: user.DefaultInfo{Name: "FooBar", Groups: []string{"B", user.AllAuthenticated}},
- Policy: &v0.Policy{
- User: "",
- Group: "A",
- },
- ExpectMatch: false,
- },
- "v0 group policy is case-sensitive": {
- User: user.DefaultInfo{Name: "Foo", Groups: []string{"A", "B", "C", user.AllAuthenticated}},
- Policy: &v0.Policy{
- User: "",
- Group: "b",
- },
- ExpectMatch: false,
- },
- "v0 group policy does not match substring": {
- User: user.DefaultInfo{Name: "Foo", Groups: []string{"A", "BBB", "C", user.AllAuthenticated}},
- Policy: &v0.Policy{
- User: "",
- Group: "B",
- },
- ExpectMatch: false,
- },
- "v0 group policy matches user in group": {
- User: user.DefaultInfo{Name: "Foo", Groups: []string{"A", "B", "C", user.AllAuthenticated}},
- Policy: &v0.Policy{
- User: "",
- Group: "B",
- },
- ExpectMatch: true,
- },
- "v0 user and group policy requires user match": {
- User: user.DefaultInfo{Name: "Bar", Groups: []string{"A", "B", "C", user.AllAuthenticated}},
- Policy: &v0.Policy{
- User: "Foo",
- Group: "B",
- },
- ExpectMatch: false,
- },
- "v0 user and group policy requires group match": {
- User: user.DefaultInfo{Name: "Foo", Groups: []string{"A", "B", "C", user.AllAuthenticated}},
- Policy: &v0.Policy{
- User: "Foo",
- Group: "D",
- },
- ExpectMatch: false,
- },
- "v0 user and group policy matches": {
- User: user.DefaultInfo{Name: "Foo", Groups: []string{"A", "B", "C", user.AllAuthenticated}},
- Policy: &v0.Policy{
- User: "Foo",
- Group: "B",
- },
- ExpectMatch: true,
- },
- "v1 empty policy does not match unauthed user": {
- User: user.DefaultInfo{Name: "system:anonymous", Groups: []string{"system:unauthenticated"}},
- Policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- User: "",
- Group: "",
- },
- },
- ExpectMatch: false,
- },
- "v1 * user policy does not match unauthed user": {
- User: user.DefaultInfo{Name: "system:anonymous", Groups: []string{"system:unauthenticated"}},
- Policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- User: "*",
- Group: "",
- },
- },
- ExpectMatch: false,
- },
- "v1 * group policy does not match unauthed user": {
- User: user.DefaultInfo{Name: "system:anonymous", Groups: []string{"system:unauthenticated"}},
- Policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- User: "",
- Group: "*",
- },
- },
- ExpectMatch: false,
- },
- "v1 empty policy does not match authed user": {
- User: user.DefaultInfo{Name: "Foo", Groups: []string{user.AllAuthenticated}},
- Policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- User: "",
- Group: "",
- },
- },
- ExpectMatch: false,
- },
- "v1 empty policy does not match authed user with groups": {
- User: user.DefaultInfo{Name: "Foo", Groups: []string{"a", "b", user.AllAuthenticated}},
- Policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- User: "",
- Group: "",
- },
- },
- ExpectMatch: false,
- },
- "v1 user policy does not match unauthed user": {
- User: user.DefaultInfo{Name: "system:anonymous", Groups: []string{"system:unauthenticated"}},
- Policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- User: "Foo",
- Group: "",
- },
- },
- ExpectMatch: false,
- },
- "v1 user policy does not match different user": {
- User: user.DefaultInfo{Name: "Bar", Groups: []string{user.AllAuthenticated}},
- Policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- User: "Foo",
- Group: "",
- },
- },
- ExpectMatch: false,
- },
- "v1 user policy is case-sensitive": {
- User: user.DefaultInfo{Name: "foo", Groups: []string{user.AllAuthenticated}},
- Policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- User: "Foo",
- Group: "",
- },
- },
- ExpectMatch: false,
- },
- "v1 user policy does not match substring": {
- User: user.DefaultInfo{Name: "FooBar", Groups: []string{user.AllAuthenticated}},
- Policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- User: "Foo",
- Group: "",
- },
- },
- ExpectMatch: false,
- },
- "v1 user policy matches username": {
- User: user.DefaultInfo{Name: "Foo", Groups: []string{user.AllAuthenticated}},
- Policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- User: "Foo",
- Group: "",
- },
- },
- ExpectMatch: true,
- },
- "v1 group policy does not match unauthed user": {
- User: user.DefaultInfo{Name: "system:anonymous", Groups: []string{"system:unauthenticated"}},
- Policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- User: "",
- Group: "Foo",
- },
- },
- ExpectMatch: false,
- },
- "v1 group policy does not match user in different group": {
- User: user.DefaultInfo{Name: "FooBar", Groups: []string{"B", user.AllAuthenticated}},
- Policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- User: "",
- Group: "A",
- },
- },
- ExpectMatch: false,
- },
- "v1 group policy is case-sensitive": {
- User: user.DefaultInfo{Name: "Foo", Groups: []string{"A", "B", "C", user.AllAuthenticated}},
- Policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- User: "",
- Group: "b",
- },
- },
- ExpectMatch: false,
- },
- "v1 group policy does not match substring": {
- User: user.DefaultInfo{Name: "Foo", Groups: []string{"A", "BBB", "C", user.AllAuthenticated}},
- Policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- User: "",
- Group: "B",
- },
- },
- ExpectMatch: false,
- },
- "v1 group policy matches user in group": {
- User: user.DefaultInfo{Name: "Foo", Groups: []string{"A", "B", "C", user.AllAuthenticated}},
- Policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- User: "",
- Group: "B",
- },
- },
- ExpectMatch: true,
- },
- "v1 user and group policy requires user match": {
- User: user.DefaultInfo{Name: "Bar", Groups: []string{"A", "B", "C", user.AllAuthenticated}},
- Policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- User: "Foo",
- Group: "B",
- },
- },
- ExpectMatch: false,
- },
- "v1 user and group policy requires group match": {
- User: user.DefaultInfo{Name: "Foo", Groups: []string{"A", "B", "C", user.AllAuthenticated}},
- Policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- User: "Foo",
- Group: "D",
- },
- },
- ExpectMatch: false,
- },
- "v1 user and group policy matches": {
- User: user.DefaultInfo{Name: "Foo", Groups: []string{"A", "B", "C", user.AllAuthenticated}},
- Policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- User: "Foo",
- Group: "B",
- },
- },
- ExpectMatch: true,
- },
- }
- for k, tc := range testCases {
- policy := &abac.Policy{}
- if err := abac.Scheme.Convert(tc.Policy, policy, nil); err != nil {
- t.Errorf("%s: error converting: %v", k, err)
- continue
- }
- attr := authorizer.AttributesRecord{
- User: &tc.User,
- }
- actualMatch := subjectMatches(*policy, attr.GetUser())
- if tc.ExpectMatch != actualMatch {
- t.Errorf("%v: Expected actorMatches=%v but actually got=%v",
- k, tc.ExpectMatch, actualMatch)
- }
- }
- }
- func newWithContents(t *testing.T, contents string) (PolicyList, error) {
- f, err := ioutil.TempFile("", "abac_test")
- if err != nil {
- t.Fatalf("unexpected error creating policyfile: %v", err)
- }
- f.Close()
- defer os.Remove(f.Name())
- if err := ioutil.WriteFile(f.Name(), []byte(contents), 0700); err != nil {
- t.Fatalf("unexpected error writing policyfile: %v", err)
- }
- pl, err := NewFromFile(f.Name())
- return pl, err
- }
- func TestPolicy(t *testing.T) {
- tests := []struct {
- policy runtime.Object
- attr authorizer.Attributes
- matches bool
- name string
- }{
- // v0 mismatches
- {
- policy: &v0.Policy{
- Readonly: true,
- },
- attr: authorizer.AttributesRecord{
- User: &user.DefaultInfo{
- Name: "foo",
- Groups: []string{user.AllAuthenticated},
- },
- Verb: "create",
- },
- matches: false,
- name: "v0 read-only mismatch",
- },
- {
- policy: &v0.Policy{
- User: "foo",
- },
- attr: authorizer.AttributesRecord{
- User: &user.DefaultInfo{
- Name: "bar",
- Groups: []string{user.AllAuthenticated},
- },
- },
- matches: false,
- name: "v0 user name mis-match",
- },
- {
- policy: &v0.Policy{
- Resource: "foo",
- },
- attr: authorizer.AttributesRecord{
- User: &user.DefaultInfo{
- Name: "foo",
- Groups: []string{user.AllAuthenticated},
- },
- Resource: "bar",
- ResourceRequest: true,
- },
- matches: false,
- name: "v0 resource mis-match",
- },
- {
- policy: &v0.Policy{
- User: "foo",
- Resource: "foo",
- Namespace: "foo",
- },
- attr: authorizer.AttributesRecord{
- User: &user.DefaultInfo{
- Name: "foo",
- Groups: []string{user.AllAuthenticated},
- },
- Resource: "foo",
- Namespace: "foo",
- ResourceRequest: true,
- },
- matches: true,
- name: "v0 namespace mis-match",
- },
- // v0 matches
- {
- policy: &v0.Policy{},
- attr: authorizer.AttributesRecord{
- User: &user.DefaultInfo{
- Name: "foo",
- Groups: []string{user.AllAuthenticated},
- },
- ResourceRequest: true,
- },
- matches: true,
- name: "v0 null resource",
- },
- {
- policy: &v0.Policy{
- Readonly: true,
- },
- attr: authorizer.AttributesRecord{
- User: &user.DefaultInfo{
- Name: "foo",
- Groups: []string{user.AllAuthenticated},
- },
- Verb: "get",
- },
- matches: true,
- name: "v0 read-only match",
- },
- {
- policy: &v0.Policy{
- User: "foo",
- },
- attr: authorizer.AttributesRecord{
- User: &user.DefaultInfo{
- Name: "foo",
- Groups: []string{user.AllAuthenticated},
- },
- },
- matches: true,
- name: "v0 user name match",
- },
- {
- policy: &v0.Policy{
- Resource: "foo",
- },
- attr: authorizer.AttributesRecord{
- User: &user.DefaultInfo{
- Name: "foo",
- Groups: []string{user.AllAuthenticated},
- },
- Resource: "foo",
- ResourceRequest: true,
- },
- matches: true,
- name: "v0 resource match",
- },
- // v1 mismatches
- {
- policy: &v1beta1.Policy{},
- attr: authorizer.AttributesRecord{
- User: &user.DefaultInfo{
- Name: "foo",
- Groups: []string{user.AllAuthenticated},
- },
- ResourceRequest: true,
- },
- matches: false,
- name: "v1 null",
- },
- {
- policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- User: "foo",
- },
- },
- attr: authorizer.AttributesRecord{
- User: &user.DefaultInfo{
- Name: "bar",
- Groups: []string{user.AllAuthenticated},
- },
- ResourceRequest: true,
- },
- matches: false,
- name: "v1 user name mis-match",
- },
- {
- policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- User: "*",
- Readonly: true,
- },
- },
- attr: authorizer.AttributesRecord{
- User: &user.DefaultInfo{
- Name: "foo",
- Groups: []string{user.AllAuthenticated},
- },
- ResourceRequest: true,
- },
- matches: false,
- name: "v1 read-only mismatch",
- },
- {
- policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- User: "*",
- Resource: "foo",
- },
- },
- attr: authorizer.AttributesRecord{
- User: &user.DefaultInfo{
- Name: "foo",
- Groups: []string{user.AllAuthenticated},
- },
- Resource: "bar",
- ResourceRequest: true,
- },
- matches: false,
- name: "v1 resource mis-match",
- },
- {
- policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- User: "foo",
- Namespace: "barr",
- Resource: "baz",
- },
- },
- attr: authorizer.AttributesRecord{
- User: &user.DefaultInfo{
- Name: "foo",
- Groups: []string{user.AllAuthenticated},
- },
- Namespace: "bar",
- Resource: "baz",
- ResourceRequest: true,
- },
- matches: false,
- name: "v1 namespace mis-match",
- },
- {
- policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- User: "*",
- NonResourcePath: "/api",
- },
- },
- attr: authorizer.AttributesRecord{
- User: &user.DefaultInfo{
- Name: "foo",
- Groups: []string{user.AllAuthenticated},
- },
- Path: "/api2",
- ResourceRequest: false,
- },
- matches: false,
- name: "v1 non-resource mis-match",
- },
- {
- policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- User: "*",
- NonResourcePath: "/api/*",
- },
- },
- attr: authorizer.AttributesRecord{
- User: &user.DefaultInfo{
- Name: "foo",
- Groups: []string{user.AllAuthenticated},
- },
- Path: "/api2/foo",
- ResourceRequest: false,
- },
- matches: false,
- name: "v1 non-resource wildcard subpath mis-match",
- },
- // v1 matches
- {
- policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- User: "foo",
- },
- },
- attr: authorizer.AttributesRecord{
- User: &user.DefaultInfo{
- Name: "foo",
- Groups: []string{user.AllAuthenticated},
- },
- ResourceRequest: true,
- },
- matches: true,
- name: "v1 user match",
- },
- {
- policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- User: "*",
- },
- },
- attr: authorizer.AttributesRecord{
- User: &user.DefaultInfo{
- Name: "foo",
- Groups: []string{user.AllAuthenticated},
- },
- ResourceRequest: true,
- },
- matches: true,
- name: "v1 user wildcard match",
- },
- {
- policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- Group: "bar",
- },
- },
- attr: authorizer.AttributesRecord{
- User: &user.DefaultInfo{
- Name: "foo",
- Groups: []string{"bar", user.AllAuthenticated},
- },
- ResourceRequest: true,
- },
- matches: true,
- name: "v1 group match",
- },
- {
- policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- Group: "*",
- },
- },
- attr: authorizer.AttributesRecord{
- User: &user.DefaultInfo{
- Name: "foo",
- Groups: []string{"bar", user.AllAuthenticated},
- },
- ResourceRequest: true,
- },
- matches: true,
- name: "v1 group wildcard match",
- },
- {
- policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- User: "*",
- Readonly: true,
- },
- },
- attr: authorizer.AttributesRecord{
- User: &user.DefaultInfo{
- Name: "foo",
- Groups: []string{user.AllAuthenticated},
- },
- Verb: "get",
- ResourceRequest: true,
- },
- matches: true,
- name: "v1 read-only match",
- },
- {
- policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- User: "*",
- Resource: "foo",
- },
- },
- attr: authorizer.AttributesRecord{
- User: &user.DefaultInfo{
- Name: "foo",
- Groups: []string{user.AllAuthenticated},
- },
- Resource: "foo",
- ResourceRequest: true,
- },
- matches: true,
- name: "v1 resource match",
- },
- {
- policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- User: "foo",
- Namespace: "bar",
- Resource: "baz",
- },
- },
- attr: authorizer.AttributesRecord{
- User: &user.DefaultInfo{
- Name: "foo",
- Groups: []string{user.AllAuthenticated},
- },
- Namespace: "bar",
- Resource: "baz",
- ResourceRequest: true,
- },
- matches: true,
- name: "v1 namespace match",
- },
- {
- policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- User: "*",
- NonResourcePath: "/api",
- },
- },
- attr: authorizer.AttributesRecord{
- User: &user.DefaultInfo{
- Name: "foo",
- Groups: []string{user.AllAuthenticated},
- },
- Path: "/api",
- ResourceRequest: false,
- },
- matches: true,
- name: "v1 non-resource match",
- },
- {
- policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- User: "*",
- NonResourcePath: "*",
- },
- },
- attr: authorizer.AttributesRecord{
- User: &user.DefaultInfo{
- Name: "foo",
- Groups: []string{user.AllAuthenticated},
- },
- Path: "/api",
- ResourceRequest: false,
- },
- matches: true,
- name: "v1 non-resource wildcard match",
- },
- {
- policy: &v1beta1.Policy{
- Spec: v1beta1.PolicySpec{
- User: "*",
- NonResourcePath: "/api/*",
- },
- },
- attr: authorizer.AttributesRecord{
- User: &user.DefaultInfo{
- Name: "foo",
- Groups: []string{user.AllAuthenticated},
- },
- Path: "/api/foo",
- ResourceRequest: false,
- },
- matches: true,
- name: "v1 non-resource wildcard subpath match",
- },
- }
- for _, test := range tests {
- policy := &abac.Policy{}
- if err := abac.Scheme.Convert(test.policy, policy, nil); err != nil {
- t.Errorf("%s: error converting: %v", test.name, err)
- continue
- }
- matches := matches(*policy, test.attr)
- if test.matches != matches {
- t.Errorf("%s: expected: %t, saw: %t", test.name, test.matches, matches)
- continue
- }
- }
- }
|