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

implement cluster-local-domain-tls in serving #14610

Merged
merged 10 commits into from Jan 25, 2024

Conversation

ReToCode
Copy link
Member

@ReToCode ReToCode commented Nov 10, 2023

Context: https://github.com/orgs/knative/projects/63/views/1 and https://github.com/knative/serving/blob/main/docs/encryption/knative-encryption.md

Fixes #14217

Changes

  • Drops the existing self-built reconcilers for certificates
  • Drops the creation of a secret for Queue-Proxy
  • Introduces reconciliation of KnativeCertificates when cluster-local-domain-tls is enabled
  • Creates a KnativeCertificate for Activator and one in each namespace where Queue-Proxy is
  • Adds new certificate type labels to KnativeCertificates
  • Added new tests and e2e tests for the functionality
  • Extracted some testing stuff to make it work on all existing tests as well. Kourier with enabled cluster-local-domain-tls will also run all existing tests with TLS.
  • Cherry-pick [Automated] Update net-istio nightly #14706

Depends on these being merged first:

Release Note

Serving now supports the experimental feature `cluster-local-domain-tls` and creates the necessary `KnativeCertificates`

/hold

@knative-prow knative-prow bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 10, 2023
@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 10, 2023
@knative-prow knative-prow bot added area/API API objects and controllers size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. area/autoscale area/networking area/test-and-release It flags unit/e2e/conformance/perf test issues for product features labels Nov 10, 2023
@knative-prow-robot knative-prow-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Nov 10, 2023
@knative-prow-robot knative-prow-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Nov 14, 2023
@ReToCode ReToCode force-pushed the encryption-certmanager-only branch 3 times, most recently from 0eeae3d to 6198bf3 Compare November 22, 2023 13:43
@knative-prow-robot knative-prow-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 22, 2023
@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 25, 2023
@knative-prow-robot knative-prow-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 30, 2023
Copy link
Member Author

@ReToCode ReToCode left a comment

Choose a reason for hiding this comment

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

Added some inline comments to help with reviews.

@@ -63,6 +65,28 @@ func GetAllDomainsAndTags(ctx context.Context, r *v1.Route, names []string, visi
return domainTagMap, nil
}

// GetDomainsForVisibility return all domains for the specified visibility.
func GetDomainsForVisibility(ctx context.Context, targetName string, r *v1.Route, visibility netv1alpha1.IngressVisibility) (sets.String, error) {
Copy link
Member Author

Choose a reason for hiding this comment

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

this is moved and renamed from ingress.go

I also added some tests for this function.

// We use https://golang.org/pkg/hash/adler32/#Checksum to compute the digest which returns a uint32.
// We represent the digest in unsigned integer format with maximum value of 4,294,967,295 which are 10 digits.
// The "-[tag digest]" is computed only if there's a tag
func certNameFromRouteAndTag(route *v1.Route, tag string) string {
Copy link
Member Author

Choose a reason for hiding this comment

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

extracted from existing function

@@ -205,27 +203,6 @@ func makeIngressSpec(
}, nil
}

func routeDomain(ctx context.Context, targetName string, r *servingv1.Route, visibility netv1alpha1.IngressVisibility) (sets.String, error) {
Copy link
Member Author

Choose a reason for hiding this comment

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

moved to domains.go, see above.

}
}

return unusedCerts, nil
}

func (c *Reconciler) deleteOrphanedCerts(ctx context.Context, orphanCerts []*netv1alpha1.Certificate) {
Copy link
Member Author

Choose a reason for hiding this comment

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

extracted to be reused from both callees.

// WithRouteConditionsTLSNotEnabledForClusterLocalMessage calls
// MarkTLSNotEnabled with TLSNotEnabledForClusterLocalMessage after initialized
// the Service's conditions.
func WithRouteConditionsTLSNotEnabledForClusterLocalMessage(rt *v1.Route) {
Copy link
Member Author

Choose a reason for hiding this comment

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

we don't longer need this, as we support it now.

"knative.dev/serving/pkg/apis/autoscaling"
"knative.dev/serving/pkg/apis/serving"
rtesting "knative.dev/serving/pkg/testing/v1"
"knative.dev/serving/test"
v1test "knative.dev/serving/test/v1"
)

const (
Copy link
Member Author

Choose a reason for hiding this comment

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

moved to separate file, see above.

@@ -229,6 +101,13 @@ func TestServiceToServiceCall(t *testing.T) {
}
t.Logf("helloworld internal domain is %s.", resources.Route.Status.URL.Host)

// if cluster-local-domain-tls is enabled, this will return the CA used to sign the certificates.
// TestProxyToHelloworld will use this CA to verify the https connection
secret, err := GetCASecret(clients)
Copy link
Member Author

Choose a reason for hiding this comment

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

All our tests that call cluster-local domains need to trust if we enable TLS, this helper gets the CA secret and the following TestProxyToHelloworld will add this CA to it's trust pool and thus validate the TLS connection.

@@ -103,27 +103,20 @@ func newTLSEnabledTransport() http.RoundTripper {
}
transport.TLSClientConfig = &tls.Config{
RootCAs: rootCAs,
// If SERVER_NAME is not set the empty value will make the
Copy link
Member Author

Choose a reason for hiding this comment

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

httpproxy no longer needs to trust a defined SERVER_NAME. The certificates will be valid for the actual service. Also we get the CA directly in the env variable.

third_party/cert-manager-latest/net-certmanager.yaml Outdated Show resolved Hide resolved
third_party/kourier-latest/kourier.yaml Outdated Show resolved Hide resolved
@ReToCode ReToCode changed the title [TEST-ONLY] testing cluster-local-domain-tls in Serving [WIP] implement cluster-local-domain-tls in serving Nov 30, 2023
@knative-prow knative-prow bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 30, 2023
@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 30, 2023
@knative-prow-robot knative-prow-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 30, 2023
@knative-prow-robot knative-prow-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 16, 2024
@dprotaso
Copy link
Member

@@ -131,6 +136,7 @@ func newControllerWithOptions(
}
deploymentInformer.Informer().AddEventHandler(handleMatchingControllers)
paInformer.Informer().AddEventHandler(handleMatchingControllers)
certificateInformer.Informer().AddEventHandler(handleMatchingControllers)
Copy link
Member

Choose a reason for hiding this comment

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

Since the namespace is the owner of the certificate - this won't work.

You could re-sync all the revisions when the cert changes by listing and enqueing (then filtering) - or you can use a tracker https://pkg.go.dev/knative.dev/pkg/tracker

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah I see, makes sense. Updated it to using a tracker, I added it after the initial creation of a Certificate was successful. If that would fail (e.g. on the first Revision), we'd have an error on the Revision reconciliation anyway.

@ReToCode
Copy link
Member Author

I disabled istio-tls testing - unsure if you want to re-enable it again as part of this PR

Let's keep that as a follow-up thing, as we also have flakiness with ambient that we'd need to look into.

@ReToCode
Copy link
Member Author

/test unit-tests

pkg/reconciler/revision/controller.go Outdated Show resolved Hide resolved
// Tell our trackers to reconcile when the KnativeCertificate changes
gvk := rev.GetGroupVersionKind()
apiVersion, kind := gvk.ToAPIVersionAndKind()
if err := c.tracker.TrackReference(tracker.Reference{
Copy link
Member

Choose a reason for hiding this comment

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

this is backwards

you want to track the cert and reconcile the revision so the invocation is

TrackReference(certificate, rev)

Copy link
Member Author

Choose a reason for hiding this comment

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

Uh that API is quite confusing, but it makes sense that it has to be this way. Thanks for explaining and bearing with me on this.

@ReToCode
Copy link
Member Author

/hold

We'll bring this in after the release cut

@knative-prow knative-prow bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 24, 2024
@ReToCode
Copy link
Member Author

/unhold

@knative-prow knative-prow bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 24, 2024
@dprotaso
Copy link
Member

/lgtm
/approve

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label Jan 25, 2024
Copy link

knative-prow bot commented Jan 25, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dprotaso, ReToCode

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 25, 2024
@knative-prow knative-prow bot merged commit 0bae8a2 into knative:main Jan 25, 2024
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/API API objects and controllers area/autoscale area/networking area/test-and-release It flags unit/e2e/conformance/perf test issues for product features lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[cluster-local-domain-tls] create KnativeCertificate in Serving when cluster-local encryption is enabled
3 participants