Compare commits

...

2 Commits

Author SHA1 Message Date
codex
596b2df8e6 ci: build release images without a missing Docker daemon 2026-10-03 16:00:22 -05:00
codex
3c0c868708 deploy: scope state access for Longhorn backups 2026-10-03 16:00:22 -05:00
6 changed files with 82 additions and 51 deletions

View File

@ -1,6 +0,0 @@
misconfigurations:
- id: KSV-0041
paths:
- deploy/clusterrole.yaml
expired_at: 2026-05-22
statement: Soteria copies restic credentials into target namespaces for backup Jobs; replace with a narrower per-namespace secret distribution model.

66
Jenkinsfile vendored
View File

@ -18,6 +18,7 @@ spec:
operator: NotIn operator: NotIn
values: values:
- titan-06 - titan-06
- titan-08
preferredDuringSchedulingIgnoredDuringExecution: preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100 - weight: 100
preference: preference:
@ -38,22 +39,22 @@ spec:
jenkins/jenkins-jenkins-agent: "true" jenkins/jenkins-jenkins-agent: "true"
containers: containers:
- name: builder - name: builder
image: registry.bstein.dev/bstein/docker:27 image: gcr.io/kaniko-project/executor@sha256:c3109d5926a997b100c4343944e06c6b30a6804b2f9abe0994d3de6ef92b028e
command: command:
- cat - /busybox/cat
tty: true tty: true
env: resources:
- name: DOCKER_HOST requests:
value: tcp://localhost:2375 cpu: 100m
- name: DOCKER_TLS_CERTDIR memory: 1Gi
value: "" limits:
cpu: 1500m
memory: 2Gi
volumeMounts: volumeMounts:
- name: workspace-volume - name: workspace-volume
mountPath: /home/jenkins/agent mountPath: /home/jenkins/agent
- name: docker-config-writable - name: docker-config-writable
mountPath: /root/.docker mountPath: /kaniko/.docker
- name: harbor-config
mountPath: /docker-config
- name: tester - name: tester
image: registry.bstein.dev/bstein/golang:1.25-bookworm image: registry.bstein.dev/bstein/golang:1.25-bookworm
command: command:
@ -73,12 +74,6 @@ spec:
volumes: volumes:
- name: docker-config-writable - name: docker-config-writable
emptyDir: {} emptyDir: {}
- name: harbor-config
secret:
secretName: harbor-robot-pipeline
items:
- key: .dockerconfigjson
path: config.json
- name: workspace-volume - name: workspace-volume
emptyDir: {} emptyDir: {}
""" """
@ -523,7 +518,7 @@ PY
expression { return params.PUBLISH_IMAGES } expression { return params.PUBLISH_IMAGES }
} }
steps { steps {
container('builder') { container('tester') {
script { script {
sh 'git config --global --add safe.directory /home/jenkins/agent/workspace/Soteria' sh 'git config --global --add safe.directory /home/jenkins/agent/workspace/Soteria'
def semver = sh(returnStdout: true, script: 'git describe --tags --exact-match || true').trim() def semver = sh(returnStdout: true, script: 'git describe --tags --exact-match || true').trim()
@ -536,24 +531,6 @@ PY
} }
} }
} }
stage('Buildx setup') {
when {
expression { return params.PUBLISH_IMAGES }
}
steps {
container('builder') {
sh '''
set -eu
seq 1 10 | while read _; do
docker info && break || sleep 2
done
BUILDER_NAME="soteria-${BUILD_NUMBER}"
docker buildx rm "${BUILDER_NAME}" >/dev/null 2>&1 || true
docker buildx create --name "${BUILDER_NAME}" --driver docker-container --driver-opt image=registry.bstein.dev/bstein/buildkit:buildx-stable-1 --bootstrap --use
'''
}
}
}
stage('Build & push image') { stage('Build & push image') {
when { when {
expression { return params.PUBLISH_IMAGES } expression { return params.PUBLISH_IMAGES }
@ -563,13 +540,20 @@ PY
withCredentials([usernamePassword(credentialsId: 'harbor-robot', usernameVariable: 'HARBOR_USERNAME', passwordVariable: 'HARBOR_PASSWORD')]) { withCredentials([usernamePassword(credentialsId: 'harbor-robot', usernameVariable: 'HARBOR_USERNAME', passwordVariable: 'HARBOR_PASSWORD')]) {
sh ''' sh '''
set -eu set -eu
set +x
VERSION_TAG=$(cut -d= -f2 build.env) VERSION_TAG=$(cut -d= -f2 build.env)
printf '%s' "${HARBOR_PASSWORD}" | docker login registry.bstein.dev -u "${HARBOR_USERNAME}" --password-stdin umask 077
docker buildx build --platform linux/arm64 \ auth=$(printf '%s:%s' "${HARBOR_USERNAME}" "${HARBOR_PASSWORD}" | base64 | tr -d '\\n')
--provenance=false \ printf '{"auths":{"registry.bstein.dev":{"auth":"%s"}}}\\n' "${auth}" > /kaniko/.docker/config.json
--tag registry.bstein.dev/bstein/soteria:${VERSION_TAG} \ trap 'rm -f /kaniko/.docker/config.json' EXIT
--tag registry.bstein.dev/bstein/soteria:latest \ /kaniko/executor \
--push . --context "${WORKSPACE}" \
--dockerfile "${WORKSPACE}/Dockerfile" \
--build-arg BUILDPLATFORM=linux/arm64 \
--build-arg TARGETOS=linux \
--build-arg TARGETARCH=arm64 \
--destination "registry.bstein.dev/bstein/soteria:${VERSION_TAG}" \
--destination registry.bstein.dev/bstein/soteria:latest
''' '''
} }
} }

16
deploy/NOTES.md Normal file
View File

@ -0,0 +1,16 @@
# Default deployment permissions
This deployment uses the Longhorn backend. It reads inventory across namespaces
and updates only `soteria-policies` and `soteria-backup-usage` in its own namespace.
The empty Secret declarations create those records on first deployment; they
deliberately contain no data field, so application-written state is preserved.
The optional `soteria-restic` credential is readable by exact name only.
Changing the state or credential names also requires updating the Role. Do not
restore cluster-wide Secret access to accommodate another deployment.
The optional restic backend needs additional, explicitly approved Roles and
RoleBindings in each backup/restore target namespace: Job creation and the
credential-copy operations in `internal/k8s/jobs.go`. Those grants are not part
of this Longhorn deployment. Review credential distribution before enabling
restic; Kubernetes RBAC cannot restrict Secret creation by resource name.

View File

@ -8,9 +8,6 @@ rules:
- apiGroups: [""] - apiGroups: [""]
resources: ["persistentvolumeclaims", "persistentvolumes"] resources: ["persistentvolumeclaims", "persistentvolumes"]
verbs: ["get", "list"] verbs: ["get", "list"]
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get", "list", "create", "update", "delete"]
- apiGroups: ["batch"] - apiGroups: ["batch"]
resources: ["jobs"] resources: ["jobs"]
verbs: ["get", "list", "create"] verbs: ["get", "list"]

View File

@ -7,5 +7,6 @@ resources:
- serviceaccount.yaml - serviceaccount.yaml
- clusterrole.yaml - clusterrole.yaml
- clusterrolebinding.yaml - clusterrolebinding.yaml
- state-access.yaml
- deployment.yaml - deployment.yaml
- service.yaml - service.yaml

39
deploy/state-access.yaml Normal file
View File

@ -0,0 +1,39 @@
# The default Longhorn mode writes only its own policy and usage records.
apiVersion: v1
kind: Secret
metadata:
name: soteria-policies
type: Opaque
---
apiVersion: v1
kind: Secret
metadata:
name: soteria-backup-usage
type: Opaque
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: soteria-state
rules:
- apiGroups: [""]
resources: ["secrets"]
resourceNames: ["soteria-policies", "soteria-backup-usage"]
verbs: ["get", "update"]
- apiGroups: [""]
resources: ["secrets"]
resourceNames: ["soteria-restic"]
verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: soteria-state
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: soteria-state
subjects:
- kind: ServiceAccount
name: soteria
namespace: soteria