Skip to content

Commit

Permalink
add scan-controller helm chart
Browse files Browse the repository at this point in the history
  • Loading branch information
portswigger-tim committed Oct 10, 2023
1 parent 20fd878 commit a825734
Show file tree
Hide file tree
Showing 10 changed files with 359 additions and 0 deletions.
23 changes: 23 additions & 0 deletions charts/scan-controller/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions charts/scan-controller/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: scan-controller
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.0.0-alpha.1

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "2023.9-14019"
64 changes: 64 additions & 0 deletions charts/scan-controller/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "scan-controller.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 "scan-controller.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 "scan-controller.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "scan-controller.labels" -}}
helm.sh/chart: {{ include "scan-controller.chart" . }}
{{ include "scan-controller.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "scan-controller.selectorLabels" -}}
app.kubernetes.io/name: {{ include "scan-controller.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Renders a value that contains template.
Usage:
{{ include "scan-controller.tplvalues.render" ( dict "value" .Values.path.to.the.Value "context" $) }}
*/}}
{{- define "scan-controller.tplvalues.render" -}}
{{- if typeIs "string" .value }}
{{- tpl .value .context }}
{{- else }}
{{- tpl (.value | toYaml) .context }}
{{- end }}
{{- end -}}
10 changes: 10 additions & 0 deletions charts/scan-controller/templates/controller-env-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ include "scan-controller.fullname" . }}-env
type: Opaque
data:
BSEE_WEB_SERVER_URL: {{ .Values.configuration.apiKey | b64enc }}
BSEE_HOSTED_SCANNING_MACHINE_API_KEY: {{ .Values.configuration.apiKey | b64enc }}
BSEE_HOSTED_SCAN_JOB_TEMPLATE: {{ include "scan-controller.tplvalues.render" ( dict "value" .Values.scanner.jobTemplate "context" $) | b64enc }}
BSEE_MAX_SCAN_CONCURRENCY: {{ .Values.configuration.maxConcurrency | quote | b64enc }}
87 changes: 87 additions & 0 deletions charts/scan-controller/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "scan-controller.fullname" . }}
labels:
{{- include "scan-controller.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "scan-controller.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "scan-controller.selectorLabels" . | nindent 8 }}
annotations:
checksum/controller-env-secret: {{ $controllerEnvSec := include (print $.Template.BasePath "/controller-env-secret.yaml") . | fromYaml }}{{ $controllerEnvSec.data | toYaml | sha256sum }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccount: {{ include "scan-controller.fullname" . }}
serviceAccountName: {{ include "scan-controller.fullname" . }}
securityContext:
fsGroup: 100000
fsGroupChangePolicy: OnRootMismatch
containers:
- name: scan-controller
securityContext:
runAsUser: 100000
readOnlyRootFilesystem: true
allowPrivilegeEscalation: false
privileged: false
capabilities:
drop:
- ALL
image: "{{ default .Values.global.image.registry .Values.controller.image.registry }}/{{ .Values.controller.image.repository }}:{{ .Values.controller.image.tag | default .Chart.AppVersion }}"
envFrom:
- secretRef:
name: {{ include "scan-controller.fullname" . }}-env
imagePullPolicy: {{ .Values.controller.image.pullPolicy }}
ports:
- name: management
containerPort: 8078
protocol: TCP
startupProbe:
httpGet:
port: management
path: /health/readiness
failureThreshold: 60
periodSeconds: 5
timeoutSeconds: 2
livenessProbe:
httpGet:
port: management
path: /health/liveness
failureThreshold: 3
periodSeconds: 10
timeoutSeconds: 2
successThreshold: 1
readinessProbe:
httpGet:
port: management
path: /health/readiness
failureThreshold: 1
periodSeconds: 10
timeoutSeconds: 2
successThreshold: 1
resources:
limits:
memory: 128Mi
requests:
cpu: 200m
memory: 128Mi
{{- with .Values.controller.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.controller.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.controller.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
4 changes: 4 additions & 0 deletions charts/scan-controller/templates/extra-deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{- range .Values.extraDeploy }}
---
{{ include "scan-controller.tplvalues.render" (dict "value" . "context" $) }}
{{- end }}
24 changes: 24 additions & 0 deletions charts/scan-controller/templates/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{include "scan-controller.fullname" .}}
rules:
- apiGroups: [""]
resources: ["pods", "pods/log"]
verbs: ["get", "watch", "list"]
- apiGroups: ["batch"]
resources: ["jobs"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{include "scan-controller.fullname" .}}
subjects:
- kind: ServiceAccount
name: {{include "scan-controller.fullname" .}}
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: {{include "scan-controller.fullname" .}}
apiGroup: rbac.authorization.k8s.io
8 changes: 8 additions & 0 deletions charts/scan-controller/templates/scanner-env-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ include "scan-controller.fullname" . }}-scanner-env
type: Opaque
data:
BSEE_WEB_SERVER_URL: {{ .Values.configuration.apiKey | b64enc }}
BSEE_HOSTED_SCANNING_MACHINE_API_KEY: {{ .Values.configuration.apiKey | b64enc }}
14 changes: 14 additions & 0 deletions charts/scan-controller/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "scan-controller.fullname" . }}
labels:
{{- include "scan-controller.labels" . | nindent 4 }}
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "scan-controller.fullname" . }}-scanner
labels:
{{- include "scan-controller.labels" . | nindent 4 }}
automountServiceAccountToken: false
101 changes: 101 additions & 0 deletions charts/scan-controller/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Default values for scan-controller.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""

global:
image:
registry: public.ecr.aws

configuration:
apiKey: ""
enterpriseUrl: ""
maxConcurrency: "20"

controller:
image:
registry: ""
repository: portswigger/scan-controller
pullPolicy: Always
tag: ""
nodeSelector: {}
tolerations: []
affinity: {}

scanner:
image:
registry: ""
repository: portswigger/portswigger-hosted-scan
tag: ""
nodeSelector: {}
tolerations: []
affinity: {}

jobTemplate: |
apiVersion: batch/v1
kind: Job
metadata:
name: scan
labels:
app.kubernetes.io/component: scanner
app.kubernetes.io/part-of: bsee
spec:
backoffLimit: 0
ttlSecondsAfterFinished: 60
template:
metadata:
labels:
app.kubernetes.io/component: scanner
app.kubernetes.io/part-of: bsee
annotations:
cluster-autoscaler.kubernetes.io/safe-to-evict: "false"
karpenter.sh/do-not-evict: "true"
spec:
serviceAccount: {{ include "scan-controller.fullname" . }}-scanner
serviceAccountName: {{ include "scan-controller.fullname" . }}-scanner
automountServiceAccountToken: false
containers:
- name: scan-container
env:
- name: JAVA_OPTS
value: -Xms512m -Xmx512m
- name: BURP_JAVA_OPTS
value: -XX:InitialRAMPercentage=75 -XX:MaxRAMPercentage=75
envFrom:
- secretRef:
name: {{ include "scan-controller.fullname" . }}-scanner-env
image: "{{ default .Values.global.image.registry .Values.scanner.image.registry }}/{{ .Values.scanner.image.repository }}:{{ .Values.scanner.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: Always
resources:
limits:
memory: 8Gi
requests:
cpu: 2
memory: 8Gi
securityContext:
runAsUser: 100000
readOnlyRootFilesystem: true
allowPrivilegeEscalation: false
privileged: false
capabilities:
drop:
- ALL
restartPolicy: Never
terminationGracePeriodSeconds: 30
{{- with .Values.scanner.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.scanner.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.scanner.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
extraDeploy: []

0 comments on commit a825734

Please sign in to comment.