Skip to content

Commit

Permalink
Add a feature to introduce BucketPolicy (#233)
Browse files Browse the repository at this point in the history
* Add bucketPolicy in type

* mod

* add new APIs in s3 backend

* add policies in RGW

* add policy

* policy

* lint

* tidy

* remove unnecessary prefix 'Bucket'

* remove meaningless comments

* add error messages

* add PolicyClient to subresourceClient

* fix code block in DEVELOPMENT
  • Loading branch information
Shunpoco authored May 21, 2024
1 parent fecd24e commit f786640
Show file tree
Hide file tree
Showing 11 changed files with 841 additions and 2 deletions.
6 changes: 6 additions & 0 deletions apis/provider-ceph/v1alpha1/bucket_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ type BucketParameters struct {
// AssumeRoleTags may be used to add custom values to an AssumeRole request.
// +optional
AssumeRoleTags []Tag `json:"assumeRoleTags,omitempty"`

// Policy is a JSON string of BucketPolicy.
// If it is set, Provider-Ceph calls PutBucketPolicy API after creating the bucket.
// Before adding it, you should validate the JSON string.
// +optional
Policy string `json:"policy,omitempty"`
}

// BackendInfo contains relevant information about an S3 backend for
Expand Down
2 changes: 1 addition & 1 deletion docs/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Spin up the test environment, but without Localstack and use your own external C

```
AWS_ACCESS_KEY_ID=<your-access-key> AWS_SECRET_ACCESS_KEY=<yoursecret-key> CEPH_ADDRESS=<your-ceph-cluster-address> make dev-ceph
`
```

In either case, after you've made some changes, kill (Ctrl+C) the existing `provider-ceph` and re-run it:

Expand Down
3 changes: 3 additions & 0 deletions internal/backendstore/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ type S3Client interface {
DeleteBucketLifecycle(context.Context, *s3.DeleteBucketLifecycleInput, ...func(*s3.Options)) (*s3.DeleteBucketLifecycleOutput, error)
GetBucketAcl(context.Context, *s3.GetBucketAclInput, ...func(*s3.Options)) (*s3.GetBucketAclOutput, error)
PutBucketAcl(context.Context, *s3.PutBucketAclInput, ...func(*s3.Options)) (*s3.PutBucketAclOutput, error)
PutBucketPolicy(context.Context, *s3.PutBucketPolicyInput, ...func(*s3.Options)) (*s3.PutBucketPolicyOutput, error)
GetBucketPolicy(context.Context, *s3.GetBucketPolicyInput, ...func(*s3.Options)) (*s3.GetBucketPolicyOutput, error)
DeleteBucketPolicy(context.Context, *s3.DeleteBucketPolicyInput, ...func(*s3.Options)) (*s3.DeleteBucketPolicyOutput, error)
}

//counterfeiter:generate . STSClient
Expand Down
249 changes: 249 additions & 0 deletions internal/backendstore/backendstorefakes/fake_s3client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions internal/controller/bucket/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,9 @@ const (
errObserveAcl = "failed to observe bucket acl"
errHandleAcl = "failed to handle bucket acl"

// Policy error messages.
errObservePolicy = "failed to observe bucket policy"
errHandlePolicy = "failed to handle bucket policy"

True = "true"
)
2 changes: 1 addition & 1 deletion internal/controller/bucket/lifecycleconfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ type LifecycleConfigurationClient struct {
log logging.Logger
}

// NewLifecycleConfigurationClient creates the client for Accelerate Configuration
func NewLifecycleConfigurationClient(b *backendstore.BackendStore, h *s3clienthandler.Handler, l logging.Logger) *LifecycleConfigurationClient {
return &LifecycleConfigurationClient{backendStore: b, s3ClientHandler: h, log: l}
}

//nolint:dupl // LifecycleConfiguration and Policy are different feature.
func (l *LifecycleConfigurationClient) Observe(ctx context.Context, bucket *v1alpha1.Bucket, backendNames []string) (ResourceStatus, error) {
ctx, span := otel.Tracer("").Start(ctx, "bucket.LifecycleConfigurationClient.Observe")
defer span.End()
Expand Down
Loading

0 comments on commit f786640

Please sign in to comment.