Skip to content

Commit

Permalink
Merge pull request #566 from kubescape/feature/detection-authneticate…
Browse files Browse the repository at this point in the history
…d-over-privileged

Adding control C-0265: detection of over-privileged system:authenticated group
  • Loading branch information
slashben authored Jan 25, 2024
2 parents 1ada7a2 + fe14341 commit eca3ba1
Show file tree
Hide file tree
Showing 11 changed files with 269 additions and 4 deletions.
24 changes: 24 additions & 0 deletions controls/C-0265-authenticateduserhasrbac.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"controlID": "C-0265",
"name": "system:authenticated user has elevated roles",
"description": "Granting permissions to the system:authenticated group is generally not recommended and can introduce security risks. This control ensures that system:authenticated users do not have cluster risking permissions.",
"remediation": "Review and modify your cluster's RBAC configuration to ensure that system:authenticated will have minimal permissions.",
"test": "Checks if ClusterRoleBinding/RoleBinding resources give permissions to system:authenticated group.",
"attributes": {
},
"rulesNames": [
"system-authenticated-allowed-to-take-over-cluster"
],
"baseScore": 7,
"category": {
"name": "Control plane",
"subCategory": {
"name": "Supply chain"
}
},
"scanningScope": {
"matches": [
"cluster"
]
}
}
8 changes: 7 additions & 1 deletion frameworks/allcontrols.json
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,17 @@
"name": "CVE-2022-47633-kyverno-signature-bypass"
}
},
{
{
"controlID": "C-0262",
"patch": {
"name": "Anonymous access enabled"
}
},
{
"controlID": "C-0265",
"patch": {
"name": "Authenticated user has sensitive permissions"
}
}
]
}
6 changes: 6 additions & 0 deletions frameworks/clusterscan.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
"name": "Anonymous access enabled"
}
},
{
"controlID": "C-0265",
"patch": {
"name": "Authenticated user has sensitive permissions"
}
},
{
"controlID": "C-0015",
"patch": {
Expand Down
12 changes: 9 additions & 3 deletions frameworks/security.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"name": "Immutable container filesystem"
}
},
{
{
"controlID": "C-0256",
"patch": {
"name": "Exposure to Internet"
Expand Down Expand Up @@ -62,7 +62,7 @@
"name": "ServiceAccount token mounted"
}
},
{
{
"controlID": "C-0255",
"patch": {
"name": "Workload with secret access"
Expand Down Expand Up @@ -104,11 +104,17 @@
"name": "Apply Security Context to Your Pods and Containers"
}
},
{
{
"controlID": "C-0262",
"patch": {
"name": "Anonymous access enabled"
}
},
{
"controlID": "C-0265",
"patch": {
"name": "Authenticated user has sensitive permissions"
}
}
]
}
65 changes: 65 additions & 0 deletions rules/system-authenticated-allowed-to-take-over-cluster/raw.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package armo_builtins

import future.keywords.in

deny[msga] {
subjectVector := input[_]

rolebinding := subjectVector.relatedObjects[j]
endswith(rolebinding.kind, "Binding")


subject := rolebinding.subjects[k]
# Check if the subject is gourp
subject.kind == "Group"
# Check if the subject is system:authenticated
subject.name == "system:authenticated"


# Find the bound roles
role := subjectVector.relatedObjects[i]
endswith(role.kind, "Role")

# Check if the role and rolebinding bound
is_same_role_and_binding(role, rolebinding)


# Check if the role has access to workloads, exec, attach, portforward
rule := role.rules[p]
rule.resources[l] in ["*","pods", "pods/exec", "pods/attach", "pods/portforward","deployments","statefulset","daemonset","jobs","cronjobs","nodes","secrets"]

finalpath := array.concat([""], [
sprintf("relatedObjects[%d].subjects[%d]", [j, k]),
sprintf("relatedObjects[%d].roleRef.name", [i]),
])

msga := {
"alertMessage": "system:authenticated has sensitive roles",
"alertScore": 5,
"reviewPaths": finalpath,
"failedPaths": finalpath,
"fixPaths": [],
"packagename": "armo_builtins",
"alertObject": {
"k8sApiObjects": [],
"externalObjects" : subjectVector
},
}
}

is_same_role_and_binding(role, rolebinding) {
rolebinding.kind == "RoleBinding"
role.kind == "Role"
rolebinding.metadata.namespace == role.metadata.namespace
rolebinding.roleRef.name == role.metadata.name
rolebinding.roleRef.kind == role.kind
startswith(role.apiVersion, rolebinding.roleRef.apiGroup)
}

is_same_role_and_binding(role, rolebinding) {
rolebinding.kind == "ClusterRoleBinding"
role.kind == "ClusterRole"
rolebinding.roleRef.name == role.metadata.name
rolebinding.roleRef.kind == role.kind
startswith(role.apiVersion, rolebinding.roleRef.apiGroup)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "system-authenticated-allowed-to-take-over-cluster",
"attributes": {
"resourcesAggregator": "subject-role-rolebinding"
},
"ruleLanguage": "Rego",
"match": [
{
"apiGroups": [
"rbac.authorization.k8s.io"
],
"apiVersions": [
"v1"
],
"resources": [
"RoleBinding",
"ClusterRoleBinding",
"Role",
"ClusterRole"
]
}
],
"ruleDependencies": [],
"description": "Fails in system:authenticated user has cluster takeover rbac permissions (is bound by a RoleBinding/ClusterRoleBinding)",
"remediation": "Remove any RBAC rules which allow system:authenticated users to perform actions",
"ruleQuery": "armo_builtins"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
[
{
"alertMessage": "system:authenticated has sensitive roles",
"alertObject": {
"externalObjects": {
"apiGroup": "rbac.authorization.k8s.io",
"kind": "Group",
"name": "system:authenticated",
"relatedObjects": [
{
"apiVersion": "rbac.authorization.k8s.io/v1",
"kind": "ClusterRoleBinding",
"metadata": {
"name": "system:viewer"
},
"roleRef": {
"apiGroup": "rbac.authorization.k8s.io",
"kind": "ClusterRole",
"name": "system:viewer"
},
"subjects": [
{
"apiGroup": "rbac.authorization.k8s.io",
"kind": "Group",
"name": "system:authenticated"
}
]
},
{
"apiVersion": "rbac.authorization.k8s.io/v1",
"kind": "ClusterRole",
"metadata": {
"name": "system:viewer"
},
"rules": [
{
"apiGroups": [
""
],
"resources": [
"nodes",
"nodes/*",
"namespaces",
"namespaces/*",
"pods",
"pods/*"
],
"verbs": [
"get",
"list",
"watch"
]
}
]
}
]
},
"k8sApiObjects": []
},
"alertScore": 5,
"failedPaths": [
"",
"relatedObjects[0].subjects[0]",
"relatedObjects[1].roleRef.name"
],
"fixPaths": [],
"packagename": "armo_builtins",
"reviewPaths": [
"",
"relatedObjects[0].subjects[0]",
"relatedObjects[1].roleRef.name"
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: system:viewer
rules:
- apiGroups:
- ""
resources:
- nodes
- nodes/*
- namespaces
- namespaces/*
- pods
- pods/*
verbs:
- get
- list
- watch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: system:viewer
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:viewer
subjects:
- apiGroup: rbac.authorization.k8s.io
kind: Group
name: system:authenticated
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: system:viewer
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:viewer
subjects:
- apiGroup: rbac.authorization.k8s.io
kind: Group
name: system:authenticated
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: system:viewer
rules:
- apiGroups:
- ""
resources:
- configmaps
verbs:
- get
- list
- watch

0 comments on commit eca3ba1

Please sign in to comment.