|
| 1 | +{{/* |
| 2 | +Envoy sidecar container template |
| 3 | +Usage: {{ include "governor.tlsInternal.sidecar" (dict "componentName" "api" "config" .Values.api "tlsInternal" .Values.envoy "hasHttpPort" true "hasGrpcPort" true) }} |
| 4 | +*/}} |
| 5 | +{{- define "governor.tlsInternal.sidecar" -}} |
| 6 | +- name: envoy-sidecar |
| 7 | + image: "{{ .tlsInternal.image.repository }}:{{ .tlsInternal.image.tag }}" |
| 8 | + imagePullPolicy: {{ .tlsInternal.image.pullPolicy }} |
| 9 | + args: |
| 10 | + - -c |
| 11 | + - /etc/envoy/envoy.yaml |
| 12 | + - --log-level |
| 13 | + - {{ .tlsInternal.logLevel }} |
| 14 | + ports: |
| 15 | + {{- if .hasHttpPort }} |
| 16 | + - name: https |
| 17 | + containerPort: {{ .tlsInternal.ports.secureHttp }} |
| 18 | + protocol: TCP |
| 19 | + {{- end }} |
| 20 | + {{- if .hasGrpcPort }} |
| 21 | + - name: grpcs |
| 22 | + containerPort: {{ .tlsInternal.ports.secureGrpc }} |
| 23 | + protocol: TCP |
| 24 | + {{- end }} |
| 25 | + - name: admin |
| 26 | + containerPort: {{ .tlsInternal.ports.admin }} |
| 27 | + protocol: TCP |
| 28 | + readinessProbe: |
| 29 | + httpGet: |
| 30 | + path: /ready |
| 31 | + port: {{ .tlsInternal.ports.admin }} |
| 32 | + initialDelaySeconds: 5 |
| 33 | + periodSeconds: 10 |
| 34 | + livenessProbe: |
| 35 | + httpGet: |
| 36 | + path: /ready |
| 37 | + port: {{ .tlsInternal.ports.admin }} |
| 38 | + initialDelaySeconds: 10 |
| 39 | + periodSeconds: 15 |
| 40 | + resources: |
| 41 | + {{- toYaml .tlsInternal.resources | nindent 4 }} |
| 42 | + volumeMounts: |
| 43 | + - name: envoy-config |
| 44 | + mountPath: /etc/envoy |
| 45 | + readOnly: true |
| 46 | + - name: tls-certs |
| 47 | + mountPath: /etc/envoy/certs |
| 48 | + readOnly: true |
| 49 | +{{- end }} |
| 50 | + |
| 51 | +{{/* |
| 52 | +Envoy init container to wait for certificates |
| 53 | +Usage: {{ include "governor.tlsInternal.initContainer" . }} |
| 54 | +*/}} |
| 55 | +{{- define "governor.tlsInternal.initContainer" -}} |
| 56 | +- name: wait-for-certs |
| 57 | + image: busybox:1.36 |
| 58 | + command: |
| 59 | + - /bin/sh |
| 60 | + - -c |
| 61 | + - | |
| 62 | + echo "Waiting for TLS certificates..." |
| 63 | + while [ ! -f /etc/envoy/certs/tls.crt ] || [ ! -f /etc/envoy/certs/tls.key ]; do |
| 64 | + echo "Certificates not ready, waiting..." |
| 65 | + sleep 2 |
| 66 | + done |
| 67 | + echo "Certificates are ready!" |
| 68 | + volumeMounts: |
| 69 | + - name: tls-certs |
| 70 | + mountPath: /etc/envoy/certs |
| 71 | + readOnly: true |
| 72 | +{{- end }} |
| 73 | + |
| 74 | +{{/* |
| 75 | +Envoy volumes template |
| 76 | +Usage: {{ include "governor.tlsInternal.volumes" (dict "componentName" "api" "config" .Values.api "tlsInternal" .Values.envoy) }} |
| 77 | +*/}} |
| 78 | +{{- define "governor.tlsInternal.volumes" -}} |
| 79 | +- name: envoy-config |
| 80 | + configMap: |
| 81 | + name: {{ .config.name }}-envoy-config |
| 82 | +- name: tls-certs |
| 83 | + secret: |
| 84 | + secretName: {{ .config.name }}-tls |
| 85 | +{{- end }} |
| 86 | + |
| 87 | +{{/* |
| 88 | +Envoy HTTP router filter (used in all listeners) |
| 89 | +*/}} |
| 90 | +{{- define "governor.envoy.httpRouter" -}} |
| 91 | +- name: envoy.filters.http.router |
| 92 | + typed_config: |
| 93 | + "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router |
| 94 | +{{- end }} |
| 95 | + |
| 96 | +{{/* |
| 97 | +Envoy downstream TLS context (for inbound TLS termination) |
| 98 | +*/}} |
| 99 | +{{- define "governor.envoy.downstreamTls" -}} |
| 100 | +transport_socket: |
| 101 | + name: envoy.transport_sockets.tls |
| 102 | + typed_config: |
| 103 | + "@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.DownstreamTlsContext |
| 104 | + common_tls_context: |
| 105 | + tls_certificates: |
| 106 | + - certificate_chain: |
| 107 | + filename: /etc/envoy/certs/tls.crt |
| 108 | + private_key: |
| 109 | + filename: /etc/envoy/certs/tls.key |
| 110 | +{{- end }} |
| 111 | + |
| 112 | +{{/* |
| 113 | +Envoy upstream TLS context (for egress with CA validation) |
| 114 | +*/}} |
| 115 | +{{- define "governor.envoy.upstreamTls" -}} |
| 116 | +transport_socket: |
| 117 | + name: envoy.transport_sockets.tls |
| 118 | + typed_config: |
| 119 | + "@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext |
| 120 | + common_tls_context: |
| 121 | + validation_context: |
| 122 | + trusted_ca: |
| 123 | + filename: /etc/envoy/certs/ca.crt |
| 124 | +{{- end }} |
| 125 | + |
| 126 | +{{/* |
| 127 | +Envoy gRPC egress listener to api (shared by front and agent) |
| 128 | +*/}} |
| 129 | +{{- define "governor.envoy.apiGrpcEgressListener" -}} |
| 130 | +- name: api_grpc_egress |
| 131 | + address: |
| 132 | + socket_address: |
| 133 | + address: 127.0.0.1 |
| 134 | + port_value: {{ .egressGrpcPort }} |
| 135 | + filter_chains: |
| 136 | + - filters: |
| 137 | + - name: envoy.filters.network.http_connection_manager |
| 138 | + typed_config: |
| 139 | + "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager |
| 140 | + stat_prefix: api_grpc_egress |
| 141 | + codec_type: HTTP2 |
| 142 | + route_config: |
| 143 | + name: api_grpc_route |
| 144 | + virtual_hosts: |
| 145 | + - name: api_grpc_service |
| 146 | + domains: ["*"] |
| 147 | + routes: |
| 148 | + - match: |
| 149 | + prefix: "/" |
| 150 | + route: |
| 151 | + cluster: api_grpcs |
| 152 | + http_filters: |
| 153 | + {{- include "governor.envoy.httpRouter" . | nindent 14 }} |
| 154 | +{{- end }} |
| 155 | + |
| 156 | +{{/* |
| 157 | +Envoy api gRPCS upstream cluster (shared by front and agent) |
| 158 | +*/}} |
| 159 | +{{- define "governor.envoy.apiGrpcsCluster" -}} |
| 160 | +- name: api_grpcs |
| 161 | + type: STRICT_DNS |
| 162 | + connect_timeout: 5s |
| 163 | + http2_protocol_options: {} |
| 164 | + load_assignment: |
| 165 | + cluster_name: api_grpcs |
| 166 | + endpoints: |
| 167 | + - lb_endpoints: |
| 168 | + - endpoint: |
| 169 | + address: |
| 170 | + socket_address: |
| 171 | + address: {{ .apiName }} |
| 172 | + port_value: {{ .apiGrpcPort }} |
| 173 | + {{- include "governor.envoy.upstreamTls" . | nindent 2 }} |
| 174 | +{{- end }} |
0 commit comments