|
| 1 | +--- |
| 2 | +title: "Buckets and Users" |
| 3 | +linkTitle: "Buckets" |
| 4 | +description: "Create S3 buckets and manage user credentials" |
| 5 | +weight: 20 |
| 6 | +--- |
| 7 | + |
| 8 | +The Bucket application creates an S3 bucket via COSI and provisions per-user credentials as Kubernetes Secrets. |
| 9 | + |
| 10 | +## Creating a Bucket |
| 11 | + |
| 12 | +A minimal bucket uses the default BucketClass and creates no users: |
| 13 | + |
| 14 | +```yaml |
| 15 | +apiVersion: apps.cozystack.io/v1alpha1 |
| 16 | +kind: Bucket |
| 17 | +metadata: |
| 18 | + name: my-bucket |
| 19 | + namespace: tenant-example |
| 20 | +spec: {} |
| 21 | +``` |
| 22 | +
|
| 23 | +This provisions a BucketClaim against the default BucketClass (`tenant-example`). |
| 24 | +To make the bucket useful, add at least one user (see [Users](#users) below). |
| 25 | + |
| 26 | +## Selecting a Storage Pool |
| 27 | + |
| 28 | +If your SeaweedFS instance defines [storage pools]({{% ref "storage-pools" %}}), use the `storagePool` field to target a specific pool: |
| 29 | + |
| 30 | +```yaml |
| 31 | +apiVersion: apps.cozystack.io/v1alpha1 |
| 32 | +kind: Bucket |
| 33 | +metadata: |
| 34 | + name: my-bucket |
| 35 | + namespace: tenant-example |
| 36 | +spec: |
| 37 | + storagePool: ssd |
| 38 | +``` |
| 39 | + |
| 40 | +This provisions the BucketClaim against the `tenant-example-ssd` BucketClass. |
| 41 | + |
| 42 | +When `storagePool` is empty (the default), the bucket uses the default BucketClass. |
| 43 | + |
| 44 | +## Object Locking |
| 45 | + |
| 46 | +To create a bucket with object locking enabled, set `locking: true`: |
| 47 | + |
| 48 | +```yaml |
| 49 | +apiVersion: apps.cozystack.io/v1alpha1 |
| 50 | +kind: Bucket |
| 51 | +metadata: |
| 52 | + name: my-bucket |
| 53 | + namespace: tenant-example |
| 54 | +spec: |
| 55 | + storagePool: ssd |
| 56 | + locking: true |
| 57 | +``` |
| 58 | + |
| 59 | +This provisions the BucketClaim against the `-lock` BucketClass (e.g. `tenant-example-ssd-lock`). |
| 60 | +Lock-enabled BucketClasses use a `Retain` deletion policy and configure COMPLIANCE-mode object locking with a default retention period. |
| 61 | + |
| 62 | +{{< note >}} |
| 63 | +Object locking cannot be enabled or disabled after bucket creation. Create a new bucket if you need to change this setting. |
| 64 | +{{< /note >}} |
| 65 | + |
| 66 | +## Users |
| 67 | + |
| 68 | +The `users` map defines named S3 users for the bucket. |
| 69 | +Each entry creates a COSI BucketAccess resource and a corresponding Kubernetes Secret with S3 credentials. |
| 70 | + |
| 71 | +```yaml |
| 72 | +apiVersion: apps.cozystack.io/v1alpha1 |
| 73 | +kind: Bucket |
| 74 | +metadata: |
| 75 | + name: my-bucket |
| 76 | + namespace: tenant-example |
| 77 | +spec: |
| 78 | + storagePool: ssd |
| 79 | + users: |
| 80 | + admin: {} |
| 81 | + reader: |
| 82 | + readonly: true |
| 83 | +``` |
| 84 | + |
| 85 | +This creates two users: |
| 86 | + |
| 87 | +| User | Access | BucketAccessClass Used | Secret Name | |
| 88 | +| --- | --- | --- | --- | |
| 89 | +| `admin` | read-write | `tenant-example-ssd` | `my-bucket-admin` | |
| 90 | +| `reader` | read-only | `tenant-example-ssd-readonly` | `my-bucket-reader` | |
| 91 | + |
| 92 | +### User Parameters |
| 93 | + |
| 94 | +| Parameter | Type | Default | Description | |
| 95 | +| --- | --- | --- | --- | |
| 96 | +| `readonly` | `bool` | `false` | When `true`, provisions credentials from the `-readonly` BucketAccessClass | |
| 97 | + |
| 98 | +### Accessing Credentials |
| 99 | + |
| 100 | +Each user gets a Kubernetes Secret named `{bucket-name}-{username}` in the same namespace. |
| 101 | +The Secret contains S3 credentials provisioned by the COSI driver: |
| 102 | + |
| 103 | +```bash |
| 104 | +kubectl get secret my-bucket-admin -n tenant-example -o yaml |
| 105 | +``` |
| 106 | + |
| 107 | +The Secret contains the fields needed to configure an S3 client (endpoint, access key, secret key). |
| 108 | +The exact fields depend on the COSI driver implementation. |
| 109 | + |
| 110 | +### Rotating Credentials |
| 111 | + |
| 112 | +Bucket user credentials (access key and secret key) are generated once when the user is first created and cannot be updated in place. |
| 113 | +To rotate credentials for a user, remove the user from the `users` map and apply, then add the user back and apply again: |
| 114 | + |
| 115 | +```yaml |
| 116 | +# Step 1: remove the user to delete existing credentials |
| 117 | +spec: |
| 118 | + users: {} |
| 119 | +``` |
| 120 | + |
| 121 | +```yaml |
| 122 | +# Step 2: re-add the user to provision a fresh set of credentials |
| 123 | +spec: |
| 124 | + users: |
| 125 | + admin: {} |
| 126 | +``` |
| 127 | + |
| 128 | +{{< warning >}} |
| 129 | +Any applications using the old credentials will lose access between step 1 and step 2. |
| 130 | +Update your applications with the new credentials from the Secret after step 2 completes. |
| 131 | +{{< /warning >}} |
| 132 | + |
| 133 | +## BucketClass Selection Logic |
| 134 | + |
| 135 | +The BucketClass name is composed from three parts: |
| 136 | + |
| 137 | +```text |
| 138 | +{seaweedfs-namespace}[-{storagePool}][-lock] |
| 139 | +``` |
| 140 | + |
| 141 | +| storagePool | locking | BucketClass Used | |
| 142 | +| --- | --- | --- | |
| 143 | +| *(empty)* | `false` | `tenant-example` | |
| 144 | +| *(empty)* | `true` | `tenant-example-lock` | |
| 145 | +| `ssd` | `false` | `tenant-example-ssd` | |
| 146 | +| `ssd` | `true` | `tenant-example-ssd-lock` | |
| 147 | + |
| 148 | +Similarly, the BucketAccessClass is composed as: |
| 149 | + |
| 150 | +```text |
| 151 | +{seaweedfs-namespace}[-{storagePool}][-readonly] |
| 152 | +``` |
| 153 | + |
| 154 | +## Complete Example |
| 155 | + |
| 156 | +Deploy a bucket on the `ssd` pool with one admin user and one read-only user: |
| 157 | + |
| 158 | +```yaml |
| 159 | +apiVersion: apps.cozystack.io/v1alpha1 |
| 160 | +kind: Bucket |
| 161 | +metadata: |
| 162 | + name: media-assets |
| 163 | + namespace: tenant-example |
| 164 | +spec: |
| 165 | + storagePool: ssd |
| 166 | + locking: false |
| 167 | + users: |
| 168 | + app: |
| 169 | + readonly: false |
| 170 | + backup-reader: |
| 171 | + readonly: true |
| 172 | +``` |
| 173 | + |
| 174 | +After the bucket is provisioned, retrieve the credentials: |
| 175 | + |
| 176 | +```bash |
| 177 | +# Read-write credentials for the "app" user |
| 178 | +kubectl get secret media-assets-app -n tenant-example \ |
| 179 | + -o jsonpath='{.data}' | jq 'map_values(@base64d)' |
| 180 | +
|
| 181 | +# Read-only credentials for the "backup-reader" user |
| 182 | +kubectl get secret media-assets-backup-reader -n tenant-example \ |
| 183 | + -o jsonpath='{.data}' | jq 'map_values(@base64d)' |
| 184 | +``` |
| 185 | + |
| 186 | +## Related Documentation |
| 187 | + |
| 188 | +- [Storage Pools]({{% ref "storage-pools" %}}) -- configure tiered storage for pool selection |
| 189 | +- [SeaweedFS Service Reference]({{% ref "/docs/v1/operations/services/seaweedfs" %}}) -- full parameter reference |
0 commit comments