-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Add support for fetching k8s Ingress TLS data from secrets #2439
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
3892fb7
Add tls support for k8s ingress ressource
gopenguin 228362c
Merge branch 'master' into k8s-ingress-tls
gopenguin 765fba4
Add docs for the k8s tls ingress feature
gopenguin 1f96b88
Fix import prefix and errorhandling
gopenguin bf648b8
Fix typo
gopenguin 4c0ba9e
Fix naming convention
gopenguin 18c5f9e
Merge branch 'master' into k8s-ingress-tls
gopenguin cc0b448
Refactor k8s ingress tls extraction and add tests
gopenguin 1c60f29
Merge branch 'master' into k8s-ingress-tls
gopenguin b0a7899
Remove cert validation and fix some other issues
gopenguin 741163e
Merge branch 'master' into k8s-ingress-tls
gopenguin c13b21a
Implement the builder pattern for TLS types
gopenguin bce97e9
Improve error messages and doc
gopenguin 383b9e8
Pass annotation 'traefik.frontend.entryPoints' to cert
gopenguin 74616a4
Merge branch 'master' into k8s-ingress-tls
gopenguin e082818
Add tls config to k8s template and extend test
gopenguin 3ecf770
Fix template file
nmengin d0a5c2f
Update documentation
gopenguin 4d156ec
Abort ingress if error in TLS and add docs
gopenguin d00111a
Merge branch 'master' into k8s-ingress-tls
gopenguin 6ab8f21
Fix tests
gopenguin 1d2e121
Add an invalid ingress to TestTLSSecretLoad to cover error case
gopenguin File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ import ( | |
"github.com/containous/traefik/provider" | ||
"github.com/containous/traefik/provider/label" | ||
"github.com/containous/traefik/safe" | ||
"github.com/containous/traefik/tls" | ||
"github.com/containous/traefik/types" | ||
"k8s.io/client-go/pkg/api/v1" | ||
"k8s.io/client-go/pkg/apis/extensions/v1beta1" | ||
|
@@ -174,6 +175,13 @@ func (p *Provider) loadIngresses(k8sClient Client) (*types.Configuration, error) | |
continue | ||
} | ||
|
||
tlsConfigs, err := getTLSConfigurations(i, k8sClient) | ||
if err != nil { | ||
log.Errorf("Error configuring TLS for ingress %s/%s: %v", i.Namespace, i.Name, err) | ||
continue | ||
} | ||
templateObjects.TLSConfiguration = append(templateObjects.TLSConfiguration, tlsConfigs...) | ||
|
||
for _, r := range i.Spec.Rules { | ||
if r.HTTP == nil { | ||
log.Warn("Error in ingress: HTTP is nil") | ||
|
@@ -441,6 +449,48 @@ func loadAuthCredentials(namespace, secretName string, k8sClient Client) ([]stri | |
return creds, nil | ||
} | ||
|
||
func getTLSConfigurations(ingress *v1beta1.Ingress, k8sClient Client) ([]*tls.Configuration, error) { | ||
var tlsConfigs []*tls.Configuration | ||
|
||
for _, t := range ingress.Spec.TLS { | ||
tlsSecret, exists, err := k8sClient.GetSecret(ingress.Namespace, t.SecretName) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to fetch secret %s/%s: %v", ingress.Namespace, t.SecretName, err) | ||
} | ||
if !exists { | ||
return nil, fmt.Errorf("secret %s/%s does not exist", ingress.Namespace, t.SecretName) | ||
} | ||
|
||
tlsCrtData, tlsCrtExists := tlsSecret.Data["tls.crt"] | ||
tlsKeyData, tlsKeyExists := tlsSecret.Data["tls.key"] | ||
|
||
var missingEntries []string | ||
if !tlsCrtExists { | ||
missingEntries = append(missingEntries, "tls.crt") | ||
} | ||
if !tlsKeyExists { | ||
missingEntries = append(missingEntries, "tls.key") | ||
} | ||
if len(missingEntries) > 0 { | ||
return nil, fmt.Errorf("secret %s/%s is missing the following TLS data entries: %s", ingress.Namespace, t.SecretName, strings.Join(missingEntries, ", ")) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this a lot 👍 |
||
|
||
entryPoints := label.GetSliceStringValue(ingress.Annotations, label.TraefikFrontendEntryPoints) | ||
|
||
tlsConfig := &tls.Configuration{ | ||
EntryPoints: entryPoints, | ||
Certificate: &tls.Certificate{ | ||
CertFile: tls.FileOrContent(tlsCrtData), | ||
KeyFile: tls.FileOrContent(tlsKeyData), | ||
}, | ||
} | ||
|
||
tlsConfigs = append(tlsConfigs, tlsConfig) | ||
} | ||
|
||
return tlsConfigs, nil | ||
} | ||
|
||
func endpointPortNumber(servicePort v1.ServicePort, endpointPorts []v1.EndpointPort) int { | ||
if len(endpointPorts) > 0 { | ||
//name is optional if there is only one port | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, my IDE is telling me that this line is supposedly missing code coverage. Are we possibly missing a test to validate that we actually skip the Ingress if
getTLSConfigurations
returns an error?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you are right. This case isn't covered.