diff --git a/PROJECT b/PROJECT index 6d660e0..c0179ea 100644 --- a/PROJECT +++ b/PROJECT @@ -7,8 +7,9 @@ domain: vitistack.io layout: - go.kubebuilder.io/v4 plugins: - helm.kubebuilder.io/v1-alpha: {} - helm.kubebuilder.io/v2-alpha: {} + helm.kubebuilder.io/v2-alpha: + manifests: dist/install.yaml + output: dist projectName: gatewayapi-securitypolicy-operator repo: github.com/vitistack/gatewayapi-securitypolicy-operator version: "3" diff --git a/dist/chart/.helmignore b/dist/chart/.helmignore new file mode 100644 index 0000000..7d92f7f --- /dev/null +++ b/dist/chart/.helmignore @@ -0,0 +1,25 @@ +# Patterns to ignore when building Helm packages. +# Operating system files +.DS_Store + +# Version control directories +.git/ +.gitignore +.bzr/ +.hg/ +.hgignore +.svn/ + +# Backup and temporary files +*.swp +*.tmp +*.bak +*.orig +*~ + +# IDE and editor-related files +.idea/ +.vscode/ + +# Helm chart artifacts +dist/chart/*.tgz diff --git a/dist/chart/Chart.yaml b/dist/chart/Chart.yaml new file mode 100644 index 0000000..c076e28 --- /dev/null +++ b/dist/chart/Chart.yaml @@ -0,0 +1,14 @@ +apiVersion: v2 +name: gatewayapi-securitypolicy-operator +description: A Helm chart to distribute gatewayapi-securitypolicy-operator +type: application + +version: 0.1.0 +appVersion: "0.1.0" + +keywords: + - kubernetes + - operator + +annotations: + kubebuilder.io/generated-by: kubebuilder diff --git a/dist/chart/templates/NOTES.txt b/dist/chart/templates/NOTES.txt new file mode 100644 index 0000000..1cec53d --- /dev/null +++ b/dist/chart/templates/NOTES.txt @@ -0,0 +1,15 @@ +Thank you for installing {{ .Chart.Name }}. + +Your release is named {{ .Release.Name }}. + +The controller and CRDs have been installed in namespace {{ .Release.Namespace }}. + +To verify the installation: + + kubectl get pods -n {{ .Release.Namespace }} + kubectl get customresourcedefinitions + +To learn more about the release, try: + + $ helm status {{ .Release.Name }} -n {{ .Release.Namespace }} + $ helm get all {{ .Release.Name }} -n {{ .Release.Namespace }} diff --git a/dist/chart/templates/_helpers.tpl b/dist/chart/templates/_helpers.tpl new file mode 100644 index 0000000..77ffbac --- /dev/null +++ b/dist/chart/templates/_helpers.tpl @@ -0,0 +1,50 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "gatewayapi-securitypolicy-operator.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 "gatewayapi-securitypolicy-operator.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Namespace for generated references. +Always uses the Helm release namespace. +*/}} +{{- define "gatewayapi-securitypolicy-operator.namespaceName" -}} +{{- .Release.Namespace }} +{{- end }} + +{{/* +Resource name with proper truncation for Kubernetes 63-character limit. +Takes a dict with: + - .suffix: Resource name suffix (e.g., "metrics", "webhook") + - .context: Template context (root context with .Values, .Release, etc.) +Dynamically calculates safe truncation to ensure total name length <= 63 chars. +*/}} +{{- define "gatewayapi-securitypolicy-operator.resourceName" -}} +{{- $fullname := include "gatewayapi-securitypolicy-operator.fullname" .context }} +{{- $suffix := .suffix }} +{{- $maxLen := sub 62 (len $suffix) | int }} +{{- if gt (len $fullname) $maxLen }} +{{- printf "%s-%s" (trunc $maxLen $fullname | trimSuffix "-") $suffix | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" $fullname $suffix | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} diff --git a/dist/chart/templates/manager/manager.yaml b/dist/chart/templates/manager/manager.yaml new file mode 100644 index 0000000..ee3d15b --- /dev/null +++ b/dist/chart/templates/manager/manager.yaml @@ -0,0 +1,89 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/name: gatewayapi-securitypolicy-operator + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + app.kubernetes.io/instance: {{ .Release.Name }} + control-plane: controller-manager + name: {{ include "gatewayapi-securitypolicy-operator.resourceName" (dict "suffix" "controller-manager" "context" $) }} + namespace: {{ .Release.Namespace }} +spec: + replicas: {{ .Values.manager.replicas }} + selector: + matchLabels: + app.kubernetes.io/name: gatewayapi-securitypolicy-operator + control-plane: controller-manager + template: + metadata: + annotations: + kubectl.kubernetes.io/default-container: manager + labels: + app.kubernetes.io/name: gatewayapi-securitypolicy-operator + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + control-plane: controller-manager + spec: + {{- with .Values.manager.tolerations }} + tolerations: {{ toYaml . | nindent 10 }} + {{- end }} + {{- with .Values.manager.affinity }} + affinity: {{ toYaml . | nindent 10 }} + {{- end }} + {{- with .Values.manager.nodeSelector }} + nodeSelector: {{ toYaml . | nindent 10 }} + {{- end }} + containers: + - args: + {{- if .Values.metrics.enable }} + - --metrics-bind-address=:{{ .Values.metrics.port }} + {{- else }} + # Bind to :0 to disable the controller-runtime managed metrics server + - --metrics-bind-address=0 + {{- end }} + - --health-probe-bind-address=:8081 + {{- range .Values.manager.args }} + - {{ . }} + {{- end }} + command: + - /manager + image: "{{ .Values.manager.image.repository }}:{{ .Values.manager.image.tag }}" + imagePullPolicy: {{ .Values.manager.image.pullPolicy }} + livenessProbe: + httpGet: + path: /healthz + port: 8081 + initialDelaySeconds: 15 + periodSeconds: 20 + name: manager + ports: [] + readinessProbe: + httpGet: + path: /readyz + port: 8081 + initialDelaySeconds: 5 + periodSeconds: 10 + resources: + {{- if .Values.manager.resources }} + {{- toYaml .Values.manager.resources | nindent 10 }} + {{- else }} + {} + {{- end }} + securityContext: + {{- if .Values.manager.securityContext }} + {{- toYaml .Values.manager.securityContext | nindent 10 }} + {{- else }} + {} + {{- end }} + volumeMounts: [] + securityContext: + {{- if .Values.manager.podSecurityContext }} + {{- toYaml .Values.manager.podSecurityContext | nindent 8 }} + {{- else }} + {} + {{- end }} + serviceAccountName: {{ include "gatewayapi-securitypolicy-operator.resourceName" (dict "suffix" "controller-manager" "context" $) }} + terminationGracePeriodSeconds: 10 + volumes: [] diff --git a/dist/chart/templates/metrics/controller-manager-metrics-service.yaml b/dist/chart/templates/metrics/controller-manager-metrics-service.yaml new file mode 100644 index 0000000..d69f1bd --- /dev/null +++ b/dist/chart/templates/metrics/controller-manager-metrics-service.yaml @@ -0,0 +1,22 @@ +{{- if .Values.metrics.enable }} +apiVersion: v1 +kind: Service +metadata: + labels: + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/name: gatewayapi-securitypolicy-operator + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + app.kubernetes.io/instance: {{ .Release.Name }} + control-plane: controller-manager + name: {{ include "gatewayapi-securitypolicy-operator.resourceName" (dict "suffix" "controller-manager-metrics-service" "context" $) }} + namespace: {{ .Release.Namespace }} +spec: + ports: + - name: https + port: {{ .Values.metrics.port }} + protocol: TCP + targetPort: {{ .Values.metrics.port }} + selector: + app.kubernetes.io/name: gatewayapi-securitypolicy-operator + control-plane: controller-manager +{{- end }} diff --git a/dist/chart/templates/monitoring/servicemonitor.yaml b/dist/chart/templates/monitoring/servicemonitor.yaml new file mode 100644 index 0000000..3895a70 --- /dev/null +++ b/dist/chart/templates/monitoring/servicemonitor.yaml @@ -0,0 +1,43 @@ +{{- if .Values.prometheus.enable }} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + labels: + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/name: {{ include "gatewayapi-securitypolicy-operator.name" . }} + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + app.kubernetes.io/instance: {{ .Release.Name }} + control-plane: controller-manager + name: {{ include "gatewayapi-securitypolicy-operator.resourceName" (dict "suffix" "controller-manager-metrics-monitor" "context" $) }} + namespace: {{ .Release.Namespace }} +spec: + endpoints: + - path: /metrics + port: https + scheme: https + bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token + tlsConfig: + {{- if .Values.certManager.enable }} + serverName: {{ include "gatewayapi-securitypolicy-operator.resourceName" (dict "suffix" "controller-manager-metrics-service" "context" $) }}.{{ .Release.Namespace }}.svc + # Apply secure TLS configuration with cert-manager + insecureSkipVerify: false + ca: + secret: + name: metrics-server-cert + key: ca.crt + cert: + secret: + name: metrics-server-cert + key: tls.crt + keySecret: + name: metrics-server-cert + key: tls.key + {{- else }} + # Development/Test mode (insecure configuration) + insecureSkipVerify: true + {{- end }} + selector: + matchLabels: + app.kubernetes.io/name: {{ include "gatewayapi-securitypolicy-operator.name" . }} + control-plane: controller-manager +{{- end }} diff --git a/dist/chart/templates/rbac/controller-manager.yaml b/dist/chart/templates/rbac/controller-manager.yaml new file mode 100644 index 0000000..b29a411 --- /dev/null +++ b/dist/chart/templates/rbac/controller-manager.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + labels: + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/name: envoy-securitypolicy-operator + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + app.kubernetes.io/instance: {{ .Release.Name }} + name: {{ include "gatewayapi-securitypolicy-operator.resourceName" (dict "suffix" "controller-manager" "context" $) }} + namespace: {{ .Release.Namespace }} diff --git a/dist/chart/templates/rbac/leader-election-role.yaml b/dist/chart/templates/rbac/leader-election-role.yaml new file mode 100644 index 0000000..0013e96 --- /dev/null +++ b/dist/chart/templates/rbac/leader-election-role.yaml @@ -0,0 +1,42 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + labels: + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/name: gatewayapi-securitypolicy-operator + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + app.kubernetes.io/instance: {{ .Release.Name }} + name: {{ include "gatewayapi-securitypolicy-operator.resourceName" (dict "suffix" "leader-election-role" "context" $) }} + namespace: {{ .Release.Namespace }} +rules: +- apiGroups: + - "" + resources: + - configmaps + verbs: + - get + - list + - watch + - create + - update + - patch + - delete +- apiGroups: + - coordination.k8s.io + resources: + - leases + verbs: + - get + - list + - watch + - create + - update + - patch + - delete +- apiGroups: + - "" + resources: + - events + verbs: + - create + - patch diff --git a/dist/chart/templates/rbac/leader-election-rolebinding.yaml b/dist/chart/templates/rbac/leader-election-rolebinding.yaml new file mode 100644 index 0000000..07f1ba9 --- /dev/null +++ b/dist/chart/templates/rbac/leader-election-rolebinding.yaml @@ -0,0 +1,18 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + labels: + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/name: gatewayapi-securitypolicy-operator + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + app.kubernetes.io/instance: {{ .Release.Name }} + name: {{ include "gatewayapi-securitypolicy-operator.resourceName" (dict "suffix" "leader-election-rolebinding" "context" $) }} + namespace: {{ .Release.Namespace }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: {{ include "gatewayapi-securitypolicy-operator.resourceName" (dict "suffix" "leader-election-role" "context" $) }} +subjects: +- kind: ServiceAccount + name: {{ include "gatewayapi-securitypolicy-operator.resourceName" (dict "suffix" "controller-manager" "context" $) }} + namespace: {{ .Release.Namespace }} diff --git a/dist/chart/templates/rbac/manager-role.yaml b/dist/chart/templates/rbac/manager-role.yaml new file mode 100644 index 0000000..2465260 --- /dev/null +++ b/dist/chart/templates/rbac/manager-role.yaml @@ -0,0 +1,36 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ include "gatewayapi-securitypolicy-operator.resourceName" (dict "suffix" "manager-role" "context" $) }} +rules: +- apiGroups: + - gateway.envoyproxy.io + resources: + - securitypolicies + verbs: + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - gateway.networking.k8s.io + resources: + - gateways + - grpcroutes + - httproutes + verbs: + - get + - list + - patch + - update + - watch +- apiGroups: + - networking.k8s.io + resources: + - networkpolicies + verbs: + - get + - list + - watch diff --git a/dist/chart/templates/rbac/manager-rolebinding.yaml b/dist/chart/templates/rbac/manager-rolebinding.yaml new file mode 100644 index 0000000..bb9b71e --- /dev/null +++ b/dist/chart/templates/rbac/manager-rolebinding.yaml @@ -0,0 +1,17 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + labels: + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/name: gatewayapi-securitypolicy-operator + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + app.kubernetes.io/instance: {{ .Release.Name }} + name: {{ include "gatewayapi-securitypolicy-operator.resourceName" (dict "suffix" "manager-rolebinding" "context" $) }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: {{ include "gatewayapi-securitypolicy-operator.resourceName" (dict "suffix" "manager-role" "context" $) }} +subjects: +- kind: ServiceAccount + name: {{ include "gatewayapi-securitypolicy-operator.resourceName" (dict "suffix" "controller-manager" "context" $) }} + namespace: {{ .Release.Namespace }} diff --git a/dist/chart/templates/rbac/metrics-auth-role.yaml b/dist/chart/templates/rbac/metrics-auth-role.yaml new file mode 100644 index 0000000..98364b4 --- /dev/null +++ b/dist/chart/templates/rbac/metrics-auth-role.yaml @@ -0,0 +1,19 @@ +{{- if .Values.metrics.enable }} +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ include "gatewayapi-securitypolicy-operator.resourceName" (dict "suffix" "metrics-auth-role" "context" $) }} +rules: +- apiGroups: + - authentication.k8s.io + resources: + - tokenreviews + verbs: + - create +- apiGroups: + - authorization.k8s.io + resources: + - subjectaccessreviews + verbs: + - create +{{- end }} diff --git a/dist/chart/templates/rbac/metrics-auth-rolebinding.yaml b/dist/chart/templates/rbac/metrics-auth-rolebinding.yaml new file mode 100644 index 0000000..2acf257 --- /dev/null +++ b/dist/chart/templates/rbac/metrics-auth-rolebinding.yaml @@ -0,0 +1,14 @@ +{{- if .Values.metrics.enable }} +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: {{ include "gatewayapi-securitypolicy-operator.resourceName" (dict "suffix" "metrics-auth-rolebinding" "context" $) }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: {{ include "gatewayapi-securitypolicy-operator.resourceName" (dict "suffix" "metrics-auth-role" "context" $) }} +subjects: +- kind: ServiceAccount + name: {{ include "gatewayapi-securitypolicy-operator.resourceName" (dict "suffix" "controller-manager" "context" $) }} + namespace: {{ .Release.Namespace }} +{{- end }} diff --git a/dist/chart/templates/rbac/metrics-reader.yaml b/dist/chart/templates/rbac/metrics-reader.yaml new file mode 100644 index 0000000..a70d0e4 --- /dev/null +++ b/dist/chart/templates/rbac/metrics-reader.yaml @@ -0,0 +1,11 @@ +{{- if .Values.metrics.enable }} +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ include "gatewayapi-securitypolicy-operator.resourceName" (dict "suffix" "metrics-reader" "context" $) }} +rules: +- nonResourceURLs: + - /metrics + verbs: + - get +{{- end }} diff --git a/dist/chart/values.yaml b/dist/chart/values.yaml new file mode 100644 index 0000000..08a7058 --- /dev/null +++ b/dist/chart/values.yaml @@ -0,0 +1,108 @@ +## String to partially override chart.fullname template (will maintain the release name) +## +# nameOverride: "" + +## String to fully override chart.fullname template +## +# fullnameOverride: "" + +## Configure the controller manager deployment +## +manager: + replicas: 1 + + image: + repository: ncr.sky.nhn.no/ghcr/vitistack/gatewayapi-securitypolicy-operator + tag: latest + pullPolicy: IfNotPresent + + ## Arguments + ## + args: + - --leader-elect + + ## Environment variables + ## + env: [] + + ## Env overrides (--set manager.envOverrides.VAR=value) + ## Same name in env above: this value takes precedence. + ## + envOverrides: {} + + ## Image pull secrets + ## + imagePullSecrets: [] + + ## Pod-level security settings + ## + podSecurityContext: + runAsNonRoot: true + seccompProfile: + type: RuntimeDefault + + ## Container-level security settings + ## + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: + - ALL + readOnlyRootFilesystem: true + + ## Resource limits and requests + ## + resources: + limits: + cpu: 500m + memory: 128Mi + requests: + cpu: 10m + memory: 64Mi + + ## Manager pod's affinity + ## + affinity: {} + + ## Manager pod's node selector + ## + nodeSelector: {} + + ## Manager pod's tolerations + ## + tolerations: [] + +## Helper RBAC roles for managing custom resources +## +rbacHelpers: + # Install convenience admin/editor/viewer roles for CRDs + enable: false + +## Custom Resource Definitions +## +crd: + # Install CRDs with the chart + enable: true + # Keep CRDs when uninstalling + keep: true + +## Controller metrics endpoint. +## Enable to expose /metrics endpoint with RBAC protection. +## +metrics: + enable: true + # Metrics server port + port: 8443 + +## Cert-manager integration for TLS certificates. +## Required for webhook certificates and metrics endpoint certificates. +## +certManager: + enable: false + +## Prometheus ServiceMonitor for metrics scraping. +## Requires prometheus-operator to be installed in the cluster. +## +prometheus: + enable: false +