Kubernetes RBAC static analysis & visualisation tool
Kubernetes RBAC Analysis made Easy
Krane is a simple Kubernetes RBAC static analysis tool. It identifies potential security risks in K8s RBAC design and makes suggestions on how to mitigate them. Krane dashboard presents current RBAC security posture and lets you navigate through its definition.
You can get started with Krane by installing it via Helm chart in your target Kubernetes cluster or running it locally with Docker.
It is assumed that you have Helm CLI installed on your machine.
$ helm repo add appvia https://appvia.github.io/krane
$ helm repo update
$ helm install krane appvia/krane --namespace krane --create-namespaceFollow Helm chart installation output on how to port-forward Krane dashboard.
It is assumed that you have docker running on your local machine. Install docker-compose if you haven't already.
Krane depends on FalkorDB. docker-compose stack defines all what's required to build and run Krane service locally. It'll also take care of its FalkorDB dependency.
docker-compose up -dKrane docker image will be pre-built automatically if not already present on local machine.
Note that when running docker-compose locally, Krane won't start RBAC report and dashboard automatically. Instead, the container will sleep for 24h by default - this value can be adjusted in docker-compose.override.yml. Exec into a running Krane container to run commands. Local docker-compose will also mount kube config (~/.kube/config) inside the container enabling you to run reports against any Kubernetes clusters to which you already have access to.
Exec into a running Krane container.
docker-compose exec krane bashOnce in the container you can start using krane commands. Try krane -help.
krane -hTo inspect what services are running and the associated ports:
docker-compose psTo stop Krane and its dependency services:
docker-compose down$ krane --help
NAME:
krane
DESCRIPTION:
Kubernetes RBAC static analysis & visualisation tool
COMMANDS:
dashboard Start K8s RBAC dashboard server
help Display global or [command] help documentation
report Run K8s RBAC report
GLOBAL OPTIONS:
-h, --help
Display help documentation
-v, --version
Display version information
-t, --trace
Display backtrace when an error occurs
AUTHOR:
Marcin Ciszak - Appvia Ltd kubectl contextTo run a report against a running cluster you must provide a kubectl context
krane report -k You may also pass -c flag if you plan to run the tool against multiple clusters and index RBAC graph separately for each cluster name.
To run a report against local RBAC yaml/json files, provide a directory path
krane report -d NOTE: Krane expects the following files (in either YAML or JSON format) to be present in specified directory path:
If Pod Security Policies are not in use you may bypass the expectation above by creating a psp file manually with the following content:
{
"items": []
}Note, PodSecurityPolicy was deprecated in Kubernetes v1.21, and removed from Kubernetes in v1.25.
To run a report from a container running in Kubernetes cluster
krane report --inclusterNOTE: Service account used by Krane will require access to RBAC resources. See Prerequisites for details.
To validate RBAC definition as a step in CI/CD pipeline
krane report --ci -d NOTE: Krane expects certain naming convention to be followed for locally stored RBAC resource files. See section above. In order to run krane commands it's recommended that CI executor references quay.io/appvia/krane:latest docker image.
CI mode is enabled by --ci flag. Krane will return non zero status code along with details of breaking risk rules when one or more dangers have been detected.
To view RBAC facets tree, network graph and latest report findings you need to start dashboard server first.
krane dashboardCluster flag -c may be passed if you want to run the dashboard against specific cluster name. Dashboard will look for data related to specified cluster name which is cached on the file system.
Command above will start local web server on default port 8000, and display the dashboard link.
The server binds to 0.0.0.0 so that it is reachable when running in a cluster. Pass -b 127.0.0.1 to keep it on the loopback interface when running locally.
The dashboard has no authentication. It serves everything Krane knows about your cluster's RBAC to anyone who can reach the port, so do not expose it directly. Reach it with kubectl port-forward, restrict access with a NetworkPolicy (the chart already labels the pod with network/krane: "true"), or put an authenticating proxy in front of it.
The dashboard is a set of static files served from dashboard/compiled, and the report writes its data into the same directory. A report generated while the dashboard is running is picked up without a restart.
Namespace kube-system admits Group system:bootstrappers:kubeadm:default-node-token to resource [certificates.k8s.io] certificatesigningrequests action create defined by ClusterRole system:node-bootstrapper.rules.yaml.Krane indexes RBAC entites in FalkorDB. This allows us to query network of dependencies efficiently and simply using subset of CypherQL supported by FalkorDB.
The following nodes are created in the Graph for the relevant RBAC objects:
Psp - A PSP node containing attributes around the pod security policy. Only applicable when working with K8s B`:COMPOSITE - Defines a link between ClusterRoles (one ClusterRole can be aggregated in another) A. Note that attributes defined in referenced macro will take precedence over the same attributes defined on the rule level.Macro can contain any of the following attributes:
query - FalkorDB query. Has precedence over template. Requires writer to be defined.writer - Writer is a Ruby expression used to format query result set. Writer has precedence over template.template - Built-in query/writer template name. If query & writer are not specified then chosen query generator will be used along with matching writer.Rule can contain any of the following attributes:
id [Required] Rule id is a unique rule identifier.
group_title [Required] Title applying to all items falling under this risk check.
severity [Required] Severity, as one of :danger, :warning, :info.
info [Required] Textual information about the check and suggestions on how to mitigate the risk.
query [Conditonal] FalkorDB query.
template. Requires writer to be defined.writer [Conditonal] Writer is a Ruby expression used to format query result set.
template. Requires query to be defined.template [Conditonal] Built-in query/writer template name. If query & writer are not specified then chosen query generator will be used along with matching writer.
Some built-in templates require match_rules attribute to be specified on individual rule level in order to build correct query. Templates currently requiring it:
match_rules. Generated graph query returns the following columns:match_rules [Conditonal] Required when template relies on match rules in order to build a query.
Example:
match_rules:
- apiGroups: ['batch']
resources: ['cronjobs']
verbs: ['update']Attributes and values follow Kubernetes RBAC role specification.
Values of a given attribute are matched together (logical AND), so a role only matches when it grants all of them. apiGroups are the exception - a role rule names a single API group per resource, so their values are matched as alternatives (logical OR), and the * API group is always accepted alongside them. Omitting apiGroups matches a role rule naming any API group, which for a resource that exists in one group only (or for the * resource) reports a wider scope than the role actually grants.
custom_params [Optional] Map of custom key-value pairs to be evaluated and replaced in a rule query and writer representation.
custoNo open issues yet, or sync has not completed.