From b236a2692313a1eae7d56d01bcd35afae0cb9be4 Mon Sep 17 00:00:00 2001 From: Stavros Kois <47820033+stavros-k@users.noreply.github.com> Date: Mon, 2 Dec 2024 00:37:37 +0200 Subject: [PATCH] chore(credentials): validate credentials.url (#29806) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Description** ⚒️ Fixes # **⚙️ Type of change** - [ ] ⚙️ Feature/App addition - [ ] 🪛 Bugfix - [ ] ⚠️ Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] 🔃 Refactor of current code **🧪 How Has This Been Tested?** **📃 Notes:** **✔️ Checklist:** - [ ] ⚖️ My code follows the style guidelines of this project - [ ] 👀 I have performed a self-review of my own code - [ ] #️⃣ I have commented my code, particularly in hard-to-understand areas - [ ] 📄 I have made corresponding changes to the documentation - [x] ⚠️ My changes generate no new warnings - [x] 🧪 I have added tests to this description that prove my fix is effective or that my feature works - [ ] ⬆️ I increased versions for any altered app according to semantic versioning - [x] I made sure the title starts with `feat(chart-name):`, `fix(chart-name):` or `chore(chart-name):` **➕ App addition** If this PR is an app addition please make sure you have done the following. - [ ] 🖼️ I have added an icon in the Chart's root directory called `icon.png` --- _Please don't blindly check all the boxes. Read them and only check those that apply. Those checkboxes are there for the reviewer to see what is this all about and the status of this PR with a quick glance._ --- .../tests/cnpg/backup_metadata_test.yaml | 2 +- .../tests/cnpg/backup_name_test.yaml | 2 +- .../backup_provider_secret_spec_test.yaml | 2 +- .../tests/cnpg/backup_spec_test.yaml | 2 +- .../tests/cnpg/backup_validation_test.yaml | 25 +++++++++++++++++++ .../tests/cnpg/cluster_backup_spec_test.yaml | 14 +++++------ .../tests/cnpg/cluster_validation_test.yaml | 2 +- .../cnpg/scheduled_backup_metadata_test.yaml | 2 +- .../cnpg/scheduled_backup_name_test.yaml | 2 +- .../cnpg/scheduled_backup_spec_test.yaml | 2 +- .../cnpg/scheduled_backup_stop_test.yaml | 2 +- .../replication_dest_metadata_test.yaml | 2 +- .../volsync/replication_dest_name_test.yaml | 2 +- .../volsync/replication_dest_spec_test.yaml | 2 +- .../replication_source_metadata_test.yaml | 2 +- .../volsync/replication_source_name_test.yaml | 2 +- .../volsync/replication_src_spec_test.yaml | 2 +- .../tests/volsync/validation_test.yaml | 12 ++++----- .../lib/cnpg/barmanObjectStore/_getData.tpl | 2 -- .../templates/lib/credentials/_validation.tpl | 6 +++++ .../library/common/templates/spawner/_pvc.tpl | 6 +++-- 21 files changed, 63 insertions(+), 32 deletions(-) diff --git a/charts/library/common-test/tests/cnpg/backup_metadata_test.yaml b/charts/library/common-test/tests/cnpg/backup_metadata_test.yaml index f7585be2c59..6d4c105ba0e 100644 --- a/charts/library/common-test/tests/cnpg/backup_metadata_test.yaml +++ b/charts/library/common-test/tests/cnpg/backup_metadata_test.yaml @@ -12,7 +12,7 @@ tests: credentials: test: &test type: s3 - url: some-url + url: http://some-url bucket: some-bucket encrKey: some-encr-key accessKey: some-access-key diff --git a/charts/library/common-test/tests/cnpg/backup_name_test.yaml b/charts/library/common-test/tests/cnpg/backup_name_test.yaml index 4a89028d9d6..d6d90612eed 100644 --- a/charts/library/common-test/tests/cnpg/backup_name_test.yaml +++ b/charts/library/common-test/tests/cnpg/backup_name_test.yaml @@ -14,7 +14,7 @@ tests: accessKey: some-access-key secretKey: some-secret-key bucket: some-bucket - url: some-url + url: http://some-url cnpg: my-pg: enabled: true diff --git a/charts/library/common-test/tests/cnpg/backup_provider_secret_spec_test.yaml b/charts/library/common-test/tests/cnpg/backup_provider_secret_spec_test.yaml index 0829d118e3b..46527204e4e 100644 --- a/charts/library/common-test/tests/cnpg/backup_provider_secret_spec_test.yaml +++ b/charts/library/common-test/tests/cnpg/backup_provider_secret_spec_test.yaml @@ -10,7 +10,7 @@ tests: credentials: test: type: s3 - url: some-url + url: http://some-url encrKey: some-encr-key bucket: some-bucket secretKey: some-secret-key diff --git a/charts/library/common-test/tests/cnpg/backup_spec_test.yaml b/charts/library/common-test/tests/cnpg/backup_spec_test.yaml index e73bbecd89d..8fabfcaca2a 100644 --- a/charts/library/common-test/tests/cnpg/backup_spec_test.yaml +++ b/charts/library/common-test/tests/cnpg/backup_spec_test.yaml @@ -14,7 +14,7 @@ tests: secretKey: some-secret-key bucket: some-bucket encrKey: some-encr-key - url: some-url + url: http://some-url cnpg: my-pg: enabled: true diff --git a/charts/library/common-test/tests/cnpg/backup_validation_test.yaml b/charts/library/common-test/tests/cnpg/backup_validation_test.yaml index 2bb1b803d60..54a5c4a245a 100644 --- a/charts/library/common-test/tests/cnpg/backup_validation_test.yaml +++ b/charts/library/common-test/tests/cnpg/backup_validation_test.yaml @@ -40,3 +40,28 @@ tests: asserts: - failedTemplate: errorMessage: Name [test-release-name-common-test-cnpg-my-pg-backup-_invalid] is not valid. Must start and end with an alphanumeric lowercase character. It can contain '-'. And must be at most 253 characters. + + - it: should fail with invalid url in s3 credentials + set: + credentials: + test: + type: s3 + url: some-url + bucket: some-bucket + encrKey: some-encr-key + accessKey: some-access-key + secretKey: some-secret-key + cnpg: + my-pg: + enabled: true + user: test-user + database: test-db + password: test-password + backups: + enabled: true + credentials: test + manualBackups: + - name: today + asserts: + - failedTemplate: + errorMessage: CNPG Backup - Expected [url] in [credentials.test] to start with [http://] or [https://]. It was observed that sometimes can cause issues if it does not. Got [some-url] diff --git a/charts/library/common-test/tests/cnpg/cluster_backup_spec_test.yaml b/charts/library/common-test/tests/cnpg/cluster_backup_spec_test.yaml index 9e4f7247d87..6d73cef2b50 100644 --- a/charts/library/common-test/tests/cnpg/cluster_backup_spec_test.yaml +++ b/charts/library/common-test/tests/cnpg/cluster_backup_spec_test.yaml @@ -14,7 +14,7 @@ tests: secretKey: some-secret-key bucket: some-bucket encrKey: some-encr-key - url: some-url + url: http://some-url cnpg: my-pg: enabled: true @@ -64,7 +64,7 @@ tests: compression: bzip2 jobs: 2 destinationPath: some-path - endpointURL: some-url + endpointURL: http://some-url s3Credentials: accessKeyId: key: ACCESS_KEY_ID @@ -132,7 +132,7 @@ tests: compression: bzip2 jobs: 2 destinationPath: some-path - endpointURL: some-url + endpointURL: http://some-url s3Credentials: accessKeyId: key: ACCESS_KEY_ID @@ -200,7 +200,7 @@ tests: compression: bzip2 jobs: 2 destinationPath: some-path - endpointURL: some-url + endpointURL: http://some-url s3Credentials: accessKeyId: key: ACCESS_KEY_ID @@ -269,7 +269,7 @@ tests: compression: bzip2 jobs: 2 destinationPath: some-path - endpointURL: some-url + endpointURL: http://some-url s3Credentials: accessKeyId: key: ACCESS_KEY_ID @@ -339,7 +339,7 @@ tests: encryption: AES256 jobs: 2 destinationPath: some-path - endpointURL: some-url + endpointURL: http://some-url s3Credentials: accessKeyId: key: ACCESS_KEY_ID @@ -408,7 +408,7 @@ tests: data: jobs: 2 destinationPath: some-path - endpointURL: some-url + endpointURL: http://some-url s3Credentials: accessKeyId: key: ACCESS_KEY_ID diff --git a/charts/library/common-test/tests/cnpg/cluster_validation_test.yaml b/charts/library/common-test/tests/cnpg/cluster_validation_test.yaml index d0e87cbd22a..0b3981ec361 100644 --- a/charts/library/common-test/tests/cnpg/cluster_validation_test.yaml +++ b/charts/library/common-test/tests/cnpg/cluster_validation_test.yaml @@ -230,7 +230,7 @@ tests: accessKey: some-access-key secretKey: some-secret-key bucket: some-bucket - url: some-url + url: http://some-url encrKey: some-encr-key cnpg: my-pg: diff --git a/charts/library/common-test/tests/cnpg/scheduled_backup_metadata_test.yaml b/charts/library/common-test/tests/cnpg/scheduled_backup_metadata_test.yaml index 562a7ab5cb3..f7356d67dfb 100644 --- a/charts/library/common-test/tests/cnpg/scheduled_backup_metadata_test.yaml +++ b/charts/library/common-test/tests/cnpg/scheduled_backup_metadata_test.yaml @@ -12,7 +12,7 @@ tests: credentials: test: &test type: s3 - url: some-url + url: http://some-url bucket: some-bucket encrKey: some-encr-key accessKey: some-access-key diff --git a/charts/library/common-test/tests/cnpg/scheduled_backup_name_test.yaml b/charts/library/common-test/tests/cnpg/scheduled_backup_name_test.yaml index 176119d36fe..b1a4f10bd97 100644 --- a/charts/library/common-test/tests/cnpg/scheduled_backup_name_test.yaml +++ b/charts/library/common-test/tests/cnpg/scheduled_backup_name_test.yaml @@ -10,7 +10,7 @@ tests: credentials: test: type: s3 - url: some-url + url: http://some-url bucket: some-bucket encrKey: some-encr-key accessKey: some-access-key diff --git a/charts/library/common-test/tests/cnpg/scheduled_backup_spec_test.yaml b/charts/library/common-test/tests/cnpg/scheduled_backup_spec_test.yaml index fef4a6c2f69..61c80a57465 100644 --- a/charts/library/common-test/tests/cnpg/scheduled_backup_spec_test.yaml +++ b/charts/library/common-test/tests/cnpg/scheduled_backup_spec_test.yaml @@ -10,7 +10,7 @@ tests: credentials: test: type: s3 - url: some-url + url: http://some-url bucket: some-bucket encrKey: some-encr-key accessKey: some-access-key diff --git a/charts/library/common-test/tests/cnpg/scheduled_backup_stop_test.yaml b/charts/library/common-test/tests/cnpg/scheduled_backup_stop_test.yaml index 6d7b0e19548..13c68301a2e 100644 --- a/charts/library/common-test/tests/cnpg/scheduled_backup_stop_test.yaml +++ b/charts/library/common-test/tests/cnpg/scheduled_backup_stop_test.yaml @@ -14,7 +14,7 @@ tests: accessKey: some-access-key secretKey: some-secret-key bucket: some-bucket - url: some-url + url: http://some-url cnpg: my-pg: enabled: true diff --git a/charts/library/common-test/tests/volsync/replication_dest_metadata_test.yaml b/charts/library/common-test/tests/volsync/replication_dest_metadata_test.yaml index 0e9e49aaccf..caeecbd8a1c 100644 --- a/charts/library/common-test/tests/volsync/replication_dest_metadata_test.yaml +++ b/charts/library/common-test/tests/volsync/replication_dest_metadata_test.yaml @@ -42,7 +42,7 @@ tests: credentials: mys3: type: s3 - url: some-url + url: http://some-url bucket: some-bucket encrKey: some-key accessKey: some-access-key diff --git a/charts/library/common-test/tests/volsync/replication_dest_name_test.yaml b/charts/library/common-test/tests/volsync/replication_dest_name_test.yaml index f52ba3ad4d9..37888ca9df2 100644 --- a/charts/library/common-test/tests/volsync/replication_dest_name_test.yaml +++ b/charts/library/common-test/tests/volsync/replication_dest_name_test.yaml @@ -32,7 +32,7 @@ tests: credentials: mys3: type: s3 - url: some-url + url: http://some-url bucket: some-bucket encrKey: some-key accessKey: some-access-key diff --git a/charts/library/common-test/tests/volsync/replication_dest_spec_test.yaml b/charts/library/common-test/tests/volsync/replication_dest_spec_test.yaml index 78f350262a6..85b1fe49500 100644 --- a/charts/library/common-test/tests/volsync/replication_dest_spec_test.yaml +++ b/charts/library/common-test/tests/volsync/replication_dest_spec_test.yaml @@ -25,7 +25,7 @@ tests: credentials: &credentials mys3: type: s3 - url: some-url + url: http://some-url bucket: some-bucket encrKey: some-key accessKey: some-access-key diff --git a/charts/library/common-test/tests/volsync/replication_source_metadata_test.yaml b/charts/library/common-test/tests/volsync/replication_source_metadata_test.yaml index 5798364ef21..c9486f3fcc9 100644 --- a/charts/library/common-test/tests/volsync/replication_source_metadata_test.yaml +++ b/charts/library/common-test/tests/volsync/replication_source_metadata_test.yaml @@ -42,7 +42,7 @@ tests: credentials: mys3: type: s3 - url: some-url + url: http://some-url bucket: some-bucket encrKey: some-key accessKey: some-access-key diff --git a/charts/library/common-test/tests/volsync/replication_source_name_test.yaml b/charts/library/common-test/tests/volsync/replication_source_name_test.yaml index 156e8b72875..8069c87d429 100644 --- a/charts/library/common-test/tests/volsync/replication_source_name_test.yaml +++ b/charts/library/common-test/tests/volsync/replication_source_name_test.yaml @@ -32,7 +32,7 @@ tests: credentials: mys3: type: s3 - url: some-url + url: http://some-url bucket: some-bucket encrKey: some-key accessKey: some-access-key diff --git a/charts/library/common-test/tests/volsync/replication_src_spec_test.yaml b/charts/library/common-test/tests/volsync/replication_src_spec_test.yaml index 22161c66634..b305949d3a5 100644 --- a/charts/library/common-test/tests/volsync/replication_src_spec_test.yaml +++ b/charts/library/common-test/tests/volsync/replication_src_spec_test.yaml @@ -25,7 +25,7 @@ tests: credentials: &credentials mys3: type: s3 - url: some-url + url: http://some-url bucket: some-bucket encrKey: some-key accessKey: some-access-key diff --git a/charts/library/common-test/tests/volsync/validation_test.yaml b/charts/library/common-test/tests/volsync/validation_test.yaml index 8812e256e35..088b047e162 100644 --- a/charts/library/common-test/tests/volsync/validation_test.yaml +++ b/charts/library/common-test/tests/volsync/validation_test.yaml @@ -62,7 +62,7 @@ tests: credentials: my-other-secret: type: s3 - url: some-url + url: http://some-url bucket: some-bucket encrKey: some-key accessKey: some-access-key @@ -88,7 +88,7 @@ tests: credentials: my-secret: type: s3 - url: some-url + url: http://some-url bucket: "" asserts: - failedTemplate: @@ -100,7 +100,7 @@ tests: credentials: my-secret: type: s3 - url: some-url + url: http://some-url bucket: some-bucket encrKey: "" asserts: @@ -113,7 +113,7 @@ tests: credentials: my-secret: type: s3 - url: some-url + url: http://some-url bucket: some-bucket encrKey: some-key accessKey: "" @@ -127,7 +127,7 @@ tests: credentials: my-secret: type: s3 - url: some-url + url: http://some-url bucket: some-bucket encrKey: some-key accessKey: some-access-key @@ -155,7 +155,7 @@ tests: credentials: &credentials my-secret: type: s3 - url: some-url + url: http://some-url bucket: some-bucket encrKey: some-key accessKey: some-access-key diff --git a/charts/library/common/templates/lib/cnpg/barmanObjectStore/_getData.tpl b/charts/library/common/templates/lib/cnpg/barmanObjectStore/_getData.tpl index 2ea9f68e1c4..6cffbdb09e9 100644 --- a/charts/library/common/templates/lib/cnpg/barmanObjectStore/_getData.tpl +++ b/charts/library/common/templates/lib/cnpg/barmanObjectStore/_getData.tpl @@ -4,7 +4,6 @@ {{- $type := .type -}} {{- $serverName := $objectData.clusterName -}} - {{- $endpointURL := "" -}} {{- $destinationPath := "" -}} {{- $creds := dict -}} {{- $key := "" -}} @@ -38,7 +37,6 @@ {{- $data := (dict "serverName" $serverName - "endpointURL" $endpointURL "destinationPath" $destinationPath "creds" $creds "key" $key diff --git a/charts/library/common/templates/lib/credentials/_validation.tpl b/charts/library/common/templates/lib/credentials/_validation.tpl index 01b52e990aa..18ae90335a6 100644 --- a/charts/library/common/templates/lib/credentials/_validation.tpl +++ b/charts/library/common/templates/lib/credentials/_validation.tpl @@ -22,4 +22,10 @@ {{- fail (printf "VolSync - Expected non-empty [%s] in [credentials.%s]" $key $credName) -}} {{- end -}} {{- end -}} + + {{- $url := get $credentials "url" -}} + {{- if and (not (hasPrefix "http://" $url)) (not (hasPrefix "https://" $url)) -}} + {{- fail (printf "%s - Expected [url] in [credentials.%s] to start with [http://] or [https://]. It was observed that sometimes can cause issues if it does not. Got [%s]" $caller $credName $url) -}} + {{- end -}} + {{- end -}} diff --git a/charts/library/common/templates/spawner/_pvc.tpl b/charts/library/common/templates/spawner/_pvc.tpl index d15de6482d7..fc8af8c367d 100644 --- a/charts/library/common/templates/spawner/_pvc.tpl +++ b/charts/library/common/templates/spawner/_pvc.tpl @@ -1,4 +1,4 @@ -{{/* PVC Spawwner */}} +{{/* PVC Spawner */}} {{/* Call this template: {{ include "tc.v1.common.spawner.pvc" $ -}} */}} @@ -102,7 +102,9 @@ {{- $credentials := get $.Values.credentials $volsync.credentials -}} - {{- $baseRepo := printf "s3:%s/%s" $credentials.url $credentials.bucket -}} + {{- $url := $credentials.url | replace "http://" "" | replace "https://" "" -}} + + {{- $baseRepo := printf "s3:%s/%s" $url $credentials.bucket -}} {{- $repoSuffix := printf "%s/volsync/%s-volsync-%s" $.Release.Name $objectData.shortName $volsyncData.name -}} {{- $resticrepository := printf "%s/%s" $baseRepo $repoSuffix -}} {{- if $credentials.path -}}