Skip to content

Commit

Permalink
Add user custom network policy (#2078)
Browse files Browse the repository at this point in the history
* add user custom network policy template

* add appPort to access grafana from host

* add kube-system as egress allow for agent

* add network policy settings as an example

* add stern in dev container

* add schema comments

* add network policy enabled to ci helm values

* add cluster role to deploy network policy

* style: Format code with prettier and gofumpt

* remove unnecesary network policy ci settings

* add pyroscope to ingress rule

---------

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
  • Loading branch information
ykadowak and deepsource-autofix[bot] authored Jun 21, 2023
1 parent cb1d401 commit b0bf240
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
}
},
"postCreateCommand": "go version",
"postAttachCommand": "sudo ln -s $(pwd)/cmd/agent/core/ngt/sample.yaml /etc/server/config.yaml"
"postAttachCommand": "sudo ln -s $(pwd)/cmd/agent/core/ngt/sample.yaml /etc/server/config.yaml",
"appPort": "3000:3000"
}
2 changes: 2 additions & 0 deletions .github/helm/values/values-lb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
defaults:
logging:
level: info
networkPolicy:
enabled: true

gateway:
lb:
Expand Down
2 changes: 2 additions & 0 deletions .github/valdrelease/valdrelease.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ spec:
defaults:
logging:
level: info
networkPolicy:
enabled: true

gateway:
lb:
Expand Down
1 change: 1 addition & 0 deletions charts/vald-helm-operator/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ rules:
- networking.k8s.io
resources:
- ingresses
- networkpolicies
verbs:
- create
- delete
Expand Down
11 changes: 11 additions & 0 deletions charts/vald/templates/agent/networkpolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,15 @@ spec:
podSelector:
matchLabels:
app: {{ $index.name }}
{{- if .Values.defaults.networkPolicy.custom.ingress }}
{{- toYaml .Values.defaults.networkPolicy.custom.ingress | nindent 4 }}
{{- end }}
egress:
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
{{- if .Values.defaults.networkPolicy.custom.egress }}
{{- toYaml .Values.defaults.networkPolicy.custom.egress | nindent 4 }}
{{- end }}
{{- end }}
6 changes: 6 additions & 0 deletions charts/vald/templates/discoverer/networkpolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,15 @@ spec:
podSelector:
matchLabels:
app: {{ $index.name }}
{{- if .Values.defaults.networkPolicy.custom.ingress }}
{{- toYaml .Values.defaults.networkPolicy.custom.ingress | nindent 4 }}
{{- end }}
egress:
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
{{- if .Values.defaults.networkPolicy.custom.egress }}
{{- toYaml .Values.defaults.networkPolicy.custom.egress | nindent 4 }}
{{- end }}
{{- end }}
7 changes: 7 additions & 0 deletions charts/vald/templates/gateway/filter/networkpolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ spec:
matchLabels:
app: {{ $filter.name }}
policyTypes:
{{- if .Values.defaults.networkPolicy.custom.ingress }}
- Ingress
{{- end }}
- Egress
{{- if .Values.defaults.networkPolicy.custom.ingress }}
ingress:
{{- toYaml .Values.defaults.networkPolicy.custom.ingress | nindent 4 }}
{{- end }}
egress:
# allow all the egress to communicate with user-defined filters
- {}
Expand Down
6 changes: 6 additions & 0 deletions charts/vald/templates/gateway/lb/networkpolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ spec:
podSelector:
matchLabels:
app: {{ $filter.name }}
{{- if .Values.defaults.networkPolicy.custom.ingress }}
{{- toYaml .Values.defaults.networkPolicy.custom.ingress | nindent 4 }}
{{- end }}
egress:
- to:
- namespaceSelector:
Expand All @@ -58,4 +61,7 @@ spec:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
{{- if .Values.defaults.networkPolicy.custom.egress }}
{{- toYaml .Values.defaults.networkPolicy.custom.egress | nindent 4 }}
{{- end }}
{{- end }}
6 changes: 6 additions & 0 deletions charts/vald/templates/manager/index/networkpolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ spec:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
{{- if .Values.defaults.networkPolicy.custom.ingress }}
{{- toYaml .Values.defaults.networkPolicy.custom.ingress | nindent 4 }}
{{- end }}
egress:
- to:
- namespaceSelector:
Expand All @@ -51,4 +54,7 @@ spec:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
{{- if .Values.defaults.networkPolicy.custom.egress }}
{{- toYaml .Values.defaults.networkPolicy.custom.egress | nindent 4 }}
{{- end }}
{{- end }}
10 changes: 9 additions & 1 deletion charts/vald/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -834,8 +834,16 @@ defaults:
networkPolicy:
# @schema {"name": "defaults.networkPolicy.enabled", "type": "boolean"}
# defaults.networkPolicy.enabled -- if network policy enabled
# TODO: Change this to true after implementing user custom network policy parser
enabled: false
# @schema {"name": "defaults.networkPolicy.custom", "type": "object"}
# defaults.networkPolicy.custom -- custom network policies that a user can add
custom:
# @schema {"name": "defaults.networkPolicy.custom.ingress", "type": "object"}
# defaults.networkPolicy.custom.ingress -- custom ingress network policies that a user can add
ingress: {}
# @schema {"name": "defaults.networkPolicy.custom.egress", "type": "object"}
# defaults.networkPolicy.custom.egress -- custom egress network policies that a user can add
egress: {}

# @schema {"name": "gateway", "type": "object"}
gateway:
Expand Down
13 changes: 13 additions & 0 deletions charts/vald/values/dev-observability.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ defaults:
collector_endpoint: "opentelemetry-collector-collector.default.svc.cluster.local:4317"
trace:
enabled: true
networkPolicy:
enabled: true
custom:
ingress:
- from:
- podSelector:
matchLabels:
app.kubernetes.io/name: pyroscope
egress:
- to:
- podSelector:
matchLabels:
app.kubernetes.io/name: opentelemetry-collector-collector

gateway:
lb:
Expand Down
2 changes: 1 addition & 1 deletion dockers/dev/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ USER vscode
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN curl -sS https://webinstall.dev/k9s | bash

WORKDIR ${GOPATH}
RUN go install github.com/stern/stern@latest

0 comments on commit b0bf240

Please sign in to comment.