Skip to content

Commit 1c123fd

Browse files
committed
feat(bucket): add access policy
1 parent c7a228d commit 1c123fd

28 files changed

Lines changed: 744 additions & 169 deletions

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ RUN go mod download
1515
COPY cmd/main.go cmd/main.go
1616
COPY api/ api/
1717
COPY internal/ internal/
18+
COPY pkg/ pkg/
1819

1920

2021
# Build

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,37 @@ spec:
199199
quota:
200200
default: 10000000
201201
# override: 20000000
202-
202+
203+
# AccessPolicy to set on the bucket
204+
# Default to Private.
205+
# The type can be "Public", "Private" or "Custom"
206+
# Public, anyone can access in rw without authentication.
207+
# Private, only authenticated users with policies can access.
208+
# Custom, define a policy to apply.
209+
# In the example below, everybody can read, but only authenticated users with policy can write.
210+
accessPolicy:
211+
type: Custom
212+
policyContent: |-
213+
{
214+
"Version": "2012-10-17",
215+
"Statement": [
216+
{
217+
"Effect": "Allow",
218+
"Principal": {
219+
"AWS": [
220+
"*"
221+
]
222+
},
223+
"Action": [
224+
"s3:GetObject"
225+
],
226+
"Resource": [
227+
"arn:aws:s3:::dummy-bucket/*"
228+
]
229+
}
230+
]
231+
}
232+
203233
# Optionnal, let empty if you have configured the default s3 else use an existing s3Instance
204234
s3InstanceRef: "s3-default-instance"
205235

api/v1alpha1/bucket_types.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1alpha1
1818

1919
import (
20+
s3model "github.com/InseeFrLab/s3-operator/pkg/s3/model"
2021
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2122
)
2223

@@ -47,6 +48,10 @@ type BucketSpec struct {
4748
// Quota to apply to the bucket
4849
// +kubebuilder:validation:Required
4950
Quota Quota `json:"quota"`
51+
52+
// AccessPolicy to apply to the bucket
53+
// +kubebuilder:validation:Optional
54+
AccessPolicy *AccessPolicy `json:"accessPolicy,omitempty"`
5055
}
5156

5257
// BucketStatus defines the observed state of Bucket
@@ -87,6 +92,18 @@ type Quota struct {
8792
Override int64 `json:"override,omitempty"`
8893
}
8994

95+
type AccessPolicy struct {
96+
// type of the AccessPolicy
97+
// +kubebuilder:validation:Required
98+
// +kubebuilder:validation:Default=Private
99+
// +kubebuilder:validation:Enum=Private;Public;Custom
100+
Type s3model.BucketAccessPolicyType `json:"type"`
101+
102+
// Content of the policy (IAM JSON format) for Custom AccessPolicy
103+
// +kubebuilder:validation:Optional
104+
PolicyContent string `json:"policyContent,omitempty"`
105+
}
106+
90107
func init() {
91108
SchemeBuilder.Register(&Bucket{}, &BucketList{})
92109
}

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
s3InstanceControllers "github.com/InseeFrLab/s3-operator/internal/controller/s3instance"
3434
userControllers "github.com/InseeFrLab/s3-operator/internal/controller/user"
3535
"github.com/InseeFrLab/s3-operator/internal/helpers"
36-
s3factory "github.com/InseeFrLab/s3-operator/internal/s3/factory/impl"
36+
s3factory "github.com/InseeFrLab/s3-operator/pkg/s3/factory/impl"
3737

3838
"go.uber.org/zap/zapcore"
3939
"k8s.io/apimachinery/pkg/runtime"

config/crd/bases/s3.onyxia.sh_buckets.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,23 @@ spec:
3939
spec:
4040
description: BucketSpec defines the desired state of Bucket
4141
properties:
42+
accessPolicy:
43+
description: AccessPolicy to apply to the bucket
44+
properties:
45+
policyContent:
46+
description: Content of the policy (IAM JSON format) for Custom
47+
AccessPolicy
48+
type: string
49+
type:
50+
description: type of the AccessPolicy
51+
enum:
52+
- Private
53+
- Public
54+
- Custom
55+
type: string
56+
required:
57+
- type
58+
type: object
4259
name:
4360
description: Name of the bucket
4461
type: string

deploy/charts/s3-operator/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ type: application
1313
# This is the chart version. This version number should be incremented each time you make changes
1414
# to the chart and its templates, including the app version.
1515
# Versions are expected to follow Semantic Versioning (https://semver.org/)
16-
version: 0.7.0
16+
version: 0.8.0
1717
# This is the version number of the application being deployed. This version number should be
1818
# incremented each time you make changes to the application. Versions are not expected to
1919
# follow Semantic Versioning. They should reflect the version the application is using.
2020
# It is recommended to use it with quotes.
21-
appVersion: "v0.12.0"
21+
appVersion: "v0.13.0"

0 commit comments

Comments
 (0)