Skip to content

Commit

Permalink
tezos signer forwarder chart
Browse files Browse the repository at this point in the history
The last remaining piece of https://github.com/midl-dev/tezos-on-gke/ to
move into tezos-k8s, tezos-signer-forwarder is a terminating pod for ssh
tunnels exposing a tezos signing endpoint from an on-prem location.
  • Loading branch information
nicolasochem committed Feb 8, 2023
1 parent 7c8e86a commit 2bbf0a3
Show file tree
Hide file tree
Showing 13 changed files with 500 additions and 0 deletions.
24 changes: 24 additions & 0 deletions charts/tezos-signer-forwarder/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: tezos-signer-forwarder
description: A chart for tezos-signer-forwarder

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
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.0.0

# 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
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "10.0"
3 changes: 3 additions & 0 deletions charts/tezos-signer-forwarder/scripts/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

/usr/sbin/sshd -D -e -p ${TUNNEL_ENDPOINT_PORT}
28 changes: 28 additions & 0 deletions charts/tezos-signer-forwarder/scripts/signer_exporter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env python
import os
from flask import Flask, request, jsonify
import requests

import logging
log = logging.getLogger('werkzeug')
log.setLevel(logging.ERROR)

application = Flask(__name__)

readiness_probe_path = os.getenv("READINESS_PROBE_PATH")

@application.route('/metrics', methods=['GET'])
def prometheus_metrics():
'''
Prometheus endpoint
'''
try:
probe = requests.get(f"http://localhost:8443{readiness_probe_path}")
except requests.exceptions.RequestException:
probe = None
return f'''# number of unhealthy signers - should be 0 or 1
unhealthy_signers_total {0 if probe else 1}
'''

if __name__ == "__main__":
application.run(host = "0.0.0.0", port = 31732, debug = False)
62 changes: 62 additions & 0 deletions charts/tezos-signer-forwarder/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "tezos-signer-forwarder.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 "tezos-signer-forwarder.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 }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "tezos-signer-forwarder.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "tezos-signer-forwarder.labels" -}}
helm.sh/chart: {{ include "tezos-signer-forwarder.chart" . }}
{{ include "tezos-signer-forwarder.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "tezos-signer-forwarder.selectorLabels" -}}
app.kubernetes.io/name: {{ include "tezos-signer-forwarder.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "tezos-signer-forwarder.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "tezos-signer-forwarder.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
54 changes: 54 additions & 0 deletions charts/tezos-signer-forwarder/templates/alertmanagerconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{{- if .Values.alertmanagerConfig.enabled }}
{{- range .Values.endpoints }}
{{- if .monitoring_email }}
apiVersion: monitoring.coreos.com/v1alpha1
kind: AlertmanagerConfig
metadata:
name: tezos-remote-signer-alerts-{{ .name }}
labels:
{{- toYaml $.Values.alertmanagerConfig.labels | nindent 4 }}
spec:
route:
groupBy: ['job']
groupWait: 30s
groupInterval: 5m
repeatInterval: 12h
receiver: 'email_{{ .name }}'
matchers:
- name: service
value: tezos-remote-signer-{{ .name }}
regex: false
- name: alertType
value: tezos-remote-signer-alert
regex: false
continue: false
receivers:
- name: 'email_{{ .name }}'
emailConfigs:
- to: "{{ .monitoring_email }}"
sendResolved: true
headers:
- key: subject
value: '{{`[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] {{ .CommonLabels.alertname }}`}}'
html: >-
{{`{{ if eq .Status "firing" }}
Your attention is required regarding the following Tezos Remote Signer alert:
{{ else }}
The following Tezos Remote Signer Alert is resolved:
{{ end }}
{{ range .Alerts -}}
{{ .Annotations.summary }}
{{ end }}`}}
text: >-
{{`{{ if eq .Status "firing" }}
Your attention is required regarding the following Tezos Remote Signer alert:
{{ else }}
The following Tezos Remote Signer Alert is resolved:
{{ end }}
{{ range .Alerts -}}
{{ .Annotations.summary }}
{{ end }}`}}
---
{{- end }}
{{- end }}
{{- end }}
10 changes: 10 additions & 0 deletions charts/tezos-signer-forwarder/templates/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{- range .Values.endpoints }}
apiVersion: v1
kind: ConfigMap
metadata:
name: tezos-signer-forwarder-config-{{ .name }}
data:
authorized_keys: "{{ .ssh_pubkey }} signer"
tunnel_endpoint_port: "{{ .tunnel_endpoint_port }}"
---
{{- end }}
51 changes: 51 additions & 0 deletions charts/tezos-signer-forwarder/templates/prometheusrule.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{{- if .Values.prometheusRule.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
labels:
{{- toYaml .Values.prometheusRule.labels | nindent 4 }}
name: tezos-remote-signer-rules
spec:
groups:
- name: tezos-remote-signer.rules
rules:
- alert: SignerPowerLoss
annotations:
description: 'Remote signer has lost power'
summary: Tezos remote signer has lost power
expr: power{namespace="{{ .Release.Namespace }}"} != 0
for: 1m
labels:
severity: critical
alertType: tezos-remote-signer-alert
- alert: SignerWiredNetworkLoss
annotations:
description: 'Remote signer has lost wired internet connection'
summary: Tezos remote signer has lost wired internet connection
expr: wired_network{namespace="{{ .Release.Namespace }}"} != 0
for: 1m
labels:
severity: critical
alertType: tezos-remote-signer-alert
---
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
labels:
{{- toYaml .Values.prometheusRule.labels | nindent 4 }}
name: tezos-remote-signer-reachability-rules
spec:
groups:
- name: tezos-remote-signer.rules
rules:
- alert: NoRemoteSigner
annotations:
description: 'Remote signer is down'
summary: Remote signer is down or unable to sign.
expr: unhealthy_signers_total{namespace="{{ .Release.Namespace }}"} != 0
for: 1m
labels:
severity: critical
alertType: tezos-remote-signer-alert
---
{{- end }}
7 changes: 7 additions & 0 deletions charts/tezos-signer-forwarder/templates/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: Secret
metadata:
name: tezos-signer-forwarder-secret-{{ .Values.name }}
data:
ssh_host_ecdsa_key: |
{{ println .Values.secrets.signer_target_host_key | b64enc | indent 4 -}}
37 changes: 37 additions & 0 deletions charts/tezos-signer-forwarder/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apiVersion: v1
kind: Service
metadata:
name: tezos-remote-signer-ssh-ingress-{{ .Values.name }}
annotations:
{{ toYaml .Values.service_annotations | indent 4 }}
spec:
type: LoadBalancer
selector:
app.kubernetes.io/name: tezos-signer-forwarder
ports:
{{- range .Values.endpoints }}
- port: {{ .tunnel_endpoint_port }}
name: tunnel-{{ .name }}
{{- end }}
# ensures that remote signers can always ssh
publishNotReadyAddresses: true
---
{{- range .Values.endpoints }}
apiVersion: v1
kind: Service
metadata:
name: tezos-remote-signer-{{ .name }}
labels:
app.kubernetes.io/name: tezos-signer-forwarder
app.kubernetes.io/baker-name: {{ .name }}
spec:
selector:
app.kubernetes.io/name: tezos-signer-forwarder
app.kubernetes.io/baker-name: {{ .name }}
ports:
- port: 8443
name: signer
- port: 31732
name: metrics
---
{{- end }}
38 changes: 38 additions & 0 deletions charts/tezos-signer-forwarder/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{{- if .Values.serviceMonitor.enabled }}
{{- range .Values.endpoints }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
app.kubernetes.io/name: tezos-signer-forwarder
name: tezos-remote-signer-monitoring-{{ .name }}
namespace: {{ $.Release.Namespace }}
spec:
endpoints:
- interval: 20s
port: signer
path: /healthz
scrapeTimeout: 20s
selector:
matchLabels:
app.kubernetes.io/name: tezos-signer-forwarder
app.kubernetes.io/baker-name: {{ .name }}
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
app.kubernetes.io/name: tezos-signer-forwarder
name: tezos-remote-signer-reachability-{{ .name }}
namespace: {{ $.Release.Namespace }}
spec:
endpoints:
- port: metrics
path: /metrics
selector:
matchLabels:
app.kubernetes.io/name: tezos-signer-forwarder
app.kubernetes.io/baker-name: {{ .name }}
---
{{- end }}
{{- end }}
Loading

0 comments on commit 2bbf0a3

Please sign in to comment.