chore(credentials): validate credentials.url (#29806)

**Description**
<!--
Please include a summary of the change and which issue is fixed. Please
also include relevant motivation and context. List any dependencies that
are required for this change.
-->
⚒️ Fixes  # <!--(issue)-->

**⚙️ 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?**
<!--
Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. Please also list any relevant details
for your test configuration
-->

**📃 Notes:**
<!-- Please enter any other relevant information here -->

**✔️ 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._
This commit is contained in:
Stavros Kois
2024-12-02 00:37:37 +02:00
committed by GitHub
parent 9465fbcad8
commit b236a26923
21 changed files with 63 additions and 32 deletions
@@ -12,7 +12,7 @@ tests:
credentials: credentials:
test: &test test: &test
type: s3 type: s3
url: some-url url: http://some-url
bucket: some-bucket bucket: some-bucket
encrKey: some-encr-key encrKey: some-encr-key
accessKey: some-access-key accessKey: some-access-key
@@ -14,7 +14,7 @@ tests:
accessKey: some-access-key accessKey: some-access-key
secretKey: some-secret-key secretKey: some-secret-key
bucket: some-bucket bucket: some-bucket
url: some-url url: http://some-url
cnpg: cnpg:
my-pg: my-pg:
enabled: true enabled: true
@@ -10,7 +10,7 @@ tests:
credentials: credentials:
test: test:
type: s3 type: s3
url: some-url url: http://some-url
encrKey: some-encr-key encrKey: some-encr-key
bucket: some-bucket bucket: some-bucket
secretKey: some-secret-key secretKey: some-secret-key
@@ -14,7 +14,7 @@ tests:
secretKey: some-secret-key secretKey: some-secret-key
bucket: some-bucket bucket: some-bucket
encrKey: some-encr-key encrKey: some-encr-key
url: some-url url: http://some-url
cnpg: cnpg:
my-pg: my-pg:
enabled: true enabled: true
@@ -40,3 +40,28 @@ tests:
asserts: asserts:
- failedTemplate: - 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. 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]
@@ -14,7 +14,7 @@ tests:
secretKey: some-secret-key secretKey: some-secret-key
bucket: some-bucket bucket: some-bucket
encrKey: some-encr-key encrKey: some-encr-key
url: some-url url: http://some-url
cnpg: cnpg:
my-pg: my-pg:
enabled: true enabled: true
@@ -64,7 +64,7 @@ tests:
compression: bzip2 compression: bzip2
jobs: 2 jobs: 2
destinationPath: some-path destinationPath: some-path
endpointURL: some-url endpointURL: http://some-url
s3Credentials: s3Credentials:
accessKeyId: accessKeyId:
key: ACCESS_KEY_ID key: ACCESS_KEY_ID
@@ -132,7 +132,7 @@ tests:
compression: bzip2 compression: bzip2
jobs: 2 jobs: 2
destinationPath: some-path destinationPath: some-path
endpointURL: some-url endpointURL: http://some-url
s3Credentials: s3Credentials:
accessKeyId: accessKeyId:
key: ACCESS_KEY_ID key: ACCESS_KEY_ID
@@ -200,7 +200,7 @@ tests:
compression: bzip2 compression: bzip2
jobs: 2 jobs: 2
destinationPath: some-path destinationPath: some-path
endpointURL: some-url endpointURL: http://some-url
s3Credentials: s3Credentials:
accessKeyId: accessKeyId:
key: ACCESS_KEY_ID key: ACCESS_KEY_ID
@@ -269,7 +269,7 @@ tests:
compression: bzip2 compression: bzip2
jobs: 2 jobs: 2
destinationPath: some-path destinationPath: some-path
endpointURL: some-url endpointURL: http://some-url
s3Credentials: s3Credentials:
accessKeyId: accessKeyId:
key: ACCESS_KEY_ID key: ACCESS_KEY_ID
@@ -339,7 +339,7 @@ tests:
encryption: AES256 encryption: AES256
jobs: 2 jobs: 2
destinationPath: some-path destinationPath: some-path
endpointURL: some-url endpointURL: http://some-url
s3Credentials: s3Credentials:
accessKeyId: accessKeyId:
key: ACCESS_KEY_ID key: ACCESS_KEY_ID
@@ -408,7 +408,7 @@ tests:
data: data:
jobs: 2 jobs: 2
destinationPath: some-path destinationPath: some-path
endpointURL: some-url endpointURL: http://some-url
s3Credentials: s3Credentials:
accessKeyId: accessKeyId:
key: ACCESS_KEY_ID key: ACCESS_KEY_ID
@@ -230,7 +230,7 @@ tests:
accessKey: some-access-key accessKey: some-access-key
secretKey: some-secret-key secretKey: some-secret-key
bucket: some-bucket bucket: some-bucket
url: some-url url: http://some-url
encrKey: some-encr-key encrKey: some-encr-key
cnpg: cnpg:
my-pg: my-pg:
@@ -12,7 +12,7 @@ tests:
credentials: credentials:
test: &test test: &test
type: s3 type: s3
url: some-url url: http://some-url
bucket: some-bucket bucket: some-bucket
encrKey: some-encr-key encrKey: some-encr-key
accessKey: some-access-key accessKey: some-access-key
@@ -10,7 +10,7 @@ tests:
credentials: credentials:
test: test:
type: s3 type: s3
url: some-url url: http://some-url
bucket: some-bucket bucket: some-bucket
encrKey: some-encr-key encrKey: some-encr-key
accessKey: some-access-key accessKey: some-access-key
@@ -10,7 +10,7 @@ tests:
credentials: credentials:
test: test:
type: s3 type: s3
url: some-url url: http://some-url
bucket: some-bucket bucket: some-bucket
encrKey: some-encr-key encrKey: some-encr-key
accessKey: some-access-key accessKey: some-access-key
@@ -14,7 +14,7 @@ tests:
accessKey: some-access-key accessKey: some-access-key
secretKey: some-secret-key secretKey: some-secret-key
bucket: some-bucket bucket: some-bucket
url: some-url url: http://some-url
cnpg: cnpg:
my-pg: my-pg:
enabled: true enabled: true
@@ -42,7 +42,7 @@ tests:
credentials: credentials:
mys3: mys3:
type: s3 type: s3
url: some-url url: http://some-url
bucket: some-bucket bucket: some-bucket
encrKey: some-key encrKey: some-key
accessKey: some-access-key accessKey: some-access-key
@@ -32,7 +32,7 @@ tests:
credentials: credentials:
mys3: mys3:
type: s3 type: s3
url: some-url url: http://some-url
bucket: some-bucket bucket: some-bucket
encrKey: some-key encrKey: some-key
accessKey: some-access-key accessKey: some-access-key
@@ -25,7 +25,7 @@ tests:
credentials: &credentials credentials: &credentials
mys3: mys3:
type: s3 type: s3
url: some-url url: http://some-url
bucket: some-bucket bucket: some-bucket
encrKey: some-key encrKey: some-key
accessKey: some-access-key accessKey: some-access-key
@@ -42,7 +42,7 @@ tests:
credentials: credentials:
mys3: mys3:
type: s3 type: s3
url: some-url url: http://some-url
bucket: some-bucket bucket: some-bucket
encrKey: some-key encrKey: some-key
accessKey: some-access-key accessKey: some-access-key
@@ -32,7 +32,7 @@ tests:
credentials: credentials:
mys3: mys3:
type: s3 type: s3
url: some-url url: http://some-url
bucket: some-bucket bucket: some-bucket
encrKey: some-key encrKey: some-key
accessKey: some-access-key accessKey: some-access-key
@@ -25,7 +25,7 @@ tests:
credentials: &credentials credentials: &credentials
mys3: mys3:
type: s3 type: s3
url: some-url url: http://some-url
bucket: some-bucket bucket: some-bucket
encrKey: some-key encrKey: some-key
accessKey: some-access-key accessKey: some-access-key
@@ -62,7 +62,7 @@ tests:
credentials: credentials:
my-other-secret: my-other-secret:
type: s3 type: s3
url: some-url url: http://some-url
bucket: some-bucket bucket: some-bucket
encrKey: some-key encrKey: some-key
accessKey: some-access-key accessKey: some-access-key
@@ -88,7 +88,7 @@ tests:
credentials: credentials:
my-secret: my-secret:
type: s3 type: s3
url: some-url url: http://some-url
bucket: "" bucket: ""
asserts: asserts:
- failedTemplate: - failedTemplate:
@@ -100,7 +100,7 @@ tests:
credentials: credentials:
my-secret: my-secret:
type: s3 type: s3
url: some-url url: http://some-url
bucket: some-bucket bucket: some-bucket
encrKey: "" encrKey: ""
asserts: asserts:
@@ -113,7 +113,7 @@ tests:
credentials: credentials:
my-secret: my-secret:
type: s3 type: s3
url: some-url url: http://some-url
bucket: some-bucket bucket: some-bucket
encrKey: some-key encrKey: some-key
accessKey: "" accessKey: ""
@@ -127,7 +127,7 @@ tests:
credentials: credentials:
my-secret: my-secret:
type: s3 type: s3
url: some-url url: http://some-url
bucket: some-bucket bucket: some-bucket
encrKey: some-key encrKey: some-key
accessKey: some-access-key accessKey: some-access-key
@@ -155,7 +155,7 @@ tests:
credentials: &credentials credentials: &credentials
my-secret: my-secret:
type: s3 type: s3
url: some-url url: http://some-url
bucket: some-bucket bucket: some-bucket
encrKey: some-key encrKey: some-key
accessKey: some-access-key accessKey: some-access-key
@@ -4,7 +4,6 @@
{{- $type := .type -}} {{- $type := .type -}}
{{- $serverName := $objectData.clusterName -}} {{- $serverName := $objectData.clusterName -}}
{{- $endpointURL := "" -}}
{{- $destinationPath := "" -}} {{- $destinationPath := "" -}}
{{- $creds := dict -}} {{- $creds := dict -}}
{{- $key := "" -}} {{- $key := "" -}}
@@ -38,7 +37,6 @@
{{- $data := (dict {{- $data := (dict
"serverName" $serverName "serverName" $serverName
"endpointURL" $endpointURL
"destinationPath" $destinationPath "destinationPath" $destinationPath
"creds" $creds "creds" $creds
"key" $key "key" $key
@@ -22,4 +22,10 @@
{{- fail (printf "VolSync - Expected non-empty [%s] in [credentials.%s]" $key $credName) -}} {{- fail (printf "VolSync - Expected non-empty [%s] in [credentials.%s]" $key $credName) -}}
{{- end -}} {{- end -}}
{{- 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 -}} {{- end -}}
@@ -1,4 +1,4 @@
{{/* PVC Spawwner */}} {{/* PVC Spawner */}}
{{/* Call this template: {{/* Call this template:
{{ include "tc.v1.common.spawner.pvc" $ -}} {{ include "tc.v1.common.spawner.pvc" $ -}}
*/}} */}}
@@ -102,7 +102,9 @@
{{- $credentials := get $.Values.credentials $volsync.credentials -}} {{- $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 -}} {{- $repoSuffix := printf "%s/volsync/%s-volsync-%s" $.Release.Name $objectData.shortName $volsyncData.name -}}
{{- $resticrepository := printf "%s/%s" $baseRepo $repoSuffix -}} {{- $resticrepository := printf "%s/%s" $baseRepo $repoSuffix -}}
{{- if $credentials.path -}} {{- if $credentials.path -}}