feature: back up OpenBao to RustFS every hour

Turns on the Helm chart's snapshot CronJob. It logs in with Kubernetes auth and uploads with an upload-only RustFS key, so it can't read or delete backups. Its own pruning is off because it would need delete access; object lock and RustFS lifecycle rules handle retention.
This commit is contained in:
kasun committed 2026-12-02 04:29:16 +01:00
1 parent 22d2320e3d
commit b50aca4aff
1 file changed
+84 -1
+84 -1
View File
@@ -8,9 +8,18 @@ const appsRef = new pulumi.StackReference(
`${pulumi.getOrganization()}/k8s-apps/dev`, `${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 kubeconfig = bootstrapRef.requireOutput("kubeconfig");
const domain = appsRef.requireOutput("domain"); const domain = appsRef.requireOutput("domain");
const openbaoHost = pulumi.interpolate`bao.${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", { const k8sProvider = new k8s.Provider("k3s", {
kubeconfig, kubeconfig,
@@ -116,6 +125,23 @@ const serversTransport = new k8s.apiextensions.CustomResource(
opts({ dependsOn: [serverCert] }), 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( new k8s.helm.v3.Release(
"openbao", "openbao",
{ {
@@ -202,6 +228,20 @@ new k8s.helm.v3.Release(
{ port: 8201, protocol: "TCP" }, { 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: { ha: {
@@ -254,7 +294,50 @@ audit "file" "stdout" {
size: "2Gi", 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" }],
}, },
}, },
opts({ dependsOn: [serversTransport], protect: true }), ],
extraVolumeMounts: [
{ name: "openbao-ca", mountPath: "/openbao/tls", readOnly: true },
],
resources: {
requests: { cpu: "50m", memory: "64Mi" },
limits: { memory: "256Mi" },
},
},
},
},
opts({
dependsOn: [serversTransport, snapshotS3Credentials],
protect: true,
}),
); );