Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(casbackends): support for s3 compatible endpoints (minio, cloudflare R2, ...) #1055

Merged
merged 4 commits into from
Jul 1, 2024

Conversation

migmartri
Copy link
Member

@migmartri migmartri commented Jun 28, 2024

Adds support to registering an S3-compatible CAS-backend by providing a custom endpoint. making it compatible with Minio and Cloudflare R2

AWS S3 support has not changed, except that the region now is optional. Region is optional now because it doesn't make much sense in the concept of other providers.

chainloop cas-backend add aws-s3 --access-key-id AKIA5CHQ4CJGSHYWLEZF --secret-access-key ${SECRET_KEY} --bucket chainloop-test --name aws-test                     
┌──────────┬────────────────┬──────────┬─────────────┬───────────────┬─────────┐
│ NAME     │ LOCATION       │ PROVIDER │ DESCRIPTION │ LIMITS        │ DEFAULT │
├──────────┼────────────────┼──────────┼─────────────┼───────────────┼─────────┤
│ aws-test │ chainloop-test │ AWS-S3   │             │ MaxSize: 100M │ false   │
└──────────┴────────────────┴──────────┴─────────────┴───────────────┴─────────┘

Minio

chainloop cas-backend add aws-s3 --name minio-test --access-key-id asdivBQsihWhMU0L --secret-access-key REDACTED --bucket test-chainloop \
--endpoint http://localhost:19000 

┌────────────┬─────────────────────────────────────┬──────────┬─────────────┬───────────────┬─────────┐
│ NAME       │ LOCATION                            │ PROVIDER │ DESCRIPTION │ LIMITS        │ DEFAULT │
├────────────┼─────────────────────────────────────┼──────────┼─────────────┼───────────────┼─────────┤
│ minio-test │ http://localhost:19000/test-chainlo │ AWS-S3   │             │ MaxSize: 100M │ true    │
│            │ op                                  │          │             │               │         │
└────────────┴─────────────────────────────────────┴──────────┴─────────────┴───────────────┴─────────┘

Cloudflare R2

chainloop cas-backend add aws-s3 --access-key-id fa95fbfa470effd79fdbe28b61b0788e --secret-access-key REDACTED --bucket chainloop \
--endpoint https://35c24d45e1cd7bc36279b8a4d130c7fe.r2.cloudflarestorage.com --name cloud-flare-test
┌──────────────────┬─────────────────────────────────────┬──────────┬─────────────┬───────────────┬─────────┐
│ NAME             │ LOCATION                            │ PROVIDER │ DESCRIPTION │ LIMITS        │ DEFAULT │
├──────────────────┼─────────────────────────────────────┼──────────┼─────────────┼───────────────┼─────────┤
│ cloud-flare-test │ https://35c24d45e1cd7bc36279b8a4d13 │ AWS-S3   │             │ MaxSize: 100M │ true    │
│                  │ 0c7fe.r2.cloudflarestorage.com/chai │          │             │               │         │
│                  │ nloop                               │          │             │               │         │
└──────────────────┴─────────────────────────────────────┴──────────┴─────────────┴───────────────┴─────────┘

note that the location shows the custom endpoint provided during registration

Closes #1053

cc/ @hanygirgis

Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
@migmartri migmartri marked this pull request as ready for review June 29, 2024 20:32
@@ -46,6 +48,11 @@ func newCASBackendAddAWSS3Cmd() *cobra.Command {
}
}

// If there is a custom endpoint we want to store it as part of the fqdn location
if endpoint != "" {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reason of storing the endpoint in the location instead of the credentials is so it's shown to the user and can't be updated later on.

// https://developers.cloudflare.com/r2/api/s3/api/
func (b *Backend) checksumVerificationEnabled() bool {
var enabled = true
if b.customEndpoint != "" && strings.Contains(b.customEndpoint, "r2.cloudflarestorage.com") {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cloudflare doesn't support this feature.

Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
@migmartri migmartri changed the title feat(casbackends): support for s3 compatible backends feat(casbackends): support for s3 compatible endpoints (minio, cloudflare R2) Jun 29, 2024
@migmartri migmartri changed the title feat(casbackends): support for s3 compatible endpoints (minio, cloudflare R2) feat(casbackends): support for s3 compatible endpoints (minio, cloudflare R2, ...) Jun 29, 2024
Copy link
Member

@jiparis jiparis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great. Thanks for tackling it.

input.ChecksumSHA256 = aws.String(hexSha256ToBinaryB64(resource.Digest))
}

if _, err := uploader.UploadWithContext(ctx, input); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on another topic, does this do streaming already?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The underlying library does, the service layer that servers bytestream does not.

@migmartri migmartri merged commit 0f09abd into chainloop-dev:main Jul 1, 2024
13 checks passed
@migmartri migmartri deleted the add-s3-custom-endpoint branch July 1, 2024 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support custom S3 object storage
3 participants