Skip to content

Commit 13de26e

Browse files
authored
fix: Set defaults for the securityContext (#149)
# Description Introduce default security context for the deployment to align with trivy rules: ```yaml securityContext: capabilities: drop: - ALL readOnlyRootFilesystem: true runAsNonRoot: true runAsUser: 1000 allowPrivilegeEscalation: false seccompProfile: type: RuntimeDefault ``` Please take the rules into the account when upgrading
1 parent 061e91b commit 13de26e

10 files changed

Lines changed: 73 additions & 22 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ jobs:
1818
}}
1919
uses: elastiflow/gha-reusable/.github/workflows/reusable_pr_checks.yml@v0
2020

21+
mandatory_checks:
22+
name: Security checks
23+
uses: elastiflow/gha-reusable/.github/workflows/reusable_mandatory_checks.yml@v0
24+
2125
renovate_config_validator:
2226
name: renovate config validator
2327
runs-on: ubuntu-latest

.github/workflows/reusable_release.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ on:
3939
default: 15
4040
description: "Job timeout in minutes"
4141

42+
env:
43+
CHART_DIR: ${{ inputs.chart_dir }}
44+
4245
jobs:
4346
# Detect if a commit was made from a release PR with title like '[release v0.1.1] (#49)'
4447
release_or_pr:
@@ -130,7 +133,7 @@ jobs:
130133
uses: azure/setup-helm@dda3372f752e03dde6b3237bc9431cdc2f7a02a2 # v5.0.0
131134
- name: Install Helm dependencies
132135
run: |
133-
(helm dependency list ${{ inputs.chart_dir }} || true) | grep -E 'https://' | while read -r dep; do
136+
(helm dependency list ${CHART_DIR} || true) | grep -E 'https://' | while read -r dep; do
134137
helm repo add $(echo ${dep} | awk '{print $1}') $(echo ${dep} | awk '{print $4}')
135138
done
136139
- name: Install chart-releaser
@@ -141,7 +144,7 @@ jobs:
141144
install_only: true
142145
- name: Package helm chart
143146
run: |
144-
cr package ${{ inputs.chart_dir }}
147+
cr package ${CHART_DIR}
145148
- name: Create GH release
146149
if: ${{ fromJson(steps.prepare_release.outputs.new_release_published) }}
147150
uses: softprops/action-gh-release@3bb12739c298aeb8a4eeaf626c5b8d85266b0e65 # v2.6.2
@@ -154,6 +157,9 @@ jobs:
154157
make_latest: true
155158
files: ".cr-release-packages/${{ inputs.chart_name }}-*.tgz"
156159
- name: Update GH pages index
160+
env:
161+
REPOSITORY_OWNER: ${{ inputs.repository_owner }}
162+
REPOSITORY_NAME: ${{ inputs.repository_name }}
157163
run: |
158164
mkdir .cr-index
159-
cr index --push -t ${{ secrets.GITHUB_TOKEN }} --owner ${{ inputs.repository_owner }} --git-repo ${{ inputs.repository_name }}
165+
cr index --push -t ${{ secrets.GITHUB_TOKEN }} --owner ${REPOSITORY_OWNER} --git-repo ${REPOSITORY_NAME}

.pre-commit-config.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,16 @@ repos:
1111
- id: check-yaml
1212
files: \.(yaml|yml)$
1313
exclude: charts/.*
14+
- repo: local
15+
hooks:
16+
- id: trivy
17+
name: trivy
18+
language: system
19+
pass_filenames: false
20+
entry: |
21+
trivy -q config --skip-files '*.hcl' --skip-dirs '**/.terragrunt-cache/*' --exit-code 1 .
22+
- repo: https://github.com/semgrep/pre-commit
23+
rev: 'v1.163.0'
24+
hooks:
25+
- id: semgrep
26+
entry: semgrep

.semgrepignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
charts/netobserv-flow/tls/netobserv.key

charts/netobserv-flow/templates/deployment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ apiVersion: apps/v1
22
kind: Deployment
33
metadata:
44
name: {{ include "netobserv.fullname" . }}
5+
namespace: {{ .Release.Namespace }}
56
labels:
67
{{- include "netobserv.labels" . | nindent 4 }}
78
spec:

charts/netobserv-flow/templates/gateway.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ metadata:
1313
{{- end }}
1414
spec:
1515
gatewayClassName: {{ .Values.gateway.className }}
16+
{{- with .Values.gateway.infrastructure }}
17+
infrastructure:
18+
{{- tpl (toYaml . | nindent 4) $ }}
19+
{{- end }}
1620
{{- with .Values.gateway.listeners }}
1721
listeners:
1822
{{- toYaml . | nindent 4 }}

charts/netobserv-flow/values.yaml

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,16 @@ podSecurityContext:
176176
runAsUser: 1000
177177
runAsGroup: 1000
178178

179-
securityContext: {}
180-
# capabilities:
181-
# drop:
182-
# - ALL
183-
# readOnlyRootFilesystem: true
184-
# runAsNonRoot: true
185-
# runAsUser: 1000
179+
securityContext:
180+
capabilities:
181+
drop:
182+
- ALL
183+
readOnlyRootFilesystem: true
184+
runAsNonRoot: true
185+
runAsUser: 1000
186+
allowPrivilegeEscalation: false
187+
seccompProfile:
188+
type: RuntimeDefault
186189

187190
# The netobserv container's ports to expose.
188191
ports:
@@ -290,18 +293,23 @@ gateway:
290293
- name: '{{ include "netobserv.fullname" $ }}'
291294
port: 8080
292295
# GRPCRoutes to be provisioned with the Gateway
293-
# grpcRoutes:
294-
# - name: api
295-
# # hostnames: ["foo.bar.com"] # Overrides the gateway.defaultHostNames
296-
# rules:
297-
# - matches:
298-
# - type: Exact
299-
# method:
300-
# service: "foo"
296+
# https://gateway-api.sigs.k8s.io/guides/user-guides/grpc-routing/
297+
grpcRoutes: []
298+
# - name: api # Supports templating
299+
# # hostnames: ["foo.bar.com"] # Overrides the gateway.defaultHostNames, supports templating
300+
# rules:
301+
# - matches:
302+
# - method:
303+
# type: "Exact"
304+
# service: "foo"
305+
# method: "Bar"
301306
# headers:
302-
# backendRefs:
303-
# - name: '{{ include "netobserv.fullname" $ }}'
304-
# port: 8080
307+
# - type: Exact
308+
# name: magic
309+
# value: foo
310+
# backendRefs:
311+
# - name: '{{ include "triton.fullname" $ }}'
312+
# port: 8080
305313

306314
resources:
307315
limits:

lintconf.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ rules:
3939
type: unix
4040
trailing-spaces: enable
4141
truthy:
42-
level: warning
42+
level: warning

trivy.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ignorefile: trivyignore.yaml

trivyignore.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
misconfigurations:
2+
- id: KSV-0020
3+
statement: Historically running as UID/GID 1000.
4+
paths:
5+
- charts/netobserv-flow/**/*
6+
- id: KSV-0021
7+
statement: Historically running as UID/GID 1000.
8+
paths:
9+
- charts/netobserv-flow/**/*
10+
- id: KSV-0125
11+
statement: "`elastiflow/flow-collector` is a NetObserv image registry"
12+
paths:
13+
- charts/netobserv-flow/**/*

0 commit comments

Comments
 (0)