|
| 1 | +package armo_builtins |
| 2 | + |
| 3 | +import future.keywords.in |
| 4 | + |
| 5 | +# fails if user has access to proxy subresources |
| 6 | +deny[msga] { |
| 7 | + subjectVector := input[_] |
| 8 | + role := subjectVector.relatedObjects[i] |
| 9 | + rolebinding := subjectVector.relatedObjects[j] |
| 10 | + endswith(role.kind, "Role") |
| 11 | + endswith(rolebinding.kind, "Binding") |
| 12 | + |
| 13 | + rule := role.rules[p] |
| 14 | + |
| 15 | + subject := rolebinding.subjects[k] |
| 16 | + is_same_subjects(subjectVector, subject) |
| 17 | + |
| 18 | +is_same_subjects(subjectVector, subject) |
| 19 | + rule_path := sprintf("relatedObjects[%d].rules[%d]", [i, p]) |
| 20 | + |
| 21 | + verbs := ["get", "create", "connect","*"] |
| 22 | + verb_path := [sprintf("%s.verbs[%d]", [rule_path, l]) | verb = rule.verbs[l]; verb in verbs] |
| 23 | + count(verb_path) > 0 |
| 24 | + |
| 25 | + api_groups := ["", "*"] |
| 26 | + api_groups_path := [sprintf("%s.apiGroups[%d]", [rule_path, a]) | apiGroup = rule.apiGroups[a]; apiGroup in api_groups] |
| 27 | + count(api_groups_path) > 0 |
| 28 | + |
| 29 | + resources := ["nodes/proxy", "*"] |
| 30 | + resources_path := [sprintf("%s.resources[%d]", [rule_path, l]) | resource = rule.resources[l]; resource in resources] |
| 31 | + count(resources_path) > 0 |
| 32 | + |
| 33 | + path := array.concat(resources_path, verb_path) |
| 34 | + path2 := array.concat(path, api_groups_path) |
| 35 | + finalpath := array.concat(path2, [ |
| 36 | + sprintf("relatedObjects[%d].subjects[%d]", [j, k]), |
| 37 | + sprintf("relatedObjects[%d].roleRef.name", [j]), |
| 38 | + ]) |
| 39 | + |
| 40 | + msga := { |
| 41 | + "alertMessage": sprintf("Subject: %s-%s can access proxy subresources", [subjectVector.kind, subjectVector.name]), |
| 42 | + "alertScore": 3, |
| 43 | + "reviewPaths": finalpath, |
| 44 | + "failedPaths": finalpath, |
| 45 | + "fixPaths": [], |
| 46 | + "packagename": "armo_builtins", |
| 47 | + "alertObject": { |
| 48 | + "k8sApiObjects": [], |
| 49 | + "externalObjects": subjectVector, |
| 50 | + }, |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +# for service accounts |
| 55 | +is_same_subjects(subjectVector, subject) { |
| 56 | + subjectVector.kind == subject.kind |
| 57 | + subjectVector.name == subject.name |
| 58 | + subjectVector.namespace == subject.namespace |
| 59 | +} |
| 60 | + |
| 61 | +# for users/ groups |
| 62 | +is_same_subjects(subjectVector, subject) { |
| 63 | + subjectVector.kind == subject.kind |
| 64 | + subjectVector.name == subject.name |
| 65 | + subjectVector.apiGroup == subject.apiGroup |
| 66 | +} |
0 commit comments