Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ check-lint-pin:

CHART_REQUIRED := --set config.rpc-url=http://rpc:8545 --set-string config.chain-id=1330 --set captcha.existingSecret=captcha
CHART_ALL := $(CHART_REQUIRED) --set httpRoute.enabled=true --set 'httpRoute.hostnames[0]=faucet.example.com' \
--set 'httpRoute.parentRefs[0].name=gateway' --set serviceMonitor.enabled=true --set prometheusRule.enabled=true
--set 'httpRoute.parentRefs[0].name=gateway' --set serviceMonitor.enabled=true --set prometheusRule.enabled=true \
--set admin.enabled=true --set 'admin.allowedServiceAccounts[0]=ns/sa'

# Lints the chart and renders it with every optional resource on.
chart-lint:
Expand Down
104 changes: 101 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ environment variable: `--rpc-url` is `WELLSPRING_RPC_URL`. Run
| `--confirm-timeout` | `30s` | Wait for a receipt before resyncing the nonce |
| `--db-path` | `wellspring.db` | SQLite database; put it on a persistent volume |
| `--listen-addr` / `--metrics-addr` | `:8080` / `:9090` | HTTP and Prometheus listeners |
| `--admin-addr` | off | Grants API listener; see [Grants](#grants) |
| `--admin-allow` | required with `--admin-addr` | Comma-separated `namespace/serviceaccount` grant callers; wildcards are refused |
| `--admin-audience` | `wellspring` | Audience a caller's token must carry |
| `--grant-max-wei` | 100000 SEI | Most one grant sends |
| `--kube-api-url` / `--kube-token-file` / `--kube-ca-file` | in-cluster defaults | Kubernetes API that reviews callers' tokens |
| `--log-level` | `info` | JSON logs to stdout at this level |

Secrets are only read from files, such as a mounted Kubernetes secret, so they
Expand All @@ -78,13 +83,103 @@ On SIGTERM it stops taking claims, stops the sender and closes the database.
Claims it had not settled are reconciled from the chain on the next start. `/healthz` is
liveness; `/readyz` also checks the RPC and the faucet balance.

## Grants

The grants API sends any amount up to `--grant-max-wei` to an address, for
partners, load tests and other test workloads. It listens on `--admin-addr`,
apart from the public page, and goes through the same store, signer and nonce
order as claims, so it never competes with them for a nonce. It skips the
captcha, cooldowns and `--max-recipient-balance-wei`, but reads the faucet's
balance afresh and refuses a grant that, with every unsettled claim, would take
it below `--min-faucet-balance-wei`.

Callers authenticate with a Kubernetes ServiceAccount token whose audience is
`--admin-audience`. wellspring sends it to the Kubernetes TokenReview API and
accepts it only for a ServiceAccount named exactly in `--admin-allow`, with no
wildcards, so there is no shared secret: a human's `wellspring grant` runs
`kubectl create token`, and a pod mounts a projected token.

```
POST /admin/grants
Authorization: Bearer <token>
{"id": "acme-2026-11", "address": "0x…", "amountWei": "5000000000000000000000", "reason": "Acme integration tests"}
```

Set `topUpToWei` instead of `amountWei` to send only what brings the address to
that balance. While a transfer to the address is still settling its balance is
not final, so a top-up gets 503 and `wellspring grant` retries it. `id` names
the grant within its caller's ServiceAccount: sending the same request again returns the grant already made, with status 200, and
reusing an ID for a different address or amount gets 409. A new grant answers
202. `GET /admin/grants/{id}` reports it; `status` is `queued`, `sent`,
`confirmed` or `failed`, and only a successful receipt confirms it. Each grant
is logged with its caller, recipient, amount and reason, and counted in
`wellspring_grants_total` and `wellspring_granted_wei_total`.

### Granting from a laptop

Install the CLI with Go, from Homebrew's `go` or any Go 1.21 or later, which
fetches the toolchain `go.mod` names:

```bash
go install github.com/sei-protocol/wellspring/cmd/wellspring@v0.2.0
```

Then, with a kubeconfig context for wellspring's cluster:

```bash
wellspring grant --kube-context <context> --to 0x… --sei 5000 --reason "Acme integration tests"
```

It runs your `kubectl`, so EKS and other exec auth plugins work as they do for
you, to mint a short-lived `grants-operator` token for the `wellspring` audience
and to port-forward a free local port to the Service's admin port. It waits for
the receipt, prints the transaction hash with the chain ID and public RPC, and
stops the port-forward. `--top-up-to-sei` tops up instead, and `--amount-wei`
and `--top-up-to-wei` take wei. Without `--id` the grant is named
`<address>-<amount>sei-<UTC date>`, printed, so rerunning the same command that
day resumes it rather than paying twice; pass `--id` to name it yourself or to
resume it on a later day. `--namespace`, `--service`, `--service-account` and
`--admin-port` default to `wellspring`, `wellspring`, `grants-operator` and
`8081`.

### Funding a test Job

The image's `wellspring grant` command requests a grant and waits until it
confirms, retrying refusals that can pass, such as an unreachable chain, and
exiting non-zero on ones that cannot. Run it as an init container, with an `--id`
that stays the same across the Job's retries, such as the Job's name, so a
retried pod resumes the grant instead of paying again:

```yaml
initContainers:
- name: fund
image: ghcr.io/sei-protocol/wellspring:<version>
args:
- grant
- --url=http://wellspring.wellspring.svc:8081
- --id=my-load-test-1
- --address=0x… # or --address-file
- --top-up-to-wei=1000000000000000000000
- --reason=my load test
volumeMounts:
- {name: wellspring-token, mountPath: /var/run/secrets/wellspring, readOnly: true}
volumes:
- name: wellspring-token
projected:
sources:
- serviceAccountToken: {audience: wellspring, path: token, expirationSeconds: 600}
```

The Job's ServiceAccount must be in `--admin-allow`, and its namespace admitted
by the chart's NetworkPolicy, which `admin.allowedServiceAccounts` does.

## Kubernetes

The Helm chart in `chart/` runs it the only safe way: a single-replica
StatefulSet, which never starts a second pod while the first is still shutting
down, since one signer owns the nonce, a PVC at `/data`, and a
fixed security context (UID/GID 65532, read-only root filesystem, no
capabilities, no service account token). Merges to main publish a snapshot
capabilities, and no service account token unless the grants API is on). Merges to main publish a snapshot
image and chart; a `vX.Y.Z` tag publishes a release, with the chart pinned to
its image by digest.

Expand All @@ -101,6 +196,9 @@ helm install wellspring oci://ghcr.io/sei-protocol/charts/wellspring --version <

`config` takes any flag by name as a string, such as `config.amount-wei`. Set
`config.trust-proxy-hops` to the number of proxies in front, or every claim
counts against the proxy's IP. See `chart/values.yaml` for the HTTPRoute,
ServiceMonitor, PrometheusRule and NetworkPolicy settings, and
counts against the proxy's IP. `admin.enabled` turns on the grants API on Service port `admin.port`, binds
the ServiceAccount to `system:auth-delegator` so wellspring can review tokens,
and admits the namespaces of `admin.allowedServiceAccounts` to the port. See
`chart/values.yaml` for the HTTPRoute, ServiceMonitor, PrometheusRule and
NetworkPolicy settings, and
[RUNBOOK.md](RUNBOOK.md) for what to do when an alert fires.
41 changes: 41 additions & 0 deletions RUNBOOK.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,47 @@ or the faucet balance cannot cover a transfer.
RPC reads are failing. Check the node behind `config.rpc-url` and the
NetworkPolicy egress rules, if set. The sender retries on its own.

## WellspringGrantFailed

A grant's transfer landed with a failed receipt, or was refused for good. The
log line `claim failed` with the grant's claim ID gives the reason. The grant
stays failed: its caller sees `status: failed` and must request again under a
new grant ID. Check the faucet balance and the sender before it does.

## WellspringGrantAuthUnavailable

wellspring could not review a grant caller's token, so it refused the grant
with 503. Check `kubectl -n $NS logs sts/<release>-wellspring` for `token review
failed`: the Kubernetes API is unreachable (NetworkPolicy egress, if set, must
allow it), the projected token is missing, or the ClusterRoleBinding to
`system:auth-delegator` is gone.

## Making a grant by hand

With `grants-operator` in `admin.allowedServiceAccounts`, install the CLI as in
the README and run, with an `--id` that says what the grant is for:

```bash
wellspring grant --kube-context <context> --namespace $NS --service <release>-wellspring \
--id acme-2026-11 --to 0x… --sei 5000 --reason "Acme integration tests"
```

It mints the token and port-forwards with your `kubectl`, waits for the receipt
and prints the transaction hash. Rerunning it with the same `--id` is safe: it
returns the same grant. Without the CLI, the same through `curl`:

```bash
kubectl -n $NS port-forward svc/<release>-wellspring 8081
TOKEN=$(kubectl -n $NS create token grants-operator --audience wellspring --duration 10m)
curl -s localhost:8081/admin/grants -H "Authorization: Bearer $TOKEN" \
-d '{"id":"acme-2026-11","address":"0x…","amountWei":"5000000000000000000000","reason":"Acme integration tests"}'
curl -s localhost:8081/admin/grants/acme-2026-11 -H "Authorization: Bearer $TOKEN"
```

Anyone allowed to create tokens for an allowed ServiceAccount, or pods under
it, can make grants up to `admin.grantMaxWei` each. The allowlist takes only
exact `namespace/serviceaccount` pairs, so add each caller by name.

## Rotating the signer key

The sender resyncs a new key against its stored in-flight claims, so no claim
Expand Down
17 changes: 17 additions & 0 deletions chart/templates/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{- if .Values.admin.enabled }}
# Lets wellspring create TokenReviews to authenticate grant callers.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ printf "%s-%s-auth-delegator" .Release.Namespace (include "wellspring.fullname" .) | trunc 63 | trimSuffix "-" }}
labels:
{{- include "wellspring.labels" . | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:auth-delegator
subjects:
- kind: ServiceAccount
name: {{ include "wellspring.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
{{- end }}
11 changes: 11 additions & 0 deletions chart/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ data:
WELLSPRING_METRICS_ADDR: ":9090"
WELLSPRING_DB_PATH: /data/wellspring.db
WELLSPRING_PRIVATE_KEY_FILE: /var/run/wellspring/signer/private-key
{{- with .Values.admin }}
{{- if .enabled }}
WELLSPRING_ADMIN_ADDR: ":8081"
WELLSPRING_ADMIN_AUDIENCE: {{ .audience | quote }}
{{- if not .allowedServiceAccounts }}
{{- fail "admin.allowedServiceAccounts is required with admin.enabled" }}
{{- end }}
WELLSPRING_ADMIN_ALLOW: {{ .allowedServiceAccounts | join "," | quote }}
WELLSPRING_GRANT_MAX_WEI: {{ .grantMaxWei | quote }}
{{- end }}
{{- end }}
{{- if include "wellspring.captchaSecret" . }}
WELLSPRING_CAPTCHA_SECRET_FILE: /var/run/wellspring/captcha/secret
{{- end }}
14 changes: 14 additions & 0 deletions chart/templates/networkpolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ spec:
ports:
- port: metrics
{{- end }}
{{- if .Values.admin.enabled }}
- from:
{{- $namespaces := list }}
{{- range .Values.admin.allowedServiceAccounts }}
{{- $namespaces = append $namespaces (splitList "/" . | first) }}
{{- end }}
{{- range $ns := $namespaces | uniq | sortAlpha }}
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: {{ $ns }}
{{- end }}
ports:
- port: admin
{{- end }}
{{- with .Values.networkPolicy.egress }}
egress:
{{- toYaml . | nindent 4 }}
Expand Down
12 changes: 12 additions & 0 deletions chart/templates/prometheusrule.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,16 @@ spec:
annotations:
summary: More than one RPC read in ten seconds is failing.
runbook_url: {{ .Values.prometheusRule.runbookURL }}#wellspringrpcerrors
- alert: WellspringGrantFailed
expr: increase(wellspring_claims_finished_total{ {{- $target -}}, kind="grant", status="failed"}[15m]) > 0
labels: {severity: warning}
annotations:
summary: A grant's transfer failed; its caller sees status failed and must retry under a new grant ID.
runbook_url: {{ .Values.prometheusRule.runbookURL }}#wellspringgrantfailed
- alert: WellspringGrantAuthUnavailable
expr: increase(wellspring_grants_total{ {{- $target -}}, outcome="auth_unavailable"}[15m]) > 0
labels: {severity: warning}
annotations:
summary: wellspring cannot reach the Kubernetes API to review grant callers' tokens.
runbook_url: {{ .Values.prometheusRule.runbookURL }}#wellspringgrantauthunavailable
{{- end }}
5 changes: 5 additions & 0 deletions chart/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ spec:
- name: metrics
port: 9090
targetPort: metrics
{{- if .Values.admin.enabled }}
- name: admin
port: {{ .Values.admin.port }}
targetPort: admin
{{- end }}
25 changes: 25 additions & 0 deletions chart/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ spec:
containerPort: 8080
- name: metrics
containerPort: 9090
{{- if .Values.admin.enabled }}
- name: admin
containerPort: 8081
{{- end }}
envFrom:
- configMapRef:
name: {{ include "wellspring.fullname" . }}
Expand Down Expand Up @@ -99,6 +103,11 @@ spec:
mountPath: /var/run/wellspring/captcha
readOnly: true
{{- end }}
{{- if .Values.admin.enabled }}
- name: kube-api-access
mountPath: /var/run/secrets/kubernetes.io/serviceaccount
readOnly: true
{{- end }}
volumes:
{{- with .Values.persistence.existingClaim }}
- name: data
Expand All @@ -121,6 +130,22 @@ spec:
- key: {{ .Values.captcha.key }}
path: secret
{{- end }}
{{- if .Values.admin.enabled }}
# Only to review grant callers' tokens; the ServiceAccount can do
# nothing else.
- name: kube-api-access
projected:
defaultMode: 0440
sources:
- serviceAccountToken:
path: token
expirationSeconds: 3600
- configMap:
name: kube-root-ca.crt
items:
- key: ca.crt
path: ca.crt
{{- end }}
{{- if not .Values.persistence.existingClaim }}
# Kept when the release is uninstalled, and immutable once created.
volumeClaimTemplates:
Expand Down
Loading
Loading