Skip to content

Commit

Permalink
feat!: major change to deploy, adhere to QSOS, use HELM , move away f…
Browse files Browse the repository at this point in the history
…rom DC(Deprecated Already.)
  • Loading branch information
mishraomp committed Oct 4, 2024
1 parent 9b147de commit 3ec8e62
Show file tree
Hide file tree
Showing 22 changed files with 780 additions and 68 deletions.
38 changes: 13 additions & 25 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,21 @@ jobs:
id: pr
uses: bcgov-nr/[email protected]

deploys:
name: TEST Deployments
needs: [vars]
environment: test
runs-on: ubuntu-22.04
strategy:
matrix:
name: [frontend, rctool]
include:
- name: frontend
file: frontend/openshift.nginx.deploy.yml
- name: rctool
file: frontend/openshift.deploy.yml
steps:
- uses: bcgov-nr/[email protected]
with:
file: ${{ matrix.file }}
oc_namespace: ${{ secrets.OC_NAMESPACE }}
oc_server: ${{ vars.OC_SERVER }}
oc_token: ${{ secrets.OC_TOKEN }}
overwrite: true
parameters:
-p ZONE=test -p PROMOTE=${{ github.repository }}/${{ matrix.name }}:${{ needs.vars.outputs.pr }} -p MAX_REPLICAS=3
deploy-test:
name: Deploy (test)
uses: bcgov/quickstart-openshift-helpers/.github/workflows/[email protected]
secrets:
oc_namespace: ${{ secrets.OC_NAMESPACE }}
oc_token: ${{ secrets.OC_TOKEN }}
with:
environment: test
params: --set global.autoscaling=true --set rctool.pdb.enabled=true --set frontend.pdb.enabled=true



zap_scan:
runs-on: ubuntu-22.04
needs: [deploys, vars]
needs: [deploy-test, vars]
name: Penetration Tests
env:
URL: ${{ github.event.repository.name }}-test-frontend.apps.silver.devops.gov.bc.ca
Expand All @@ -66,7 +54,7 @@ jobs:
target: https://${{ env.URL }}
promotions:
name: Promote Images
needs: [deploys, vars]
needs: [deploy-test, vars]
permissions:
packages: write
runs-on: ubuntu-22.04
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-close.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ jobs:
oc_namespace: ${{ secrets.OC_NAMESPACE }}
oc_token: ${{ secrets.OC_TOKEN }}
with:
cleanup: label
cleanup: helm
packages: frontend rctool
32 changes: 11 additions & 21 deletions .github/workflows/pr-open.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,19 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
triggers: ('frontend/')

# https://github.com/bcgov/quickstart-openshift-helpers
deploys:
name: Deploys
needs: [builds]
runs-on: ubuntu-22.04
strategy:
matrix:
name: [frontend, rctool]
include:
- name: frontend
file: frontend/openshift.nginx.deploy.yml
- name: rctool
file: frontend/openshift.deploy.yml
steps:
- uses: bcgov-nr/[email protected]
with:
file: ${{ matrix.file }}
oc_namespace: ${{ secrets.OC_NAMESPACE }}
oc_server: ${{ vars.OC_SERVER }}
oc_token: ${{ secrets.OC_TOKEN }}
overwrite: true
parameters:
-p ZONE=${{ github.event.number }}
-p PROMOTE=${{ github.repository }}/${{ matrix.name }}:${{ github.event.number }}
needs: [ builds ]
uses: bcgov/quickstart-openshift-helpers/.github/workflows/[email protected]
secrets:
oc_namespace: ${{ secrets.OC_NAMESPACE }}
oc_token: ${{ secrets.OC_TOKEN }}
with:
triggers: ('frontend/')
params: --set global.secrets.persist=false
oc_server: ${{ vars.OC_SERVER }}


results:
name: PR Results
Expand Down
30 changes: 9 additions & 21 deletions .github/workflows/prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,15 @@ concurrency:

jobs:
deploys:
name: PROD Deployments
environment: prod
runs-on: ubuntu-22.04
strategy:
matrix:
name: [frontend, rctool]
include:
- name: frontend
file: frontend/openshift.nginx.deploy.yml
- name: rctool
file: frontend/openshift.deploy.yml
steps:
- uses: bcgov-nr/[email protected]
with:
file: ${{ matrix.file }}
oc_namespace: ${{ secrets.OC_NAMESPACE }}
oc_server: ${{ vars.OC_SERVER }}
oc_token: ${{ secrets.OC_TOKEN }}
overwrite: true
parameters:
-p ZONE=prod -p PROMOTE=${{ github.repository }}/${{ matrix.name }}:test -p MAX_REPLICAS=3
name: Deploy (test)
uses: bcgov/quickstart-openshift-helpers/.github/workflows/[email protected]
secrets:
oc_namespace: ${{ secrets.OC_NAMESPACE }}
oc_token: ${{ secrets.OC_TOKEN }}
with:
environment: prod
tag: test
params: --set global.autoscaling=true --set rctool.pdb.enabled=true --set frontend.pdb.enabled=true

promotions:
name: Promote Images
Expand Down
23 changes: 23 additions & 0 deletions charts/app/.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/
6 changes: 6 additions & 0 deletions charts/app/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dependencies:
- name: postgresql
repository: https://charts.bitnami.com/bitnami
version: 15.5.36
digest: sha256:2a03d437947bc841ae70d07e6b84735b6cc4651a7a31804afa188cf75131669a
generated: "2024-10-03T22:49:27.151720296Z"
31 changes: 31 additions & 0 deletions charts/app/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: v2
name: nr-hydrometric-rating-curve
description: A Helm chart for Kubernetes deployment.
icon: https://www.nicepng.com/png/detail/521-5211827_bc-icon-british-columbia-government-logo.png

# 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.1.0

# 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: "1.16.0"

maintainers:
- name: Om Mishra
email: [email protected]
- name: Derek Roberts
email: [email protected]
47 changes: 47 additions & 0 deletions charts/app/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "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 "fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s" .Release.Name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "name.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

43 changes: 43 additions & 0 deletions charts/app/templates/frontend/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "frontend.name" -}}
{{- printf "frontend" }}
{{- 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 "frontend.fullname" -}}
{{- $componentName := include "frontend.name" . }}
{{- if .Values.frontend.fullnameOverride }}
{{- .Values.frontend.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $componentName | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}


{{/*
Common labels
*/}}
{{- define "frontend.labels" -}}
{{ include "frontend.selectorLabels" . }}
{{- if .Values.global.tag }}
app.kubernetes.io/image-version: {{ .Values.global.tag | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/short-name: {{ include "frontend.name" . }}
{{- end }}

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


87 changes: 87 additions & 0 deletions charts/app/templates/frontend/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{{- if .Values.frontend.enabled }}

Check warning

Code scanning / Trivy

Seccomp policies disabled Medium

Artifact: charts/app/templates/frontend/templates/deployment.yaml
Type: helm
Vulnerability KSV104
Severity: MEDIUM
Message: container "nr-hydrometric-rating-curve-frontend" of deployment "nr-hydrometric-rating-curve-frontend" in "default" namespace should specify a seccomp profile
Link: KSV104
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "frontend.fullname" . }}
labels:
{{- include "frontend.labels" . | nindent 4 }}
spec:
strategy:
type: {{ .Values.frontend.deploymentStrategy }}
{{- if not .Values.frontend.autoscaling.enabled }}
replicas: {{ .Values.frontend.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "frontend.selectorLabels" . | nindent 6 }}
template:
metadata:
annotations:
rollme: {{ randAlphaNum 5 | quote }}
labels:
{{- include "frontend.labels" . | nindent 8 }}
spec:
{{- if .Values.frontend.podSecurityContext }}
securityContext:
{{- toYaml .Values.frontend.podSecurityContext | nindent 12 }}
{{- end }}
containers:
- name: {{ include "frontend.fullname" . }}
securityContext:
capabilities:
add: [ "NET_BIND_SERVICE" ]
image: "{{.Values.global.registry}}/{{.Values.global.repository}}/nginx:{{ .Values.global.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ default "Always" .Values.frontend.imagePullPolicy }}
env:
- name: BACKEND_URL
value: "http://{{ .Release.Name }}-rctool"
- name: LOG_LEVEL
value: "info"
ports:
- name: http
containerPort: 3000
protocol: TCP
readinessProbe:
httpGet:
path: /rctool
port: 3000
scheme: HTTP
initialDelaySeconds: 5
periodSeconds: 2
timeoutSeconds: 2
successThreshold: 1
failureThreshold: 30
#-- the liveness probe for the container. it is optional and is an object. for default values check this link: https://github.com/bcgov/helm-service/blob/main/charts/component/templates/deployment.yaml#L324-L328
livenessProbe:
successThreshold: 1
failureThreshold: 3
httpGet:
path: /rctool
port: 3000
scheme: HTTP
initialDelaySeconds: 15
periodSeconds: 30
timeoutSeconds: 5
resources:
limits:
cpu: 50m
memory: 60Mi
requests:
cpu: 10m
memory: 20Mi

Check warning

Code scanning / Trivy

Can elevate its own privileges Medium

Artifact: charts/app/templates/frontend/templates/deployment.yaml
Type: helm
Vulnerability KSV001
Severity: MEDIUM
Message: Container 'nr-hydrometric-rating-curve-frontend' of Deployment 'nr-hydrometric-rating-curve-frontend' should set 'securityContext.allowPrivilegeEscalation' to false
Link: KSV001

Check notice

Code scanning / Trivy

Default capabilities: some containers do not drop all Low

Artifact: charts/app/templates/frontend/templates/deployment.yaml
Type: helm
Vulnerability KSV003
Severity: LOW
Message: Container 'nr-hydrometric-rating-curve-frontend' of Deployment 'nr-hydrometric-rating-curve-frontend' should add 'ALL' to 'securityContext.capabilities.drop'
Link: KSV003

Check warning

Code scanning / Trivy

Runs as root user Medium

Artifact: charts/app/templates/frontend/templates/deployment.yaml
Type: helm
Vulnerability KSV012
Severity: MEDIUM
Message: Container 'nr-hydrometric-rating-curve-frontend' of Deployment 'nr-hydrometric-rating-curve-frontend' should set 'securityContext.runAsNonRoot' to true
Link: KSV012

Check failure

Code scanning / Trivy

Root file system is not read-only High

Artifact: charts/app/templates/frontend/templates/deployment.yaml
Type: helm
Vulnerability KSV014
Severity: HIGH
Message: Container 'nr-hydrometric-rating-curve-frontend' of Deployment 'nr-hydrometric-rating-curve-frontend' should set 'securityContext.readOnlyRootFilesystem' to true
Link: KSV014

Check notice

Code scanning / Trivy

Runs with UID <= 10000 Low

Artifact: charts/app/templates/frontend/templates/deployment.yaml
Type: helm
Vulnerability KSV020
Severity: LOW
Message: Container 'nr-hydrometric-rating-curve-frontend' of Deployment 'nr-hydrometric-rating-curve-frontend' should set 'securityContext.runAsUser' > 10000
Link: KSV020

Check notice

Code scanning / Trivy

Runs with GID <= 10000 Low

Artifact: charts/app/templates/frontend/templates/deployment.yaml
Type: helm
Vulnerability KSV021
Severity: LOW
Message: Container 'nr-hydrometric-rating-curve-frontend' of Deployment 'nr-hydrometric-rating-curve-frontend' should set 'securityContext.runAsGroup' > 10000
Link: KSV021

Check warning

Code scanning / Trivy

Specific capabilities added Medium

Artifact: charts/app/templates/frontend/templates/deployment.yaml
Type: helm
Vulnerability KSV022
Severity: MEDIUM
Message: Container 'nr-hydrometric-rating-curve-frontend' of Deployment 'nr-hydrometric-rating-curve-frontend' should not set 'securityContext.capabilities.add'
Link: KSV022

Check notice

Code scanning / Trivy

Runtime/Default Seccomp profile not set Low

Artifact: charts/app/templates/frontend/templates/deployment.yaml
Type: helm
Vulnerability KSV030
Severity: LOW
Message: Either Pod or Container should set 'securityContext.seccompProfile.type' to 'RuntimeDefault'
Link: KSV030

Check notice

Code scanning / Trivy

Container capabilities must only include NET_BIND_SERVICE Low

Artifact: charts/app/templates/frontend/templates/deployment.yaml
Type: helm
Vulnerability KSV106
Severity: LOW
Message: container should drop all
Link: KSV106
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app.kubernetes.io/name
operator: In
values:
- {{ include "frontend.fullname" . }}
- key: app.kubernetes.io/instance
operator: In
values:
- {{ .Release.Name }}
topologyKey: "kubernetes.io/hostname"

{{- end }}
Loading

0 comments on commit 3ec8e62

Please sign in to comment.