Skip to content

Commit f099ac7

Browse files
jkremserCopilot
andauthored
Swagger at / + some tls tuneability (#162)
* Complex pipeline where evertything is TLS encrypted and certs are rotated Signed-off-by: Jirka Kremser <jiri.kremser@gmail.com> * Update examples/pipelines-tls/setup.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update examples/vllm/setup.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update examples/otel-operator/setup.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Jirka Kremser <jiri.kremser@gmail.com> * Swagger + own certs for keda <-> scaler comm Signed-off-by: Jirka Kremser <jiri.kremser@gmail.com> --------- Signed-off-by: Jirka Kremser <jiri.kremser@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 985c827 commit f099ac7

File tree

8 files changed

+43
-19
lines changed

8 files changed

+43
-19
lines changed

examples/pipelines-tls/prometheus-values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ configmapReload:
2020
server:
2121
extraFlags:
2222
- web.enable-remote-write-receiver
23-
readinessProbeInitialDelay: 240
23+
readinessProbeInitialDelay: 90
2424
retention: "7d"
2525
retentionSize: "1GB"
2626
resources:

examples/pipelines-tls/scaler-pipelines-tls-values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ settings:
88
# caFile: "/etc/scaler-tls/ca.crt"
99
certFile: "/etc/scaler-tls/tls.crt"
1010
keyFile: "/etc/scaler-tls/tls.key"
11+
keda:
12+
enabled: true
13+
certFile: "/etc/scaler-tls/tls.crt"
14+
keyFile: "/etc/scaler-tls/tls.key"
1115
reloadInterval: "15s"
1216
secrets:
1317
- name: keda-otel-root-ca-bundle

examples/pipelines-tls/setup.sh

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ kubectl rollout status -n observability --timeout=600s deploy/prometheus-server
8383

8484
# SO
8585
kubectl wait -nkeda --for condition=ready --timeout=300s cert/keda-operator-tls-certificates
86-
#certSecret="-nkeda secret/kedaorg-certs"
8786
certSecret="-nkeda secret/keda-otel-scaler-cert-secret"
8887
export _caCertPem=$(kubectl get $(echo $certSecret) -o'go-template={{index .data "ca.crt"}}' | base64 -d | awk '{ print " " $0 }')
8988
export _tlsClientKey=$(kubectl get $(echo $certSecret) -o'go-template={{index .data "tls.key"}}' | base64 -d | awk '{ print " " $0 }')
@@ -109,18 +108,17 @@ k get otelcol -A
109108
k get cert -A -owide
110109
111110
# create traffic
112-
(hey -z 60s http://localhost:8080 &> /dev/null)&
111+
(hey -z 30s http://localhost:8080 &> /dev/null)&
113112
114113
# check how it scales out
115114
k get hpa -A && k get so -A
116115
117116
# verify SSL works
118-
_pod=$(kubectl get po -nobservability -lapp.kubernetes.io/name=router-collector --no-headers -ocustom-columns=":metadata.name")
119-
kubectl debug -it -n observability ${_pod} --image=dockersec/tcpdump --target otc-container -- tcpdump -i any 'port 4317 and (tcp[tcpflags] & (tcp-syn|tcp-ack) == tcp-syn)'
120-
and you should be able to observe beginnings of SSL handshakes (kill nginx pod to force one)
117+
kubectl debug -it -n observability $(kubectl get po -nobservability -lapp.kubernetes.io/name=router-collector --no-headers -ocustom-columns=":metadata.name") --image=dockersec/tcpdump --target otc-container -- tcpdump -i any 'port 4317 and (tcp[tcpflags] & (tcp-syn|tcp-ack) == tcp-syn)'
118+
# and you should be able to observe beginnings of SSL handshakes (kill nginx pod to force one)
121119
122-
# force cert rotation in app ns
123-
cmctl renew --namespace=app --all
120+
# force cert rotations
121+
cmctl renew -A --all
124122
125123
🚀
126124
USAGE

helmchart/otel-add-on/templates/deployment.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ spec:
6565
- name: IS_ACTIVE_POLLING_INTERVAL_MS
6666
value: {{ .Values.settings.isActivePollingIntervalMilliseconds | quote }}
6767

68-
# TLS
68+
# TLS OTLP
6969
- name: OTLP_TLS_CA_FILE
7070
value: {{ .Values.settings.tls.caFile | quote }}
7171
- name: OTLP_TLS_CERT_FILE
@@ -74,6 +74,13 @@ spec:
7474
value: {{ .Values.settings.tls.keyFile | quote }}
7575
- name: OTLP_CERTIFICATE_RELOAD_INTERVAL
7676
value: {{ .Values.settings.tls.reloadInterval | quote }}
77+
# TLS KEDA
78+
- name: KEDA_TLS_ENABLED
79+
value: {{ .Values.settings.tls.keda.enabled | quote }}
80+
- name: KEDA_TLS_CERT_FILE
81+
value: {{ .Values.settings.tls.keda.certFile | default .Values.settings.tls.certFile | quote }}
82+
- name: KEDA_TLS_KEY_FILE
83+
value: {{ .Values.settings.tls.keda.keyFile | default .Values.settings.tls.keyFile | quote }}
7784
{{- if .Values.settings.logs.noColor }}
7885
- name: NO_COLOR
7986
value: {{ .Values.settings.logs.noColor | quote }}

helmchart/otel-add-on/values.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ settings:
6565
# -- (optional) specifies the duration after which the certificates will be reloaded.
6666
# This is useful when using the CertManager for rotating the certs mounted as Secrets.
6767
reloadInterval: "5m"
68+
keda:
69+
enabled: false
70+
# -- (optional) path to TLS certificate that will be used for KEDA gRPC server. If empty, defaults to `settings.tls.certFile`
71+
certFile: ""
72+
# -- (optional) path to TLS key that will be used for KEDA gRPC server. If empty, defaults to `settings.tls.keyFile`
73+
keyFile: ""
6874
# -- (optional) list of secrets that will be mounted to deployment's pod. One entry in this list, will create one volume and one volumeMount for pod.
6975
# This is a convenient way for mounting the certs for TLS, but using `.volumes & .volumeMounts` for anything advanced will also work.
7076
secrets: []

main.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func main() {
8080
setupLog.Info("🔒 TLS for gRPC server enabled (OTLP receiver)", "tlsSettings", tlsSettings)
8181
}
8282

83-
if e = startGrpcServer(ctx, ctrl.Log, ms, mp, cfg); !util.IsIgnoredErr(e) {
83+
if e = startKEDAGrpcServer(ctx, ctrl.Log, ms, mp, cfg); !util.IsIgnoredErr(e) {
8484
setupLog.Error(e, "gRPC server failed (KEDA external scaler)")
8585
return e
8686
}
@@ -182,7 +182,7 @@ func startReceiver(ctx context.Context, otlpReceiverPort int, tlsSettings *confi
182182
return nil
183183
}
184184

185-
func startGrpcServer(
185+
func startKEDAGrpcServer(
186186
ctx context.Context,
187187
lggr logr.Logger,
188188
ms types.MemStore,
@@ -197,14 +197,17 @@ func startGrpcServer(
197197
}
198198

199199
var serverOpts []grpc.ServerOption
200-
tlsSettings := makeTlsSettings(cfg)
201-
if tlsSettings.CertFile != "" && tlsSettings.KeyFile != "" {
202-
creds, e := credentials.NewServerTLSFromFile(tlsSettings.CertFile, tlsSettings.KeyFile)
203-
if e != nil {
204-
setupLog.Error(e, "failed to get certificates")
200+
if cfg.TLSKedaComm {
201+
if cfg.TLSKedaCertFile != "" && cfg.TLSKedaKeyFile != "" {
202+
creds, e := credentials.NewServerTLSFromFile(cfg.TLSKedaCertFile, cfg.TLSKedaKeyFile)
203+
if e != nil {
204+
setupLog.Error(e, "failed to get certificates")
205+
os.Exit(1)
206+
}
207+
setupLog.Info("🔒 TLS for gRPC server enabled (KEDA scaler <-> KEDA comm)", "cert", cfg.TLSKedaCertFile, "key", cfg.TLSKedaKeyFile)
208+
setupLog.Info("🔒 caveat: ^ these are not being actively watched and automatically reloaded")
209+
serverOpts = append(serverOpts, grpc.Creds(creds))
205210
}
206-
setupLog.Info("🔒 gRPC server for KEDA scaler has TLS enabled")
207-
serverOpts = append(serverOpts, grpc.Creds(creds))
208211
}
209212

210213
grpcServer := grpc.NewServer(serverOpts...)

rest/api.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,16 @@ func Init(restApiPort int, info prometheus.Labels, ms types.MemStore, isDebug bo
5858
a.lggr.Error(err, "Disabling trusted proxies failed")
5959
}
6060
docs.SwaggerInfo.BasePath = "/"
61+
router.GET("/", func(ctx *gin.Context) {
62+
ctx.Redirect(http.StatusPermanentRedirect, "/swagger/index.html")
63+
})
6164
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
6265
router.GET("/memstore/names", a.getMetricNames)
6366
router.GET("/memstore/data", a.getMetricData)
6467
router.POST("/memstore/query", a.query)
6568
router.POST("/memstore/reset", a.reset)
6669
router.GET("/info", a.getInfo)
67-
a.lggr.Info(fmt.Sprintf("Swagger docs available at: http://localhost:%d/swagger/index.html", restApiPort))
70+
a.lggr.Info(fmt.Sprintf("Swagger docs available at: http://localhost:%d", restApiPort))
6871
return router.Run(fmt.Sprintf(":%d", restApiPort))
6972
}
7073

util/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ type Config struct {
2525
TLSCertFile string `envconfig:"OTLP_TLS_CERT_FILE" default:""`
2626
TLSKeyFile string `envconfig:"OTLP_TLS_KEY_FILE" default:""`
2727
CertReloadInterval time.Duration `envconfig:"OTLP_CERTIFICATE_RELOAD_INTERVAL" default:"5m"`
28+
TLSKedaComm bool `envconfig:"KEDA_TLS_ENABLED" default:"false"`
29+
TLSKedaCertFile string `envconfig:"KEDA_TLS_CERT_FILE" default:""`
30+
TLSKedaKeyFile string `envconfig:"KEDA_TLS_KEY_FILE" default:""`
2831

2932
// Other
3033
NoColor bool `envconfig:"NO_COLOR" default:"false"`

0 commit comments

Comments
 (0)