diff --git a/backend/azureblob/azureblob.go b/backend/azureblob/azureblob.go index 878321097..6df71619c 100644 --- a/backend/azureblob/azureblob.go +++ b/backend/azureblob/azureblob.go @@ -70,6 +70,7 @@ const ( defaultChunkSize = 4 * fs.Mebi defaultAccessTier = blob.AccessTier("") // FIXME AccessTierNone sasCopyValidity = time.Hour // how long SAS should last when doing server side copy + sasCopyStartSkew = 15 * time.Minute // how far back SAS should start to allow for clock skew ) // setAcceptEncodingGzip is a per-call policy that sets Accept-Encoding: gzip @@ -1827,7 +1828,7 @@ func (f *Fs) getUserDelegation(ctx context.Context) (*service.UserDelegationCred } // Validity window - start := time.Now().UTC() + start := time.Now().UTC().Add(-sasCopyStartSkew) expiry := start.Add(2 * sasCopyValidity) startStr := start.Format(time.RFC3339) expiryStr := expiry.Format(time.RFC3339) @@ -1876,7 +1877,7 @@ func (o *Object) getAuth(ctx context.Context, noAuth bool) (srcURL string, err e // Build the SAS values perms := sas.BlobPermissions{Read: true} container, containerPath := o.split() - start := time.Now().UTC() + start := time.Now().UTC().Add(-sasCopyStartSkew) expiry := start.Add(sasCopyValidity) vals := sas.BlobSignatureValues{ StartTime: start, diff --git a/backend/azureblob/azureblob_internal_test.go b/backend/azureblob/azureblob_internal_test.go index acad39aad..c234463c2 100644 --- a/backend/azureblob/azureblob_internal_test.go +++ b/backend/azureblob/azureblob_internal_test.go @@ -54,6 +54,11 @@ func TestBlockIDCreator(t *testing.T) { assert.ErrorContains(t, bic2.checkID(chunkNumber, got), "random bytes") } +func TestCopySASTimingConstants(t *testing.T) { + require.Greater(t, sasCopyStartSkew, time.Duration(0)) + require.Greater(t, sasCopyValidity, sasCopyStartSkew) +} + func (f *Fs) testFeatures(t *testing.T) { // Check first feature flags are set on this remote enabled := f.Features().SetTier