Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions apis/installer/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ type PSPSpec struct {
Enabled bool `json:"enabled"`
}

// NetworkPolicyFlavor selects which API flavor is used when network policies
// are emitted. Defaults to "kubernetes".
// +kubebuilder:validation:Enum=kubernetes;cilium
type NetworkPolicyFlavor string

const (
NetworkPolicyFlavorKubernetes NetworkPolicyFlavor = "kubernetes"
NetworkPolicyFlavorCilium NetworkPolicyFlavor = "cilium"
)

type NetworkPolicySpec struct {
Enabled bool `json:"enabled"`
// +optional
// +kubebuilder:default=kubernetes
Flavor NetworkPolicyFlavor `json:"flavor,omitempty"`
}
29 changes: 29 additions & 0 deletions charts/kubedb-certified/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,35 @@ Returns whether the NetworkPolicy should be enabled
{{- or .Values.global.networkPolicy.enabled (and .Values.networkPolicy .Values.networkPolicy.enabled) -}}
{{- end }}

{{/*
Returns the configured NetworkPolicy flavor.
"cilium" emits cilium.io/v2 CiliumNetworkPolicy; anything else emits the
default networking.k8s.io/v1 NetworkPolicy.
Local chart-scoped networkPolicy.flavor wins over the global value.
*/}}
{{- define "security.networkPolicyFlavor" -}}
{{- $local := "" -}}
{{- if and .Values.networkPolicy .Values.networkPolicy.flavor -}}
{{- $local = .Values.networkPolicy.flavor -}}
{{- end -}}
{{- default (default "kubernetes" .Values.global.networkPolicy.flavor) $local -}}
{{- end }}

{{/*
Returns "true" when CiliumNetworkPolicy resources should be emitted.
*/}}
{{- define "security.useCiliumNetworkPolicy" -}}
{{- and (eq "true" (include "security.enableNetworkPolicy" .)) (eq "cilium" (include "security.networkPolicyFlavor" .)) | ternary "true" "false" -}}
{{- end }}

{{/*
Returns "true" when the built-in networking.k8s.io/v1 NetworkPolicy resources
should be emitted (the default flavor).
*/}}
{{- define "security.useKubernetesNetworkPolicy" -}}
{{- and (eq "true" (include "security.enableNetworkPolicy" .)) (ne "cilium" (include "security.networkPolicyFlavor" .)) | ternary "true" "false" -}}
{{- end }}

{{/*
Returns whether the OpenShift distribution is used
*/}}
Expand Down
53 changes: 53 additions & 0 deletions charts/kubedb-certified/templates/cilium-network-policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{{- if eq "true" ( include "security.useCiliumNetworkPolicy" . ) }}
# Allow every pod in the operator namespace to reach the Kubernetes API server.
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
name: {{ .Release.Name }}-egress-kubernetes-api
namespace: {{ .Release.Namespace }}
spec:
endpointSelector: {}
egress:
- toEntities:
- remote-node
- host
toPorts:
- ports:
- port: "6443"
protocol: TCP
---
# Allow the operator pods to reach the database pods (any kubedb-managed
# namespace, on the standard DB ports).
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
name: {{ .Release.Name }}-egress-to-databases
namespace: {{ .Release.Namespace }}
spec:
endpointSelector:
matchLabels:
app.kubernetes.io/instance: {{ .Release.Name }}
egress:
- toEndpoints:
- matchLabels:
app.kubernetes.io/component: database
app.kubernetes.io/managed-by: kubedb.com
toPorts:
- ports:
- port: "5432"
protocol: TCP
- port: "27017"
protocol: TCP
- port: "3306"
protocol: TCP
- port: "6379"
protocol: TCP
- port: "9200"
protocol: TCP
- port: "9092"
protocol: TCP
- port: "9000"
protocol: TCP
- port: "9042"
protocol: TCP
{{- end }}
2 changes: 1 addition & 1 deletion charts/kubedb-certified/templates/network-policy.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if eq "true" ( include "security.enableNetworkPolicy" . ) }}
{{- if eq "true" ( include "security.useKubernetesNetworkPolicy" . ) }}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
Expand Down
10 changes: 10 additions & 0 deletions charts/kubedb-certified/values.openapiv3_schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2683,6 +2683,11 @@ properties:
properties:
enabled:
type: boolean
flavor:
enum:
- kubernetes
- cilium
type: string
required:
- enabled
type: object
Expand Down Expand Up @@ -21330,6 +21335,11 @@ properties:
properties:
enabled:
type: boolean
flavor:
enum:
- kubernetes
- cilium
type: string
required:
- enabled
type: object
Expand Down
3 changes: 3 additions & 0 deletions charts/kubedb-certified/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ global:
# Controls the network policy creation
networkPolicy:
enabled: false
# flavor selects which network policy API is used.
# Accepted values: "kubernetes" (default) or "cilium".
flavor: kubernetes

distro:
openshift: false
Expand Down
29 changes: 29 additions & 0 deletions charts/kubedb-opscenter/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,35 @@ Returns whether the NetworkPolicy should be enabled
{{- or .Values.global.networkPolicy.enabled (and .Values.networkPolicy .Values.networkPolicy.enabled) -}}
{{- end }}

{{/*
Returns the configured NetworkPolicy flavor.
"cilium" emits cilium.io/v2 CiliumNetworkPolicy; anything else emits the
default networking.k8s.io/v1 NetworkPolicy.
Local chart-scoped networkPolicy.flavor wins over the global value.
*/}}
{{- define "security.networkPolicyFlavor" -}}
{{- $local := "" -}}
{{- if and .Values.networkPolicy .Values.networkPolicy.flavor -}}
{{- $local = .Values.networkPolicy.flavor -}}
{{- end -}}
{{- default (default "kubernetes" .Values.global.networkPolicy.flavor) $local -}}
{{- end }}

{{/*
Returns "true" when CiliumNetworkPolicy resources should be emitted.
*/}}
{{- define "security.useCiliumNetworkPolicy" -}}
{{- and (eq "true" (include "security.enableNetworkPolicy" .)) (eq "cilium" (include "security.networkPolicyFlavor" .)) | ternary "true" "false" -}}
{{- end }}

{{/*
Returns "true" when the built-in networking.k8s.io/v1 NetworkPolicy resources
should be emitted (the default flavor).
*/}}
{{- define "security.useKubernetesNetworkPolicy" -}}
{{- and (eq "true" (include "security.enableNetworkPolicy" .)) (ne "cilium" (include "security.networkPolicyFlavor" .)) | ternary "true" "false" -}}
{{- end }}

{{/*
Returns whether the OpenShift distribution is used
*/}}
Expand Down
20 changes: 20 additions & 0 deletions charts/kubedb-opscenter/templates/cilium-network-policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{- if eq "true" ( include "security.useCiliumNetworkPolicy" . ) }}
# Allow the opscenter pods to reach the Kubernetes API server.
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
name: {{ .Release.Name }}-egress-kubernetes-api
namespace: {{ .Release.Namespace }}
spec:
endpointSelector:
matchLabels:
app.kubernetes.io/instance: {{ .Release.Name }}
egress:
- toEntities:
- remote-node
- host
toPorts:
- ports:
- port: "6443"
protocol: TCP
{{- end }}
2 changes: 1 addition & 1 deletion charts/kubedb-opscenter/templates/network-policy.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if eq "true" ( include "security.enableNetworkPolicy" . ) }}
{{- if eq "true" ( include "security.useKubernetesNetworkPolicy" . ) }}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
Expand Down
3 changes: 3 additions & 0 deletions charts/kubedb-opscenter/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ global:
# Controls the network policy creation
networkPolicy:
enabled: false
# flavor selects which network policy API is used.
# Accepted values: "kubernetes" (default) or "cilium".
flavor: kubernetes

distro:
openshift: false
Expand Down
1 change: 1 addition & 0 deletions charts/kubedb-provisioner/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ spec:
{{- end }}
{{- if and .Values.global .Values.global.networkPolicy.enabled }}
- --enable-network-policy=true
- --network-policy-flavor={{ default "kubernetes" .Values.global.networkPolicy.flavor }}
{{- end }}
{{- with .Values.envFrom }}
envFrom:
Expand Down
33 changes: 33 additions & 0 deletions charts/kubedb-webhook-server/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,39 @@ Returns whether the NetworkPolicy should be enabled
{{- ternary "true" "false" .Values.networkPolicy.enabled -}}
{{- end }}

{{/*
Returns the configured NetworkPolicy flavor.
"cilium" emits cilium.io/v2 CiliumNetworkPolicy; anything else emits the
default networking.k8s.io/v1 NetworkPolicy. The local chart's
networkPolicy.flavor wins over the global value.
*/}}
{{- define "security.networkPolicyFlavor" -}}
{{- $globalFlavor := "" -}}
{{- if and .Values.global .Values.global.networkPolicy -}}
{{- $globalFlavor = .Values.global.networkPolicy.flavor -}}
{{- end -}}
{{- $localFlavor := "" -}}
{{- if and .Values.networkPolicy .Values.networkPolicy.flavor -}}
{{- $localFlavor = .Values.networkPolicy.flavor -}}
{{- end -}}
{{- default (default "kubernetes" $globalFlavor) $localFlavor -}}
{{- end }}

{{/*
Returns "true" when CiliumNetworkPolicy resources should be emitted.
*/}}
{{- define "security.useCiliumNetworkPolicy" -}}
{{- and (eq "true" (include "security.enableNetworkPolicy" .)) (eq "cilium" (include "security.networkPolicyFlavor" .)) | ternary "true" "false" -}}
{{- end }}

{{/*
Returns "true" when the built-in networking.k8s.io/v1 NetworkPolicy resources
should be emitted (the default flavor).
*/}}
{{- define "security.useKubernetesNetworkPolicy" -}}
{{- and (eq "true" (include "security.enableNetworkPolicy" .)) (ne "cilium" (include "security.networkPolicyFlavor" .)) | ternary "true" "false" -}}
{{- end }}

{{/*
Returns whether the OpenShift distribution is used
*/}}
Expand Down
23 changes: 23 additions & 0 deletions charts/kubedb-webhook-server/templates/cilium-network-policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{{- if eq "true" ( include "security.useCiliumNetworkPolicy" . ) }}
# Allow the kube-apiserver (via host / remote-node identities in Cilium) to
# reach the webhook server's mutating, validating, and conversion endpoints.
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
name: {{ include "kubedb-webhook-server.fullname" . }}-ingress-from-apiserver
namespace: {{ .Release.Namespace }}
spec:
endpointSelector:
matchLabels:
{{- include "kubedb-webhook-server.selectorLabels" . | nindent 6 }}
ingress:
- fromEntities:
- remote-node
- host
toPorts:
- ports:
- port: "8443"
protocol: TCP
- port: "9443"
protocol: TCP
{{- end }}
2 changes: 1 addition & 1 deletion charts/kubedb-webhook-server/templates/network-policy.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if eq "true" ( include "security.enableNetworkPolicy" . ) }}
{{- if eq "true" ( include "security.useKubernetesNetworkPolicy" . ) }}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
Expand Down
5 changes: 5 additions & 0 deletions charts/kubedb-webhook-server/values.openapiv3_schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,11 @@ properties:
properties:
enabled:
type: boolean
flavor:
enum:
- kubernetes
- cilium
type: string
required:
- enabled
type: object
Expand Down
3 changes: 3 additions & 0 deletions charts/kubedb-webhook-server/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ hostNetwork: false

networkPolicy:
enabled: false
# flavor selects which network policy API is used.
# Accepted values: "kubernetes" (default) or "cilium".
flavor: kubernetes

defaultSeccompProfileType: ""

Expand Down
29 changes: 29 additions & 0 deletions charts/kubedb/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,35 @@ Returns whether the NetworkPolicy should be enabled
{{- or .Values.global.networkPolicy.enabled (and .Values.networkPolicy .Values.networkPolicy.enabled) -}}
{{- end }}

{{/*
Returns the configured NetworkPolicy flavor.
"cilium" emits cilium.io/v2 CiliumNetworkPolicy; anything else emits the
default networking.k8s.io/v1 NetworkPolicy.
Local chart-scoped networkPolicy.flavor wins over the global value.
*/}}
{{- define "security.networkPolicyFlavor" -}}
{{- $local := "" -}}
{{- if and .Values.networkPolicy .Values.networkPolicy.flavor -}}
{{- $local = .Values.networkPolicy.flavor -}}
{{- end -}}
{{- default (default "kubernetes" .Values.global.networkPolicy.flavor) $local -}}
{{- end }}

{{/*
Returns "true" when CiliumNetworkPolicy resources should be emitted.
*/}}
{{- define "security.useCiliumNetworkPolicy" -}}
{{- and (eq "true" (include "security.enableNetworkPolicy" .)) (eq "cilium" (include "security.networkPolicyFlavor" .)) | ternary "true" "false" -}}
{{- end }}

{{/*
Returns "true" when the built-in networking.k8s.io/v1 NetworkPolicy resources
should be emitted (the default flavor).
*/}}
{{- define "security.useKubernetesNetworkPolicy" -}}
{{- and (eq "true" (include "security.enableNetworkPolicy" .)) (ne "cilium" (include "security.networkPolicyFlavor" .)) | ternary "true" "false" -}}
{{- end }}

{{/*
Returns whether the OpenShift distribution is used
*/}}
Expand Down
Loading
Loading