Skip to content

Adopt Kubernetes style TLS Secret #597

Merged
stefanprodan merged 1 commit intomainfrom
kube-tls-secret
Aug 23, 2023
Merged

Adopt Kubernetes style TLS Secret #597
stefanprodan merged 1 commit intomainfrom
kube-tls-secret

Conversation

@somtochiama
Copy link
Copy Markdown
Member

Deprecate the usage of caFile for the .spec.certSecretRef secret in Provider. Both caFile and ca.crt keys are supported for Provider with the latter taking precedence.

Part of: fluxcd/flux2#4137

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would be good to include a makefile that generates this and the other files in this directory.
Similar to https://github.com/fluxcd/source-controller/blob/aa370f284db70e09d8acb49d5bed4e42908b8cb3/internal/controller/testdata/certs/Makefile#L17-L20 .

Comment thread internal/controller/alert_controller.go Outdated
if err := r.Get(ctx, providerName, provider); err != nil {
// log not found errors since they get filtered out
ctrl.LoggerFrom(ctx).Error(err, "failed to get provider %s", providerName.String())
ctrl.LoggerFrom(ctx).Error(err, fmt.Sprintf("failed to get provider '%s'", providerName.String()))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In favor of structured logging I suggest:

Suggested change
ctrl.LoggerFrom(ctx).Error(err, fmt.Sprintf("failed to get provider '%s'", providerName.String()))
ctrl.LoggerFrom(ctx).Error(err, "failed to get provider", "provider", providerName.String())

return fmt.Errorf("no caFile found in secret %s", provider.Spec.CertSecretRef.Name)
caFile, ok = secret.Data["caFile"]
if !ok {
return fmt.Errorf("no `ca.crt` key found in secret '%s'", provider.Spec.CertSecretRef.Name)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
return fmt.Errorf("no `ca.crt` key found in secret '%s'", provider.Spec.CertSecretRef.Name)
return fmt.Errorf("no 'ca.crt' nor 'caFile' key found in secret", "secret", provider.Spec.CertSecretRef.Name)

Copy link
Copy Markdown
Member Author

@somtochiama somtochiama Aug 16, 2023

Choose a reason for hiding this comment

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

I am not sure if we want to add the deprecated key caFile to the log so as not to encourage users to use it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, had the same thought. Up to you.

if !ok {
return fmt.Errorf("no `ca.crt` key found in secret '%s'", provider.Spec.CertSecretRef.Name)
}
log.Info("warning: specifying CA cert via `caFile` is deprecated, please use `ca.crt` instead")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
log.Info("warning: specifying CA cert via `caFile` is deprecated, please use `ca.crt` instead")
log.Info("warning: specifying CA cert via 'caFile' is deprecated, please use 'ca.crt' instead")

Comment thread internal/server/event_handlers.go Outdated
continue
caFile, ok = secret.Data["caFile"]
if !ok {
alertLogger.Error(nil, "no `ca.crt` key found in secret '%s'", provider.Spec.CertSecretRef.Name)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
alertLogger.Error(nil, "no `ca.crt` key found in secret '%s'", provider.Spec.CertSecretRef.Name)
alertLogger.Error(nil, "no 'ca.crt' nor 'caFile' key found in secret", "secret", provider.Spec.CertSecretRef.Name)


To enable notification-controller to communicate with a provider API over HTTPS
using a self-signed TLS certificate, set the `caFile` like so:
using a self-signed TLS certificate, set the `ca.crt` like so:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we also need to add a deprecation notice for the caFile key like the one here: https://github.com/fluxcd/source-controller/blob/main/docs/spec/v1beta2/helmrepositories.md#secret-reference

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

my bad, skipped it somehow but the same goes for the API docs

Comment thread docs/spec/v1beta2/providers.md Outdated
Comment on lines +1127 to +1128
**Note:** Support for the `caFile` key have been
deprecated. If you have any Secrets using these keys,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
**Note:** Support for the `caFile` key have been
deprecated. If you have any Secrets using these keys,
**Warning:** Support for the `caFile` key has been
deprecated. If you have any Secrets using this key,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also, maybe mention the types of Secret that's allowed in the above section, not part of this warning.

Copy link
Copy Markdown
Member

@aryan9600 aryan9600 left a comment

Choose a reason for hiding this comment

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

lgtm!

Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
@stefanprodan stefanprodan added the area/alerting Alerting related issues and PRs label Aug 23, 2023
Copy link
Copy Markdown
Member

@stefanprodan stefanprodan left a comment

Choose a reason for hiding this comment

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

LGTM

Thanks @somtochiama 🏅

@stefanprodan stefanprodan merged commit c04ad84 into main Aug 23, 2023
@stefanprodan stefanprodan deleted the kube-tls-secret branch August 23, 2023 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/alerting Alerting related issues and PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants