All Projects → chrisns → k8s-opa-boilerplate

chrisns / k8s-opa-boilerplate

Licence: MIT License
Boilerplate example of managing OPA with kustomize

Programming Languages

Open Policy Agent
39 projects
shell
77523 projects

Projects that are alternatives of or similar to k8s-opa-boilerplate

opa-kafka-plugin
Open Policy Agent (OPA) plug-in for Kafka authorization
Stars: ✭ 46 (+228.57%)
Mutual labels:  opa, open-policy-agent, rego
ccheck
A command line tool for validating Kubernetes configs with rego
Stars: ✭ 63 (+350%)
Mutual labels:  yaml, opa, rego
opal
Policy and data administration, distribution, and real-time updates on top of Open Policy Agent
Stars: ✭ 459 (+3178.57%)
Mutual labels:  opa, open-policy-agent
OPA-python-client
Python client for Open Policy Agent
Stars: ✭ 24 (+71.43%)
Mutual labels:  opa, open-policy-agent
awesome-opa
A curated list of OPA related tools, frameworks and articles
Stars: ✭ 316 (+2157.14%)
Mutual labels:  opa, open-policy-agent
Conftest
Write tests against structured configuration data using the Open Policy Agent Rego query language
Stars: ✭ 2,047 (+14521.43%)
Mutual labels:  open-policy-agent, rego
Opa
An open source, general-purpose policy engine.
Stars: ✭ 5,939 (+42321.43%)
Mutual labels:  opa, open-policy-agent
container-image-sign-and-verify-with-cosign-and-opa
This is just a proof-of-concept project that aims to sign and verify container images using cosign and OPA (Open Policy Agent)
Stars: ✭ 54 (+285.71%)
Mutual labels:  opa, open-policy-agent
pre-commit-opa
Pre-commit git hooks for Open Policy Agent (OPA) and Rego development
Stars: ✭ 53 (+278.57%)
Mutual labels:  opa, rego
dotnet-opa-wasm
Call Open Policy Agent (OPA) policies in WASM (Web Assembly) from .NET Core
Stars: ✭ 36 (+157.14%)
Mutual labels:  opa, open-policy-agent
postee
Simple message routing system that receives input messages through a webhook interface and can enforce actions using predefined outputs via integrations.
Stars: ✭ 160 (+1042.86%)
Mutual labels:  opa, rego
prancer-compliance-test
This repository includes cloud security policies for IaC and live resources.
Stars: ✭ 32 (+128.57%)
Mutual labels:  opa, rego
pyaml env
Parse YAML configuration with environment variables in Python
Stars: ✭ 36 (+157.14%)
Mutual labels:  yaml
CoreFormatters
.NET Core Custom Formatter for Yaml
Stars: ✭ 21 (+50%)
Mutual labels:  yaml
Obsidian-Markdown-Parser
This repository will give you tools to parse and fetch useful informations of your notes in your Obsidian vault.
Stars: ✭ 32 (+128.57%)
Mutual labels:  yaml
crystalizer
(De)serialize any Crystal object - out of the box. Supports JSON, YAML and Byte format.
Stars: ✭ 32 (+128.57%)
Mutual labels:  yaml
online-resume
A Jekyll theme for resume / cv based on Markdown. Demo: https://tarrex.github.io/online-resume
Stars: ✭ 27 (+92.86%)
Mutual labels:  yaml
website
Prometheus monitoring mixins
Stars: ✭ 91 (+550%)
Mutual labels:  yaml
gsheet to arb
Import translations (ARB/Dart) from Google Sheets
Stars: ✭ 21 (+50%)
Mutual labels:  yaml
dby
Simple Yaml DB
Stars: ✭ 47 (+235.71%)
Mutual labels:  yaml

Boiler plate example of managing OPA with kustomize

Test the boilerplate Test the rego

Motivation

I wanted a boilerplate to help me write OPA Gatekeeper policy documents in Rego.

I'm a developer that cares about testing, and general code quality so to achieve that its important to seperate the Rego from being embedded in the yaml like much of the official documentation 😭

I also like simplicity and sticking with vanilla tooling so rather than using the kustomize generator custom generator plugin approach I've opted for a pretty hacky stringing together of yaml to get the Rego embedded in to the Kind: ConstraintTemplate. Hopefully something will emerge with kustomize that allows for piping in files like how the SecretGenerator and ConfigMapGenerator work. The annoying side effect is that you end up with a pointless ConfigMap, you could putt his in a separate namespace to be sure it won't pollute things.

I've included a test for the yaml to assert that works consistently.

Usage

Local testing

I've tested this with this: (I found it was handy to prepend with watch -n 0.5 while I was coding)

$ opa test *.rego -v --explain full
data.simpleRegistryCheck_test.test_mix_of_good_and_bad_images: PASS (1.025336ms)
data.simpleRegistryCheck_test.test_bad_images: PASS (186.052µs)
data.simpleRegistryCheck_test.test_good_image_no_violation: PASS (163.964µs)
data.simpleRegistryCheck_test.test_good_images_no_violation: PASS (256.612µs)
--------------------------------------------------------------------------------
PASS: 4/4

Automated testing / CI

Tests and coverage are monitored with a github action

Example compilation of Kubernetes resources

$ kubectl apply --dry-run=client -k . -o yaml
apiVersion: v1
items:
- apiVersion: v1
  data:
    myrego: "package simpleRegistryCheck\n\nviolation {\n\timage := input.request.object.spec.containers[_].image\n\tnot
      startswith(image, \"k8s.gcr.io/\")\n\tnot startswith(image, \"docker.io/\")\n}\n"
  kind: ConfigMap
  metadata:
    annotations:
      kubectl.kubernetes.io/last-applied-configuration: |
        {"apiVersion":"v1","data":{"myrego":"package simpleRegistryCheck\n\nviolation {\n\timage := input.request.object.spec.containers[_].image\n\tnot startswith(image, \"k8s.gcr.io/\")\n\tnot startswith(image, \"docker.io/\")\n}\n"},"kind":"ConfigMap","metadata":{"annotations":{},"name":"myrego-dk457tft5k","namespace":"magicmirror"}}
    name: myrego-dk457tft5k
    namespace: magicmirror
- apiVersion: templates.gatekeeper.sh/v1beta1
  kind: ConstraintTemplate
  metadata:
    annotations:
      kubectl.kubernetes.io/last-applied-configuration: |
        {"apiVersion":"templates.gatekeeper.sh/v1beta1","kind":"ConstraintTemplate","metadata":{"annotations":{},"name":"k8strustedimages"},"spec":{"crd":{"spec":{"names":{"kind":"K8sTrustedImages"}}},"targets":[{"rego":"package simpleRegistryCheck\n\nviolation {\n\timage := input.request.object.spec.containers[_].image\n\tnot startswith(image, \"k8s.gcr.io/\")\n\tnot startswith(image, \"docker.io/\")\n}\n","target":"admission.k8s.gatekeeper.sh"}]}}
    name: k8strustedimages
  spec:
    crd:
      spec:
        names:
          kind: K8sTrustedImages
    targets:
    - rego: "package simpleRegistryCheck\n\nviolation {\n\timage := input.request.object.spec.containers[_].image\n\tnot
        startswith(image, \"k8s.gcr.io/\")\n\tnot startswith(image, \"docker.io/\")\n}\n"
      target: admission.k8s.gatekeeper.sh
kind: List
metadata: {}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].