diff --git a/06-openbao/index.ts b/06-openbao/index.ts index d479edb..171ca9f 100644 --- a/06-openbao/index.ts +++ b/06-openbao/index.ts @@ -8,9 +8,18 @@ const appsRef = new pulumi.StackReference( `${pulumi.getOrganization()}/k8s-apps/dev`, ); +const config = new pulumi.Config(); +const snapshotS3AccessKeyId = config.requireSecret("snapshotS3AccessKeyId"); +const snapshotS3SecretAccessKey = config.requireSecret( + "snapshotS3SecretAccessKey", +); + const kubeconfig = bootstrapRef.requireOutput("kubeconfig"); const domain = appsRef.requireOutput("domain"); const openbaoHost = pulumi.interpolate`bao.${domain}`; +// RustFS on TrueNAS, see docs/runbooks/truenas-rustfs.md. +const snapshotS3Host = pulumi.interpolate`rustfs.${domain}:30292`; +const snapshotBucket = "openbao-backups"; const k8sProvider = new k8s.Provider("k3s", { kubeconfig, @@ -116,6 +125,23 @@ const serversTransport = new k8s.apiextensions.CustomResource( opts({ dependsOn: [serverCert] }), ); +// Upload-only RustFS key for the snapshot CronJob. Object lock on the bucket +// keeps uploaded snapshots from being deleted or overwritten. +const snapshotS3Credentials = new k8s.core.v1.Secret( + "openbao-snapshot-s3", + { + metadata: { + name: "openbao-snapshot-s3", + namespace: openbaoNs.metadata.name, + }, + stringData: { + AWS_ACCESS_KEY_ID: snapshotS3AccessKeyId, + AWS_SECRET_ACCESS_KEY: snapshotS3SecretAccessKey, + }, + }, + opts(), +); + new k8s.helm.v3.Release( "openbao", { @@ -202,6 +228,20 @@ new k8s.helm.v3.Release( { port: 8201, protocol: "TCP" }, ], }, + { + from: [ + { + podSelector: { + matchLabels: { + "app.kubernetes.io/name": "openbao", + "app.kubernetes.io/instance": "openbao", + "app.kubernetes.io/component": "snapshot-agent", + }, + }, + }, + ], + ports: [{ port: 8200, protocol: "TCP" }], + }, ], }, ha: { @@ -254,7 +294,50 @@ audit "file" "stdout" { size: "2Gi", }, }, + // Hourly Raft snapshots to RustFS. The job logs in to OpenBao with + // Kubernetes auth, set up by hand in docs/runbooks/openbao.md. + snapshotAgent: { + enabled: true, + schedule: "0 * * * *", + s3CredentialsSecret: "openbao-snapshot-s3", + config: { + s3Host: snapshotS3Host, + // s3cmd's --host-bucket. Using the host itself keeps requests + // path-style, so DNS doesn't need a record per bucket. + s3Bucket: snapshotS3Host, + s3Uri: `s3://${snapshotBucket}`, + // Empty turns off the agent's own pruning, which would need delete + // access. RustFS lifecycle rules handle retention instead. + s3ExpireDays: "", + // RustFS rejects s3cmd's default signing region, "US". + s3cmdExtraFlag: "-v --region=us-east-1", + baoAuthPath: "kubernetes", + baoRole: "openbao-snapshot", + }, + extraEnvironmentVars: { + BAO_CACERT: "/openbao/tls/ca.crt", + }, + extraVolumes: [ + { + name: "openbao-ca", + secret: { + secretName: "openbao-server-tls", + items: [{ key: "ca.crt", path: "ca.crt" }], + }, + }, + ], + extraVolumeMounts: [ + { name: "openbao-ca", mountPath: "/openbao/tls", readOnly: true }, + ], + resources: { + requests: { cpu: "50m", memory: "64Mi" }, + limits: { memory: "256Mi" }, + }, + }, }, }, - opts({ dependsOn: [serversTransport], protect: true }), + opts({ + dependsOn: [serversTransport, snapshotS3Credentials], + protect: true, + }), );