diff --git a/charts/bbook/README.md b/charts/bbook/README.md index b357aad..c790c5f 100644 --- a/charts/bbook/README.md +++ b/charts/bbook/README.md @@ -54,12 +54,16 @@ Kubernetes: `>= 1.21.0` | externalDatabase.username | string | `"bbook"` | database user name | | extraObjects | list | `[]` | extra Kubernetes objects deployed with the chart, rendered through tpl. | | fullnameOverride | string | `""` | fullnameOverride configuration | +| httpRoute.allowlist | list | `[]` | source CIDRs allowed to reach the route, empty allows all. Creates a kgateway TrafficPolicy and needs kgateway as the gateway implementation | | httpRoute.annotations | object | `{}` | HTTPRoute annotations | | httpRoute.enabled | bool | `false` | create an HTTPRoute attaching bbook to an existing Gateway API gateway, as an alternative to the ingress | | httpRoute.filters | list | `[]` | optional HTTPRoute rule filters | | httpRoute.hosts | list | `["bbook.local"]` | hostnames served by the route | | httpRoute.matches | object | `{"path":{"type":"PathPrefix","value":"/"}}` | path match for the route | | httpRoute.parentRefs | list | `[]` | gateways to attach to, e.g. {name: infra, namespace: infra-kgateway} | +| httpRoute.redirect.enabled | bool | `false` | create a second HTTPRoute redirecting plain HTTP requests for the same hosts to HTTPS | +| httpRoute.redirect.parentRefs | list | `[]` | HTTP listeners to attach the redirect to, e.g. {name: infra, namespace: infra-kgateway, sectionName: http} | +| httpRoute.redirect.statusCode | int | `308` | status code of the redirect | | httpRoute.timeouts | object | `{}` | optional HTTPRoute rule timeouts | | image.pullPolicy | string | `"IfNotPresent"` | pullPolicy to use | | image.repository | string | `"ghcr.io/adfinis/bbook"` | repository where the image is located | diff --git a/charts/bbook/templates/httproute.yaml b/charts/bbook/templates/httproute.yaml index c442ebb..fc56378 100644 --- a/charts/bbook/templates/httproute.yaml +++ b/charts/bbook/templates/httproute.yaml @@ -34,4 +34,26 @@ spec: - kind: Service name: {{ include "bbook.fullname" . }} port: {{ .Values.service.port }} +{{- if .Values.httpRoute.redirect.enabled }} +--- +apiVersion: gateway.networking.k8s.io/v1 +kind: HTTPRoute +metadata: + name: {{ include "bbook.fullname" . }}-redirect + labels: + {{- include "bbook.labels" . | nindent 4 }} +spec: + hostnames: + {{- range .Values.httpRoute.hosts }} + - {{ . | quote }} + {{- end }} + parentRefs: + {{- toYaml .Values.httpRoute.redirect.parentRefs | nindent 4 }} + rules: + - filters: + - type: RequestRedirect + requestRedirect: + scheme: https + statusCode: {{ .Values.httpRoute.redirect.statusCode }} +{{- end }} {{- end }} diff --git a/charts/bbook/templates/trafficpolicy.yaml b/charts/bbook/templates/trafficpolicy.yaml new file mode 100644 index 0000000..66e4ee0 --- /dev/null +++ b/charts/bbook/templates/trafficpolicy.yaml @@ -0,0 +1,19 @@ +{{- if and .Values.httpRoute.enabled .Values.httpRoute.allowlist -}} +apiVersion: gateway.kgateway.dev/v1alpha1 +kind: TrafficPolicy +metadata: + name: {{ include "bbook.fullname" . }}-allowlist + labels: + {{- include "bbook.labels" . | nindent 4 }} +spec: + targetRefs: + - group: gateway.networking.k8s.io + kind: HTTPRoute + name: {{ include "bbook.fullname" . }} + acl: + defaultAction: deny + rules: + - action: allow + cidrs: + {{- toYaml .Values.httpRoute.allowlist | nindent 10 }} +{{- end }} diff --git a/charts/bbook/values.yaml b/charts/bbook/values.yaml index 14f1b51..50ea9cd 100644 --- a/charts/bbook/values.yaml +++ b/charts/bbook/values.yaml @@ -92,6 +92,16 @@ httpRoute: timeouts: {} # -- optional HTTPRoute rule filters filters: [] + redirect: + # -- create a second HTTPRoute redirecting plain HTTP requests for the same hosts to HTTPS + enabled: false + # -- HTTP listeners to attach the redirect to, e.g. {name: infra, namespace: infra-kgateway, sectionName: http} + parentRefs: [] + # -- status code of the redirect + statusCode: 308 + # -- source CIDRs allowed to reach the route, empty allows all. Creates a kgateway TrafficPolicy and needs kgateway as the gateway implementation + allowlist: [] + # - 10.0.0.0/8 # -- Pod resources to define resources: {}