GithubHelp home page GithubHelp logo

plallin / kube-mgmt Goto Github PK

View Code? Open in Web Editor NEW

This project forked from open-policy-agent/kube-mgmt

0.0 1.0 0.0 14.07 MB

Sidecar for managing OPA on top of Kubernetes.

License: Apache License 2.0

Dockerfile 0.33% Makefile 2.85% Shell 2.19% Go 94.63%

kube-mgmt's Introduction

logo kube-mgmt

Policy-based control for Kubernetes deployments.

About

kube-mgmt manages instances of the Open Policy Agent on top of Kubernetes. Use kube-mgmt to:

NOTE: kube-mgmt is currently in alpha. Join the discussion on slack.openpolicyagent.org.

Deployment Guide

Hello World

  1. Create a new Namespace to deploy OPA into:

    kubectl create namespace opa
  2. Create a new Deployment that includes OPA and kube-mgmt (manifests/deployment.yml):

    kubectl -n opa create -f https://raw.githubusercontent.com/open-policy-agent/kube-mgmt/master/manifests/deployment.yml
  3. Define a simple policy (example.rego) with the following content:

    package kubernetes
    
    example = "Hello, Kubernetes!"
  4. Create a ConfigMap containing the policy:

    kubectl -n opa create configmap hello-world --from-file example.rego
  5. Create a Service to expose OPA:

    kubectl -n opa expose deployment opa --type=NodePort
  6. Execute a policy query against OPA:

    OPA_URL=$(minikube service -n opa opa --url)
    curl $OPA_URL/v1/data/kubernetes/example

Policies

kube-mgmt automatically discovers policies stored in ConfigMaps in Kubernetes and loads them into OPA. kube-mgmt assumes a ConfigMap contains policies if the ConfigMap is:

  • Created in a namespace listed in the --policies option.
  • Labelled with openpolicyagent.org/policy=rego.

When a policy has been successfully loaded into OPA, the openpolicyagent.org/policy-status annotation is set to {"status": "ok"}.

If loading fails for some reason (e.g., because of a parse error), the openpolicyagent.org/policy-status annotation is set to {"status": "error", "error": ...} where the error field contains details about the failure.

Caching

kube-mgmt can be configured to replicate Kubernetes resources into OPA so that you can express policies over an eventually consistent cache of Kubernetes state.

Replication is enabled with the following options:

# Replicate namespace-level resources. May be specified multiple times.
--replicate=<[group/]version/resource>

# Replicate cluster-level resources. May be specified multiple times.
--replicate-cluster=<[group/]version/resource>

Kubernetes resources replicated into OPA are layed out as follos:

<replicate-path>/<resource>/<namespace>/<name> # namespace scoped
<replicate-path>/<resource>/<name>             # cluster scoped
  • <replicate-path> is configurable (via --replicate-path) and defaults to kubernetes.
  • <resource> is the Kubernetes resource plural, e.g., nodes, pods, services, etc.
  • <namespace> is the namespace of the Kubernetes resource.
  • <name> is the name of the Kubernetes resource.

For example, to search for services with the label "foo" you could write:

service := data.kubernetes.services[namespace][name].metadata.labels["foo"]

An alternative way to visualize the layout is as single JSON document:

{
	"kubernetes": {
		"services": {
			"default": {
				"example-service": {...},
				"another-service": {...},
				...
			},
			...
		},
		...
}

The example below would replicate Deployments, Services, and Nodes into OPA:

--replicate=apps/v1beta/deployments
--replicate=v1/services
--replicate-cluster=v1/nodes

Custom Resource Definitions (CRDs)

kube-mgmt can also be configured to replicate Kubernetes Custom Resources using the --replicate and --replicate-cluster options. For an example of how OPA can be used to enforce admission control polices on Kubernetes custom resources see Admission Control For Custom Resources

Admission Control

To get started with admission control policy enforcement in Kubernetes 1.9 or later see the Kubernetes Admission Control tutorial. For older versions of Kubernetes, see Admission Control (1.7).

In the Kubernetes Admission Control tutorial, OPA is NOT running with an authorization policy configured and hence clients can read and write policies in OPA. When deploying OPA in an insecure environment, it is recommended to configure authentication and authorization on the OPA daemon. For an example of how OPA can be securely deployed as an admission controller see Admission Control Secure.

Development Guide

To run all of the tests and build the Docker image run make in this directory.

kube-mgmt's People

Contributors

tsandall avatar ashutosh-narkar avatar alban avatar shrinandj avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.