From e82abea6b8ad7bbb17a25d70358d588cf19a7d0a Mon Sep 17 00:00:00 2001 From: pingqiu Date: Wed, 25 Nov 2026 00:20:11 -0800 Subject: [PATCH] k8s: Kubernetes installs run blockmaster with mutual TLS; the plaintext off-host bind flag is refused blockmaster refuses --insecure-external-bind (a non-loopback --listen needs mutual TLS; the runtime HTTP listener stays on loopback), and --launcher-master-tls-secret-prefix makes each generated volume mount its server's node certificate Secret and dial with it. The chart, the launcher renderer, the alpha/g15b/g15d manifests and gate scripts mount the Secrets and pass the TLS flags; network.externalStatus and the frontend runtime HTTP option fail the render. scripts/k8s-alpha-certs.sh issues development certificates and the role file. The systemd startup gate runs its off-loopback master with mutual TLS. Co-Authored-By: Claude Opus 5.5 --- seaweed-block/README.md | 10 +- seaweed-block/charts/seaweed-block/README.md | 10 +- .../seaweed-block/examples/values-3node.yaml | 2 +- .../seaweed-block/templates/_helpers.tpl | 29 +++++ .../seaweed-block/templates/blockmaster.yaml | 29 ++++- .../templates/csi-controller.yaml | 3 + .../seaweed-block/templates/csi-node.yaml | 3 + .../templates/failback-executor.yaml | 6 + .../templates/operator-status.yaml | 6 + .../charts/seaweed-block/values.schema.json | 9 ++ .../charts/seaweed-block/values.yaml | 18 +++ .../cmd/blockcsi/g15d_manifest_test.go | 28 +++-- seaweed-block/cmd/blockmaster/auth.go | 8 +- .../cmd/blockmaster/auth_flags_test.go | 11 +- .../cmd/blockmaster/external_bind_test.go | 39 +++--- seaweed-block/cmd/blockmaster/main.go | 26 ++-- seaweed-block/cmd/blockmaster/main_test.go | 5 +- .../startup_systemd_integration_test.go | 50 +++++++- seaweed-block/cmd/sw-block/main.go | 2 +- seaweed-block/cmd/sw-block/main_test.go | 4 +- seaweed-block/core/auth/authtest/certs.go | 8 +- .../core/host/master/journal_isolation.go | 13 +- seaweed-block/core/launcher/k8s_renderer.go | 58 ++++++++- .../core/launcher/k8s_renderer_test.go | 41 ++++++ .../core/ops/failback_runtime_grpc.go | 2 +- seaweed-block/deploy/k8s/alpha/README.md | 5 + .../deploy/k8s/alpha/block-stack.yaml | 19 ++- .../deploy/k8s/alpha/csi-controller.yaml | 9 ++ seaweed-block/deploy/k8s/alpha/csi-node.yaml | 9 ++ .../deploy/k8s/g15b/block-stack.yaml | 36 +++++- .../deploy/k8s/g15b/csi-controller.yaml | 9 ++ seaweed-block/deploy/k8s/g15b/csi-node.yaml | 9 ++ .../deploy/k8s/g15d/block-stack.yaml | 19 ++- .../deploy/k8s/g15d/csi-controller.yaml | 9 ++ seaweed-block/docs/design/invariants.md | 2 +- .../docs/design/kubernetes-block-design.md | 2 +- seaweed-block/docs/quickstart-kubernetes.md | 15 ++- seaweed-block/docs/standalone-deployment.md | 2 +- .../blockvolume-process-readiness.md | 2 +- seaweed-block/scripts/install-k8s-alpha.sh | 13 +- seaweed-block/scripts/k8s-alpha-certs.sh | 79 ++++++++++++ seaweed-block/scripts/k8s_alpha_certs_test.go | 117 ++++++++++++++++++ seaweed-block/scripts/run-alpha-app-demo.sh | 17 +-- seaweed-block/scripts/run-g15b-k8s-static.sh | 2 + seaweed-block/scripts/run-g15d-k8s-dynamic.sh | 2 + .../node-loss-topology-eligibility-chain.yaml | 2 +- 46 files changed, 683 insertions(+), 116 deletions(-) create mode 100755 seaweed-block/scripts/k8s-alpha-certs.sh create mode 100644 seaweed-block/scripts/k8s_alpha_certs_test.go diff --git a/seaweed-block/README.md b/seaweed-block/README.md index cb7bdebc5f..2787c44c4a 100644 --- a/seaweed-block/README.md +++ b/seaweed-block/README.md @@ -197,11 +197,11 @@ bash scripts/uninstall-k8s-alpha.sh "$PWD" && bash scripts/verify-helm-cleanup.s Full table and conditions: [Kubernetes status](docs/kubernetes-status.md); run evidence: [release notes](docs/releases/README.md). -**Upgrade note:** blockmaster now refuses a non-loopback `--listen` (and a -non-loopback `--frontend-publication-runtime-listen` when that API is on) -unless `--insecure-external-bind` is given, because its control API is -unauthenticated. The Helm chart and the shipped manifests already pass it; -a launcher of your own that binds blockmaster to a node address must add it. +**Upgrade note:** blockmaster listens off loopback only with mutual TLS +(`--tls-cert`, `--tls-key`, `--tls-client-ca`, `--role-file`); the runtime HTTP +listener always stays on loopback, and `--insecure-external-bind` is refused. +The Helm chart and the shipped manifests run with mutual TLS; create their +Secrets first ([quickstart](docs/quickstart-kubernetes.md)). ### Not claimed yet diff --git a/seaweed-block/charts/seaweed-block/README.md b/seaweed-block/charts/seaweed-block/README.md index 716d2147c2..06c39cc575 100644 --- a/seaweed-block/charts/seaweed-block/README.md +++ b/seaweed-block/charts/seaweed-block/README.md @@ -18,12 +18,18 @@ the live Kubernetes nodes and writes the node names/IPs that the launcher uses for placement. On a single-node lab it keeps loopback/local-consumer mode; on a multi-node lab it switches to non-loopback iSCSI with CHAP. For the experimental NVMe/TCP path, pass `--protocol nvme`; this switches to -non-loopback NVMe/TCP plus external status, without enabling iSCSI CHAP. +non-loopback NVMe/TCP, without enabling iSCSI CHAP. + +blockmaster runs with mutual TLS, so create its Secrets before installing +(`tls.*` values name them; the helper issues development certificates, one +node certificate per server id). ```bash SW_BLOCK_HELM_VALUES_OUT=values.day1.yaml \ bash scripts/generate-helm-values-day1.sh "$PWD" +bash scripts/k8s-alpha-certs.sh kube-system ~/.sw-block-alpha-tls ... + helm install sw-block charts/seaweed-block \ --namespace kube-system \ -f values.day1.yaml @@ -114,7 +120,7 @@ replication: network: externalISCSI: true externalNVMe: false - externalStatus: true + externalStatus: false rejectLoopbackPublishTargets: true chap: enabled: true diff --git a/seaweed-block/charts/seaweed-block/examples/values-3node.yaml b/seaweed-block/charts/seaweed-block/examples/values-3node.yaml index c27fd63bf2..ccee983eac 100644 --- a/seaweed-block/charts/seaweed-block/examples/values-3node.yaml +++ b/seaweed-block/charts/seaweed-block/examples/values-3node.yaml @@ -14,7 +14,7 @@ csiImage: network: externalISCSI: true externalNVMe: false - externalStatus: true + externalStatus: false # not supported with mutual TLS (the volume status stays on loopback) rejectLoopbackPublishTargets: true compat: diff --git a/seaweed-block/charts/seaweed-block/templates/_helpers.tpl b/seaweed-block/charts/seaweed-block/templates/_helpers.tpl index adaa23cfd2..2110a1e36e 100644 --- a/seaweed-block/charts/seaweed-block/templates/_helpers.tpl +++ b/seaweed-block/charts/seaweed-block/templates/_helpers.tpl @@ -55,3 +55,32 @@ helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} {{- .Values.storageClass.replicationFactor -}} {{- end -}} {{- end -}} + +{{/* Mutual TLS toward blockmaster for an in-cluster client: the Secret + .Values.tls.clientSecret mounted at /etc/sw-block/master-tls. */}} +{{- define "seaweed-block.masterTLSClientFlags" -}} +- "--master-tls-cert=/etc/sw-block/master-tls/tls.crt" +- "--master-tls-key=/etc/sw-block/master-tls/tls.key" +- "--master-ca=/etc/sw-block/master-tls/ca.crt" +{{- end -}} + +{{- define "seaweed-block.masterTLSClientEnv" -}} +- name: SW_BLOCK_TLS_CERT + value: /etc/sw-block/master-tls/tls.crt +- name: SW_BLOCK_TLS_KEY + value: /etc/sw-block/master-tls/tls.key +- name: SW_BLOCK_TLS_CA + value: /etc/sw-block/master-tls/ca.crt +{{- end -}} + +{{- define "seaweed-block.masterTLSClientMount" -}} +- name: master-tls + mountPath: /etc/sw-block/master-tls + readOnly: true +{{- end -}} + +{{- define "seaweed-block.masterTLSClientVolume" -}} +- name: master-tls + secret: + secretName: {{ .Values.tls.clientSecret }} +{{- end -}} diff --git a/seaweed-block/charts/seaweed-block/templates/blockmaster.yaml b/seaweed-block/charts/seaweed-block/templates/blockmaster.yaml index 2e7535f715..53f340d92b 100644 --- a/seaweed-block/charts/seaweed-block/templates/blockmaster.yaml +++ b/seaweed-block/charts/seaweed-block/templates/blockmaster.yaml @@ -1,8 +1,11 @@ {{- if and .Values.network.externalISCSI (not .Values.chap.enabled) -}} {{- fail "network.externalISCSI=true requires chap.enabled=true so cross-node iSCSI is not published without CHAP credentials" -}} {{- end -}} -{{- if and .Values.network.externalStatus (not (or .Values.network.externalISCSI .Values.network.externalNVMe)) -}} -{{- fail "network.externalStatus=true requires network.externalISCSI=true or network.externalNVMe=true because external status is only supported with external block frontend publishing" -}} +{{- if .Values.network.externalStatus -}} +{{- fail "network.externalStatus=true is not supported: blockmaster runs with mutual TLS and an authenticated volume's status listener stays on loopback" -}} +{{- end -}} +{{- if .Values.blockmaster.frontendPublicationRuntimeHTTP -}} +{{- fail "blockmaster.frontendPublicationRuntimeHTTP=true is not supported: the runtime HTTP API is unauthenticated and stays on loopback, out of reach of the executor pod" -}} {{- end -}} {{- if and (ne .Values.blockmaster.durableImpl "walstore") (not .Values.compat.launcherDurableImplFlag) -}} {{- fail "blockmaster.durableImpl requires compat.launcherDurableImplFlag=true because older published images do not accept --launcher-durable-impl" -}} @@ -98,15 +101,17 @@ spec: {{- if .Values.network.externalNVMe }} - "--launcher-external-nvme" {{- end }} - {{- if .Values.network.externalStatus }} - - "--launcher-external-status" - {{- end }} {{- if and .Values.network.rejectLoopbackPublishTargets .Values.compat.launcherRejectLoopbackFlag }} - "--launcher-reject-loopback-publish-targets" {{- end }} - "--launcher-kubernetes-apply" - "--listen=0.0.0.0:{{ .Values.blockmaster.listenPort }}" - - "--insecure-external-bind" + - "--tls-cert=/etc/sw-block/tls/tls.crt" + - "--tls-key=/etc/sw-block/tls/tls.key" + - "--tls-client-ca=/etc/sw-block/tls/ca.crt" + - "--role-file=/etc/sw-block/roles/roles" + - "--audit-log=/var/lib/sw-block/audit.log" + - "--launcher-master-tls-secret-prefix={{ .Values.tls.nodeSecretPrefix }}" {{- if .Values.blockmaster.failbackRuntimeRPC }} - "--failback-runtime-rpc" {{- end }} @@ -130,6 +135,12 @@ spec: mountPath: /var/lib/sw-block - name: manifests mountPath: /manifests + - name: tls + mountPath: /etc/sw-block/tls + readOnly: true + - name: roles + mountPath: /etc/sw-block/roles + readOnly: true volumes: - name: cluster-spec configMap: @@ -144,6 +155,12 @@ spec: {{- end }} - name: manifests emptyDir: {} + - name: tls + secret: + secretName: {{ .Values.tls.masterSecret }} + - name: roles + secret: + secretName: {{ .Values.tls.roleSecret }} --- apiVersion: v1 kind: Service diff --git a/seaweed-block/charts/seaweed-block/templates/csi-controller.yaml b/seaweed-block/charts/seaweed-block/templates/csi-controller.yaml index 5aa0ae0104..7817550ffc 100644 --- a/seaweed-block/charts/seaweed-block/templates/csi-controller.yaml +++ b/seaweed-block/charts/seaweed-block/templates/csi-controller.yaml @@ -26,6 +26,7 @@ spec: - "--endpoint=unix:///csi/csi.sock" - "--master=$(BLOCKMASTER_ADDR)" - "--node-id=$(NODE_NAME)" + {{- include "seaweed-block.masterTLSClientFlags" . | nindent 12 }} {{- if .Values.blockmaster.launcherPVCOwnerRef }} - "--kubernetes-pvc-uid-lookup" {{- end }} @@ -48,6 +49,7 @@ spec: volumeMounts: - name: socket-dir mountPath: /csi + {{- include "seaweed-block.masterTLSClientMount" . | nindent 12 }} - name: csi-provisioner image: {{ .Values.sidecars.provisionerImage | quote }} args: @@ -70,3 +72,4 @@ spec: volumes: - name: socket-dir emptyDir: {} + {{- include "seaweed-block.masterTLSClientVolume" . | nindent 8 }} diff --git a/seaweed-block/charts/seaweed-block/templates/csi-node.yaml b/seaweed-block/charts/seaweed-block/templates/csi-node.yaml index f7689c3704..26c920aea2 100644 --- a/seaweed-block/charts/seaweed-block/templates/csi-node.yaml +++ b/seaweed-block/charts/seaweed-block/templates/csi-node.yaml @@ -43,6 +43,7 @@ spec: - "--endpoint=unix:///csi/csi.sock" - "--master=$(BLOCKMASTER_ADDR)" - "--node-id=$(NODE_NAME)" + {{- include "seaweed-block.masterTLSClientFlags" . | nindent 12 }} {{- if .Values.stage2Multipath.enabled }} - "--stage2-multipath" {{- end }} @@ -75,6 +76,7 @@ spec: - name: udev-run mountPath: /run/udev readOnly: true + {{- include "seaweed-block.masterTLSClientMount" . | nindent 12 }} - name: csi-node-driver-registrar image: {{ .Values.sidecars.nodeDriverRegistrarImage | quote }} args: @@ -86,6 +88,7 @@ spec: - name: registration-dir mountPath: /registration volumes: + {{- include "seaweed-block.masterTLSClientVolume" . | nindent 8 }} - name: socket-dir hostPath: path: {{ .Values.csiNode.pluginPath | quote }} diff --git a/seaweed-block/charts/seaweed-block/templates/failback-executor.yaml b/seaweed-block/charts/seaweed-block/templates/failback-executor.yaml index fc0337eebf..294a705857 100644 --- a/seaweed-block/charts/seaweed-block/templates/failback-executor.yaml +++ b/seaweed-block/charts/seaweed-block/templates/failback-executor.yaml @@ -63,4 +63,10 @@ spec: - "--failback-runtime-url={{ .Values.failbackExecutor.execution.failbackRuntimeURL }}" {{- end }} - "--interval={{ .Values.failbackExecutor.interval }}" + env: + {{- include "seaweed-block.masterTLSClientEnv" . | nindent 12 }} + volumeMounts: + {{- include "seaweed-block.masterTLSClientMount" . | nindent 12 }} + volumes: + {{- include "seaweed-block.masterTLSClientVolume" . | nindent 8 }} {{- end }} diff --git a/seaweed-block/charts/seaweed-block/templates/operator-status.yaml b/seaweed-block/charts/seaweed-block/templates/operator-status.yaml index 7d44ce7253..91527ac6bb 100644 --- a/seaweed-block/charts/seaweed-block/templates/operator-status.yaml +++ b/seaweed-block/charts/seaweed-block/templates/operator-status.yaml @@ -38,4 +38,10 @@ spec: - "--namespace={{ .Release.Namespace }}" - "--cluster-name={{ .Values.operatorStatus.clusterName }}" - "--interval={{ .Values.operatorStatus.interval }}" + env: + {{- include "seaweed-block.masterTLSClientEnv" . | nindent 12 }} + volumeMounts: + {{- include "seaweed-block.masterTLSClientMount" . | nindent 12 }} + volumes: + {{- include "seaweed-block.masterTLSClientVolume" . | nindent 8 }} {{- end }} diff --git a/seaweed-block/charts/seaweed-block/values.schema.json b/seaweed-block/charts/seaweed-block/values.schema.json index a1bdaa9ed9..386036c560 100644 --- a/seaweed-block/charts/seaweed-block/values.schema.json +++ b/seaweed-block/charts/seaweed-block/values.schema.json @@ -59,6 +59,15 @@ "stateHostPath": { "type": "string" } } }, + "tls": { + "type": "object", + "properties": { + "masterSecret": { "type": "string", "minLength": 1 }, + "roleSecret": { "type": "string", "minLength": 1 }, + "clientSecret": { "type": "string", "minLength": 1 }, + "nodeSecretPrefix": { "type": "string", "minLength": 1 } + } + }, "network": { "type": "object", "properties": { diff --git a/seaweed-block/charts/seaweed-block/values.yaml b/seaweed-block/charts/seaweed-block/values.yaml index 2b99961d80..b441c8d531 100644 --- a/seaweed-block/charts/seaweed-block/values.yaml +++ b/seaweed-block/charts/seaweed-block/values.yaml @@ -78,6 +78,24 @@ replication: ackProfile: best-effort expectedSlotsPerVolume: 0 +# blockmaster listens on the pod network only with mutual TLS: create these +# Secrets before installing (docs/operator-guide.md, "Authenticate the control +# API"). Every certificate is signed by the CA in each Secret's ca.crt. +tls: + # blockmaster's own certificate (tls.crt, tls.key) and the CA every client + # certificate must verify against (ca.crt). Its subjectAltName must include + # the blockmaster Service name the clients dial. + masterSecret: sw-block-master-tls + # The role file (key "roles"): one line per certificate, + # "sha256: ". + roleSecret: sw-block-roles + # The in-cluster controllers' certificate (CSI, operator status, failback + # executor): tls.crt, tls.key, ca.crt. Its role-file line is admin. + clientSecret: sw-block-client-tls + # Each volume host's certificate is the Secret - + # (tls.crt, tls.key, ca.crt); its CN is the server id, its role node. + nodeSecretPrefix: sw-block-node-tls + network: externalISCSI: false externalNVMe: false diff --git a/seaweed-block/cmd/blockcsi/g15d_manifest_test.go b/seaweed-block/cmd/blockcsi/g15d_manifest_test.go index 5dfb390539..8f64a0b784 100644 --- a/seaweed-block/cmd/blockcsi/g15d_manifest_test.go +++ b/seaweed-block/cmd/blockcsi/g15d_manifest_test.go @@ -257,19 +257,25 @@ func TestNodeLoss_AlphaScriptsCanRejectLoopbackPublishTargets(t *testing.T) { } } -func TestNodeLoss_AlphaScriptsCanExposeExternalStatusForPromotionProbes(t *testing.T) { - for _, script := range []string{"install-k8s-alpha.sh", "run-alpha-app-demo.sh"} { +// The alpha scripts install the mutual-TLS Secrets before the stack, and +// refuse external status: an authenticated volume's status stays on loopback. +func TestAlphaScriptsInstallTLSAndRefuseExternalStatus(t *testing.T) { + for _, script := range []string{"install-k8s-alpha.sh", "run-alpha-app-demo.sh", "run-g15d-k8s-dynamic.sh", "run-g15b-k8s-static.sh"} { t.Run(script, func(t *testing.T) { body := g15dReadFile(t, "scripts", script) - for _, want := range []string{ - "SW_BLOCK_LAUNCHER_EXTERNAL_STATUS", - "SW_BLOCK_LAUNCHER_EXTERNAL_STATUS requires SW_BLOCK_LAUNCHER_EXTERNAL_ISCSI=1", - "--launcher-external-status", - "launcher_external_status=", - } { - if !strings.Contains(body, want) { - t.Fatalf("%s missing %q", script, want) - } + certs := strings.Index(body, "scripts/k8s-alpha-certs.sh") + stack := strings.Index(body, "kubectl apply -f \"$STACK_RENDERED\"") + if stack < 0 { + stack = strings.Index(body, "kubectl apply -f \"$ROOT/deploy/k8s/g15b/block-stack.yaml\"") + } + if certs < 0 || stack < 0 || certs > stack { + t.Fatalf("%s must apply the TLS Secrets before the block stack (certs at %d, stack at %d)", script, certs, stack) + } + if strings.Contains(body, "--launcher-external-status") { + t.Fatalf("%s still renders --launcher-external-status", script) + } + if strings.Contains(body, "SW_BLOCK_LAUNCHER_EXTERNAL_STATUS") && !strings.Contains(body, "SW_BLOCK_LAUNCHER_EXTERNAL_STATUS is not supported") { + t.Fatalf("%s accepts SW_BLOCK_LAUNCHER_EXTERNAL_STATUS without refusing it", script) } }) } diff --git a/seaweed-block/cmd/blockmaster/auth.go b/seaweed-block/cmd/blockmaster/auth.go index 32d1675f93..acb5c7aded 100644 --- a/seaweed-block/cmd/blockmaster/auth.go +++ b/seaweed-block/cmd/blockmaster/auth.go @@ -34,9 +34,8 @@ func (a authFlags) files() link.TLSFiles { return link.TLSFiles{Cert: a.tlsCert, Key: a.tlsKey, CA: a.tlsClientCA} } -// validate refuses a partial set, and the plaintext escape hatch together -// with authentication. -func (a authFlags) validate(insecureExternalBind bool) error { +// validate refuses a partial set. +func (a authFlags) validate() error { if a.auditLog != "" && !a.enabled() { return fmt.Errorf("--audit-log needs authentication (--tls-cert, --tls-key, --tls-client-ca, --role-file)") } @@ -49,9 +48,6 @@ func (a authFlags) validate(insecureExternalBind bool) error { if a.auditLog == "" { return fmt.Errorf("authentication needs --audit-log: every changing call is recorded before it runs, and is refused when it cannot be") } - if insecureExternalBind { - return fmt.Errorf("--insecure-external-bind cannot be combined with mutual TLS: the authenticated listener may bind any address; drop the flag") - } return nil } diff --git a/seaweed-block/cmd/blockmaster/auth_flags_test.go b/seaweed-block/cmd/blockmaster/auth_flags_test.go index a50d097400..70dd846616 100644 --- a/seaweed-block/cmd/blockmaster/auth_flags_test.go +++ b/seaweed-block/cmd/blockmaster/auth_flags_test.go @@ -6,8 +6,9 @@ import ( ) // Phase 0 flags: the four authentication flags go together; with them the -// listener may bind any address and --insecure-external-bind is refused; -// without them the control listener stays loopback-only. +// listener may bind any address; without them the control listener stays +// loopback-only; --insecure-external-bind is refused either way; the +// launcher's node TLS needs blockmaster's own and no external status. func TestAuthFlags(t *testing.T) { base := []string{"--authority-store", t.TempDir()} all := []string{"--tls-cert", "c.pem", "--tls-key", "k.pem", "--tls-client-ca", "ca.pem", "--role-file", "roles", "--audit-log", "audit.log"} @@ -23,7 +24,11 @@ func TestAuthFlags(t *testing.T) { {"partial: role file only", []string{"--role-file", "roles"}, "together"}, {"audit log without authentication", []string{"--audit-log", "audit.log"}, "needs authentication"}, {"authentication without an audit log", []string{"--listen", "192.0.2.5:9180", "--tls-cert", "c.pem", "--tls-key", "k.pem", "--tls-client-ca", "ca.pem", "--role-file", "roles"}, "needs --audit-log"}, - {"authenticated with --insecure-external-bind", append([]string{"--listen", "192.0.2.5:9180", "--insecure-external-bind"}, all...), "cannot be combined"}, + {"authenticated with --insecure-external-bind", append([]string{"--listen", "192.0.2.5:9180", "--insecure-external-bind"}, all...), "no longer accepted"}, + {"development mode with --insecure-external-bind", []string{"--listen", "192.0.2.5:9180", "--insecure-external-bind"}, "no longer accepted"}, + {"launcher node TLS without blockmaster TLS", []string{"--launcher-master-tls-secret-prefix", "sw-block-node-tls"}, "needs blockmaster's own mutual TLS"}, + {"launcher node TLS", append([]string{"--launcher-master-tls-secret-prefix", "sw-block-node-tls"}, all...), ""}, + {"launcher node TLS with external status", append([]string{"--launcher-master-tls-secret-prefix", "sw-block-node-tls", "--launcher-external-status"}, all...), "cannot be combined"}, } { _, err := parseFlags(append(append([]string{}, base...), c.args...)) switch { diff --git a/seaweed-block/cmd/blockmaster/external_bind_test.go b/seaweed-block/cmd/blockmaster/external_bind_test.go index 1aa740a42e..71c884bdea 100644 --- a/seaweed-block/cmd/blockmaster/external_bind_test.go +++ b/seaweed-block/cmd/blockmaster/external_bind_test.go @@ -6,10 +6,10 @@ import ( "testing" ) -// The unauthenticated control listeners bind loopback unless -// --insecure-external-bind is given: --listen always, and the runtime HTTP -// listener when its API is enabled. -func TestParseFlags_ControlListenersNeedInsecureExternalBind(t *testing.T) { +// A plaintext control listener binds loopback only: --listen in development +// mode, and the runtime HTTP listener always when its API is enabled. +// --insecure-external-bind is refused with a cure line. +func TestParseFlags_PlaintextControlListenersStayOnLoopback(t *testing.T) { base := func(extra ...string) []string { return append([]string{"--authority-store", t.TempDir()}, extra...) } for _, ok := range []string{"127.0.0.1:9333", "localhost:9333", "[::1]:9333", "127.0.0.1:0"} { if _, err := parseFlags(base("--listen", ok)); err != nil { @@ -18,36 +18,39 @@ func TestParseFlags_ControlListenersNeedInsecureExternalBind(t *testing.T) { } for _, bad := range []string{"0.0.0.0:9333", ":9333", "10.0.0.5:9333", "[::]:9333"} { _, err := parseFlags(base("--listen", bad)) - if err == nil || !strings.Contains(err.Error(), "--insecure-external-bind") { - t.Fatalf("--listen %s without the opt-in: %v, want a refusal naming --insecure-external-bind", bad, err) + if err == nil || !strings.Contains(err.Error(), "not a loopback address") || !strings.Contains(err.Error(), "--tls-cert") { + t.Fatalf("--listen %s in development mode: %v, want a refusal naming mutual TLS", bad, err) } - if _, err := parseFlags(base("--listen", bad, "--insecure-external-bind")); err != nil { - t.Fatalf("--listen %s with --insecure-external-bind: %v", bad, err) + if _, err := parseFlags(base("--listen", bad, "--insecure-external-bind")); err == nil || !strings.Contains(err.Error(), "no longer accepted") { + t.Fatalf("--listen %s with --insecure-external-bind: %v, want refused", bad, err) } } if _, err := parseFlags(base("--frontend-publication-runtime-listen", "0.0.0.0:9334")); err != nil { t.Fatalf("runtime listener disabled: its address is not checked: %v", err) } _, err := parseFlags(base("--frontend-publication-runtime-http", "--frontend-publication-runtime-listen", "0.0.0.0:9334")) - if err == nil || !strings.Contains(err.Error(), "frontend-publication-runtime-listen") { - t.Fatalf("enabled runtime listener on 0.0.0.0 without the opt-in: %v", err) - } - if _, err := parseFlags(base("--frontend-publication-runtime-http", "--frontend-publication-runtime-listen", "0.0.0.0:9334", "--insecure-external-bind")); err != nil { - t.Fatalf("with the opt-in: %v", err) + if err == nil || !strings.Contains(err.Error(), "frontend-publication-runtime-listen") || !strings.Contains(err.Error(), "always stays on loopback") { + t.Fatalf("enabled runtime listener on 0.0.0.0: %v, want refused", err) } } -// Every shipped manifest that binds blockmaster to 0.0.0.0 carries the -// explicit opt-in, so the change refuses nothing that ships. -func TestManifests_ExternalBlockmasterBindCarriesTheOptIn(t *testing.T) { +// No shipped manifest passes the removed flag or binds blockmaster off +// loopback without mutual TLS. +func TestManifests_NoPlaintextExternalBlockmasterBind(t *testing.T) { for _, p := range []string{"../../charts/seaweed-block/templates/blockmaster.yaml", "../../deploy/k8s/alpha/block-stack.yaml", "../../deploy/k8s/g15b/block-stack.yaml", "../../deploy/k8s/g15d/block-stack.yaml"} { b, err := os.ReadFile(p) if err != nil { t.Fatal(err) } s := string(b) - if strings.Contains(s, "--listen=0.0.0.0") && !strings.Contains(s, "--insecure-external-bind") { - t.Fatalf("%s binds blockmaster to 0.0.0.0 without --insecure-external-bind", p) + if strings.Contains(s, "--insecure-external-bind") { + t.Fatalf("%s passes --insecure-external-bind, which blockmaster refuses", p) + } + if strings.Contains(s, "--listen=0.0.0.0") && !strings.Contains(s, "--tls-cert") { + t.Fatalf("%s binds blockmaster to 0.0.0.0 without mutual TLS", p) + } + if strings.Contains(s, "--tls-cert") && !strings.Contains(s, "--audit-log") { + t.Fatalf("%s runs blockmaster with mutual TLS but without --audit-log, which it refuses", p) } } } diff --git a/seaweed-block/cmd/blockmaster/main.go b/seaweed-block/cmd/blockmaster/main.go index 9817499267..3c34d528ad 100644 --- a/seaweed-block/cmd/blockmaster/main.go +++ b/seaweed-block/cmd/blockmaster/main.go @@ -56,6 +56,7 @@ type flags struct { launcherExternalNVMe bool launcherExternalStatus bool launcherCHAPSecretName string + launcherMasterTLSSecretPrefix string launcherCHAPUserKey string launcherCHAPSecretKey string failbackRuntimeRPC bool @@ -82,13 +83,13 @@ func parseFlags(args []string) (flags, error) { fs.StringVar(&f.lifecycleStore, "lifecycle-store", "", "optional G9D product lifecycle registration store directory (desired volumes, node inventory, placement intents); read-only with respect to assignment publication") fs.StringVar(&f.lifecyclePlacementSeed, "lifecycle-placement-seed", "", "placement-only seed JSON; lifecycle volumes must already be registered (CreateVolume)") fs.StringVar(&f.clusterSpec, "cluster-spec", "", "cluster spec YAML; positive size_bytes imports desired volumes before topology/placement publication") - fs.StringVar(&f.listen, "listen", "127.0.0.1:0", "gRPC listen address (e.g. 127.0.0.1:9180); non-loopback requires --insecure-external-bind") + fs.StringVar(&f.listen, "listen", "127.0.0.1:0", "gRPC listen address (e.g. 127.0.0.1:9180); non-loopback requires mutual TLS (--tls-cert, --tls-key, --tls-client-ca, --role-file)") fs.StringVar(&f.auth.tlsCert, "tls-cert", "", "blockmaster's TLS certificate (PEM): with --tls-key, --tls-client-ca and --role-file, every gRPC call needs mutual TLS") fs.StringVar(&f.auth.tlsKey, "tls-key", "", "the key of --tls-cert (PEM)") fs.StringVar(&f.auth.tlsClientCA, "tls-client-ca", "", "CA (PEM) every client certificate must verify against") fs.StringVar(&f.auth.auditLog, "audit-log", "", "append-only audit log (JSON lines): every operator and admin call, refused node calls, role-file reloads") fs.StringVar(&f.auth.roleFile, "role-file", "", "role file: lines 'sha256: '; SIGHUP reloads it") - fs.BoolVar(&f.insecureExternalBind, "insecure-external-bind", false, "allow the unauthenticated control listeners (--listen, --frontend-publication-runtime-listen) on non-loopback addresses") + fs.BoolVar(&f.insecureExternalBind, "insecure-external-bind", false, "removed: refused at start (a non-loopback --listen needs mutual TLS; the runtime HTTP listener stays on loopback)") fs.StringVar(&f.topology, "topology", "", "path to accepted-topology YAML (required for assignment to mint)") fs.IntVar(&f.expectedSlotsPerVol, "expected-slots-per-volume", 3, "RF/expected slot count per volume; the controller rejects observation snapshots whose slot count differs (default 3, set to 2 for 2-node smoke clusters)") fs.DurationVar(&f.freshnessWindow, "freshness-window", 30*time.Second, "observation freshness window before a server's heartbeat expires") @@ -114,6 +115,7 @@ func parseFlags(args []string) (flags, error) { fs.BoolVar(&f.launcherExternalISCSI, "launcher-external-iscsi", false, "render generated iSCSI frontends on node addresses instead of loopback; requires --launcher-iscsi-chap-secret-name") fs.BoolVar(&f.launcherExternalNVMe, "launcher-external-nvme", false, "render generated NVMe/TCP frontends on node addresses instead of loopback; unauthenticated and intended only for explicit Kubernetes NVMe/TCP gates") fs.BoolVar(&f.launcherExternalStatus, "launcher-external-status", false, "render blockvolume status endpoints on node addresses instead of loopback; intended for explicit Kubernetes node-loss gates") + fs.StringVar(&f.launcherMasterTLSSecretPrefix, "launcher-master-tls-secret-prefix", "", "generated blockvolume Deployments dial blockmaster with mutual TLS from the Secret - (keys tls.crt, tls.key, ca.crt); needs blockmaster's own mutual TLS") fs.StringVar(&f.launcherCHAPSecretName, "launcher-iscsi-chap-secret-name", "", "optional Kubernetes Secret name used by generated blockvolume Deployments for target-side iSCSI CHAP") fs.StringVar(&f.launcherCHAPUserKey, "launcher-iscsi-chap-username-key", "chapUsername", "Kubernetes Secret key for generated blockvolume iSCSI CHAP username") fs.StringVar(&f.launcherCHAPSecretKey, "launcher-iscsi-chap-secret-key", "chapSecret", "Kubernetes Secret key for generated blockvolume iSCSI CHAP secret") @@ -154,19 +156,28 @@ func parseFlags(args []string) (flags, error) { if err := master.ValidateStatusListen(f.statusListen); err != nil { return flags{}, err } - if err := f.auth.validate(f.insecureExternalBind); err != nil { + if f.insecureExternalBind { + return flags{}, fmt.Errorf("--insecure-external-bind is no longer accepted: a plaintext control listener stays on loopback; to listen on the node network start blockmaster with mutual TLS (--tls-cert, --tls-key, --tls-client-ca, --role-file) and drop the flag") + } + if err := f.auth.validate(); err != nil { return flags{}, err } if !f.auth.enabled() { - if err := master.ValidateControlListen("listen", f.listen, f.insecureExternalBind); err != nil { - return flags{}, err + if err := master.ValidateControlListen("listen", f.listen); err != nil { + return flags{}, fmt.Errorf("%w; start blockmaster with mutual TLS (--tls-cert, --tls-key, --tls-client-ca, --role-file) to listen on the node network", err) } } if f.frontendPublicationRuntimeHTTP { - if err := master.ValidateControlListen("frontend-publication-runtime-listen", f.frontendPublicationRuntimeListen, f.insecureExternalBind); err != nil { - return flags{}, err + if err := master.ValidateControlListen("frontend-publication-runtime-listen", f.frontendPublicationRuntimeListen); err != nil { + return flags{}, fmt.Errorf("%w; the runtime HTTP API is unauthenticated and always stays on loopback", err) } } + if f.launcherMasterTLSSecretPrefix != "" && !f.auth.enabled() { + return flags{}, fmt.Errorf("--launcher-master-tls-secret-prefix needs blockmaster's own mutual TLS (--tls-cert, --tls-key, --tls-client-ca, --role-file)") + } + if f.launcherMasterTLSSecretPrefix != "" && f.launcherExternalStatus { + return flags{}, fmt.Errorf("--launcher-external-status cannot be combined with --launcher-master-tls-secret-prefix: an authenticated volume's status listener stays on loopback") + } if f.launcherExternalISCSI && f.launcherCHAPSecretName == "" { return flags{}, fmt.Errorf("cannot enable --launcher-external-iscsi without --launcher-iscsi-chap-secret-name") } @@ -474,6 +485,7 @@ func runLifecycleLauncherTick(h *master.Host, f flags) error { ExternalISCSI: f.launcherExternalISCSI, ExternalNVMe: f.launcherExternalNVMe, ExternalStatus: f.launcherExternalStatus, + MasterTLSSecretPrefix: f.launcherMasterTLSSecretPrefix, NVMeMaxH2CDataLength: uint32(f.launcherNVMeMaxH2CDataLength), ISCSICHAP: launcher.CHAPSecretRef{ Name: f.launcherCHAPSecretName, diff --git a/seaweed-block/cmd/blockmaster/main_test.go b/seaweed-block/cmd/blockmaster/main_test.go index 0bed50e3c5..f7e7b0e820 100644 --- a/seaweed-block/cmd/blockmaster/main_test.go +++ b/seaweed-block/cmd/blockmaster/main_test.go @@ -86,13 +86,12 @@ func TestParseFlags_FrontendPublicationRuntimeHTTPDisabledByDefault(t *testing.T f, err = parseFlags([]string{ "--authority-store", "authority-dir", "--frontend-publication-runtime-http", - "--frontend-publication-runtime-listen", "0.0.0.0:9334", - "--insecure-external-bind", // a non-loopback control listener is an explicit choice + "--frontend-publication-runtime-listen", "127.0.0.1:9334", // unauthenticated: loopback only }) if err != nil { t.Fatalf("parseFlags with frontend publication runtime HTTP: %v", err) } - if !f.frontendPublicationRuntimeHTTP || f.frontendPublicationRuntimeListen != "0.0.0.0:9334" { + if !f.frontendPublicationRuntimeHTTP || f.frontendPublicationRuntimeListen != "127.0.0.1:9334" { t.Fatalf("frontend publication runtime flags=%+v", f) } } diff --git a/seaweed-block/cmd/blockvolume/startup_systemd_integration_test.go b/seaweed-block/cmd/blockvolume/startup_systemd_integration_test.go index 9a5e3996fa..898a44e6ec 100644 --- a/seaweed-block/cmd/blockvolume/startup_systemd_integration_test.go +++ b/seaweed-block/cmd/blockvolume/startup_systemd_integration_test.go @@ -19,12 +19,13 @@ import ( "testing" "time" + "github.com/seaweedfs/seaweed-block/core/auth/authtest" "github.com/seaweedfs/seaweed-block/core/frontend/durable" hostvolume "github.com/seaweedfs/seaweed-block/core/host/volume" control "github.com/seaweedfs/seaweed-block/core/rpc/control" + "github.com/seaweedfs/seaweed-block/core/rpc/link" "github.com/seaweedfs/seaweed-block/core/storage" "google.golang.org/grpc" - "google.golang.org/grpc/credentials/insecure" ) // Real systemd owns every restart. No test goroutine relaunches the holder. @@ -79,18 +80,27 @@ func TestSystemdExpiredStartupExits75ThenRegrantServes(t *testing.T) { if err := os.WriteFile(spec, []byte(cfg), 0600); err != nil { t.Fatal(err) } + // The master listens off loopback, so it runs with mutual TLS: the test + // is an admin, s1 and s2 are nodes (certificates in root/tls). + tlsDir := gap1WriteTLS(t, root, target) fixture.start(t, stem+"-master", false, filepath.Join(bin, "blockmaster"), - "--listen", masterListen, "--insecure-external-bind", "--authority-store", filepath.Join(root, "auth"), "--lifecycle-store", filepath.Join(root, "life"), + "--listen", masterListen, "--tls-cert", filepath.Join(tlsDir, "master.crt"), "--tls-key", filepath.Join(tlsDir, "master.key"), + "--tls-client-ca", filepath.Join(tlsDir, "ca.crt"), "--role-file", filepath.Join(tlsDir, "roles"), "--audit-log", filepath.Join(tlsDir, "audit.log"), "--authority-store", filepath.Join(root, "auth"), "--lifecycle-store", filepath.Join(root, "life"), "--cluster-spec", spec, "--lifecycle-product-loop-interval", "200ms", "--expected-slots-per-volume", "1", "--workspace-rpc", "--workspace-head-base-url", "http://"+cluster.filerHTTP+base) w4WaitTCP(t, masterAddr, 20*time.Second) - conn, err := grpc.NewClient(masterAddr, grpc.WithTransportCredentials(insecure.NewCredentials())) + admin, err := link.ClientCredentials(link.TLSFiles{Cert: filepath.Join(tlsDir, "admin.crt"), Key: filepath.Join(tlsDir, "admin.key"), CA: filepath.Join(tlsDir, "ca.crt")}, "") + if err != nil { + t.Fatal(err) + } + conn, err := grpc.NewClient(masterAddr, admin) if err != nil { t.Fatal(err) } t.Cleanup(func() { _ = conn.Close() }) ws := control.NewWorkspaceServiceClient(conn) - args := []string{"--master", masterAddr, "--server-id", "s1", "--volume-id", volume, "--replica-id", "r1", + args := []string{"--master", masterAddr, "--server-id", "s1", + "--master-tls-cert", filepath.Join(tlsDir, "s1.crt"), "--master-tls-key", filepath.Join(tlsDir, "s1.key"), "--master-ca", filepath.Join(tlsDir, "ca.crt"), "--volume-id", volume, "--replica-id", "r1", "--data-addr", dataAddr, "--ctrl-addr", ctrlAddr, "--heartbeat-interval", "200ms", "--t1-readiness", "--status-addr", statusAddr, "--durable-root", filepath.Join(root, "store"), "--durable-impl", "walstore-chunk", "--durable-blocks", "64", "--chunk-filer", cluster.filerGRPC, "--chunk-path", base, "--chunk-control-endpoint", "--workspace-lease", @@ -680,6 +690,35 @@ type gap1Target struct { masterAddr, dataAddr, ctrlAddr string } +// gap1WriteTLS writes a CA, the master's certificate (valid for loopback and +// the target's address), node certificates for s1 and s2, an admin +// certificate and the role file to root/tls. +func gap1WriteTLS(t *testing.T, root string, target gap1Target) string { + t.Helper() + dir := filepath.Join(root, "tls") + if err := os.MkdirAll(dir, 0o700); err != nil { + t.Fatal(err) + } + host, _, err := net.SplitHostPort(target.masterAddr) + if err != nil { + t.Fatal(err) + } + ca := authtest.NewCA(t, "gap1 CA") + ca.WriteCA(t, dir) + until := time.Now().Add(24 * time.Hour) + ca.Issue(t, "blockmaster", until, net.ParseIP(host)).WriteFiles(t, dir, "master") + var roles strings.Builder + for _, p := range []struct{ name, role, id string }{{"s1", "node", "s1"}, {"s2", "node", "s2"}, {"admin", "admin", "gap1-test"}} { + leaf := ca.Issue(t, p.id, until) + leaf.WriteFiles(t, dir, p.name) + fmt.Fprintln(&roles, leaf.Fingerprint, p.role, p.id) + } + if err := os.WriteFile(filepath.Join(dir, "roles"), []byte(roles.String()), 0o600); err != nil { + t.Fatal(err) + } + return dir +} + func gap1TargetAddresses(t *testing.T, masterAddr string) (gap1Target, string) { t.Helper() _, port, err := net.SplitHostPort(masterAddr) @@ -731,7 +770,8 @@ func gap1PrestartedTargetServesAfterMove(t *testing.T, fixture *gap1Fixture, ws changed := append([]string(nil), args...) addr, nvmeAddr := leaseBinaryAddress(t), leaseBinaryAddress(t) nqn := "nqn.2026-11.test:" + stem + "-prestarted-target" - replacements := map[string]string{"--master": target.masterAddr, "--server-id": "s2", "--data-addr": target.dataAddr, "--ctrl-addr": target.ctrlAddr, "--status-addr": addr, "--durable-root": filepath.Join(root, "target-store"), "--nvme-listen": nvmeAddr, "--nvme-subsysnqn": nqn} + replacements := map[string]string{"--master": target.masterAddr, "--server-id": "s2", "--data-addr": target.dataAddr, "--ctrl-addr": target.ctrlAddr, "--status-addr": addr, "--durable-root": filepath.Join(root, "target-store"), "--nvme-listen": nvmeAddr, "--nvme-subsysnqn": nqn, + "--master-tls-cert": filepath.Join(root, "tls", "s2.crt"), "--master-tls-key": filepath.Join(root, "tls", "s2.key")} for i := 0; i+1 < len(changed); i++ { if value, ok := replacements[changed[i]]; ok { changed[i+1] = value diff --git a/seaweed-block/cmd/sw-block/main.go b/seaweed-block/cmd/sw-block/main.go index 14ade59525..6b97f4ac45 100644 --- a/seaweed-block/cmd/sw-block/main.go +++ b/seaweed-block/cmd/sw-block/main.go @@ -1882,7 +1882,7 @@ func runOpsGenerateHelmValues(args []string, stdout, stderr io.Writer) int { Network: helmValuesNetwork{ ExternalISCSI: externalISCSI, ExternalNVMe: externalNVMe, - ExternalStatus: multiNode || nvmeTransport == "rdma", + ExternalStatus: false, // blockmaster runs with mutual TLS: volume status stays on loopback RejectLoopbackPublishTargets: multiNode || nvmeTransport == "rdma", }, Compat: helmValuesCompat{ diff --git a/seaweed-block/cmd/sw-block/main_test.go b/seaweed-block/cmd/sw-block/main_test.go index 07af7d5c32..6aa24b69fb 100644 --- a/seaweed-block/cmd/sw-block/main_test.go +++ b/seaweed-block/cmd/sw-block/main_test.go @@ -2631,7 +2631,7 @@ func TestOpsGenerateHelmValuesMultiNodeExternalISCSI(t *testing.T) { "expectedSlotsPerVolume: 3", "externalISCSI: true", "externalNVMe: false", - "externalStatus: true", + "externalStatus: false", "rejectLoopbackPublishTargets: true", "restartPersistence:", "mode: ephemeral", @@ -2700,7 +2700,7 @@ func TestOpsGenerateHelmValuesMultiNodeExternalNVMe(t *testing.T) { "protocol: nvme", "externalISCSI: false", "externalNVMe: true", - "externalStatus: true", + "externalStatus: false", "rejectLoopbackPublishTargets: true", "enabled: false", "create: false", diff --git a/seaweed-block/core/auth/authtest/certs.go b/seaweed-block/core/auth/authtest/certs.go index e9cfe7c718..f9a3c9a1fe 100644 --- a/seaweed-block/core/auth/authtest/certs.go +++ b/seaweed-block/core/auth/authtest/certs.go @@ -67,9 +67,9 @@ func NewCA(t testing.TB, name string) *CA { var serial = big.NewInt(100) // Issue signs a leaf certificate with the given CN that expires at notAfter; -// it is valid as a TLS client and server certificate for 127.0.0.1 and -// localhost. -func (ca *CA) Issue(t testing.TB, cn string, notAfter time.Time) *Leaf { +// it is valid as a TLS client and server certificate for 127.0.0.1, +// localhost and any extra IP addresses. +func (ca *CA) Issue(t testing.TB, cn string, notAfter time.Time, extraIPs ...net.IP) *Leaf { t.Helper() key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) if err != nil { @@ -84,7 +84,7 @@ func (ca *CA) Issue(t testing.TB, cn string, notAfter time.Time) *Leaf { KeyUsage: x509.KeyUsageDigitalSignature, ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth, x509.ExtKeyUsageServerAuth}, DNSNames: []string{"localhost"}, - IPAddresses: []net.IP{net.ParseIP("127.0.0.1")}, + IPAddresses: append([]net.IP{net.ParseIP("127.0.0.1")}, extraIPs...), } der, err := x509.CreateCertificate(rand.Reader, tmpl, ca.Cert, &key.PublicKey, ca.key) if err != nil { diff --git a/seaweed-block/core/host/master/journal_isolation.go b/seaweed-block/core/host/master/journal_isolation.go index eb4bd99814..2bfbdc4c8f 100644 --- a/seaweed-block/core/host/master/journal_isolation.go +++ b/seaweed-block/core/host/master/journal_isolation.go @@ -169,12 +169,11 @@ func ValidateStatusListen(addr string) error { return fmt.Errorf("--status-listen %q must be a loopback address (127.0.0.0/8, ::1 or localhost)", addr) } -// ValidateControlListen refuses a control listener on a non-loopback address -// unless allowExternal: the gRPC control API and the runtime HTTP API are -// unauthenticated, so binding them to the node network must be an explicit -// choice (--insecure-external-bind). An empty address is off. -func ValidateControlListen(flag, addr string, allowExternal bool) error { - if addr == "" || allowExternal { +// ValidateControlListen refuses an unauthenticated control listener (the +// plaintext gRPC control API, the runtime HTTP API) on a non-loopback +// address. An empty address is off. +func ValidateControlListen(flag, addr string) error { + if addr == "" { return nil } host, _, err := net.SplitHostPort(addr) @@ -187,7 +186,7 @@ func ValidateControlListen(flag, addr string, allowExternal bool) error { if ip := net.ParseIP(host); ip != nil && ip.IsLoopback() { return nil } - return fmt.Errorf("--%s %q is not a loopback address: the control API is unauthenticated; pass --insecure-external-bind to expose it on the node network", flag, addr) + return fmt.Errorf("--%s %q is not a loopback address: an unauthenticated listener stays on loopback", flag, addr) } // WorkspaceLeaseStatus is the GET /status/workspace-lease body. diff --git a/seaweed-block/core/launcher/k8s_renderer.go b/seaweed-block/core/launcher/k8s_renderer.go index ff163a5fc2..3543034f0d 100644 --- a/seaweed-block/core/launcher/k8s_renderer.go +++ b/seaweed-block/core/launcher/k8s_renderer.go @@ -31,6 +31,11 @@ type K8sRenderConfig struct { ExternalStatus bool NVMeMaxH2CDataLength uint32 ISCSICHAP CHAPSecretRef + // MasterTLSSecretPrefix, when set, gives every volume mutual TLS to + // blockmaster: the Secret - (keys tls.crt, tls.key, + // ca.crt; the certificate's CN is the server id) is mounted read-only and + // passed as --master-tls-cert/--master-tls-key/--master-ca. + MasterTLSSecretPrefix string } type CHAPSecretRef struct { @@ -85,6 +90,9 @@ func RenderBlockVolumeDeployments(plan lifecycle.BlockVolumeWorkloadPlan, cfg K8 if cfg.MasterAddr == "" { return nil, fmt.Errorf("launcher: master addr is required") } + if cfg.MasterTLSSecretPrefix != "" && cfg.ExternalStatus { + return nil, fmt.Errorf("launcher: external status cannot be combined with master TLS: an authenticated volume's status listener stays on loopback") + } namespace := cfg.Namespace ownerRefs, err := ownerReferences(plan, cfg) if err != nil { @@ -102,6 +110,14 @@ func RenderBlockVolumeDeployments(plan lifecycle.BlockVolumeWorkloadPlan, cfg K8 } volumeMounts := []volumeMount{{Name: "state", MountPath: stateMountPath}} volumes := []volume{stateVolume(cfg)} + if cfg.MasterTLSSecretPrefix != "" { + secret, err := masterTLSSecretName(cfg.MasterTLSSecretPrefix, replica.ServerID) + if err != nil { + return nil, err + } + volumeMounts = append(volumeMounts, volumeMount{Name: "master-tls", MountPath: masterTLSMountPath, ReadOnly: true}) + volumes = append(volumes, volume{Name: "master-tls", Secret: &secretVolume{SecretName: secret}}) + } var securityContext *containerSecurityContext if plan.Protocol == "nvme" && plan.NVMeTransport == "rdma" { volumeMounts = append(volumeMounts, @@ -168,6 +184,30 @@ func RenderBlockVolumeDeployments(plan lifecycle.BlockVolumeWorkloadPlan, cfg K8 return out, nil } +const masterTLSMountPath = "/etc/sw-block/master-tls" + +// masterTLSSecretName is the Secret holding one server's node certificate. +// The server id is the certificate's CN, so it is used as given: an id that +// cannot be part of a Secret name is refused, never rewritten. +func masterTLSSecretName(prefix, serverID string) (string, error) { + name := prefix + "-" + serverID + if serverID == "" || len(name) > 253 || !dnsSubdomain(name) { + return "", fmt.Errorf("launcher: master TLS Secret name %q for server id %q is not a valid Kubernetes name (lowercase letters, digits, '-' and '.')", name, serverID) + } + return name, nil +} + +func dnsSubdomain(s string) bool { + for i, c := range s { + alnum := c >= 'a' && c <= 'z' || c >= '0' && c <= '9' + edge := i == 0 || i == len(s)-1 + if !alnum && (edge || c != '-' && c != '.') { + return false + } + } + return s != "" +} + func stateVolume(cfg K8sRenderConfig) volume { if cfg.StateHostPathBase == "" { return volume{Name: "state", EmptyDir: &emptyDir{}} @@ -215,6 +255,13 @@ func blockVolumeArgs(plan lifecycle.BlockVolumeWorkloadPlan, replica lifecycle.B if cfg.WALRecoveryTestDisableFlusher { args = append(args, "--durable-wal-recovery-test-disable-flusher") } + if cfg.MasterTLSSecretPrefix != "" { + args = append(args, + "--master-tls-cert="+masterTLSMountPath+"/tls.crt", + "--master-tls-key="+masterTLSMountPath+"/tls.key", + "--master-ca="+masterTLSMountPath+"/ca.crt", + ) + } if cfg.EnableStatus { port, err := blockVolumeStatusPort(plan, replica) if err != nil { @@ -493,9 +540,14 @@ type volumeMount struct { } type volume struct { - Name string `yaml:"name"` - EmptyDir *emptyDir `yaml:"emptyDir,omitempty"` - HostPath *hostPath `yaml:"hostPath,omitempty"` + Name string `yaml:"name"` + EmptyDir *emptyDir `yaml:"emptyDir,omitempty"` + HostPath *hostPath `yaml:"hostPath,omitempty"` + Secret *secretVolume `yaml:"secret,omitempty"` +} + +type secretVolume struct { + SecretName string `yaml:"secretName"` } type emptyDir struct{} diff --git a/seaweed-block/core/launcher/k8s_renderer_test.go b/seaweed-block/core/launcher/k8s_renderer_test.go index 79defd8187..73b4a66dad 100644 --- a/seaweed-block/core/launcher/k8s_renderer_test.go +++ b/seaweed-block/core/launcher/k8s_renderer_test.go @@ -738,3 +738,44 @@ func sampleWorkloadPlan() lifecycle.BlockVolumeWorkloadPlan { }, } } + +// With a master TLS Secret prefix, each volume mounts its own server's node +// certificate and dials blockmaster with it; an id that cannot name a Secret, +// and external status, are refused. +func TestK8sRenderer_MasterTLSMountsTheServersNodeSecret(t *testing.T) { + plan := sampleWorkloadPlan() + manifests, err := RenderBlockVolumeDeployments(plan, K8sRenderConfig{MasterAddr: "m:9333", MasterTLSSecretPrefix: "sw-block-node-tls"}) + if err != nil { + t.Fatalf("RenderBlockVolumeDeployments: %v", err) + } + for i, m := range manifests { + raw := string(m.YAML) + for _, want := range []string{ + "secretName: sw-block-node-tls-" + plan.Replicas[i].ServerID, + "mountPath: /etc/sw-block/master-tls", + "--master-tls-cert=/etc/sw-block/master-tls/tls.crt", + "--master-tls-key=/etc/sw-block/master-tls/tls.key", + "--master-ca=/etc/sw-block/master-tls/ca.crt", + } { + if !strings.Contains(raw, want) { + t.Fatalf("manifest %s missing %q:\n%s", m.Name, want, raw) + } + } + } + plain, err := RenderBlockVolumeDeployments(plan, K8sRenderConfig{MasterAddr: "m:9333"}) + if err != nil || strings.Contains(string(plain[0].YAML), "master-tls") { + t.Fatalf("without a prefix the manifest must carry no master TLS: %v\n%s", err, plain[0].YAML) + } + + bad := sampleWorkloadPlan() + bad.Replicas[0].ServerID = "Node_A" + if _, err := RenderBlockVolumeDeployments(bad, K8sRenderConfig{MasterAddr: "m:9333", MasterTLSSecretPrefix: "sw-block-node-tls"}); err == nil || !strings.Contains(err.Error(), "not a valid Kubernetes name") { + t.Fatalf("server id Node_A: %v, want refused", err) + } + if _, err := RenderBlockVolumeDeployments(plan, K8sRenderConfig{ + MasterAddr: "m:9333", MasterTLSSecretPrefix: "sw-block-node-tls", + EnableStatus: true, ExternalISCSI: true, ExternalStatus: true, ISCSICHAP: CHAPSecretRef{Name: "chap"}, + }); err == nil || !strings.Contains(err.Error(), "external status") { + t.Fatalf("external status with master TLS: %v, want refused", err) + } +} diff --git a/seaweed-block/core/ops/failback_runtime_grpc.go b/seaweed-block/core/ops/failback_runtime_grpc.go index d104e13b83..c8ceab50e9 100644 --- a/seaweed-block/core/ops/failback_runtime_grpc.go +++ b/seaweed-block/core/ops/failback_runtime_grpc.go @@ -29,7 +29,7 @@ func (r *GRPCFailbackRuntime) ExecuteFailback(ctx context.Context, req FailbackR if len(r.Opts) > 0 { conn, err = link.DialWith(r.Addr, r.Opts...) } else { - conn, err = link.Dial(r.Addr) + conn, err = link.DialMasterFromEnv(r.Addr) } if err != nil { return FailbackRuntimeResult{}, err diff --git a/seaweed-block/deploy/k8s/alpha/README.md b/seaweed-block/deploy/k8s/alpha/README.md index 50f78bb880..b63fe8efd8 100644 --- a/seaweed-block/deploy/k8s/alpha/README.md +++ b/seaweed-block/deploy/k8s/alpha/README.md @@ -89,6 +89,11 @@ YAML files manually, replace `sw-block:local` and `sw-block-csi:local` yourself. ## Deploy +blockmaster runs with mutual TLS: `scripts/install-k8s-alpha.sh` applies the +Secrets with `scripts/k8s-alpha-certs.sh` (development CA, keys under +`$SW_BLOCK_TLS_DIR`, default `~/.local/state/sw-block-alpha-tls`). By hand, run +`bash scripts/k8s-alpha-certs.sh kube-system ` first. + The blockmaster manifest contains a `__NODE_NAME__` placeholder for the lab node. Render it first: diff --git a/seaweed-block/deploy/k8s/alpha/block-stack.yaml b/seaweed-block/deploy/k8s/alpha/block-stack.yaml index 12630817d5..1ea5da978e 100644 --- a/seaweed-block/deploy/k8s/alpha/block-stack.yaml +++ b/seaweed-block/deploy/k8s/alpha/block-stack.yaml @@ -46,12 +46,23 @@ spec: - "--launcher-iscsi-port-base=3260" - "--launcher-kubernetes-apply" - "--listen=0.0.0.0:9333" - - "--insecure-external-bind" + - "--tls-cert=/etc/sw-block/tls/tls.crt" + - "--tls-key=/etc/sw-block/tls/tls.key" + - "--tls-client-ca=/etc/sw-block/tls/ca.crt" + - "--role-file=/etc/sw-block/roles/roles" + - "--audit-log=/var/lib/sw-block/audit.log" + - "--launcher-master-tls-secret-prefix=sw-block-node-tls" - "--expected-slots-per-volume=__EXPECTED_SLOTS_PER_VOLUME__" ports: - name: grpc containerPort: 9333 volumeMounts: + - name: tls + mountPath: /etc/sw-block/tls + readOnly: true + - name: roles + mountPath: /etc/sw-block/roles + readOnly: true - name: cluster-spec mountPath: /config readOnly: true @@ -60,6 +71,12 @@ spec: - name: manifests mountPath: /manifests volumes: + - name: tls + secret: + secretName: sw-block-master-tls + - name: roles + secret: + secretName: sw-block-roles - name: cluster-spec configMap: name: sw-block-cluster-spec diff --git a/seaweed-block/deploy/k8s/alpha/csi-controller.yaml b/seaweed-block/deploy/k8s/alpha/csi-controller.yaml index 4efdd74a16..674664f321 100644 --- a/seaweed-block/deploy/k8s/alpha/csi-controller.yaml +++ b/seaweed-block/deploy/k8s/alpha/csi-controller.yaml @@ -22,6 +22,9 @@ spec: - "--endpoint=unix:///csi/csi.sock" - "--master=$(BLOCKMASTER_ADDR)" - "--node-id=$(NODE_NAME)" + - "--master-tls-cert=/etc/sw-block/master-tls/tls.crt" + - "--master-tls-key=/etc/sw-block/master-tls/tls.key" + - "--master-ca=/etc/sw-block/master-tls/ca.crt" env: - name: BLOCKMASTER_ADDR value: "blockmaster.kube-system.svc.cluster.local:9333" @@ -30,6 +33,9 @@ spec: fieldRef: fieldPath: spec.nodeName volumeMounts: + - name: master-tls + mountPath: /etc/sw-block/master-tls + readOnly: true - name: socket-dir mountPath: /csi - name: csi-provisioner @@ -52,5 +58,8 @@ spec: - name: socket-dir mountPath: /csi volumes: + - name: master-tls + secret: + secretName: sw-block-client-tls - name: socket-dir emptyDir: {} diff --git a/seaweed-block/deploy/k8s/alpha/csi-node.yaml b/seaweed-block/deploy/k8s/alpha/csi-node.yaml index 2357b9c24c..a185e24b97 100644 --- a/seaweed-block/deploy/k8s/alpha/csi-node.yaml +++ b/seaweed-block/deploy/k8s/alpha/csi-node.yaml @@ -37,6 +37,9 @@ spec: - "--endpoint=unix:///csi/csi.sock" - "--master=$(BLOCKMASTER_ADDR)" - "--node-id=$(NODE_NAME)" + - "--master-tls-cert=/etc/sw-block/master-tls/tls.crt" + - "--master-tls-key=/etc/sw-block/master-tls/tls.key" + - "--master-ca=/etc/sw-block/master-tls/ca.crt" env: - name: BLOCKMASTER_ADDR value: "blockmaster.kube-system.svc.cluster.local:9333" @@ -47,6 +50,9 @@ spec: securityContext: privileged: true volumeMounts: + - name: master-tls + mountPath: /etc/sw-block/master-tls + readOnly: true - name: socket-dir mountPath: /csi - name: kubelet-dir @@ -70,6 +76,9 @@ spec: - name: registration-dir mountPath: /registration volumes: + - name: master-tls + secret: + secretName: sw-block-client-tls - name: socket-dir hostPath: path: /var/lib/kubelet/plugins/block.csi.seaweedfs.com diff --git a/seaweed-block/deploy/k8s/g15b/block-stack.yaml b/seaweed-block/deploy/k8s/g15b/block-stack.yaml index 08a4c558c8..7b9ad654b4 100644 --- a/seaweed-block/deploy/k8s/g15b/block-stack.yaml +++ b/seaweed-block/deploy/k8s/g15b/block-stack.yaml @@ -43,18 +43,34 @@ spec: - "--cluster-spec=/config/cluster-spec.yaml" - "--lifecycle-product-loop-interval=100ms" - "--listen=0.0.0.0:9333" - - "--insecure-external-bind" + - "--tls-cert=/etc/sw-block/tls/tls.crt" + - "--tls-key=/etc/sw-block/tls/tls.key" + - "--tls-client-ca=/etc/sw-block/tls/ca.crt" + - "--role-file=/etc/sw-block/roles/roles" + - "--audit-log=/var/lib/sw-block/audit.log" - "--expected-slots-per-volume=2" ports: - name: grpc containerPort: 9333 volumeMounts: + - name: tls + mountPath: /etc/sw-block/tls + readOnly: true + - name: roles + mountPath: /etc/sw-block/roles + readOnly: true - name: cluster-spec mountPath: /config readOnly: true - name: state mountPath: /var/lib/sw-block volumes: + - name: tls + secret: + secretName: sw-block-master-tls + - name: roles + secret: + secretName: sw-block-roles - name: cluster-spec configMap: name: sw-block-cluster-spec @@ -99,6 +115,9 @@ spec: args: - "--master=blockmaster.kube-system.svc.cluster.local:9333" - "--server-id=s1" + - "--master-tls-cert=/etc/sw-block/master-tls/tls.crt" + - "--master-tls-key=/etc/sw-block/master-tls/tls.key" + - "--master-ca=/etc/sw-block/master-tls/ca.crt" - "--volume-id=v1" - "--replica-id=r1" - "--data-addr=127.0.0.1:19101" @@ -113,9 +132,15 @@ spec: - "--iscsi-listen=127.0.0.1:3260" - "--iscsi-iqn=iqn.2026-05.io.seaweedfs:g15b-v1" volumeMounts: + - name: master-tls + mountPath: /etc/sw-block/master-tls + readOnly: true - name: state mountPath: /var/lib/sw-block volumes: + - name: master-tls + secret: + secretName: sw-block-node-tls-s1 - name: state emptyDir: {} --- @@ -144,6 +169,9 @@ spec: args: - "--master=blockmaster.kube-system.svc.cluster.local:9333" - "--server-id=s2" + - "--master-tls-cert=/etc/sw-block/master-tls/tls.crt" + - "--master-tls-key=/etc/sw-block/master-tls/tls.key" + - "--master-ca=/etc/sw-block/master-tls/ca.crt" - "--volume-id=v1" - "--replica-id=r2" - "--data-addr=127.0.0.1:19201" @@ -156,8 +184,14 @@ spec: - "--t1-readiness" - "--recovery-mode=dual-lane" volumeMounts: + - name: master-tls + mountPath: /etc/sw-block/master-tls + readOnly: true - name: state mountPath: /var/lib/sw-block volumes: + - name: master-tls + secret: + secretName: sw-block-node-tls-s2 - name: state emptyDir: {} diff --git a/seaweed-block/deploy/k8s/g15b/csi-controller.yaml b/seaweed-block/deploy/k8s/g15b/csi-controller.yaml index 7f25886bf7..3700e15d85 100644 --- a/seaweed-block/deploy/k8s/g15b/csi-controller.yaml +++ b/seaweed-block/deploy/k8s/g15b/csi-controller.yaml @@ -22,6 +22,9 @@ spec: - "--endpoint=unix:///csi/csi.sock" - "--master=$(BLOCKMASTER_ADDR)" - "--node-id=$(NODE_NAME)" + - "--master-tls-cert=/etc/sw-block/master-tls/tls.crt" + - "--master-tls-key=/etc/sw-block/master-tls/tls.key" + - "--master-ca=/etc/sw-block/master-tls/ca.crt" env: - name: BLOCKMASTER_ADDR value: "blockmaster.kube-system.svc.cluster.local:9333" @@ -30,6 +33,9 @@ spec: fieldRef: fieldPath: spec.nodeName volumeMounts: + - name: master-tls + mountPath: /etc/sw-block/master-tls + readOnly: true - name: socket-dir mountPath: /csi - name: csi-attacher @@ -42,5 +48,8 @@ spec: - name: socket-dir mountPath: /csi volumes: + - name: master-tls + secret: + secretName: sw-block-client-tls - name: socket-dir emptyDir: {} diff --git a/seaweed-block/deploy/k8s/g15b/csi-node.yaml b/seaweed-block/deploy/k8s/g15b/csi-node.yaml index c4685471a1..32c6a9b93c 100644 --- a/seaweed-block/deploy/k8s/g15b/csi-node.yaml +++ b/seaweed-block/deploy/k8s/g15b/csi-node.yaml @@ -37,6 +37,9 @@ spec: - "--endpoint=unix:///csi/csi.sock" - "--master=$(BLOCKMASTER_ADDR)" - "--node-id=$(NODE_NAME)" + - "--master-tls-cert=/etc/sw-block/master-tls/tls.crt" + - "--master-tls-key=/etc/sw-block/master-tls/tls.key" + - "--master-ca=/etc/sw-block/master-tls/ca.crt" env: - name: BLOCKMASTER_ADDR value: "blockmaster.kube-system.svc.cluster.local:9333" @@ -47,6 +50,9 @@ spec: securityContext: privileged: true volumeMounts: + - name: master-tls + mountPath: /etc/sw-block/master-tls + readOnly: true - name: socket-dir mountPath: /csi - name: kubelet-dir @@ -67,6 +73,9 @@ spec: - name: registration-dir mountPath: /registration volumes: + - name: master-tls + secret: + secretName: sw-block-client-tls - name: socket-dir hostPath: path: /var/lib/kubelet/plugins/block.csi.seaweedfs.com diff --git a/seaweed-block/deploy/k8s/g15d/block-stack.yaml b/seaweed-block/deploy/k8s/g15d/block-stack.yaml index 932db66b7b..fd9debc9f1 100644 --- a/seaweed-block/deploy/k8s/g15d/block-stack.yaml +++ b/seaweed-block/deploy/k8s/g15d/block-stack.yaml @@ -48,12 +48,23 @@ spec: - "--launcher-durable-root=/var/lib/sw-block" - "--launcher-iscsi-port-base=3260" - "--listen=0.0.0.0:9333" - - "--insecure-external-bind" + - "--tls-cert=/etc/sw-block/tls/tls.crt" + - "--tls-key=/etc/sw-block/tls/tls.key" + - "--tls-client-ca=/etc/sw-block/tls/ca.crt" + - "--role-file=/etc/sw-block/roles/roles" + - "--audit-log=/var/lib/sw-block/audit.log" + - "--launcher-master-tls-secret-prefix=sw-block-node-tls" - "--expected-slots-per-volume=1" ports: - name: grpc containerPort: 9333 volumeMounts: + - name: tls + mountPath: /etc/sw-block/tls + readOnly: true + - name: roles + mountPath: /etc/sw-block/roles + readOnly: true - name: cluster-spec mountPath: /config readOnly: true @@ -62,6 +73,12 @@ spec: - name: manifests mountPath: /manifests volumes: + - name: tls + secret: + secretName: sw-block-master-tls + - name: roles + secret: + secretName: sw-block-roles - name: cluster-spec configMap: name: sw-block-cluster-spec diff --git a/seaweed-block/deploy/k8s/g15d/csi-controller.yaml b/seaweed-block/deploy/k8s/g15d/csi-controller.yaml index 4efdd74a16..674664f321 100644 --- a/seaweed-block/deploy/k8s/g15d/csi-controller.yaml +++ b/seaweed-block/deploy/k8s/g15d/csi-controller.yaml @@ -22,6 +22,9 @@ spec: - "--endpoint=unix:///csi/csi.sock" - "--master=$(BLOCKMASTER_ADDR)" - "--node-id=$(NODE_NAME)" + - "--master-tls-cert=/etc/sw-block/master-tls/tls.crt" + - "--master-tls-key=/etc/sw-block/master-tls/tls.key" + - "--master-ca=/etc/sw-block/master-tls/ca.crt" env: - name: BLOCKMASTER_ADDR value: "blockmaster.kube-system.svc.cluster.local:9333" @@ -30,6 +33,9 @@ spec: fieldRef: fieldPath: spec.nodeName volumeMounts: + - name: master-tls + mountPath: /etc/sw-block/master-tls + readOnly: true - name: socket-dir mountPath: /csi - name: csi-provisioner @@ -52,5 +58,8 @@ spec: - name: socket-dir mountPath: /csi volumes: + - name: master-tls + secret: + secretName: sw-block-client-tls - name: socket-dir emptyDir: {} diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index 2d90feea50..f1e98f8ccd 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -747,7 +747,7 @@ Notes: | `INV-LIFECYCLE-STORE-DURABLE-001` | Node registration, volume record and placement-intent puts/replacements are atomic and durable: after a crash the record file is the complete old or the complete new record; a put that returned nil has fsynced the file and its directory. | M2 lifecycle record publication | `core/lifecycle/record_file.go` `writeRecordDurably`; `node_inventory.go`, `store.go`, `placement_intent.go` `putLocked` | `TestNodeInventoryCrashKeepsCompleteRegistration` (`core/lifecycle/node_inventory_crash_test.go`); `TestFileStoreCrashKeepsCompleteRecord`, `TestPlacementStoreCrashKeepsCompleteRecord`, `TestLifecyclePutSyncOrderAndFailure` (`core/lifecycle/store_crash_test.go`); `TestLifecycleStoreParentSync` (`core/lifecycle/store_parent_sync_test.go`) | � | ACTIVE | | `INV-VOL-ID-NO-REUSE-001` | A deleted volume id is never created or attached again. | M2 Deleting; M6 purging → deleted | `core/host/master/services.go` `MarkVolumeDeleting`; `core/frontend/chunkstore/catalog.go` `EnsureVolume` | `TestMarkVolumeDeleting_ReservesUnknownIdsAndSurvivesDeleteAndRestart` (`core/host/master/volume_deleting_test.go`); `TestCatalog_DeleteVolumeTombstonesAndRefusesReuse` (`core/frontend/chunkstore/volume_delete_test.go`) | `ChunkLifecycleFixed` `NoIdReuse` | ACTIVE | | `INV-MASTER-JOURNAL-ISOLATION-001` | Under strict journal isolation, blockmaster gives no new work to a node whose durable root shares the authority store's file system: it refuses that node's heartbeat while it serves no volume, a new placement on it and a move onto it; work the node already has is kept. | M2 workspace move: Acked or Expired → (move refused, nothing written); workspace placement admission; node heartbeat | `core/host/master/journal_isolation.go` `refuseColocatedHeartbeat`, `colocatedTargetRefused`, `reconcilePlacements`, `nodeServesVolumes`; `core/host/master/workspace_service.go` `workspaceMoveCheckLocked`; `core/host/master/workspace_binding.go` `PlaceWorkspace` | `TestColocatedNodeIsAlarmedButAcceptedByDefault`, `TestStrictRefusesColocatedNodeWithoutVolumes`, `TestStrictAcceptsColocatedNodeThatAlreadyServes`, `TestStrictRefusesPlacementAndMoveOntoColocatedNode`, `TestStrictProductLoopSkipsColocatedNodeForNewPlacement` (`core/host/master/journal_isolation_test.go`); `TestStrictReplaysAnIssuedMoveToANowColocatedTarget`, `TestStrictKeepsAnIdempotentPlacementOnANowColocatedNode` (`core/host/master/journal_isolation_fold_test.go`) | — | ACTIVE | -| `INV-SEC-CONTROL-BIND-001` | blockmaster's unauthenticated control listeners (--listen, and the runtime HTTP listener when enabled) bind only loopback unless --insecure-external-bind is given; a non-loopback address is refused at startup. | AUTHORITY: control API reachability | `core/host/master/journal_isolation.go` `ValidateControlListen`; `cmd/blockmaster/main.go` `parseFlags` | `TestParseFlags_ControlListenersNeedInsecureExternalBind`, `TestManifests_ExternalBlockmasterBindCarriesTheOptIn` (`cmd/blockmaster/external_bind_test.go`) | — (no state machine; the flag test is the proof form) | ACTIVE | +| `INV-SEC-CONTROL-BIND-001` | blockmaster's unauthenticated control listeners bind only loopback: --listen without mutual TLS, and the runtime HTTP listener always; a non-loopback address, and --insecure-external-bind, are refused at startup. | AUTHORITY: control API reachability | `core/host/master/journal_isolation.go` `ValidateControlListen`; `cmd/blockmaster/main.go` `parseFlags` | `TestParseFlags_PlaintextControlListenersStayOnLoopback`, `TestManifests_NoPlaintextExternalBlockmasterBind` (`cmd/blockmaster/external_bind_test.go`); `TestAuthFlags` (`cmd/blockmaster/auth_flags_test.go`) | — (no state machine; the flag test is the proof form) | ACTIVE | Notes: diff --git a/seaweed-block/docs/design/kubernetes-block-design.md b/seaweed-block/docs/design/kubernetes-block-design.md index b12b036e9b..4dfeeb2619 100644 --- a/seaweed-block/docs/design/kubernetes-block-design.md +++ b/seaweed-block/docs/design/kubernetes-block-design.md @@ -116,7 +116,7 @@ sequenceDiagram The chart is `charts/seaweed-block`. It deploys blockmaster (with `--launcher-kubernetes-apply`), the CSI controller and node, the `CSIDriver` (`attachRequired: true`), the CRDs, RBAC, a StorageClass (default name `sw-block-dynamic`, `allowVolumeExpansion: false`), and the operator controllers below. `sw-block ops generate-helm-values` writes a values file for a cluster. -Key values: `blockNodes[]`; `ports.iscsiBase`, `ports.nvmeBase`, `ports.statusBase`; `network.externalISCSI` (requires `chap.enabled`), `network.externalNVMe`, `network.externalStatus`; `stage2Multipath.enabled` (false); `restartPersistence.mode` (ephemeral by default) and `blockmaster.stateHostPath`; `replication.expectedSlotsPerVolume`, `replication.ackProfile`, `compat.launcherReplicationAckFlag` (false); `blockmaster.launcherStatus`. +Key values: `blockNodes[]`; `ports.iscsiBase`, `ports.nvmeBase`, `ports.statusBase`; `network.externalISCSI` (requires `chap.enabled`), `network.externalNVMe`; `tls.masterSecret`, `tls.roleSecret`, `tls.clientSecret`, `tls.nodeSecretPrefix` (blockmaster runs with mutual TLS; `network.externalStatus` is refused); `stage2Multipath.enabled` (false); `restartPersistence.mode` (ephemeral by default) and `blockmaster.stateHostPath`; `replication.expectedSlotsPerVolume`, `replication.ackProfile`, `compat.launcherReplicationAckFlag` (false); `blockmaster.launcherStatus`. **Operator controllers.** Each is a Deployment running `sw-block ops `; every one is off by default (`create: false`), and the executors also default to dry run. diff --git a/seaweed-block/docs/quickstart-kubernetes.md b/seaweed-block/docs/quickstart-kubernetes.md index 7b459eb230..2e4a44feec 100644 --- a/seaweed-block/docs/quickstart-kubernetes.md +++ b/seaweed-block/docs/quickstart-kubernetes.md @@ -119,7 +119,7 @@ Single-node behavior: Multi-node behavior: - multiple selected nodes, -- non-loopback iSCSI/status addresses, +- non-loopback iSCSI addresses (volume status stays on loopback), - CHAP enabled, - loopback publish-target rejection recorded in values. @@ -158,6 +158,19 @@ unless the publish commit is known. ## Step 2 — Install Seaweed Block With Helm +blockmaster listens on the pod network only with mutual TLS, so create its +Secrets first. For a trial, the helper issues a development CA and one node +certificate per server id (the `blockNodes[]` names, or their `serverID`): + +```bash +bash scripts/k8s-alpha-certs.sh kube-system ~/.sw-block-alpha-tls node-a node-b node-c +``` + +It applies `sw-block-master-tls`, `sw-block-client-tls`, `sw-block-roles` and +`sw-block-node-tls-`. Keep the directory private: a node key controls +that host's volumes. For production, issue them from your own CA +([operator guide](operator-guide.md#authenticate-the-control-api)). + ```bash helm install sw-block charts/seaweed-block \ --namespace kube-system \ diff --git a/seaweed-block/docs/standalone-deployment.md b/seaweed-block/docs/standalone-deployment.md index 1b150ca45a..6224300df9 100644 --- a/seaweed-block/docs/standalone-deployment.md +++ b/seaweed-block/docs/standalone-deployment.md @@ -483,7 +483,7 @@ The commands below use these placeholders: - `STATUS` is a blockvolume's status address (its `--status-addr`, with `--chunk-control-endpoint` set). **About the control endpoint.** `--chunk-control-endpoint` carries destructive operations (cut, snapshot, snapshot delete, detach, restore) on the status listener. -- **Binding:** that listener binds loopback addresses only, unless `--allow-external-status-bind` is set. +- **Binding:** that listener binds loopback addresses only, unless `--allow-external-status-bind` is set; that flag is refused together with `--master-tls-cert`. - **No authentication:** nothing authenticates it in this release. Keep it on loopback, or behind your own access control. ### Scheduled snapshots diff --git a/seaweed-block/docs/wiki/deep-dives/blockvolume-process-readiness.md b/seaweed-block/docs/wiki/deep-dives/blockvolume-process-readiness.md index fb08ad5476..c52b788b36 100644 --- a/seaweed-block/docs/wiki/deep-dives/blockvolume-process-readiness.md +++ b/seaweed-block/docs/wiki/deep-dives/blockvolume-process-readiness.md @@ -121,7 +121,7 @@ sequenceDiagram | Flag | Meaning | |---|---| | `--status-addr` | expose diagnostics/status endpoint | -| `--allow-external-status-bind` | explicit node-loss gate opt-in; default status is loopback safe | +| `--allow-external-status-bind` | explicit node-loss gate opt-in, refused together with `--master-tls-cert`; default status is loopback safe | | `--iscsi-listen` | enable iSCSI frontend | | `--allow-external-iscsi-bind` | external iSCSI requires explicit opt-in and CHAP | | `--nvme-listen` | enable NVMe/TCP frontend | diff --git a/seaweed-block/scripts/install-k8s-alpha.sh b/seaweed-block/scripts/install-k8s-alpha.sh index 13daf2c014..7e3bbaeba2 100755 --- a/seaweed-block/scripts/install-k8s-alpha.sh +++ b/seaweed-block/scripts/install-k8s-alpha.sh @@ -162,12 +162,6 @@ if [[ "$LAUNCHER_EXTERNAL_ISCSI" == "1" || "$LAUNCHER_EXTERNAL_ISCSI" == "true" exit 2 fi fi -if [[ "$LAUNCHER_EXTERNAL_STATUS" == "1" || "$LAUNCHER_EXTERNAL_STATUS" == "true" ]]; then - if [[ "$LAUNCHER_EXTERNAL_ISCSI" != "1" && "$LAUNCHER_EXTERNAL_ISCSI" != "true" ]]; then - echo "SW_BLOCK_LAUNCHER_EXTERNAL_STATUS requires SW_BLOCK_LAUNCHER_EXTERNAL_ISCSI=1" >&2 - exit 2 - fi -fi STACK_RENDERED="$ARTIFACT_DIR/block-stack.rendered.yaml" CSI_CONTROLLER_RENDERED="$ARTIFACT_DIR/csi-controller.rendered.yaml" CSI_NODE_RENDERED="$ARTIFACT_DIR/csi-node.rendered.yaml" @@ -213,9 +207,8 @@ if [[ "$LAUNCHER_EXTERNAL_ISCSI" == "1" || "$LAUNCHER_EXTERNAL_ISCSI" == "true" grep -q -- '--launcher-iscsi-chap-secret-name' "$STACK_RENDERED" || { echo "failed to inject --launcher-iscsi-chap-secret-name into $STACK_RENDERED" >&2; exit 1; } fi if [[ "$LAUNCHER_EXTERNAL_STATUS" == "1" || "$LAUNCHER_EXTERNAL_STATUS" == "true" ]]; then - awk '/--launcher-status/{print; print " - \"--launcher-external-status\""; next} {print}' "$STACK_RENDERED" >"$STACK_RENDERED.tmp" - mv "$STACK_RENDERED.tmp" "$STACK_RENDERED" - grep -q -- '--launcher-external-status' "$STACK_RENDERED" || { echo "failed to inject --launcher-external-status into $STACK_RENDERED" >&2; exit 1; } + echo "SW_BLOCK_LAUNCHER_EXTERNAL_STATUS is not supported: blockmaster runs with mutual TLS and an authenticated volume's status listener stays on loopback" >&2 + exit 2 fi sed -e "s/sw-block-csi:local/${CSI_IMAGE_SED}/g" \ -e "s/imagePullPolicy: Never/imagePullPolicy: IfNotPresent/g" \ @@ -269,6 +262,8 @@ log "apply RBAC" kubectl apply -f "$ROOT/deploy/k8s/alpha/rbac.yaml" | tee "$ARTIFACT_DIR/apply-rbac.log" log "apply seaweed-block control plane" +log "apply mutual TLS Secrets (keys kept outside the artifact directory)" +bash "$ROOT/scripts/k8s-alpha-certs.sh" kube-system "${SW_BLOCK_TLS_DIR:-${XDG_STATE_HOME:-$HOME/.local/state}/sw-block-alpha-tls}" $(awk '/server_id:/{print $NF}' "$STACK_RENDERED" | sort -u) | tee "$ARTIFACT_DIR/apply-tls.log" kubectl apply -f "$STACK_RENDERED" | tee "$ARTIFACT_DIR/apply-block-stack.log" kubectl -n kube-system wait --for=condition=available deploy/sw-blockmaster --timeout=120s diff --git a/seaweed-block/scripts/k8s-alpha-certs.sh b/seaweed-block/scripts/k8s-alpha-certs.sh new file mode 100755 index 0000000000..533fbb81c2 --- /dev/null +++ b/seaweed-block/scripts/k8s-alpha-certs.sh @@ -0,0 +1,79 @@ +#!/usr/bin/env bash +# Development certificates for a Kubernetes alpha install: blockmaster listens +# on the pod network only with mutual TLS. Creates (or reuses) a CA in OUT_DIR, +# issues the blockmaster, controller and per-server node certificates, writes +# the role file, and applies the Secrets the chart and the alpha manifests +# mount. For production, issue the certificates from your own CA (see +# docs/operator-guide.md, "Authenticate the control API"). +# +# usage: scripts/k8s-alpha-certs.sh NAMESPACE OUT_DIR SERVER_ID... +# SW_BLOCK_TLS_SECRET_PREFIX node Secret prefix (default sw-block-node-tls) +# SW_BLOCK_TLS_APPLY=0 write the files only, apply nothing +set -euo pipefail + +if [[ $# -lt 3 ]]; then + echo "usage: $0 NAMESPACE OUT_DIR SERVER_ID..." >&2 + exit 2 +fi +NS="$1" +OUT="$2" +shift 2 +PREFIX="${SW_BLOCK_TLS_SECRET_PREFIX:-sw-block-node-tls}" +APPLY="${SW_BLOCK_TLS_APPLY:-1}" +mkdir -p "$OUT" +umask 077 + +if [[ ! -s "$OUT/ca.crt" || ! -s "$OUT/ca.key" ]]; then + openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes -days 3650 \ + -subj "/CN=sw-block alpha CA" -keyout "$OUT/ca.key" -out "$OUT/ca.crt" 2>/dev/null +fi + +# issue NAME CN [SAN]: NAME.crt/NAME.key signed by the CA (reused when present) +issue() { + local name="$1" cn="$2" san="${3:-}" + [[ -s "$OUT/$name.crt" && -s "$OUT/$name.key" ]] && return 0 + openssl req -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes -subj "/CN=$cn" \ + -keyout "$OUT/$name.key" -out "$OUT/$name.csr" 2>/dev/null + local ext="$OUT/$name.ext" + : >"$ext" + [[ -n "$san" ]] && echo "subjectAltName=$san" >"$ext" + openssl x509 -req -in "$OUT/$name.csr" -CA "$OUT/ca.crt" -CAkey "$OUT/ca.key" -CAcreateserial \ + -days 825 -extfile "$ext" -out "$OUT/$name.crt" 2>/dev/null + rm -f "$OUT/$name.csr" "$ext" +} + +fingerprint() { + echo "sha256:$(openssl x509 -in "$1" -outform DER | sha256sum | cut -d' ' -f1)" +} + +issue master blockmaster "DNS:blockmaster.$NS.svc.cluster.local,DNS:blockmaster.$NS.svc,DNS:blockmaster,IP:127.0.0.1" +issue controller sw-block-controller +{ + echo "# sw-block alpha role file: sha256: " + echo "$(fingerprint "$OUT/controller.crt") admin sw-block-controller" +} >"$OUT/roles" +for id in "$@"; do + if ! [[ "$id" =~ ^[a-z0-9]([a-z0-9.-]*[a-z0-9])?$ ]]; then + echo "server id $id cannot name a Kubernetes Secret (lowercase letters, digits, '-' and '.')" >&2 + exit 2 + fi + issue "node-$id" "$id" + echo "$(fingerprint "$OUT/node-$id.crt") node $id" >>"$OUT/roles" +done + +[[ "$APPLY" == "0" ]] && { echo "certificates and role file written to $OUT (not applied)"; exit 0; } + +apply_tls() { + local secret="$1" name="$2" + kubectl -n "$NS" create secret generic "$secret" \ + --from-file=tls.crt="$OUT/$name.crt" --from-file=tls.key="$OUT/$name.key" --from-file=ca.crt="$OUT/ca.crt" \ + --dry-run=client -o yaml | kubectl apply -f - +} +apply_tls sw-block-master-tls master +apply_tls sw-block-client-tls controller +for id in "$@"; do + apply_tls "$PREFIX-$id" "node-$id" +done +kubectl -n "$NS" create secret generic sw-block-roles --from-file=roles="$OUT/roles" \ + --dry-run=client -o yaml | kubectl apply -f - +echo "mutual TLS Secrets applied in namespace $NS (CA and keys in $OUT)" diff --git a/seaweed-block/scripts/k8s_alpha_certs_test.go b/seaweed-block/scripts/k8s_alpha_certs_test.go new file mode 100644 index 0000000000..030696c279 --- /dev/null +++ b/seaweed-block/scripts/k8s_alpha_certs_test.go @@ -0,0 +1,117 @@ +package scripts_test + +import ( + "context" + "crypto/x509" + "encoding/pem" + "net" + "os" + "os/exec" + "path/filepath" + "runtime" + "strings" + "testing" + "time" + + "github.com/seaweedfs/seaweed-block/core/auth" + "github.com/seaweedfs/seaweed-block/core/rpc/link" + "google.golang.org/grpc" + "google.golang.org/protobuf/types/known/emptypb" +) + +// The alpha certificate helper issues what blockmaster accepts: a role file +// that parses, a node certificate whose CN is its server id and which +// authenticates as that node over a real mutual-TLS link, and a controller +// certificate that authenticates as admin. +func TestK8sAlphaCertsAreAcceptedByBlockmaster(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("bash and openssl script") + } + if _, err := exec.LookPath("openssl"); err != nil { + t.Skip("openssl not installed") + } + out := t.TempDir() + cmd := exec.Command("bash", filepath.Join(repoRoot(t), "scripts", "k8s-alpha-certs.sh"), "kube-system", out, "node-a", "node-b") + cmd.Env = append(os.Environ(), "SW_BLOCK_TLS_APPLY=0") + if b, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("k8s-alpha-certs.sh: %v\n%s", err, b) + } + table, err := auth.LoadRoleFile(filepath.Join(out, "roles")) + if err != nil { + t.Fatal(err) + } + a := auth.NewAuthenticator(table, nil) + master := link.TLSFiles{Cert: filepath.Join(out, "master.crt"), Key: filepath.Join(out, "master.key"), CA: filepath.Join(out, "ca.crt")} + for _, c := range []struct { + name, role, id string + }{{"node-node-a", "node", "node-a"}, {"node-node-b", "node", "node-b"}, {"controller", "admin", "sw-block-controller"}} { + client := link.TLSFiles{Cert: filepath.Join(out, c.name+".crt"), Key: filepath.Join(out, c.name+".key"), CA: filepath.Join(out, "ca.crt")} + p, err := handshake(t, master, client, a) + if err != nil { + t.Fatalf("%s: %v", c.name, err) + } + if string(p.Role) != c.role || p.ID != c.id { + t.Fatalf("%s authenticated as %s %s, want %s %s", c.name, p.Role, p.ID, c.role, c.id) + } + } + raw, err := os.ReadFile(filepath.Join(out, "master.crt")) + if err != nil { + t.Fatal(err) + } + blk, _ := pem.Decode(raw) + leaf, err := x509.ParseCertificate(blk.Bytes) + if err != nil { + t.Fatal(err) + } + if err := leaf.VerifyHostname("blockmaster.kube-system.svc.cluster.local"); err != nil { + t.Fatalf("master certificate does not name the Service the clients dial: %v", err) + } + cmd = exec.Command("bash", filepath.Join(repoRoot(t), "scripts", "k8s-alpha-certs.sh"), "kube-system", t.TempDir(), "Node_A") + cmd.Env = append(os.Environ(), "SW_BLOCK_TLS_APPLY=0") + if b, err := cmd.CombinedOutput(); err == nil || !strings.Contains(string(b), "cannot name a Kubernetes Secret") { + t.Fatalf("server id Node_A: %v\n%s, want refused", err, b) + } +} + +// handshake runs one mutual-TLS gRPC call from client to a server with the +// master's credentials and returns who the server says is calling. +func handshake(t *testing.T, master, client link.TLSFiles, a *auth.Authenticator) (auth.Principal, error) { + t.Helper() + srvCreds, err := link.ServerCredentials(master) + if err != nil { + return auth.Principal{}, err + } + got := make(chan auth.Principal, 1) + srv := grpc.NewServer(srvCreds, grpc.UnknownServiceHandler(func(_ any, ss grpc.ServerStream) error { + p, err := a.PeerIdentity(ss.Context()) + if err != nil { + return err + } + got <- p + return nil + })) + lis, err := net.Listen("tcp", "127.0.0.1:0") + if err != nil { + return auth.Principal{}, err + } + go srv.Serve(lis) + defer srv.Stop() + dial, err := link.ClientCredentials(client, "blockmaster.kube-system.svc.cluster.local") + if err != nil { + return auth.Principal{}, err + } + conn, err := link.DialMaster(lis.Addr().String(), dial) + if err != nil { + return auth.Principal{}, err + } + defer conn.Close() + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + callErr := conn.Invoke(ctx, "/probe.Probe/Who", &emptypb.Empty{}, &emptypb.Empty{}) + select { + case p := <-got: + return p, nil + default: + return auth.Principal{}, callErr + } +} diff --git a/seaweed-block/scripts/run-alpha-app-demo.sh b/seaweed-block/scripts/run-alpha-app-demo.sh index ee8d21936d..082143dca9 100755 --- a/seaweed-block/scripts/run-alpha-app-demo.sh +++ b/seaweed-block/scripts/run-alpha-app-demo.sh @@ -1385,12 +1385,6 @@ if [[ "$LAUNCHER_EXTERNAL_ISCSI" == "1" || "$LAUNCHER_EXTERNAL_ISCSI" == "true" exit 2 fi fi -if [[ "$LAUNCHER_EXTERNAL_STATUS" == "1" || "$LAUNCHER_EXTERNAL_STATUS" == "true" ]]; then - if [[ "$LAUNCHER_EXTERNAL_ISCSI" != "1" && "$LAUNCHER_EXTERNAL_ISCSI" != "true" ]]; then - echo "SW_BLOCK_LAUNCHER_EXTERNAL_STATUS requires SW_BLOCK_LAUNCHER_EXTERNAL_ISCSI=1" >&2 - exit 2 - fi -fi APP_NODE_NAME="${SW_BLOCK_DEMO_APP_NODE_NAME:-$NODE_NAME}" READER_NODE_NAME="${SW_BLOCK_DEMO_READER_NODE_NAME:-$APP_NODE_NAME}" STACK_RENDERED="$ARTIFACT_DIR/block-stack.rendered.yaml" @@ -1444,13 +1438,8 @@ if [[ "$RESTART_BLOCKVOLUME_BEFORE_READER" == "1" || "$RESTART_BLOCKVOLUME_BEFOR grep -q -- '--launcher-status' "$STACK_RENDERED" || { echo "failed to inject --launcher-status into $STACK_RENDERED" >&2; exit 1; } fi if [[ "$LAUNCHER_EXTERNAL_STATUS" == "1" || "$LAUNCHER_EXTERNAL_STATUS" == "true" ]]; then - grep -q -- '--launcher-status' "$STACK_RENDERED" || { - awk '/--launcher-durable-root=/{print; print " - \"--launcher-status\""; next} {print}' "$STACK_RENDERED" >"$STACK_RENDERED.tmp" - mv "$STACK_RENDERED.tmp" "$STACK_RENDERED" - } - awk '/--launcher-status/{print; print " - \"--launcher-external-status\""; next} {print}' "$STACK_RENDERED" >"$STACK_RENDERED.tmp" - mv "$STACK_RENDERED.tmp" "$STACK_RENDERED" - grep -q -- '--launcher-external-status' "$STACK_RENDERED" || { echo "failed to inject --launcher-external-status into $STACK_RENDERED" >&2; exit 1; } + echo "SW_BLOCK_LAUNCHER_EXTERNAL_STATUS is not supported: blockmaster runs with mutual TLS and an authenticated volume's status listener stays on loopback" >&2 + exit 2 fi sed -e "s/sw-block-csi:local/${CSI_IMAGE_SED}/g" \ -e "s/imagePullPolicy: Never/imagePullPolicy: IfNotPresent/g" \ @@ -1550,6 +1539,8 @@ log "apply RBAC" kubectl apply -f "$ROOT/deploy/k8s/alpha/rbac.yaml" | tee "$ARTIFACT_DIR/apply-rbac.log" log "apply seaweed-block service stack" +log "apply mutual TLS Secrets (keys kept outside the artifact directory)" +bash "$ROOT/scripts/k8s-alpha-certs.sh" kube-system "${SW_BLOCK_TLS_DIR:-${XDG_STATE_HOME:-$HOME/.local/state}/sw-block-alpha-tls}" $(awk '/server_id:/{print $NF}' "$STACK_RENDERED" | sort -u) | tee "$ARTIFACT_DIR/apply-tls.log" kubectl apply -f "$STACK_RENDERED" | tee "$ARTIFACT_DIR/apply-block-stack.log" kubectl -n kube-system wait --for=condition=available deploy/sw-blockmaster --timeout=120s diff --git a/seaweed-block/scripts/run-g15b-k8s-static.sh b/seaweed-block/scripts/run-g15b-k8s-static.sh index 4eb534f773..4a8e385c87 100755 --- a/seaweed-block/scripts/run-g15b-k8s-static.sh +++ b/seaweed-block/scripts/run-g15b-k8s-static.sh @@ -54,6 +54,8 @@ collect_daemon_logs() { trap 'collect_daemon_logs; cleanup' EXIT log "preflight: apply product stack" +log "apply mutual TLS Secrets (keys kept outside the artifact directory)" +bash "$ROOT/scripts/k8s-alpha-certs.sh" kube-system "${SW_BLOCK_TLS_DIR:-${XDG_STATE_HOME:-$HOME/.local/state}/sw-block-alpha-tls}" $(awk '/server_id:/{print $NF}' "$ROOT/deploy/k8s/g15b/block-stack.yaml" | sort -u) | tee "$ARTIFACT_DIR/apply-tls.log" kubectl apply -f "$ROOT/deploy/k8s/g15b/block-stack.yaml" | tee "$ARTIFACT_DIR/apply-block-stack.log" kubectl -n kube-system wait --for=condition=available deploy/sw-blockmaster --timeout=120s kubectl -n kube-system wait --for=condition=available deploy/sw-blockvolume-r1 --timeout=120s diff --git a/seaweed-block/scripts/run-g15d-k8s-dynamic.sh b/seaweed-block/scripts/run-g15d-k8s-dynamic.sh index 24856ee14e..0898be92aa 100755 --- a/seaweed-block/scripts/run-g15d-k8s-dynamic.sh +++ b/seaweed-block/scripts/run-g15d-k8s-dynamic.sh @@ -360,6 +360,8 @@ cleanup trap 'collect_daemon_logs; cleanup' EXIT log "apply product stack without pre-created blockvolumes" +log "apply mutual TLS Secrets (keys kept outside the artifact directory)" +bash "$ROOT/scripts/k8s-alpha-certs.sh" kube-system "${SW_BLOCK_TLS_DIR:-${XDG_STATE_HOME:-$HOME/.local/state}/sw-block-alpha-tls}" $(awk '/server_id:/{print $NF}' "$STACK_RENDERED" | sort -u) | tee "$ARTIFACT_DIR/apply-tls.log" kubectl apply -f "$STACK_RENDERED" | tee "$ARTIFACT_DIR/apply-block-stack.log" kubectl -n kube-system wait --for=condition=available deploy/sw-blockmaster --timeout=120s if ! kubectl -n kube-system exec deploy/sw-blockmaster -c blockmaster -- /usr/local/bin/blockmaster --version >"$ARTIFACT_DIR/blockmaster.version.txt" 2>"$ARTIFACT_DIR/blockmaster.version.err"; then diff --git a/seaweed-block/testops/scenarios/node-loss-topology-eligibility-chain.yaml b/seaweed-block/testops/scenarios/node-loss-topology-eligibility-chain.yaml index 3e1d897f45..fd28422a77 100644 --- a/seaweed-block/testops/scenarios/node-loss-topology-eligibility-chain.yaml +++ b/seaweed-block/testops/scenarios/node-loss-topology-eligibility-chain.yaml @@ -225,7 +225,7 @@ phases: threshold: "0" - action: exec node: m02 - cmd: "B=/mnt/smb/work/share/g15d-k8s/{{ run_id }}-node-loss-topology/demo; test \"$(grep -c -- '--replica-id=r' \"$B/generated-blockvolume.yaml\")\" -ge 3; test \"$(grep -c -- '--allow-external-iscsi-bind' \"$B/generated-blockvolume.yaml\")\" -ge 3; test \"$(grep -c -- '--allow-external-status-bind' \"$B/generated-blockvolume.yaml\")\" -ge 3" + cmd: "B=/mnt/smb/work/share/g15d-k8s/{{ run_id }}-node-loss-topology/demo; test \"$(grep -c -- '--replica-id=r' \"$B/generated-blockvolume.yaml\")\" -ge 3; test \"$(grep -c -- '--allow-external-iscsi-bind' \"$B/generated-blockvolume.yaml\")\" -ge 3; test \"$(grep -c -- '--master-tls-cert=' \"$B/generated-blockvolume.yaml\")\" -ge 3" - action: exec node: m02 cmd: "B=/mnt/smb/work/share/g15d-k8s/{{ run_id }}-node-loss-topology/demo; ! grep -Eq -- '--(iscsi-listen|status-addr)=127\\.0\\.0\\.1|--(iscsi-listen|status-addr)=localhost' \"$B/generated-blockvolume.yaml\""