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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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]

View File

@@ -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

View File

@@ -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:

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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 -}}

View File

@@ -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 -}}