authzed / spicedb-kubeapi-proxy

Secure access to the Kubernetes API using SpiceDB
https://authzed.com/spicedb
Apache License 2.0
21 stars 1 forks source link
acl authorization cloud-native fga fine-grained-access-control kubernetes permissions proxy rebac security spicedb zanzibar

spicedb-kubeapi-proxy

spicedb-kubeapi-proxy is a proxy that runs in between clients and the kube apiserver that can authorize requests and filter responses using an embedded or remote SpiceDB.

Status

The issues track the current state of the project, but the primary goals before 1.0 are:

Features

Architecture

Arch Diagram DarkArch Diagram Light

The proxy authenticates itself with the downstream kube-apiserver (client certs if running out-of-cluster, service account token if running in-cluster). The proxy is configured with a set of rules that define how to authorize requests and how to filter responses by communicating with SpiceDB.

There are three basic types of rule:

Rules often work in tendem; for example, a Check rule might authorize a request to list pods in a namespace, and a Filter rule might further restrict the response to only include certain pods.

Note that the proxy does not assume anything about the structure of the data in SpiceDB. It is up to the user to define the data in SpiceDB and the rules that the proxy uses to authorize and filter requests.

The proxy rejects any request for which it doesn't find a matching rule.

Development

This project uses mage to offer various development-related commands.

# run to get all available commands 
brew install mage
mage

Tests

Runs both unit and e2e tests

mage test:all

Development environment

mage dev:up

This brings a development kind cluster with the proxy running in it with an embedded SpiceDB. A development dev.kubeconfig file will be generated so that you can configure your client to talk to either the proxy or the upstream kind cluster.

Examples:

kubectl --kubeconfig $(pwd)/dev.kubeconfig --context proxy get namespace

or

export KUBECONFIG=$(pwd)/dev.kubeconfig
kubectx proxy
kubectl get namespace

You can also talk to the upstream cluster to verify things by switching to the context name admin:

kubectl --kubeconfig $(pwd)/dev.kubeconfig --context admin get namespace

To clean everything up just run:

mage dev:clean

Run the proxy locally

Sometimes you may want to debug the proxy. The easiest way would be to spin up the development environment with mage dev:up and then run the proxy targeting it as upstream:

mage dev:run

Alternatively if you want to run with delve or your IDE, do:

go run ./cmd/spicedb-kubeapi-proxy/main.go --bind-address=127.0.0.1 --secure-port=8443 --backend-kubeconfig $(pwd)/spicedb-kubeapi-proxy.kubeconfig --client-ca-file $(pwd)/client-ca.crt --requestheader-client-ca-file $(pwd)/client-ca.crt --spicedb-endpoint embedded://

You'll then be able to reach out to your local proxy instance with the context local. Note TLS certs are auto-generated by Kube so --insecure-skip-tls-verify must be provided.

export KUBECONFIG=$(pwd)/dev.kubeconfig
kubectx proxy
kubectl --insecure-skip-tls-verify get namespace