fix(bucket): refuse COSI classes of another SeaweedFS instance

BucketClass and BucketAccessClass are cluster-scoped and every
SeaweedFS instance names its classes after its own namespace. The
bucket chart builds class names from the resolved SeaweedFS namespace
and the free-form storagePool, and a child tenant's namespace is its
parent's namespace plus its name, so a storagePool could produce the
name of a class that belongs to a different tenant's instance and
provision the bucket there.

Before rendering, the chart now looks up every class the release will
reference and refuses the render when a class exists with a driver
other than the resolved instance's, or when storagePool is set and the
class does not exist. The driver, not the name, identifies the
instance, and requiring the pool class to exist keeps a claim from
waiting for a matching class to appear later. The check fails a
release that already references such a class on its next upgrade; a
bucket with a pool of its own instance, or with no pool, renders
unchanged. Offline renders, where the release namespace is not found,
skip the check.

Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
This commit is contained in:
Aleksei Sviridkin committed 2026-11-26 11:03:20 +03:00
1 parent c0b53abb72
commit d3711f2380
2 files changed
+197

No files matched your search

@@ -1,5 +1,32 @@
{{- $seaweedfs := .Values._namespace.seaweedfs }}
{{- $pool := .Values.storagePool }}
{{- /*
COSI classes are cluster-scoped and named after the namespace of the instance
that owns them, so a class name built from a storagePool can also be the name
of another tenant's instance class. The driver identifies the instance; a
storage pool class that does not exist is refused too, so that a claim cannot
wait for another instance to create it. The release namespace lookup is empty
only when no cluster is reachable.
*/}}
{{- if and $seaweedfs (lookup "v1" "Namespace" "" .Release.Namespace) }}
{{- $base := $seaweedfs }}
{{- if $pool }}{{ $base = printf "%s-%s" $seaweedfs $pool }}{{ end }}
{{- $claimClass := $base }}
{{- if .Values.locking }}
{{- $claimClass = printf "%s-lock" $base }}
{{- end }}
{{- $classes := list (list "BucketClass" $claimClass) }}
{{- range $name, $user := .Values.users }}
{{- $classes = append $classes (list "BucketAccessClass" (printf "%s%s" $base (ternary "-readonly" "" (not (not $user.readonly))))) }}
{{- end }}
{{- $driver := printf "%s.seaweedfs.objectstorage.k8s.io" $seaweedfs }}
{{- range $class := $classes }}
{{- $live := lookup "objectstorage.k8s.io/v1alpha1" (index $class 0) "" (index $class 1) }}
{{- if or (and $live (ne (toString $live.driverName) $driver)) (and (not $live) $pool) }}
{{- fail (printf "%s %q is not provided by the SeaweedFS instance in namespace %q: set storagePool to a pool declared in that instance's volume.pools or volume.zones.<zone>.pools, or leave it empty" (index $class 0) (index $class 1) $seaweedfs) }}
{{- end }}
{{- end }}
{{- end }}
apiVersion: objectstorage.k8s.io/v1alpha1
kind: BucketClaim
metadata:
@@ -0,0 +1,170 @@
suite: bucket refuses COSI classes that the resolved SeaweedFS instance does not provide
# The tenant inherits the SeaweedFS of tenant-foo; tenant-foo-b is a child
# tenant running its own instance, whose base classes are named tenant-foo-b.
templates:
- templates/bucketclaim.yaml
release:
name: bucket-data
namespace: tenant-foo-c
set:
_namespace:
seaweedfs: tenant-foo
users:
alice: {}
bob:
readonly: true
scheme: &scheme
"v1/Namespace":
gvr:
group: ""
version: v1
resource: namespaces
namespaced: false
"objectstorage.k8s.io/v1alpha1/BucketClass":
gvr:
group: objectstorage.k8s.io
version: v1alpha1
resource: bucketclasses
namespaced: false
"objectstorage.k8s.io/v1alpha1/BucketAccessClass":
gvr:
group: objectstorage.k8s.io
version: v1alpha1
resource: bucketaccessclasses
namespaced: false
releaseNamespace: &releaseNamespace
apiVersion: v1
kind: Namespace
metadata:
name: tenant-foo-c
ownBase: &ownBase
apiVersion: objectstorage.k8s.io/v1alpha1
kind: BucketClass
metadata:
name: tenant-foo
driverName: tenant-foo.seaweedfs.objectstorage.k8s.io
ownBaseAccess: &ownBaseAccess
apiVersion: objectstorage.k8s.io/v1alpha1
kind: BucketAccessClass
metadata:
name: tenant-foo
driverName: tenant-foo.seaweedfs.objectstorage.k8s.io
ownBaseReadonly: &ownBaseReadonly
apiVersion: objectstorage.k8s.io/v1alpha1
kind: BucketAccessClass
metadata:
name: tenant-foo-readonly
driverName: tenant-foo.seaweedfs.objectstorage.k8s.io
ownPool: &ownPool
apiVersion: objectstorage.k8s.io/v1alpha1
kind: BucketClass
metadata:
name: tenant-foo-fast
driverName: tenant-foo.seaweedfs.objectstorage.k8s.io
ownPoolAccess: &ownPoolAccess
apiVersion: objectstorage.k8s.io/v1alpha1
kind: BucketAccessClass
metadata:
name: tenant-foo-fast
driverName: tenant-foo.seaweedfs.objectstorage.k8s.io
ownPoolReadonly: &ownPoolReadonly
apiVersion: objectstorage.k8s.io/v1alpha1
kind: BucketAccessClass
metadata:
name: tenant-foo-fast-readonly
driverName: tenant-foo.seaweedfs.objectstorage.k8s.io
childBase: &childBase
apiVersion: objectstorage.k8s.io/v1alpha1
kind: BucketClass
metadata:
name: tenant-foo-b
driverName: tenant-foo-b.seaweedfs.objectstorage.k8s.io
childBaseAccess: &childBaseAccess
apiVersion: objectstorage.k8s.io/v1alpha1
kind: BucketAccessClass
metadata:
name: tenant-foo-b
driverName: tenant-foo-b.seaweedfs.objectstorage.k8s.io
childBaseReadonly: &childBaseReadonly
apiVersion: objectstorage.k8s.io/v1alpha1
kind: BucketAccessClass
metadata:
name: tenant-foo-b-readonly
driverName: tenant-foo-b.seaweedfs.objectstorage.k8s.io
childLock: &childLock
apiVersion: objectstorage.k8s.io/v1alpha1
kind: BucketClass
metadata:
name: tenant-foo-lock
driverName: tenant-foo-lock.seaweedfs.objectstorage.k8s.io
tests:
- it: renders a pool the resolved instance declares
set:
storagePool: fast
kubernetesProvider:
scheme: *scheme
objects: [*releaseNamespace, *ownBase, *ownBaseAccess, *ownBaseReadonly, *ownPool, *ownPoolAccess, *ownPoolReadonly, *childBase, *childBaseAccess, *childBaseReadonly]
asserts:
- notFailedTemplate: {}
- equal:
path: spec.bucketClassName
value: tenant-foo-fast
documentSelector:
path: kind
value: BucketClaim
- it: renders the base class when no storagePool is set
kubernetesProvider:
scheme: *scheme
objects: [*releaseNamespace, *ownBase, *ownBaseAccess, *ownBaseReadonly, *childBase, *childBaseAccess, *childBaseReadonly]
asserts:
- notFailedTemplate: {}
- equal:
path: spec.bucketClassName
value: tenant-foo
documentSelector:
path: kind
value: BucketClaim
- it: refuses a storagePool that names the class of another tenant's instance
set:
storagePool: b
kubernetesProvider:
scheme: *scheme
objects: [*releaseNamespace, *ownBase, *ownBaseAccess, *ownBaseReadonly, *ownPool, *ownPoolAccess, *ownPoolReadonly, *childBase, *childBaseAccess, *childBaseReadonly]
asserts:
- failedTemplate:
errorPattern: 'is not provided by the SeaweedFS instance in namespace "tenant-foo"'
- it: refuses a storagePool the instance does not declare
set:
storagePool: slow
kubernetesProvider:
scheme: *scheme
objects: [*releaseNamespace, *ownBase, *ownBaseAccess, *ownBaseReadonly, *ownPool, *ownPoolAccess, *ownPoolReadonly]
asserts:
- failedTemplate:
errorPattern: 'BucketClass "tenant-foo-slow" is not provided by the SeaweedFS instance in namespace "tenant-foo"'
- it: refuses a variant class that another tenant's instance owns
set:
locking: true
kubernetesProvider:
scheme: *scheme
objects: [*releaseNamespace, *ownBase, *ownBaseAccess, *ownBaseReadonly, *childLock]
asserts:
- failedTemplate:
errorPattern: 'BucketClass "tenant-foo-lock" is not provided by the SeaweedFS instance in namespace "tenant-foo"'
- it: keeps the offline render when the cluster is not reachable
set:
storagePool: b
asserts:
- notFailedTemplate: {}
- equal:
path: spec.bucketClassName
value: tenant-foo-b
documentSelector:
path: kind
value: BucketClaim