Skip to content

Commit

Permalink
feat(firehose-ethereum): rework JWT without lookup (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjorge-graphops authored Sep 20, 2024
1 parent 62d1aaf commit c474375
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 17 deletions.
2 changes: 1 addition & 1 deletion charts/firehose-ethereum/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0-canary.1
version: 0.1.0-canary.2

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
6 changes: 3 additions & 3 deletions charts/firehose-ethereum/README.md

Large diffs are not rendered by default.

59 changes: 59 additions & 0 deletions charts/firehose-ethereum/templates/resources/job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{{ define "templates.jwtJob" }}
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "metadata.fullname" $ }}-{{ .componentName }}-generate-jwt-{{ .Root.Release.Revision }}
{{- $labels := include "metadata.allLabels" ( set ( deepCopy $ ) "labels" dict ) | fromYaml }}
{{- $annotations := include "metadata.allAnnotations" ( set ( deepCopy $ ) "annotations" dict ) | fromYaml }}
labels:
{{- range $key, $value := $labels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
annotations:
"helm.sh/hook": post-install,post-upgrade
"helm.sh/hook-weight": "-5"
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
"helm.sh/resource-policy": keep
{{- range $key, $value := $annotations }}
{{ $key }}: {{ $value | quote }}
{{- end }}
namespace: {{ .Root.Release.Namespace }}
spec:
ttlSecondsAfterFinished: 100
template:
metadata:
name: {{ include "metadata.fullname" $ }}-{{ .componentName }}-generate-jwt-{{ .Root.Release.Revision }}
{{- $labels := include "metadata.allLabels" ( set ( deepCopy $ ) "labels" dict ) | fromYaml }}
{{- $annotations := include "metadata.allAnnotations" ( set ( deepCopy $ ) "annotations" dict ) | fromYaml }}
labels:
{{- range $key, $value := $labels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
annotations:
{{- range $key, $value := $annotations }}
{{ $key }}: {{ $value | quote }}
{{- end }}
spec:
serviceAccountName: {{ include "metadata.serviceAccountName" $ }}
restartPolicy: OnFailure
containers:
- name: generate-jwt-secret
image: bitnami/kubectl:latest
env:
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: SECRET_NAME
value: {{ printf "%s-%s-jwt" (include "metadata.fullname" $) .componentName | quote }}
command:
- /bin/sh
- -c
- |
if kubectl -n ${NAMESPACE} get secret ${SECRET_NAME}; then
echo "Secret $SECRET_NAME already exists. Skipping creation."
else
echo "Creating new secret $SECRET_NAME"
kubectl -n ${NAMESPACE} create secret generic ${SECRET_NAME} --from-literal=jwt.hex=$(openssl rand -hex 32)
fi
{{- end }}
10 changes: 7 additions & 3 deletions charts/firehose-ethereum/templates/resources/render.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
{{- $finalConfigMap := list $baseConfigMap (omit $values.configMap "enabled" "options") | include "utils.deepMerge" | fromYaml }}
---
{{ $finalConfigMap | toYaml }}
---
{{ $values.configMap | toYaml }}
{{- end -}}

{{- if $values.enabled }}
Expand Down Expand Up @@ -85,10 +83,16 @@
{{ $renderedServiceMonitor | toYaml }}
{{- end -}}

{{- if and ($values.fireeth.jwt.enabled) (empty $values.fireeth.jwt.existingSecret.name) (empty $values.fireeth.jwt.existingSecret.key) }}
{{- if and ($values.fireeth.jwt.enabled) (empty $values.fireeth.jwt.existingSecret.name) (empty $values.fireeth.jwt.existingSecret.key) (not (empty $values.fireeth.jwt.fromLiteral)) }}
{{- $renderedSecret := include "templates.Secret" $templateCtx | fromYaml }}
---
{{ $renderedSecret | toYaml }}
{{- end -}}

{{- if and ($values.fireeth.jwt.enabled) (empty $values.fireeth.jwt.existingSecret.name) (empty $values.fireeth.jwt.existingSecret.key) (empty $values.fireeth.jwt.fromLiteral) }}
{{- $renderedJob := include "templates.jwtJob" $templateCtx | fromYaml }}
---
{{ $renderedJob | toYaml }}
{{- end -}}

{{- end }}
8 changes: 0 additions & 8 deletions charts/firehose-ethereum/templates/resources/secret.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{{ define "templates.Secret" }}
{{- $secretName := printf "%s-%s-jwt" (include "metadata.fullname" $) .componentName -}}
{{- $secret := lookup "v1" "Secret" .Root.Release.Namespace $secretName }}
apiVersion: v1
kind: Secret
metadata:
Expand All @@ -18,13 +17,6 @@ metadata:
namespace: {{ .Root.Release.Namespace }}
type: Opaque
data:
{{/* randAlphaNum 44 has slightly over 256 bits of entropy so it's enough */}}
jwt.hex: |-
{{- if not (empty .Pod.fireeth.jwt.fromLiteral) }}
{{ .Pod.fireeth.jwt.fromLiteral | b64enc }}
{{- else if $secret }}
{{ index $secret.data "jwt.hex" }}
{{- else }}
{{ randAlphaNum 44 | sha256sum | lower | b64enc }}
{{- end }}
{{- end }}
6 changes: 6 additions & 0 deletions charts/firehose-ethereum/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,12 @@ firehoseServiceDefaults:
- "get"
- "list"
- "watch"
- apiGroups: [""]
resources:
- "secrets"
verbs:
- "get"
- "create"

clusterRbac:
enabled: '{{ .Pod.fireeth.p2p.enabled }}'
Expand Down
4 changes: 2 additions & 2 deletions charts/graph-toolbox/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Graph-Toolbox Helm Chart

Deploy a preconfigured toolbox container for to be used alongside the
Deploy a preconfigured toolbox container for to be used alongside the Graph Network Indexer stack

[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) ![Version: 0.1.0](https://img.shields.io/badge/Version-0.1.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: main](https://img.shields.io/badge/AppVersion-main-informational?style=flat-square)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) ![Version: 0.1.1](https://img.shields.io/badge/Version-0.1.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: main](https://img.shields.io/badge/AppVersion-main-informational?style=flat-square)

## Introduction

Expand Down

0 comments on commit c474375

Please sign in to comment.