diff --git a/charts/nextportal/CONTRIBUTING.md b/charts/nextportal/CONTRIBUTING.md new file mode 100644 index 0000000..146427d --- /dev/null +++ b/charts/nextportal/CONTRIBUTING.md @@ -0,0 +1,38 @@ +# Contribution guide + +## Validate on a test cluster + +Create the chart configuration file: + +```bash +# example for an Instruqt track, with a Traefik ingress controller, with cert-manager and Let's Encrypt +cat > values.mine.yaml << 'EOF' +ingress: + enabled: true + className: "traefik" + annotations: + cert-manager.io/cluster-issuer: "letsencrypt-prod" + tls: + enabled: true +EOF +``` + +Install the chart: + +```bash +helm upgrade --install nextportal . -f values.yaml -f values.mine.yaml \ + --set ingress.domain=nextportal.console.$SANDBOX_ID.instruqt.io \ + --namespace nextportal --create-namespace +``` + +Wait for all pods to be ready: + +```bash +kubectl get all -n nextportal +``` + +Open the web application in a browser. + +```bash +echo "https://nextportal.console.${SANDBOX_ID}.instruqt.io" +``` diff --git a/charts/nextportal/Chart.yaml b/charts/nextportal/Chart.yaml new file mode 100644 index 0000000..69d77c8 --- /dev/null +++ b/charts/nextportal/Chart.yaml @@ -0,0 +1,14 @@ +apiVersion: v2 +name: nextportal +description: NextPortal web application - intentionally vulnerable by default for security workshops +type: application +version: 0.1.0 +appVersion: "0.1.0" +keywords: + - security + - vulnerable + - workshop + - owasp +maintainers: + - name: devpro + email: bertrand@devpro.fr diff --git a/charts/nextportal/README.md b/charts/nextportal/README.md new file mode 100644 index 0000000..c896379 --- /dev/null +++ b/charts/nextportal/README.md @@ -0,0 +1,34 @@ +# NextPortal Helm Chart + +Helm chart for [NextPortal Web Application](https://github.com/devpro/container-images/tree/main/src/nextportal) — designed for container security workshops. + +## Quick Start + +Add the chart repository: + +```bash +helm repo add devpro https://devpro.github.io/helm-charts +helm repo update +``` + +Create the `values.yaml` file to override [default values](values.yaml). + +Install the chart: + +```bash +helm upgrade --install nextportal devpro/nextportal -f values.yaml --namespace nextportal --create-namespace +``` + +## Uninstall + +```bash +helm uninstall nextportal -n nextportal +kubectl delete namespace nextportal +``` + +## Going further + +Check the [contribution guide](CONTRIBUTING.md). + +--- +> ⚠️ **FOR WORKSHOP USE ONLY** — intentionally vulnerable, never expose to the internet. diff --git a/charts/nextportal/templates/NOTES.txt b/charts/nextportal/templates/NOTES.txt new file mode 100644 index 0000000..1a7b9b5 --- /dev/null +++ b/charts/nextportal/templates/NOTES.txt @@ -0,0 +1,20 @@ +1. NextPortal web application has been deployed. + +{{- if .Values.ingress.enabled }} + URL: https://{{ .Values.ingress.domain }} + + TLS certificate will be issued automatically by cert-manager. + Watch progress with: + kubectl get certificate -n {{ .Release.Namespace }} + kubectl describe certificaterequest -n {{ .Release.Namespace }} +{{- else }} + Port-forward to access locally: + kubectl port-forward svc/{{ include "nextportal.fullname" . }} 3000:3000 -n {{ .Release.Namespace }} + then open http://localhost:3000 +{{- end }} + +2. Check pod status: + kubectl get pods -n {{ .Release.Namespace }} -l app.kubernetes.io/name={{ include "nextportal.name" . }} + +3. View logs: + kubectl logs -n {{ .Release.Namespace }} -l app.kubernetes.io/name={{ include "nextportal.name" . }} -f diff --git a/charts/nextportal/templates/_helpers.tpl b/charts/nextportal/templates/_helpers.tpl new file mode 100644 index 0000000..8f1b1ac --- /dev/null +++ b/charts/nextportal/templates/_helpers.tpl @@ -0,0 +1,49 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "nextportal.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +*/}} +{{- define "nextportal.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 }} + +{{/* +Chart label. +*/}} +{{- define "nextportal.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels. +*/}} +{{- define "nextportal.labels" -}} +helm.sh/chart: {{ include "nextportal.chart" . }} +{{ include "nextportal.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels. +*/}} +{{- define "nextportal.selectorLabels" -}} +app.kubernetes.io/name: {{ include "nextportal.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} diff --git a/charts/nextportal/templates/deployment.yaml b/charts/nextportal/templates/deployment.yaml new file mode 100644 index 0000000..e3c60f1 --- /dev/null +++ b/charts/nextportal/templates/deployment.yaml @@ -0,0 +1,76 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "nextportal.fullname" . }} + labels: + {{- include "nextportal.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + strategy: + type: RollingUpdate + selector: + matchLabels: + {{- include "nextportal.selectorLabels" . | nindent 6 }} + template: + metadata: + annotations: + # forces a rollout when values change even if the image tag is the same + checksum/config: {{ toYaml .Values.env | sha256sum }} + {{- with .Values.podAnnotations }} + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "nextportal.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- if .Values.podSecurityContext }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + {{- end }} + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + {{- if .Values.containerSecurityContext }} + securityContext: + {{- toYaml .Values.containerSecurityContext | nindent 12 }} + {{- end }} + ports: + - name: http + containerPort: 3000 + protocol: TCP + env: + {{- range $key, $val := .Values.env }} + - name: {{ $key }} + value: {{ $val | quote }} + {{- end }} + {{- with .Values.envFrom }} + envFrom: + {{- toYaml . | nindent 12 }} + {{- end }} + livenessProbe: + {{- toYaml .Values.livenessProbe | nindent 12 }} + readinessProbe: + {{- toYaml .Values.readinessProbe | nindent 12 }} + {{- if .Values.resources }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- end }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} + restartPolicy: Always diff --git a/charts/nextportal/templates/hpa.yaml b/charts/nextportal/templates/hpa.yaml new file mode 100644 index 0000000..f5dbebf --- /dev/null +++ b/charts/nextportal/templates/hpa.yaml @@ -0,0 +1,22 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "nextportal.fullname" . }} + labels: + {{- include "nextportal.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "nextportal.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} +{{- end }} diff --git a/charts/nextportal/templates/ingress.yaml b/charts/nextportal/templates/ingress.yaml new file mode 100644 index 0000000..0d8be98 --- /dev/null +++ b/charts/nextportal/templates/ingress.yaml @@ -0,0 +1,33 @@ +{{- if .Values.ingress.enabled -}} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ include "nextportal.fullname" . }} + labels: + {{- include "nextportal.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if .Values.ingress.className }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + rules: + - host: {{ .Values.ingress.domain | quote }} + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: {{ include "nextportal.fullname" $ }} + port: + name: http + {{- if .Values.ingress.tls.enabled }} + tls: + - secretName: nextportal-tls + hosts: + - {{ .Values.ingress.domain | quote }} + {{- end }} +{{- end }} diff --git a/charts/nextportal/templates/service.yaml b/charts/nextportal/templates/service.yaml new file mode 100644 index 0000000..6283c1c --- /dev/null +++ b/charts/nextportal/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "nextportal.fullname" . }} + labels: + {{- include "nextportal.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + selector: + {{- include "nextportal.selectorLabels" . | nindent 4 }} + ports: + - name: http + port: {{ .Values.service.port }} + targetPort: http + protocol: TCP diff --git a/charts/nextportal/values.yaml b/charts/nextportal/values.yaml new file mode 100644 index 0000000..c04318f --- /dev/null +++ b/charts/nextportal/values.yaml @@ -0,0 +1,81 @@ +image: + repository: ghcr.io/devpro/nextportal + tag: "0.1.0" + pullPolicy: IfNotPresent + +imagePullSecrets: [] + # - name: "" + +replicaCount: 1 + +podAnnotations: {} + +resources: {} + # requests: + # cpu: 100m + # memory: 128Mi + # limits: + # cpu: 500m + # memory: 512Mi + +service: + type: ClusterIP + port: 3000 + +ingress: + enabled: false + # e.g. traefik + className: "" + domain: "" + annotations: {} + # cert-manager.io/cluster-issuer: "letsencrypt-prod" + # traefik.ingress.kubernetes.io/router.entrypoints: websecure + # traefik.ingress.kubernetes.io/router.tls: "true" + # traefik.ingress.kubernetes.io/router.middlewares: default-redirect-https@kubernetescrd + tls: + enabled: false + +livenessProbe: + httpGet: + path: / + port: 3000 + initialDelaySeconds: 15 + periodSeconds: 20 + +readinessProbe: + httpGet: + path: / + port: 3000 + initialDelaySeconds: 5 + periodSeconds: 10 + +podSecurityContext: {} + # runAsNonRoot: true + # runAsUser: 1001 + # runAsGroup: 1001 + # fsGroup: 1001 + +containerSecurityContext: {} + # allowPrivilegeEscalation: false + # readOnlyRootFilesystem: false + # capabilities: + # drop: + # - ALL + +autoscaling: + enabled: false + minReplicas: 2 + maxReplicas: 10 + targetCPUUtilizationPercentage: 70 + +nodeSelector: {} +tolerations: [] +affinity: {} + +env: + NODE_ENV: production + NEXT_TELEMETRY_DISABLED: "1" + +# envFrom: +# - secretRef: +# name: "" diff --git a/docs/application-guides/developer-platforms/drupal.md b/docs/application-guides/developer-platforms/drupal.md index aa8f8e0..8fa8467 100644 --- a/docs/application-guides/developer-platforms/drupal.md +++ b/docs/application-guides/developer-platforms/drupal.md @@ -1,4 +1,4 @@ -# Drupal +# Drupal ## Stable repository @@ -34,3 +34,34 @@ minikube service d8cluster-drupal --url ## Additional reading - Article from Jeff Geerling on [Running Drupal in Kubernetes with Docker in production](https://www.jeffgeerling.com/blog/2019/running-drupal-kubernetes-docker-production) _April 12, 2019_ + +{/* + +[bitnami/charts](https://github.com/bitnami/charts/blob/main/bitnami/drupal/README.md) + +```bash +helm repo add bitnami https://charts.bitnami.com/bitnami +helm repo update + +cat < drupal_values.yaml +image: + registry: docker.io + repository: drupal + tag: "8.5" +ingress: + enabled: true + className: traefik + annotations: + cert-manager.io/cluster-issuer: "letsencrypt-prod" +EOF + +helm install drupal bitnami/drupal -f drupal_values.yaml --namespace drupal --create-namespace \ + --set ingress.hosts[0].host="drupal.console.${_SANDBOX_ID}.instruqt.io" \ + --set ingress.tls[0].host[0]="drupal.console.${_SANDBOX_ID}.instruqt.io" + +echo "https://drupal.console.${_SANDBOX_ID}.instruqt.io" + +kubectl get all -n drupal +``` + +*/}