Skip to content

Commit

Permalink
feat: add support for network policy (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
fastlorenzo authored Dec 8, 2022
2 parents 25eb5e5 + e0892e8 commit e42623b
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 3 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/lint-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: '3.9'
python-version: "3.9"
check-latest: true

# - name: Run helm lint
Expand All @@ -47,15 +47,24 @@ jobs:
run: |
changed=$(ct list-changed --config ct.yaml --target-branch ${{ github.event.repository.default_branch }})
if [[ -n "$changed" ]]; then
echo "::set-output name=changed::true"
echo "changed=true" >> $GITHUB_OUTPUT
fi
- name: Run chart-testing (lint)
run: ct lint --config ct.yaml --target-branch ${{ github.event.repository.default_branch }} --check-version-increment=false

- name: Create kind cluster
if: steps.list-changed.outputs.changed == 'true'
uses: helm/[email protected]
with:
config: kind-cluster.yaml

- name: Install Calico
if: steps.list-changed.outputs.changed == 'true'
run: |
kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.24.5/manifests/calico.yaml
kubectl -n kube-system rollout status daemonset/calico-node --timeout=120s
kubectl -n kube-system rollout status deployment calico-kube-controllers --timeout=120s
- name: Fix CoreDNS upstream resolver
if: steps.list-changed.outputs.changed == 'true'
Expand Down
20 changes: 20 additions & 0 deletions kind-cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
disableDefaultCNI: true # disable kindnet
podSubnet: 192.168.0.0/16 # set to Calico's default subnet
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
extraPortMappings:
- containerPort: 80
hostPort: 80
protocol: TCP
- containerPort: 443
hostPort: 443
protocol: TCP
1 change: 1 addition & 0 deletions mailu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ Check that the deployed pods are all running.
| `initialAccount.existingSecretPasswordKey` | Name of the key in the existing secret to use for the initial account's password | `""` |
| `initialAccount.mode` | How to treat the creationg of the initial account. Possible values: "create", "update" or "ifmissing" | `update` |
| `subnet` | Change this if you're using different address ranges for pods | `10.42.0.0/16` |
| `networkPolicy.enabled` | Enable network policy | `false` |
| `mailuVersion` | Version/tag of mailu images - must be master or a version >= 1.9 | `1.9.39` |
| `logLevel` | default log level. can be overridden globally or per service | `WARNING` |
| `postmaster` | local part of the postmaster email address (Mailu will use @$DOMAIN as domain part) | `postmaster` |
Expand Down
5 changes: 4 additions & 1 deletion mailu/ci/helm-lint-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ initialAccount:

secretKey: chang3m3!

subnet: 10.0.0.0/8
subnet: 192.168.0.0/16

networkPolicy:
enabled: true

persistence:
single_pvc: false
Expand Down
108 changes: 108 additions & 0 deletions mailu/templates/network-policies.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{{- if and .Values.networkPolicy.enabled }}
---
apiVersion: {{ include "common.capabilities.networkPolicy.apiVersion" . }}
kind: NetworkPolicy
metadata:
name: {{ printf "%s-default-deny" (include "common.names.fullname" .) | trunc 63 | trimSuffix "-" }}
namespace: {{ .Release.Namespace }}
labels: {{- include "common.labels.standard" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{- include "common.tplvalues.render" (dict "value" .Values.commonLabels "context" $) | nindent 4 }}
{{- end }}
{{- if .Values.commonAnnotations }}
annotations: {{- include "common.tplvalues.render" (dict "value" .Values.commonAnnotations "context" $) | nindent 4 }}
{{- end }}
spec:
podSelector:
matchLabels:
app.kubernetes.io/instance: {{ .Release.Name }}
policyTypes:
- Ingress
- Egress
---
apiVersion: {{ include "common.capabilities.networkPolicy.apiVersion" . }}
kind: NetworkPolicy
metadata:
name: {{ printf "%s-allow-egress-all" (include "common.names.fullname" .) | trunc 63 | trimSuffix "-" }}
namespace: {{ .Release.Namespace }}
labels: {{- include "common.labels.standard" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{- include "common.tplvalues.render" (dict "value" .Values.commonLabels "context" $) | nindent 4 }}
{{- end }}
{{- if .Values.commonAnnotations }}
annotations: {{- include "common.tplvalues.render" (dict "value" .Values.commonAnnotations "context" $) | nindent 4 }}
{{- end }}
spec:
podSelector:
matchLabels:
app.kubernetes.io/instance: {{ .Release.Name }}
policyTypes:
- Egress
egress:
- {}
---
---
apiVersion: {{ include "common.capabilities.networkPolicy.apiVersion" . }}
kind: NetworkPolicy
metadata:
name: {{ printf "%s-allow-front" (include "common.names.fullname" .) | trunc 63 | trimSuffix "-" }}
namespace: {{ .Release.Namespace }}
labels: {{- include "common.labels.standard" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{- include "common.tplvalues.render" (dict "value" .Values.commonLabels "context" $) | nindent 4 }}
{{- end }}
{{- if .Values.commonAnnotations }}
annotations: {{- include "common.tplvalues.render" (dict "value" .Values.commonAnnotations "context" $) | nindent 4 }}
{{- end }}
spec:
podSelector:
matchLabels:
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: front
ingress:
# Allow ports 25/TCP, 80/TCP, 110/TCP, 143/TCP, 443/TCP, 465/TCP, 587/TCP, 995/TCP, 993/TCP
- ports:
- port: 25
protocol: TCP
- port: 80
protocol: TCP
- port: 110
protocol: TCP
- port: 143
protocol: TCP
- port: 443
protocol: TCP
- port: 465
protocol: TCP
- port: 587
protocol: TCP
- port: 995
protocol: TCP
- port: 993
protocol: TCP
---
apiVersion: {{ include "common.capabilities.networkPolicy.apiVersion" . }}
kind: NetworkPolicy
metadata:
name: {{ printf "%s-allow-internal" (include "common.names.fullname" .) | trunc 63 | trimSuffix "-" }}
namespace: {{ .Release.Namespace }}
labels: {{- include "common.labels.standard" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{- include "common.tplvalues.render" (dict "value" .Values.commonLabels "context" $) | nindent 4 }}
{{- end }}
{{- if .Values.commonAnnotations }}
annotations: {{- include "common.tplvalues.render" (dict "value" .Values.commonAnnotations "context" $) | nindent 4 }}
{{- end }}
spec:
podSelector:
matchLabels:
app.kubernetes.io/instance: {{ .Release.Name }}
ingress:
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: {{ .Release.Namespace }}
podSelector:
matchLabels:
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
4 changes: 4 additions & 0 deletions mailu/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ initialAccount:
## @param subnet Change this if you're using different address ranges for pods
subnet: 10.42.0.0/16

## @param networkPolicy.enabled Enable network policy
networkPolicy:
enabled: false

## @param mailuVersion Version/tag of mailu images - must be master or a version >= 1.9
mailuVersion: 1.9.39

Expand Down

0 comments on commit e42623b

Please sign in to comment.