-
Notifications
You must be signed in to change notification settings - Fork 193
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
List objects when checking if bucket exists to allow use of container-level SAS token #906
Conversation
68a02ac
to
d029140
Compare
pkg/azure/blob.go
Outdated
var max int32 = 1 | ||
items := container.ListBlobsFlat(&azblob.ContainerListBlobsFlatOptions{ | ||
MaxResults: &max, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Azure SDK has a helper for this, see: https://github.com/Azure/azure-sdk-for-go/blob/b386adc15c2e60e3812956f68d244b608330c479/sdk/azcore/to/to.go#L10
Given this, I would likely replace this with:
var max int32 = 1 | |
items := container.ListBlobsFlat(&azblob.ContainerListBlobsFlatOptions{ | |
MaxResults: &max, | |
}) | |
items := container.ListBlobsFlat(&azblob.ContainerListBlobsFlatOptions{ | |
MaxResults: to.Ptr(1), | |
}) |
docs/spec/v1beta2/buckets.md
Outdated
**Note:** SAS Token has an expiry date and it should be updated before it expires so that Flux can | ||
continue to access Azure Storage. Also, The source-controller can use a account-level SAS token or a container-level SAS token. | ||
The minimum permissions for an account-level SAS Token is: | ||
- Allowed services: Blob | ||
- Allowed resource types: Container, Object | ||
- Allowed permission: Read, List | ||
|
||
The minimum permissions for a container-level SAS Token is: | ||
- Permission: Read, List |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
**Note:** SAS Token has an expiry date and it should be updated before it expires so that Flux can | |
continue to access Azure Storage. Also, The source-controller can use a account-level SAS token or a container-level SAS token. | |
The minimum permissions for an account-level SAS Token is: | |
- Allowed services: Blob | |
- Allowed resource types: Container, Object | |
- Allowed permission: Read, List | |
The minimum permissions for a container-level SAS Token is: | |
- Permission: Read, List | |
**Note:** The SAS token has an expiry date and it must be updated before it expires to allow Flux to | |
continue to access Azure Storage. It is allowed to use an account-level or container-level SAS token. | |
The minimum permissions for an account-level SAS token are: | |
- Allowed services: `Blob` | |
- Allowed resource types: `Container`, `Object` | |
- Allowed permissions: `Read`, `List` | |
The minimum permissions for a container-level SAS token are: | |
- Allowed permissions: `Read`, `List` | |
Refer to the [Azure documentation](https://learn.microsoft.com/en-us/rest/api/storageservices/create-account-sas#blob-service) for a full overview on permissions. |
pkg/azure/blob.go
Outdated
|
||
// For a container-level SASToken, we get an AuthenticationFailed when the bucket doesn't exist | ||
if respErr.ErrorCode == string(azblob.StorageErrorCodeAuthenticationFailed) { | ||
return false, fmt.Errorf("(Bucket might not exist) %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return false, fmt.Errorf("(Bucket might not exist) %w", err) | |
return false, fmt.Errorf("%w (Bucket name may be incorrect or non-existent)", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message is a bit long. I was thinking it might not be easily seen by users if placed at the end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e.g
3ab-4b60-b393-094065902f97","error":"failed to confirm existence of 'fluxes' bucket: GET https://testfluxsaas.blob.core.windows.net/fluxes\n--------------------------------------------------------------------------------\nRESPONSE 403: 403 Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.\nERROR CODE: AuthenticationFailed\n--------------------------------------------------------------------------------\n<?xml version=\"1.0\" encoding=\"utf-8\"?><Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.\nRequestId:daf54521-101e-003f-5ceb-d8649e000000\nTime:2022-10-05T18:50:34.3475175Z</Message><AuthenticationErrorDetail>Signature did not match. String to sign used was rl\n2022-10-05T10:53:36Z\n2022-10-05T18:53:36Z\n/blob/testfluxsaas/fluxes\n\n\nhttps\n2021-06-08\nc\n\n\n\n\n\n\n</AuthenticationErrorDetail></Error>\n--------------------------------------------------------------------------------\n (Bucket might not exist) "
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for pointing that out. Starting the error within parenthesis does not feel right, so potentially?
return false, fmt.Errorf("Bucket name may be incorrect, it does not exist or caller does not have enough permissions: %w", err)
err = respErr | ||
|
||
// For a container-level SASToken, we get an AuthenticationFailed when the bucket doesn't exist | ||
if respErr.ErrorCode == string(azblob.StorageErrorCodeAuthenticationFailed) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The library seems to have a helper method for this since v0.5.0
: Azure/azure-sdk-for-go@0e6a11e#diff-2c126bccb5ce0d58738ebd81c556270990a2f9f71a5bbfe8021f458c919c72aaR18
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The upgrade to v0.5.0
introduces some other changes that I think should come in a different PR.
Wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
docs/spec/v1beta2/buckets.md
Outdated
The minimum permissions for an account-level SAS token are: | ||
- Allowed services: `Blob` | ||
- Allowed resource types: `Container`, `Object` | ||
- Allowed permissions: `Read`, `List` | ||
|
||
The minimum permissions for a container-level SAS token are: | ||
- Allowed permissions: `Read`, `List` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The minimum permissions for an account-level SAS token are: | |
- Allowed services: `Blob` | |
- Allowed resource types: `Container`, `Object` | |
- Allowed permissions: `Read`, `List` | |
The minimum permissions for a container-level SAS token are: | |
- Allowed permissions: `Read`, `List` | |
The minimum permissions for an account-level SAS token are: | |
- Allowed services: `Blob` | |
- Allowed resource types: `Container`, `Object` | |
- Allowed permissions: `Read`, `List` | |
The minimum permissions for a container-level SAS token are: | |
- Allowed permissions: `Read`, `List` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than the indent nit, this looks good to me.
Signed-off-by: Somtochi Onyekwere <[email protected]>
Signed-off-by: Somtochi Onyekwere <[email protected]>
Closes #902
Signed-off-by: Somtochi Onyekwere [email protected]