Skip to content

Commit b2f0826

Browse files
committed
Only add query values not already present in the token
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
1 parent 0670db7 commit b2f0826

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

docs/spec/v1beta2/buckets.md

+3
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,9 @@ data:
532532
sasKey: <base64>
533533
```
534534

535+
The query values from the `sasKey` data field in the Secrets gets merged with the `spec.endpoint` of the `Bucket`.
536+
If there are the same key is present in the both of them, The token takes precedence.
537+
535538
Note that the Azure SAS Token has an expiry date and it should be updated before it expires so that Flux can
536539
continue to access Azure Storage.
537540

pkg/azure/blob.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,10 @@ func sasTokenFromSecret(ep string, secret *corev1.Secret) (string, error) {
378378
//merge the query values in the endpoint wuth the token
379379
epValues := epURL.Query()
380380
for key, val := range epValues {
381-
for _, str := range val {
382-
values.Set(key, str)
381+
if !values.Has(key) {
382+
for _, str := range val {
383+
values.Add(key, str)
384+
}
383385
}
384386
}
385387

pkg/azure/blob_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,16 @@ func Test_sasTokenFromSecret(t *testing.T) {
339339
},
340340
want: "https://accountName.blob.windows.net?sv=2020-08-04&ss=bfqt&srt=co&sp=rwdl&se=2022-05-26T21:55:35Z&st=2022-05-26&spr=https&sig=JlHT",
341341
},
342+
{
343+
name: "conflicting query values in token",
344+
endpoint: "https://accountName.blob.windows.net?sv=2020-08-04&ss=abcde",
345+
secret: &corev1.Secret{
346+
Data: map[string][]byte{
347+
sasKeyField: []byte("sv=2019-07-06&ss=bfqt&srt=co&sp=rwdl&se=2022-05-26T21:55:35Z&st=2022-05-26&spr=https&sig=JlHT"),
348+
},
349+
},
350+
want: "https://accountName.blob.windows.net?sv=2019-07-06&ss=bfqt&srt=co&sp=rwdl&se=2022-05-26T21:55:35Z&st=2022-05-26&spr=https&sig=JlHT",
351+
},
342352
{
343353
name: "invalid sas token",
344354
secret: &corev1.Secret{

0 commit comments

Comments
 (0)