mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-21 12:13:55 +09:00
feat(bucket): add publicRead to serve a bucket without credentials
A bucket cannot serve its objects without a signature: every BucketAccess issues a key, and the keys grant neither WriteAcp nor PutBucketPolicy, so a tenant cannot open the bucket themselves with put-bucket-acl. Static assets then need a proxy, presigned URLs or an operator running weed shell by hand, which no reconcile tracks and which outlives the bucket. publicRead renders one more BucketAccess on a new -public access class whose accessPolicy is public-read. The COSI driver handles that policy by adding Read:<bucket> to the gateway's anonymous identity and removing only that action on revoke, so deleting the bucket or turning the flag off closes it again without touching other public buckets. Anonymous callers can read objects but cannot list the bucket or write to it. The access is named <bucket>-public-read, the name a user called public-read would take, so that combination fails to render instead of fighting over one BucketAccess. Assisted-by: LLM Signed-off-by: Mattia Eleuteri <mattia@hidora.io>
This commit is contained in:
1 parent
56224a156c
commit
21fd2b7b69
13 files changed
+231
-11
No files matched your search
Generated
+3
@@ -25,6 +25,9 @@ type ConfigSpec struct {
|
||||
// Deploys the web UI (s3manager) with its Service and its Ingress or HTTPRoute at `<bucket>.<tenant host>`. Set to `false` to run the bucket without them.
|
||||
// +kubebuilder:default:=true
|
||||
Ui bool `json:"ui"`
|
||||
// Serves the bucket's objects to anyone without credentials at `<endpoint>/<bucket>/<key>`. Anonymous callers can read objects but cannot list the bucket or write to it.
|
||||
// +kubebuilder:default:=false
|
||||
PublicRead bool `json:"publicRead"`
|
||||
// Users configuration map.
|
||||
// +kubebuilder:default:={}
|
||||
Users map[string]User `json:"users,omitempty"`
|
||||
|
||||
@@ -4,11 +4,12 @@
|
||||
|
||||
### Parameters
|
||||
|
||||
| Name | Description | Type | Value |
|
||||
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------- | ------- |
|
||||
| `locking` | Provisions bucket from the `-lock` BucketClass (with object lock enabled). | `bool` | `false` |
|
||||
| `storagePool` | Selects a specific BucketClass by storage pool name. | `string` | `""` |
|
||||
| `ui` | Deploys the web UI (s3manager) with its Service and its Ingress or HTTPRoute at `<bucket>.<tenant host>`. Set to `false` to run the bucket without them. | `bool` | `true` |
|
||||
| `users` | Users configuration map. | `map[string]object` | `{}` |
|
||||
| `users[name].readonly` | Whether the user has read-only access. | `bool` | `false` |
|
||||
| Name | Description | Type | Value |
|
||||
| ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------- | ------- |
|
||||
| `locking` | Provisions bucket from the `-lock` BucketClass (with object lock enabled). | `bool` | `false` |
|
||||
| `storagePool` | Selects a specific BucketClass by storage pool name. | `string` | `""` |
|
||||
| `ui` | Deploys the web UI (s3manager) with its Service and its Ingress or HTTPRoute at `<bucket>.<tenant host>`. Set to `false` to run the bucket without them. | `bool` | `true` |
|
||||
| `publicRead` | Serves the bucket's objects to anyone without credentials at `<endpoint>/<bucket>/<key>`. Anonymous callers can read objects but cannot list the bucket or write to it. | `bool` | `false` |
|
||||
| `users` | Users configuration map. | `map[string]object` | `{}` |
|
||||
| `users[name].readonly` | Whether the user has read-only access. | `bool` | `false` |
|
||||
|
||||
@@ -22,3 +22,18 @@ spec:
|
||||
credentialsSecretName: {{ $.Release.Name }}-{{ $name }}
|
||||
protocol: s3
|
||||
{{- end }}
|
||||
{{- if .Values.publicRead }}
|
||||
{{- if hasKey .Values.users "public-read" }}
|
||||
{{- fail "publicRead creates the BucketAccess <bucket>-public-read, which the user \"public-read\" already owns: rename that user" }}
|
||||
{{- end }}
|
||||
---
|
||||
apiVersion: objectstorage.k8s.io/v1alpha1
|
||||
kind: BucketAccess
|
||||
metadata:
|
||||
name: {{ .Release.Name }}-public-read
|
||||
spec:
|
||||
bucketAccessClassName: {{ $seaweedfs }}{{- if $pool }}-{{ $pool }}{{- end }}-public
|
||||
bucketClaimName: {{ .Release.Name }}
|
||||
credentialsSecretName: {{ .Release.Name }}-public-read
|
||||
protocol: s3
|
||||
{{- end }}
|
||||
@@ -0,0 +1,82 @@
|
||||
suite: bucket publicRead
|
||||
templates:
|
||||
- templates/bucketclaim.yaml
|
||||
|
||||
release:
|
||||
name: bucket-my-bucket
|
||||
namespace: tenant-root
|
||||
|
||||
set:
|
||||
_namespace:
|
||||
seaweedfs: tenant-root
|
||||
|
||||
tests:
|
||||
- it: renders no public BucketAccess by default
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 1
|
||||
- isKind:
|
||||
of: BucketClaim
|
||||
|
||||
- it: renders a public-read BucketAccess on the -public class
|
||||
set:
|
||||
publicRead: true
|
||||
documentSelector:
|
||||
path: metadata.name
|
||||
value: bucket-my-bucket-public-read
|
||||
asserts:
|
||||
- isKind:
|
||||
of: BucketAccess
|
||||
- equal:
|
||||
path: spec.bucketAccessClassName
|
||||
value: tenant-root-public
|
||||
- equal:
|
||||
path: spec.bucketClaimName
|
||||
value: bucket-my-bucket
|
||||
- equal:
|
||||
path: spec.credentialsSecretName
|
||||
value: bucket-my-bucket-public-read
|
||||
|
||||
- it: uses the storage pool's -public class
|
||||
set:
|
||||
publicRead: true
|
||||
storagePool: fast
|
||||
documentSelector:
|
||||
path: metadata.name
|
||||
value: bucket-my-bucket-public-read
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.bucketAccessClassName
|
||||
value: tenant-root-fast-public
|
||||
|
||||
- it: keeps the access class free of -lock on a locked bucket
|
||||
set:
|
||||
publicRead: true
|
||||
locking: true
|
||||
documentSelector:
|
||||
path: metadata.name
|
||||
value: bucket-my-bucket-public-read
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.bucketAccessClassName
|
||||
value: tenant-root-public
|
||||
|
||||
- it: keeps the users' BucketAccesses next to the public one
|
||||
set:
|
||||
publicRead: true
|
||||
users:
|
||||
app: {}
|
||||
reader:
|
||||
readonly: true
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 4
|
||||
|
||||
- it: refuses a user that would own the public BucketAccess name
|
||||
set:
|
||||
publicRead: true
|
||||
users:
|
||||
public-read: {}
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorPattern: user "public-read" already owns
|
||||
@@ -20,6 +20,11 @@
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"publicRead": {
|
||||
"description": "Serves the bucket's objects to anyone without credentials at `\u003cendpoint\u003e/\u003cbucket\u003e/\u003ckey\u003e`. Anonymous callers can read objects but cannot list the bucket or write to it.",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"users": {
|
||||
"description": "Users configuration map.",
|
||||
"type": "object",
|
||||
|
||||
@@ -8,6 +8,9 @@ storagePool: ""
|
||||
## @param {bool} ui=true - Deploys the web UI (s3manager) with its Service and its Ingress or HTTPRoute at `<bucket>.<tenant host>`. Set to `false` to run the bucket without them.
|
||||
ui: true
|
||||
|
||||
## @param {bool} publicRead=false - Serves the bucket's objects to anyone without credentials at `<endpoint>/<bucket>/<key>`. Anonymous callers can read objects but cannot list the bucket or write to it.
|
||||
publicRead: false
|
||||
|
||||
## @typedef {struct} User - Bucket user configuration.
|
||||
## @field {bool} [readonly] - Whether the user has read-only access.
|
||||
|
||||
|
||||
@@ -35,4 +35,13 @@ driverName: {{ .Release.Namespace }}.seaweedfs.objectstorage.k8s.io
|
||||
authenticationType: KEY
|
||||
parameters:
|
||||
accessPolicy: readonly
|
||||
---
|
||||
kind: BucketAccessClass
|
||||
apiVersion: objectstorage.k8s.io/v1alpha1
|
||||
metadata:
|
||||
name: {{ .Release.Namespace }}-public
|
||||
driverName: {{ .Release.Namespace }}.seaweedfs.objectstorage.k8s.io
|
||||
authenticationType: KEY
|
||||
parameters:
|
||||
accessPolicy: public-read
|
||||
{{- end }}
|
||||
@@ -51,5 +51,14 @@ driverName: {{ $.Release.Namespace }}.seaweedfs.objectstorage.k8s.io
|
||||
authenticationType: KEY
|
||||
parameters:
|
||||
accessPolicy: readonly
|
||||
---
|
||||
kind: BucketAccessClass
|
||||
apiVersion: objectstorage.k8s.io/v1alpha1
|
||||
metadata:
|
||||
name: {{ $.Release.Namespace }}-{{ $poolName }}-public
|
||||
driverName: {{ $.Release.Namespace }}.seaweedfs.objectstorage.k8s.io
|
||||
authenticationType: KEY
|
||||
parameters:
|
||||
accessPolicy: public-read
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
@@ -0,0 +1,50 @@
|
||||
suite: seaweedfs public-read BucketAccessClass
|
||||
release:
|
||||
name: seaweedfs
|
||||
namespace: tenant-root
|
||||
|
||||
set:
|
||||
filer:
|
||||
grpcHost: seaweedfs-filer.tenant-other.svc
|
||||
_namespace:
|
||||
host: example.org
|
||||
ingress: tenant-root
|
||||
_cluster:
|
||||
issuer-name: letsencrypt-prod
|
||||
solver: http01
|
||||
|
||||
tests:
|
||||
- it: offers a -public access class to a Client instance
|
||||
template: templates/client/cosi-bucket-class.yaml
|
||||
set:
|
||||
topology: Client
|
||||
documentSelector:
|
||||
path: metadata.name
|
||||
value: tenant-root-public
|
||||
asserts:
|
||||
- isKind:
|
||||
of: BucketAccessClass
|
||||
- equal:
|
||||
path: parameters.accessPolicy
|
||||
value: public-read
|
||||
- equal:
|
||||
path: driverName
|
||||
value: tenant-root.seaweedfs.objectstorage.k8s.io
|
||||
|
||||
- it: offers a -public access class per storage pool
|
||||
template: templates/storage-pool-bucket-classes.yaml
|
||||
set:
|
||||
topology: Simple
|
||||
volume:
|
||||
pools:
|
||||
fast:
|
||||
diskType: ssd
|
||||
documentSelector:
|
||||
path: metadata.name
|
||||
value: tenant-root-fast-public
|
||||
asserts:
|
||||
- isKind:
|
||||
of: BucketAccessClass
|
||||
- equal:
|
||||
path: parameters.accessPolicy
|
||||
value: public-read
|
||||
+2
-2
@@ -8,7 +8,7 @@ spec:
|
||||
plural: buckets
|
||||
singular: bucket
|
||||
openAPISchema: |-
|
||||
{"title":"Chart Values","type":"object","properties":{"locking":{"description":"Provisions bucket from the `-lock` BucketClass (with object lock enabled).","type":"boolean","default":false},"storagePool":{"description":"Selects a specific BucketClass by storage pool name.","type":"string","default":"","x-cozystack-options":{"source":"storagepool"}},"ui":{"description":"Deploys the web UI (s3manager) with its Service and its Ingress or HTTPRoute at `<bucket>.<tenant host>`. Set to `false` to run the bucket without them.","type":"boolean","default":true},"users":{"description":"Users configuration map.","type":"object","default":{},"additionalProperties":{"type":"object","properties":{"readonly":{"description":"Whether the user has read-only access.","type":"boolean"}}}}}}
|
||||
{"title":"Chart Values","type":"object","properties":{"locking":{"description":"Provisions bucket from the `-lock` BucketClass (with object lock enabled).","type":"boolean","default":false},"storagePool":{"description":"Selects a specific BucketClass by storage pool name.","type":"string","default":"","x-cozystack-options":{"source":"storagepool"}},"ui":{"description":"Deploys the web UI (s3manager) with its Service and its Ingress or HTTPRoute at `<bucket>.<tenant host>`. Set to `false` to run the bucket without them.","type":"boolean","default":true},"publicRead":{"description":"Serves the bucket's objects to anyone without credentials at `<endpoint>/<bucket>/<key>`. Anonymous callers can read objects but cannot list the bucket or write to it.","type":"boolean","default":false},"users":{"description":"Users configuration map.","type":"object","default":{},"additionalProperties":{"type":"object","properties":{"readonly":{"description":"Whether the user has read-only access.","type":"boolean"}}}}}}
|
||||
release:
|
||||
prefix: bucket-
|
||||
labels:
|
||||
@@ -26,7 +26,7 @@ spec:
|
||||
tags:
|
||||
- storage
|
||||
icon: PHN2ZyB3aWR0aD0iMTQ0IiBoZWlnaHQ9IjE0NCIgdmlld0JveD0iMCAwIDE0NCAxNDQiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIxNDQiIGhlaWdodD0iMTQ0IiByeD0iMjQiIGZpbGw9InVybCgjcGFpbnQwX2xpbmVhcl82ODNfMzA5MSkiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik03MiAzMC4xNjQxTDExNy45ODMgMzYuNzc4OVY0MC42NzM5QzExNy45ODMgNDYuNDY1MyA5Ny4zODYyIDUxLjEzMzIgNzEuOTgyNyA1MS4xMzMyQzQ2LjU3OTIgNTEuMTMzMiAyNiA0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zIDU0LjEwMzdaIiBmaWxsPSIjRTA1MjQzIi8+CjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNNjEuMTcyNSA2MC4wMjkzSDgxLjA5MjhWNzkuMTY3Nkg2MS4xNzI1VjYwLjAyOTNaTTQ1LjMzMDEgOTUuMzY4OEM0NS4zMzAxIDkwLjE0MiA0OS43MTA0IDg1LjkzNDIgNTUuMTUxMSA4NS45MzQyQzYwLjU5MTcgODUuOTM0MiA2NC45NzIxIDkwLjE0MiA2NC45NzIxIDk1LjM2ODhDNjQuOTcyMSAxMDAuNTk2IDYwLjU5MTcgMTA0LjgwMyA1NS4xNTExIDEwNC44MDNDNDkuNzEwNCAxMDQuODAzIDQ1LjMzMDEgMTAwLjU5NiA0NS4zMzAxIDk1LjM2ODhaTTk2LjQ0ODcgMTA0LjM2OEg3Ni43NzIyTDg2LjYxMDUgODYuNzczN0w5Ni40NDg3IDEwNC4zNjhaIiBmaWxsPSJ3aGl0ZSIvPgo8ZGVmcz4KPGxpbmVhckdyYWRpZW50IGlkPSJwYWludDBfbGluZWFyXzY4M18zMDkxIiB4MT0iMCIgeTE9IjAiIHgyPSIxNTEiIHkyPSIxODAiIGdyYWRpZW50VW5pdHM9InVzZXJTcGFjZU9uVXNlIj4KPHN0b3Agc3RvcC1jb2xvcj0iI0ZGRjBFRSIvPgo8c3RvcCBvZmZzZXQ9IjEiIHN0b3AtY29sb3I9IiNFQzg4N0QiLz4KPC9saW5lYXJHcmFkaWVudD4KPC9kZWZzPgo8L3N2Zz4K
|
||||
keysOrder: [["apiVersion"], ["appVersion"], ["kind"], ["metadata"], ["metadata", "name"], ["spec", "locking"], ["spec", "storagePool"], ["spec", "ui"], ["spec", "users"]]
|
||||
keysOrder: [["apiVersion"], ["appVersion"], ["kind"], ["metadata"], ["metadata", "name"], ["spec", "locking"], ["spec", "storagePool"], ["spec", "ui"], ["spec", "publicRead"], ["spec", "users"]]
|
||||
secrets:
|
||||
exclude: []
|
||||
include:
|
||||
|
||||
@@ -39,4 +39,13 @@ driverName: {{ .Values.cosi.driverName }}
|
||||
authenticationType: KEY
|
||||
parameters:
|
||||
accessPolicy: readonly
|
||||
---
|
||||
kind: BucketAccessClass
|
||||
apiVersion: objectstorage.k8s.io/v1alpha1
|
||||
metadata:
|
||||
name: {{ .Values.cosi.bucketClassName }}-public
|
||||
driverName: {{ .Values.cosi.driverName }}
|
||||
authenticationType: KEY
|
||||
parameters:
|
||||
accessPolicy: public-read
|
||||
{{- end }}
|
||||
@@ -1,8 +1,8 @@
|
||||
diff --git a/packages/system/seaweedfs/charts/seaweedfs/templates/cosi/cosi-bucket-class.yaml b/packages/system/seaweedfs/charts/seaweedfs/templates/cosi/cosi-bucket-class.yaml
|
||||
index 4d19cc128..1ff0e7768 100644
|
||||
index 4d19cc128..11d7fb779 100644
|
||||
--- a/packages/system/seaweedfs/charts/seaweedfs/templates/cosi/cosi-bucket-class.yaml
|
||||
+++ b/packages/system/seaweedfs/charts/seaweedfs/templates/cosi/cosi-bucket-class.yaml
|
||||
@@ -11,10 +11,32 @@ parameters:
|
||||
@@ -11,10 +11,41 @@
|
||||
{{- toYaml . | nindent 2 }}
|
||||
{{- end }}
|
||||
---
|
||||
@@ -34,4 +34,13 @@ index 4d19cc128..1ff0e7768 100644
|
||||
+authenticationType: KEY
|
||||
+parameters:
|
||||
+ accessPolicy: readonly
|
||||
+---
|
||||
+kind: BucketAccessClass
|
||||
+apiVersion: objectstorage.k8s.io/v1alpha1
|
||||
+metadata:
|
||||
+ name: {{ .Values.cosi.bucketClassName }}-public
|
||||
+driverName: {{ .Values.cosi.driverName }}
|
||||
+authenticationType: KEY
|
||||
+parameters:
|
||||
+ accessPolicy: public-read
|
||||
{{- end }}
|
||||
@@ -0,0 +1,25 @@
|
||||
suite: vendored COSI classes include public-read
|
||||
templates:
|
||||
- charts/seaweedfs/templates/cosi/cosi-bucket-class.yaml
|
||||
|
||||
release:
|
||||
name: seaweedfs-system
|
||||
namespace: tenant-root
|
||||
|
||||
tests:
|
||||
- it: renders a -public BucketAccessClass with the public-read policy
|
||||
set:
|
||||
seaweedfs:
|
||||
cosi:
|
||||
enabled: true
|
||||
bucketClassName: tenant-root
|
||||
driverName: tenant-root.seaweedfs.objectstorage.k8s.io
|
||||
documentSelector:
|
||||
path: metadata.name
|
||||
value: tenant-root-public
|
||||
asserts:
|
||||
- isKind:
|
||||
of: BucketAccessClass
|
||||
- equal:
|
||||
path: parameters.accessPolicy
|
||||
value: public-read
|
||||
Reference in new issue
Block a user