From 4824837eedcfc06108676273376591cf9ff37bbf Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Wed, 17 Jul 2024 15:46:19 +0100 Subject: [PATCH] azureblob: allow anonymous access for public resources See: https://forum.rclone.org/t/azure-blob-public-resources/46882 --- backend/azureblob/azureblob.go | 12 +++++++++++- docs/content/azureblob.md | 7 +++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/backend/azureblob/azureblob.go b/backend/azureblob/azureblob.go index 6c07a3320..662be58a7 100644 --- a/backend/azureblob/azureblob.go +++ b/backend/azureblob/azureblob.go @@ -711,10 +711,11 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e ClientOptions: policyClientOptions, } - // Here we auth by setting one of cred, sharedKeyCred or f.svc + // Here we auth by setting one of cred, sharedKeyCred, f.svc or anonymous var ( cred azcore.TokenCredential sharedKeyCred *service.SharedKeyCredential + anonymous = false ) switch { case opt.EnvAuth: @@ -874,6 +875,9 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e if err != nil { return nil, fmt.Errorf("failed to acquire MSI token: %w", err) } + case opt.Account != "": + // Anonymous access + anonymous = true default: return nil, errors.New("no authentication method configured") } @@ -903,6 +907,12 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e if err != nil { return nil, fmt.Errorf("create client failed: %w", err) } + } else if anonymous { + // Anonymous public access + f.svc, err = service.NewClientWithNoCredential(opt.Endpoint, &clientOpt) + if err != nil { + return nil, fmt.Errorf("create public client failed: %w", err) + } } } if f.svc == nil { diff --git a/docs/content/azureblob.md b/docs/content/azureblob.md index 987045cb2..58c3f1f05 100644 --- a/docs/content/azureblob.md +++ b/docs/content/azureblob.md @@ -289,6 +289,13 @@ be explicitly specified using exactly one of the `msi_object_id`, If none of `msi_object_id`, `msi_client_id`, or `msi_mi_res_id` is set, this is is equivalent to using `env_auth`. +#### Anonymous {#anonymous} + +If you want to access resources with public anonymous access then set +`account` only. You can do this without making an rclone config: + + rclone lsf :azureblob,account=ACCOUNT:CONTAINER + {{< rem autogenerated options start" - DO NOT EDIT - instead edit fs.RegInfo in backend/azureblob/azureblob.go then run make backenddocs" >}} ### Standard options