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

List objects when checking if bucket exists to allow use of container-level SAS token #906

Merged
merged 2 commits into from
Oct 7, 2022

Conversation

somtochiama
Copy link
Member

Closes #902

Signed-off-by: Somtochi Onyekwere somtochionyekwere@gmail.com

@somtochiama somtochiama changed the title Add docs on SAS permission List objects when checking if bucket exists to allow use of container-level SAS token Sep 27, 2022
@somtochiama somtochiama marked this pull request as draft September 27, 2022 03:13
@somtochiama somtochiama reopened this Sep 27, 2022
@somtochiama somtochiama marked this pull request as ready for review October 5, 2022 08:56
@somtochiama somtochiama requested a review from pjbgf October 5, 2022 08:57
Comment on lines 184 to 187
var max int32 = 1
items := container.ListBlobsFlat(&azblob.ContainerListBlobsFlatOptions{
MaxResults: &max,
})
Copy link
Member

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:

Suggested change
var max int32 = 1
items := container.ListBlobsFlat(&azblob.ContainerListBlobsFlatOptions{
MaxResults: &max,
})
items := container.ListBlobsFlat(&azblob.ContainerListBlobsFlatOptions{
MaxResults: to.Ptr(1),
})

Comment on lines 540 to 548
**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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
**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.


// 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)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return false, fmt.Errorf("(Bucket might not exist) %w", err)
return false, fmt.Errorf("%w (Bucket name may be incorrect or non-existent)", err)

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 error message is a bit long. I was thinking it might not be easily seen by users if placed at the end.

Copy link
Member Author

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) "

Copy link
Member

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) {
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

@somtochiama somtochiama Oct 6, 2022

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?

Copy link
Member

@pjbgf pjbgf left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines 543 to 549
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`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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`

Copy link
Member

@hiddeco hiddeco left a 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.

@hiddeco hiddeco added enhancement New feature or request area/bucket Bucket related issues and pull requests labels Oct 7, 2022
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
@pjbgf pjbgf merged commit 34f127b into fluxcd:main Oct 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/bucket Bucket related issues and pull requests enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Azure Blob Storage - failed to confirm existence of 'test-container' bucket
3 participants