Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding the option to use a new crd modules in policies #2

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
206 changes: 123 additions & 83 deletions charts/bridgekeeper/templates/crds.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{{- if .Values.installCRDs }}
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
Expand All @@ -14,88 +13,129 @@ spec:
singular: policy
scope: Cluster
versions:
- additionalPrinterColumns: []
name: v1alpha1
schema:
openAPIV3Schema:
description: "Auto-generated derived type for PolicySpec via `CustomResource`"
properties:
spec:
properties:
audit:
nullable: true
type: boolean
enforce:
nullable: true
type: boolean
rule:
properties:
python:
- additionalPrinterColumns: []
name: v1alpha1
schema:
openAPIV3Schema:
description: Auto-generated derived type for PolicySpec via `CustomResource`
properties:
spec:
properties:
audit:
nullable: true
type: boolean
enforce:
nullable: true
type: boolean
rule:
properties:
modules:
items:
type: string
nullable: true
type: array
python:
type: string
required:
- python
type: object
target:
properties:
excludedNamespaces:
items:
type: string
required:
- python
type: object
target:
properties:
excludedNamespaces:
items:
type: string
nullable: true
type: array
matches:
items:
properties:
apiGroup:
type: string
kind:
type: string
required:
- apiGroup
- kind
type: object
type: array
namespaces:
items:
type: string
nullable: true
type: array
required:
- matches
type: object
required:
- rule
- target
type: object
status:
nullable: true
properties:
audit:
nullable: true
properties:
timestamp:
nullable: true
nullable: true
type: array
matches:
items:
properties:
apiGroup:
type: string
kind:
type: string
required:
- apiGroup
- kind
type: object
type: array
namespaces:
items:
type: string
violations:
items:
properties:
identifier:
type: string
message:
type: string
required:
- identifier
- message
type: object
nullable: true
type: array
type: object
type: object
required:
- spec
title: Policy
type: object
served: true
storage: true
subresources:
status: {}
nullable: true
type: array
required:
- matches
type: object
required:
- rule
- target
type: object
status:
nullable: true
properties:
audit:
nullable: true
properties:
timestamp:
nullable: true
type: string
violations:
items:
properties:
identifier:
type: string
message:
type: string
required:
- identifier
- message
type: object
nullable: true
type: array
type: object
type: object
required:
- spec
title: Policy
type: object
served: true
storage: true
subresources:
status: {}
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: modules.bridgekeeper.maibornwolff.de
spec:
group: bridgekeeper.maibornwolff.de
names:
categories: []
kind: Module
plural: modules
shortNames: []
singular: module
scope: Cluster
versions:
- additionalPrinterColumns: []
name: v1alpha1
schema:
openAPIV3Schema:
description: Auto-generated derived type for ModuleSpec via `CustomResource`
properties:
spec:
properties:
python:
type: string
required:
- python
type: object
required:
- spec
title: Module
type: object
served: true
storage: true
subresources: {}
---
{{- end }}
4 changes: 3 additions & 1 deletion charts/bridgekeeper/templates/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
{{- include "bridgekeeper.labels" . | nindent 4 }}
name: bridgekeeper-role
rules:
# During audit runs bridgekeeper needs to potentially access all resources in the cluster
# During audit runs bridgekeeper needs to potentially access all resources in the cluster
- apiGroups:
- '*'
resources:
Expand Down Expand Up @@ -42,6 +42,8 @@ rules:
resources:
- policies
- policies/status
- modules
- modules/status
verbs:
- patch
- update
Expand Down
5 changes: 3 additions & 2 deletions src/api.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::crd::Policy;
use crate::evaluator::{validate_policy_admission, EvaluationResult, PolicyEvaluatorRef};
use crate::evaluator::{EvaluationResult, PolicyEvaluatorRef};
use crate::util::cert::CertKeyPair;
use kube::{
api::DynamicObject,
Expand Down Expand Up @@ -84,6 +84,7 @@ async fn admission_mutate(
#[rocket::post("/validate-policy", data = "<data>")]
async fn api_validate_policy(
data: Json<AdmissionReview<Policy>>,
evaluator: &State<PolicyEvaluatorRef>,
) -> Result<Json<AdmissionReview<DynamicObject>>, ApiError> {
HTTP_REQUEST_COUNTER
.with_label_values(&["/validate-policy"])
Expand All @@ -94,7 +95,7 @@ async fn api_validate_policy(
})?;
let mut response: AdmissionResponse = AdmissionResponse::from(&admission_request);

let (allowed, reason) = validate_policy_admission(&admission_request).await;
let (allowed, reason) = evaluator.validate_policy_admission(&admission_request);
response.allowed = allowed;
if !allowed {
response.result.message = reason.unwrap_or_default();
Expand Down
Loading