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

Use default entryPoints when certificates are added with no entryPoints. #2534

Conversation

nmengin
Copy link
Contributor

@nmengin nmengin commented Dec 6, 2017

What does this PR do?

The PR allows introducing a mechanism by default for all the providers which add TLScertificates dynamically.
If no entryPoints are given, the certificates are added to all of the defaultEntryPoints (from Træfik global configuration) wich have a TLS configuration.

Motivation

This PR helps to create the certificates management from K8s secret (#2439)

More

  • Added/updated tests
  • Added/updated documentation

tls/tls.go Outdated
if len(certName) > 50 {
certName = certName[0:50]
}
log.Debugf("No entryPoint is defined to add the certificate %s, it will be added to the default entryPoints: %s", certName, strings.Join(defaultEntryPoints, ","))
Copy link
Contributor

Choose a reason for hiding this comment

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

if log.GetLevel() >= logrus.DebugLevel {
	certName := conf.Certificate.CertFile.String()
	// Keep only 50 characters to generate a readable log
	if len(certName) > 50 {
		certName = certName[:50]
	}
	log.Debugf("No entryPoint is defined to add the certificate %s, it will be added to the default entryPoints: %s", certName, strings.Join(defaultEntryPoints, ","))
}

Copy link
Member

@mmatur mmatur left a comment

Choose a reason for hiding this comment

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

LGTM

@nmengin nmengin force-pushed the feature/add-default-entrypoints-to-dynamic-certificates branch from 9e5f1c0 to 3bff3b0 Compare December 7, 2017 15:50
tls/tls.go Outdated
if conf.Certificate.CertFile.Path() {
certName = conf.Certificate.CertFile.String()
} else {
certName = strings.TrimPrefix(conf.Certificate.CertFile.String(), "-----BEGIN CERTIFICATE-----\n")[:50]
Copy link
Contributor

Choose a reason for hiding this comment

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

if the CertFile content if empty or malformed, this can panicing.

tls/tls.go Outdated
if log.GetLevel() >= logrus.DebugLevel {
certName := conf.Certificate.CertFile.String()
// Truncate certificate information only if it's a well formed certificate content with more than 50 characters
if !conf.Certificate.CertFile.Path() && strings.Index(conf.Certificate.CertFile.String(), certificateHeader) == 0 && len(conf.Certificate.CertFile.String()) > 50 {
Copy link
Member

Choose a reason for hiding this comment

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

HasPrefix instead of Index ?
You need to compare len with 50+len(certificateHeader)

@@ -67,6 +67,12 @@ func (f FileOrContent) String() string {
return string(f)
}

// Path returns true if the FileOrContent is a file path, otherwise returns false
func (f FileOrContent) Path() bool {
Copy link
Member

Choose a reason for hiding this comment

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

if it's a boolean, isPath or you must return a string with filepath if you have one ?

@@ -435,8 +435,12 @@ func (s *Server) loadConfiguration(configMsg types.ConfigMessage) {
if err == nil {
for newServerEntryPointName, newServerEntryPoint := range newServerEntryPoints {
s.serverEntryPoints[newServerEntryPointName].httpRouter.UpdateHandler(newServerEntryPoint.httpRouter.GetHandler())
if &newServerEntryPoint.certs != nil {
s.serverEntryPoints[newServerEntryPointName].certs.Set(newServerEntryPoint.certs.Get())
if newServerEntryPoint.certs.Get() != nil {
Copy link
Member

Choose a reason for hiding this comment

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

certs can be nil

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not possible because it's a struct and not a pointer

@nmengin nmengin force-pushed the feature/add-default-entrypoints-to-dynamic-certificates branch from 995acc9 to 546c710 Compare December 8, 2017 08:22
Copy link
Member

@juliens juliens left a comment

Choose a reason for hiding this comment

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

LGTM

@nmengin nmengin force-pushed the feature/add-default-entrypoints-to-dynamic-certificates branch from 546c710 to 29b61e6 Compare December 8, 2017 09:02
Copy link
Contributor

@ldez ldez left a comment

Choose a reason for hiding this comment

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

LGTM

@traefiker traefiker merged commit c446c29 into traefik:master Dec 8, 2017
@nmengin nmengin deleted the feature/add-default-entrypoints-to-dynamic-certificates branch August 3, 2018 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/tls kind/enhancement a new or improved feature. size/S
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants