Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Avoid recreating random secrets #1550

Closed
wants to merge 9 commits into from
Closed

Conversation

xoanmi
Copy link
Contributor

@xoanmi xoanmi commented Jul 21, 2023

Avoid recreating secrets with dynamic/random content on every helm update. This causes the core, registry and jobservice services to be redeployed in each update.

Related to https://cloud-native.slack.com/archives/CC1E09J6S/p1689925408303219

Close #1549

@xoanmi xoanmi changed the title GH-1549: Use lookup function to avoid recreating random secrets Fix: Avoid recreating random secrets Jul 21, 2023
@Cjericho4
Copy link

Anyway we can get this reviewed so it can get merged in?

@Kajot-dev
Copy link
Contributor

Actually, I think that tls.key and tls.cert can be defined using existing Secret via core.secretName which is something that is separate from the secret created by the chart (harbor.core template). This PR removes it and assumes that all the required values are already present it the secret if it exists.

While this PR will work for new deployment it removes defining certificate for token signing from external secret (you can use CertManager to do just that) - it will break the installation for those who already use core.secretName by not using it and inserting nil values into the -core secret (since -core secret exists and does not have tls.cert and tls.key)

The idea is good though - but it needs to preserve the core.secretName feature and it needs to check for presence of each individual value inside the secret.

@xoanmi
Copy link
Contributor Author

xoanmi commented Sep 15, 2023

Actually, I think that tls.key and tls.cert can be defined using existing Secret via core.secretName which is something that is separate from the secret created by the chart (harbor.core template). This PR removes it and assumes that all the required values are already present it the secret if it exists.

While this PR will work for new deployment it removes defining certificate for token signing from external secret (you can use CertManager to do just that) - it will break the installation for those who already use core.secretName by not using it and inserting nil values into the -core secret (since -core secret exists and does not have tls.cert and tls.key)

The idea is good though - but it needs to preserve the core.secretName feature and it needs to check for presence of each individual value inside the secret.

Hi @Kajot-dev it should be solved. Could you review it again please?

Copy link
Contributor

@Kajot-dev Kajot-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, you did a lot of work, thanks!!

Nice changes, but some of them apply only when generating new data.
Also there is much code duplication like this:

{{- $secret := lookup ... }}
{(- if $secret }}
old data..
{{- else }}
new data
{{- end }}

Also not all secret values are reused - for example if user won't put S3 secrets in external secret it will not use lookup for them

If you want to you can avoid code duplications by leveraging the fact that when secret is not present helm returns an empty object. Instead of having two blocks for reusing data and generation of the new data which share most of the code you can do something like this:

{{/* template definition */}}
{{- define "harbor.keyExtractor" -}}
{{- if hasKey .data .key }}
{{- $val := (index .data .key) }}
{{- if kindIs "string" $val }}
{{ .key }}: {{ $val | quote }}
{{- else }}
{{ .key }}: {{ $val }}
{{- end }}
{{- else }}
{{ .default }}
{{- end }}
{{- end -}}

{{/* and then */}}
{{- $secret := lookup ... }}
{{- template "harbor.keyExtractor" (dict "key" "SOME_PASSWORD_KEY" "data" $secret.data "default" "DEFAULT_VALUE" ) }}

templates/_helpers.tpl Show resolved Hide resolved
templates/_helpers.tpl Show resolved Hide resolved
templates/_helpers.tpl Show resolved Hide resolved
templates/_helpers.tpl Show resolved Hide resolved
templates/_helpers.tpl Show resolved Hide resolved
templates/_helpers.tpl Show resolved Hide resolved
templates/_helpers.tpl Show resolved Hide resolved
xoanmi and others added 8 commits September 15, 2023 13:31
Co-authored-by: Carlos Vega <[email protected]>
Signed-off-by: Joan Miquel Luque Oliver <[email protected]>
…tion.

Co-authored-by: Carlos Vega <[email protected]>
Signed-off-by: Joan Miquel Luque Oliver <[email protected]>
Co-authored-by: Jakub Jaruszewski <[email protected]>
Signed-off-by: Joan Miquel Luque Oliver <[email protected]>
Co-authored-by: Jakub Jaruszewski <[email protected]>
Signed-off-by: Joan Miquel Luque Oliver <[email protected]>
Co-authored-by: Jakub Jaruszewski <[email protected]>
Signed-off-by: Joan Miquel Luque Oliver <[email protected]>
Co-authored-by: Jakub Jaruszewski <[email protected]>
Signed-off-by: Joan Miquel Luque Oliver <[email protected]>
Co-authored-by: Jakub Jaruszewski <[email protected]>
Signed-off-by: Joan Miquel Luque Oliver <[email protected]>
Signed-off-by: Joan Miquel Luque Oliver <[email protected]>
@xoanmi xoanmi requested a review from Kajot-dev September 15, 2023 11:39
Copy link
Contributor

@Kajot-dev Kajot-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me
Nice work!

@Kajot-dev
Copy link
Contributor

Could we get this reviewed and merged please?

@Kajot-dev
Copy link
Contributor

fix: #1609

@zyyw
Copy link
Collaborator

zyyw commented Dec 14, 2023

Thanks for contributing to harbor-helm!
Closing this PR now as it was fixed in PR:

@zyyw zyyw closed this Dec 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Helm chart recreate secrets on every deploy
4 participants