Skip to content

Commit

Permalink
chore(credentials): validate credentials.url (#29806)
Browse files Browse the repository at this point in the history
**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._
  • Loading branch information
stavros-k authored Dec 1, 2024
1 parent 9465fbc commit b236a26
Show file tree
Hide file tree
Showing 21 changed files with 63 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions charts/library/common-test/tests/cnpg/backup_validation_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -408,7 +408,7 @@ tests:
data:
jobs: 2
destinationPath: some-path
endpointURL: some-url
endpointURL: http://some-url
s3Credentials:
accessKeyId:
key: ACCESS_KEY_ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions charts/library/common-test/tests/volsync/validation_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -88,7 +88,7 @@ tests:
credentials:
my-secret:
type: s3
url: some-url
url: http://some-url
bucket: ""
asserts:
- failedTemplate:
Expand All @@ -100,7 +100,7 @@ tests:
credentials:
my-secret:
type: s3
url: some-url
url: http://some-url
bucket: some-bucket
encrKey: ""
asserts:
Expand All @@ -113,7 +113,7 @@ tests:
credentials:
my-secret:
type: s3
url: some-url
url: http://some-url
bucket: some-bucket
encrKey: some-key
accessKey: ""
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
{{- $type := .type -}}

{{- $serverName := $objectData.clusterName -}}
{{- $endpointURL := "" -}}
{{- $destinationPath := "" -}}
{{- $creds := dict -}}
{{- $key := "" -}}
Expand Down Expand Up @@ -38,7 +37,6 @@

{{- $data := (dict
"serverName" $serverName
"endpointURL" $endpointURL
"destinationPath" $destinationPath
"creds" $creds
"key" $key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
6 changes: 4 additions & 2 deletions charts/library/common/templates/spawner/_pvc.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{/* PVC Spawwner */}}
{{/* PVC Spawner */}}
{{/* Call this template:
{{ include "tc.v1.common.spawner.pvc" $ -}}
*/}}
Expand Down Expand Up @@ -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 -}}
Expand Down

0 comments on commit b236a26

Please sign in to comment.