-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 TLS serving option for metrics #993
✨ Add TLS serving option for metrics #993
Conversation
Welcome @Danil-Grigorev! |
Hi @Danil-Grigorev. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Danil-Grigorev The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/ok-to-test |
@Danil-Grigorev: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/ok-to-test |
pkg/manager/manager_suite_test.go
Outdated
const testCrt = `-----BEGIN CERTIFICATE----- | ||
MIIC8zCCAdugAwIBAgIJAOBRXEjnBd8DMA0GCSqGSIb3DQEBBQUAMCQxIjAgBgNV | ||
BAMTGWh0dHBzbG9jYWxob3N0NDQ0M21ldHJpY3MwHhcNMjAwNjExMTEzMDI3WhcN | ||
MzAwNjA5MTEzMDI3WjAkMSIwIAYDVQQDExlodHRwc2xvY2FsaG9zdDQ0NDNtZXRy | ||
aWNzMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxY6bVSLkfdHlI9kl | ||
4nAYTXCEdqEjVyrBQpwNeOkQ+E2hX2T28CBUPgWcHfD2wD85rVRh26Cs1ACifpIS | ||
SJI5nSswBqkA+whzV1uIofcjbxGFlVBfeOEQnbuXpHb60ZzgCVH5/9XIlw5NiR7V | ||
wfDzm9ZlNZz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YWPXX9Hg30Q | ||
oPwitgId3tjJn/rRxRrIbXzLoIS6JjIx+defPWjuySZe+5cmJ4iJ4OkMXa/1z22K | ||
eWPOWhkCgYEA19jUW9NweDMWlkYm92SNzvZIv8brPrWGNthTxUUflaA9NQRe++fZ | ||
RR1wT84WmV94lDOC4AKHtCQXx4o9m4GVwFcNIzdtexxbdBYPY9FPpZlR/S/VC9Ef | ||
73rEV46bie8TMDd0CmHBSpiDHDqgPyNwaYpttuoVFGNxw59/8OdeJQM= | ||
-----END RSA PRIVATE KEY----- | ||
` | ||
|
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.
Perhaps we could generate a new key and certificate on the fly rather than storing one? I don't know how complex that would be, but I suspect this will flag up those tools that scan repositories for secrets as it is know
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.
Moved it to testdata directory, should be little more sane. Can't really see a good solution to generate it on the go, and judging from the examples, it should be ok: https://golang.org/src/crypto/tls/example_test.go
e8b2eaf
to
be3e6dd
Compare
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.
One super nitpick. Other than that this looks good to me.
@@ -31,8 +31,8 @@ import ( | |||
|
|||
"github.com/prometheus/client_golang/prometheus" | |||
"github.com/prometheus/client_golang/prometheus/promhttp" | |||
"sigs.k8s.io/controller-runtime/pkg/internal/certwatcher" |
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.
I believe that imports are intentionally grouped together such that all sigs.k8s.io/controller-runtime
would be separate.
e6c854e
to
12f3eb3
Compare
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.
Had another look, added a few more minor things
pkg/manager/manager_test.go
Outdated
@@ -233,6 +235,24 @@ var _ = Describe("manger.Manager", func() { | |||
Expect(listener.Close()).ToNot(HaveOccurred()) | |||
}) | |||
|
|||
It("should create a TLS listener for the metrics if a valid address is provided", func() { |
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.
Perhaps rename this one, as it creates a normal listener if a valid address is provided, we need certs to create the TLS listener, WDYT?
|
||
// NewSecureListener creates a new TCP listener over TLS bound to the given address. | ||
func NewSecureListener(addr, certDir string) (net.Listener, error) { | ||
ln, err := NewListener(addr) |
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.
This error is unchecked
ln, err := NewListener(addr) | |
ln, err := NewListener(addr) | |
if err != nil { | |
return nil, err | |
} |
pkg/metrics/listener.go
Outdated
} | ||
|
||
go func() { | ||
if err = certWatcher.Start(context.Background().Done()); err != nil { |
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.
I'm normally not a fan of shadowing, but in this situation I'd be tempted to use a different variable since it's within a go routine, WDYT?
if err = certWatcher.Start(context.Background().Done()); err != nil { | |
if err := certWatcher.Start(context.Background().Done()); err != nil { |
a0366e0
to
5c909a0
Compare
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.
/lgtm
pkg/manager/manager_test.go
Outdated
@@ -233,6 +235,24 @@ var _ = Describe("manger.Manager", func() { | |||
Expect(listener.Close()).ToNot(HaveOccurred()) | |||
}) | |||
|
|||
It("should create a TLS listener for the metrics if a certificates are provided and the address is correct", func() { |
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.
Nit
It("should create a TLS listener for the metrics if a certificates are provided and the address is correct", func() { | |
It("should create a TLS listener for the metrics if certificates are provided and the address is correct", func() { |
5c909a0
to
0a62376
Compare
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.
/lgtm
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.
/lgtm
@JoelSpeed @Danil-Grigorev Instead of forcing callers into always having to get certs on disk in their image (albeit not that hard), WDYT of instead exposing a The default |
/hold For above discussion. |
Hey, so we generally wanted to sidestep this by using kube-rbac-proxy. I'm open to rediscussion, but the historical decision we made was largely to just let sidecar containers (rbac proxy, service mesh, etc) handle that. |
Closing in favour of #1007 to be exposed for the user modification. This PR introduces sample implementation for that on https://github.com/kubernetes-sigs/controller-runtime/pull/993/files#diff-652ee3c14d4f011345992fadfb31853eR66-R92 |
This PR introduces new option to the
manager
to pass aTLS
certificate and key in a separate directory, which will be used to serve metrics endpoint overhttps://
MetricsCertDir
is a location where the certificate files would be located. Those should be namedtls.crt
andtls.key
. Non empty value in the variable enables secure metrics endpoint.Fixes #979