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

[WIP] Remove generic admission server #40

Closed
wants to merge 67 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
7165ecb
inital commit of anchore-policy-validator
pbalogh-sa Aug 31, 2018
d0d64dd
fix external anchore values
pbalogh-sa Sep 3, 2018
b718c81
create validationwebhook with job
pbalogh-sa Sep 3, 2018
9b9a90c
fix repo in requirements
pbalogh-sa Sep 3, 2018
883733b
add missing job delete
pbalogh-sa Sep 4, 2018
b9325f4
add readme to anchore-policy validator
pbalogh-sa Sep 5, 2018
30b76dd
fix typo
pbalogh-sa Sep 5, 2018
9553efe
remove anchore-engine dependency and fix templates based on Chart sty…
pbalogh-sa Sep 5, 2018
3c7e5dd
fix README
pbalogh-sa Sep 11, 2018
bde2670
use banzaicloud/admission-image-validator image
pbalogh-sa Sep 17, 2018
061b4dd
add crd, validationwebhook exlude noscan
pbalogh-sa Sep 17, 2018
13987f1
fix readme
pbalogh-sa Sep 17, 2018
472712b
Anchore default policies (#375)
pbalogh-sa Sep 25, 2018
45910c2
fix kind in whitelist-crd (#384)
pbalogh-sa Oct 4, 2018
c92fcb4
remove releaseName from WhiteListItem Spec and add custom columns
pbalogh-sa Oct 15, 2018
f1c1870
increase nchore-image-validator version
pbalogh-sa Oct 15, 2018
4b23e13
change anchore-image-validator version and executable path (#399)
pbalogh-sa Oct 16, 2018
0ab65fd
new version of anchore-image-validator (#423)
pbalogh-sa Oct 24, 2018
859f40f
Selector, Affinity, Tolerations added (#424)
ahma Oct 26, 2018
7d1440b
Add pre and post delete helm hook (#452)
pbalogh-sa Nov 8, 2018
bae8212
refactor policyvalidator chart (#464)
pbalogh-sa Nov 10, 2018
233eb1a
add additional information to image
pbalogh-sa Nov 12, 2018
041f63c
use image-validator version 0.1.0
pbalogh-sa Nov 12, 2018
1617b90
bump image-validator version, add taints and tolerations (#529)
pbalogh-sa Nov 30, 2018
149a758
delete default anchore policy bundle (#554)
pbalogh-sa Dec 4, 2018
e4ca0d7
add whitelist regexp
pbalogh-sa Dec 4, 2018
b612860
bump anchore-image-validator version (#561)
pbalogh-sa Dec 6, 2018
4d71314
ValidatingWebhookConfiguration is created by image-validator (#568)
pbalogh-sa Dec 11, 2018
806d20d
use fullname in case of secret name and job (#579)
pbalogh-sa Dec 18, 2018
c9619d6
add maintainers to all charts' metadata (#580)
orymate Dec 19, 2018
878c39f
fix anchore-policy-validator README
pbalogh-sa Jan 7, 2019
a1d267e
add unauthenticated discovery binding
pbalogh-sa Jan 12, 2019
aff4d9e
images without setcap
pbalogh-sa Feb 25, 2019
d0954fd
use unprivileged internalPort (#696)
pbalogh-sa Mar 7, 2019
505beca
add psp
pbalogh-sa Apr 12, 2019
956cf14
use emptydir for /tmp
pbalogh-sa Apr 16, 2019
25f66cd
update readme
pbalogh-sa Apr 16, 2019
6d35b86
minor fixes
pbalogh-sa Apr 16, 2019
3ca8364
refactor psp
pbalogh-sa Apr 16, 2019
bd19a7d
remove namespacereservation realted binding
pbalogh-sa Apr 18, 2019
7ec0914
add seccomp
pbalogh-sa Apr 22, 2019
1d6b6f8
remove cluster-admin clusterrolebinding
pbalogh-sa Apr 23, 2019
a90aed9
update readme
pbalogh-sa Apr 23, 2019
5d808f5
do not delete default policy
pbalogh-sa Jul 10, 2019
a161f0d
fix anchore-policy-validator rbac
pbalogh-sa Aug 1, 2019
3b10230
bump anchore-image validator version
pbalogh-sa Aug 22, 2019
3b69329
add capability to define include rule in namespaceSelector
pbalogh-sa Sep 23, 2019
c7e6335
use NAMESPACE_SELECTOR instead of WEBHOOK_SELECTOR
pbalogh-sa Sep 23, 2019
72c304b
update remove generic-admission-server
pbalogh-sa Oct 20, 2019
d68fb48
udate dockerfiles
pbalogh-sa Oct 21, 2019
3f2bd2c
drop generic-admission-server and move out validation
pbalogh-sa Oct 21, 2019
2c20470
use controller-runtime
pbalogh-sa Oct 21, 2019
b4fe496
update license header
pbalogh-sa Oct 21, 2019
8538d7d
add config
pbalogh-sa Oct 21, 2019
8d122fd
add log
pbalogh-sa Oct 21, 2019
b94d263
move validation to internal
pbalogh-sa Oct 21, 2019
c56c736
use controller-runtime in handler
pbalogh-sa Oct 21, 2019
7f28fff
filter anchore-policy-validator chart
pbalogh-sa Nov 28, 2019
88a769a
Merge branch 'master' of github.com/banzaicloud/banzai-charts into 'r…
pbalogh-sa Nov 28, 2019
2b655d4
update charts
pbalogh-sa Nov 29, 2019
fe9c95e
minor fixes for health check
pbalogh-sa Dec 16, 2019
cf29aff
cleanup self
pbalogh-sa Dec 17, 2019
42e23b6
fix lint
pbalogh-sa Dec 17, 2019
7cc0c66
implement original logic
pbalogh-sa Dec 17, 2019
3225279
minor fixes
pbalogh-sa Dec 17, 2019
e010557
update go version in circleci config
pbalogh-sa Dec 18, 2019
81149df
fix licensei and check-header
pbalogh-sa Dec 18, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
docker_layer_caching: true

environment:
GO_VERSION: "1.12.3"
GO_VERSION: "1.13"
# K8S_VERSION: v1.13.1
# KUBECONFIG: /home/circleci/.kube/config
# MINIKUBE_VERSION: v0.33.1
Expand Down Expand Up @@ -45,7 +45,7 @@ jobs:
key: go-mod-v1-{{ .Branch }}-{{ checksum "go.sum" }}
paths:
- "/go/pkg/mod"

- run:
name: Install license checker
command: make bin/licensei
Expand Down
21 changes: 21 additions & 0 deletions .helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
3 changes: 3 additions & 0 deletions .licensei.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ ignored = [
"go.uber.org/atomic",
"go.uber.org/multierr",
"emperror.dev/errors",
"emperror.dev/emperror",
"logur.dev/logur",
"logur.dev/adapter/logrus",
]
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceRoot}/cmd/main.go",
"env": {},
"args": ["--dev-http"]
}
]
}
6 changes: 2 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.12-alpine AS builder
FROM golang:1.13-alpine AS builder

RUN apk add --update --no-cache ca-certificates git

Expand All @@ -10,11 +10,9 @@ RUN go mod download
COPY . /build
RUN go install ./cmd

FROM alpine:3.9
FROM alpine:3.10

COPY --from=builder /go/bin/cmd /usr/local/bin/anchore-image-validator
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

USER 65534:65534

ENTRYPOINT ["/usr/local/bin/anchore-image-validator"]
4 changes: 2 additions & 2 deletions Dockerfile.debug
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM golang:1.12-alpine AS builder
FROM golang:1.13-alpine AS builder

RUN apk add --update --no-cache ca-certificates git

RUN go get github.com/derekparker/delve/cmd/dlv

FROM alpine:3.9
FROM alpine:3.10

RUN apk add --update --no-cache libc6-compat

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ endif
DOCKER_TAG ?= ${VERSION}

# Dependency versions
GOLANGCI_VERSION = 1.12.3
GOLANGCI_VERSION = 1.21.0
LICENSEI_VERSION = 0.1.0

GOLANG_VERSION = 1.12
GOLANG_VERSION = 1.13

.PHONY: clean
clean: ## Clean the working area and the project
Expand Down
21 changes: 21 additions & 0 deletions charts/anchore-policy-validator/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
14 changes: 14 additions & 0 deletions charts/anchore-policy-validator/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
description: A Helm chart for anchore-policy-validator admission controller
name: anchore-policy-validator
version: 0.4.4
appVersion: 0.3.6
keywords:
- analysis
- "anchore-policy-validator"
- image
- security
maintainers:
- name: Banzai Cloud
email: info@banzaicloud.com
engine: gotpl
54 changes: 54 additions & 0 deletions charts/anchore-policy-validator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Anchore policy validator

This chart deploys an admission-server that is used as a ValidatingWebhook in a k8s cluster. If it's working, kubernetes will send requests to the admission server when a Pod creation is initiated. The server checks the image, which is defined in PodSpec, against configured Anchore-engine API. If the API responds with an error, that the image is not valid according to defined policy, k8s will reject the Pod creation request.

## Installing the Chart

```bash
$ helm repo add banzaicloud-stable http://kubernetes-charts.banzaicloud.com/branch/master
$ helm repo update
```

Deploying anchore-policy-validator using external Anchore-engine service:

```bash
$ helm install --name <name> --set externalAnchore.anchoreHost=<my.anchore.host> --set externalAnchore.anchoreUser=<username> -set externalAnchore.anchorePass=<password> banzaicloud-stable/anchore-policy-validator
```


During deploying this chart, it's creating predefined policy bundles and activates `AllowAll` by default.

## Policy bundles

| PolicyName | Description |
|---------------|-------------------------------------------------------------|
|AllowAll |Allow all images to deploy |
|RejectCritical |Reject deploying images that contain `critical` vulnerabiliy |
|RejectHigh |Reject deploying images that contain `high` vulnerabiliy |
|BlockRoot |Block deploying images that using `root` as effective user |
|DenyAll |Deny all imagest to deploy |


## Configuration

The following tables lists configurable parameters of the anchore-policy-validator chart and their default values.

| Parameter | Description | Default |
| ----------------------------------- | ------------------------------------------- | -----------------------------------------|
|replicaCount |number of replicas |1 |
|logVerbosity |log verbosity level |8 |
|apiService.group |group of registered api service |admission.anchore.io |
|apiService.version |version of registered api service |v1beta1 |
|image.repository |admission-server image repo |banzaicloud/anchore-image-validator |
|image.tag |admission-server image tag |0.3.6 |
|image.pullPolicy |admission-server image pull policy |IfNotPresent |
|service.name |validation sevice name |anchoreimagecheck |
|service.type |validation service type |ClusterIP |
|service.externalPort |validation service external port |443 |
|service.internalPort |validation service external port |443 |
|externalAnchore.anchoreHost |external anchore-engine host |"" |
|externalAnchore.anchoreUser |external anchore-engine username |"" |
|externalAnchore.anchorePass |external anchore-engine password |"" |
|rbac.enabled |enable RBAC |true |
|rbac.psp.enabled |add PSP resources if enabled |false |
|namespaceSelector |webHookConfig namespaceSelector behaviour |"" (exclude) |
Empty file.
32 changes: 32 additions & 0 deletions charts/anchore-policy-validator/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "anchore-policy-validator.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "anchore-policy-validator.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "anchore-policy-validator.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{{ $ca := genCA "svc-cat-ca" 3650 }}
{{- $svcName := include "anchore-policy-validator.fullname" . }}
{{- $cn := printf "%s.%s.svc" $svcName .Release.Namespace }}
{{- $altName1 := printf "%s.cluster.local" $cn }}
{{- $altName2 := printf "%s" $cn }}
{{- $server := genSignedCert $cn nil (list $altName1 $altName2) 365 $ca }}
{{- $major := .Capabilities.KubeVersion.Major -}}
{{- $minor := .Capabilities.KubeVersion.Minor -}}
apiVersion: v1
kind: Secret
metadata:
name: {{ template "anchore-policy-validator.fullname" . }}
type: kubernetes.io/tls
data:
tls.crt: {{ b64enc $server.Cert }}
tls.key: {{ b64enc $server.Key }}
ca.crt: {{ b64enc $ca.Cert }}
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
name: {{ template "anchore-policy-validator.fullname" . }}
namespace: {{ .Release.Namespace }}
webhooks:
- name: pods.{{ template "anchore-policy-validator.name" . }}.admission.banzaicloud.com
clientConfig:
service:
namespace: {{ .Release.Namespace }}
name: {{ template "anchore-policy-validator.fullname" . }}
path: /imagecheck
caBundle: {{ b64enc $ca.Cert }}
rules:
- apiGroups: [""]
apiVersions: ["v1"]
operations: ["CREATE"]
resources: ["pods"]
scope: "*"
admissionReviewVersions: ["v1", "v1beta1"]
failurePolicy: {{ .Values.podsFailurePolicy }}
sideEffects: None
namespaceSelector:
{{- if .Values.namespaceSelector.matchLabels }}
matchLabels:
{{ toYaml .Values.namespaceSelector.matchLabels | indent 6 }}
{{- end }}
matchExpressions:
{{- if .Values.namespaceSelector.matchExpressions }}
{{ toYaml .Values.namespaceSelector.matchExpressions | indent 6 }}
{{- end }}
- key: name
operator: NotIn
values:
- {{ .Release.Namespace }}
{{- if and (eq (int $major) 1) (ge (int $minor) 15) }}
objectSelector:
matchExpressions:
{{- if .Values.objectSelector.matchExpressions }}
{{ toYaml .Values.objectSelector.matchExpressions | indent 4 }}
{{- end }}
- key: security.banzaicloud.io/validate
operator: NotIn
values:
- skip
{{- end }}
67 changes: 67 additions & 0 deletions charts/anchore-policy-validator/templates/audit-crd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: audits.security.banzaicloud.com
spec:
group: security.banzaicloud.com
version: v1alpha1
names:
kind: Audit
plural: audits
singular: audit
scope: Cluster
validation:
openAPIV3Schema:
properties:
spec:
required:
- releaseName
- resource
- image
- result
- action
properties:
releaseName:
type: string
resource:
type: string
image:
type: array
items:
type: object
properties:
imageName:
type: string
imageTag:
type: string
imageDigest:
type: string
lastUpdated:
type: string
result:
type: array
items:
type: string
action:
type: string
status:
properties:
state:
type: string
additionalPrinterColumns:
- name: ReleaseName
type: string
JSONPath: .spec.releaseName
priority: 1
- name: Image
type: string
JSONPath: .spec.image[*].imageName
priority: 2
- name: result
type: string
JSONPath: .spec.result
priority: 3
- name: action
type: string
JSONPath: .spec.action
priority: 4
Loading