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

Add additional encryption config flags + labels #891

Merged
merged 2 commits into from
Nov 23, 2023

Conversation

ReToCode
Copy link
Member

@ReToCode ReToCode commented Nov 13, 2023

Changes

/kind enhancement

Example of KnativeIngress with TLS block for cluster-local-domain-tls:

apiVersion: networking.internal.knative.dev/v1alpha1
kind: Ingress
metadata:
  name: helloworld
  namespace: default
spec:
  httpOption: Enabled
  rules:
  - hosts:
    - helloworld.default
    - helloworld.default.svc
    - helloworld.default.svc.cluster.local
    http:
      paths:
      - splits:
        - appendHeaders:
            Knative-Serving-Namespace: default
            Knative-Serving-Revision: helloworld-00001
          percent: 100
          serviceName: helloworld-00001
          serviceNamespace: default
          servicePort: 443
    visibility: ClusterLocal
  - hosts:
    - helloworld.default.10.89.0.200.sslip.io
    http:
      paths:
      - splits:
        - appendHeaders:
            Knative-Serving-Namespace: default
            Knative-Serving-Revision: helloworld-00001
          percent: 100
          serviceName: helloworld-00001
          serviceNamespace: default
          servicePort: 443
  tls:
  - hosts:
    - helloworld.default
    - helloworld.default.svc
    - helloworld.default.svc.cluster.local
    secretName: route-ba07ea4e-2548-4632-9187-e615c876cffc-local
    secretNamespace: default

@knative-prow knative-prow bot added the kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API label Nov 13, 2023
@knative-prow knative-prow bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Nov 13, 2023
@ReToCode
Copy link
Member Author

PTAL:

/assign @dprotaso
/assign @nak3
/assign @skonto
/assign @KauzClay

@ReToCode ReToCode changed the title Add encryption config Add additional encryption config flags + labels Nov 13, 2023
Copy link

codecov bot commented Nov 13, 2023

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (25da91b) 82.14% compared to head (db5cba2) 82.18%.
Report is 1 commits behind head on main.

Files Patch % Lines
pkg/apis/networking/v1alpha1/ingress_helpers.go 85.71% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #891      +/-   ##
==========================================
+ Coverage   82.14%   82.18%   +0.04%     
==========================================
  Files          45       46       +1     
  Lines        1725     1746      +21     
==========================================
+ Hits         1417     1435      +18     
- Misses        266      268       +2     
- Partials       42       43       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

pkg/apis/networking/v1alpha1/ingress_types.go Outdated Show resolved Hide resolved
pkg/config/config.go Outdated Show resolved Hide resolved
@nak3
Copy link
Contributor

nak3 commented Nov 14, 2023

/lgtm
/hold

Thank you!
For knative-extensions/net-istio, I think we need to add IngressTLS.Vibility in the unit test.
/hold for other reviewers. Please feel free to unhold if no one will take a look.

@knative-prow knative-prow bot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm Indicates that a PR is ready to be merged. labels Nov 14, 2023
@ReToCode
Copy link
Member Author

For knative-extensions/net-istio, I think we need to add IngressTLS.Vibility in the unit test.

👍 I'll do that as a follow-up

@dprotaso
Copy link
Member

Add visibility to KnativeIngress.TLS (see example below)

Why does the ingress need this?

@ReToCode
Copy link
Member Author

Why does the ingress need this?

Hm, thinking about it based on your question, it is probably not totally necessary. But without having it, each net-* solution would need to compare the tls section with the hosts list to find out if the tls config is relevant for a cluster-local domain or an external domain. In net-kourier, we use this flag to distinguish which listener to configure:

@nak3
Copy link
Contributor

nak3 commented Nov 15, 2023

Should we restructure the spec.tls and spec.rules at this time? For example,

option a) merge `spec.tls` into `spec.rules` like:
apiVersion: networking.internal.knative.dev/v1alpha1
kind: Ingress
metadata:
  name: helloworld
  namespace: default
spec:
  httpOption: Enabled
  rules:
  - hosts:
    - helloworld.default
    - helloworld.default.svc
    - helloworld.default.svc.cluster.local
    http:
      paths:
      - splits:
        - appendHeaders:
            Knative-Serving-Namespace: default
            Knative-Serving-Revision: helloworld-00001
          percent: 100
          serviceName: helloworld-00001
          serviceNamespace: default
          servicePort: 443
    visibility: ClusterLocal
    secretName: some-local-secret  # optional - omitting means no TLS.
    secretNamespace: default
  - hosts:
    - helloworld.default.10.89.0.200.sslip.io
    http:
      paths:
      - splits:
        - appendHeaders:
            Knative-Serving-Namespace: default
            Knative-Serving-Revision: helloworld-00001
          percent: 100
          serviceName: helloworld-00001
          serviceNamespace: default
          servicePort: 443
    visibility: ExternalIP
    secretName: route-ba07ea4e-2548-4632-9187-e615c876cffc-local # optional - omitting means no TLS.
    secretNamespace: default
option b) drop `spec.tls.hosts[]` and use the `spec.tls.visibility` as a key like:
apiVersion: networking.internal.knative.dev/v1alpha1
kind: Ingress
metadata:
  name: helloworld
  namespace: default
spec:
  httpOption: Enabled
  rules:
  - hosts:
    - helloworld.default
    - helloworld.default.svc
    - helloworld.default.svc.cluster.local
    http:
      paths:
      - splits:
        - appendHeaders:
            Knative-Serving-Namespace: default
            Knative-Serving-Revision: helloworld-00001
          percent: 100
          serviceName: helloworld-00001
          serviceNamespace: default
          servicePort: 443
    visibility: ClusterLocal
  - hosts:
    - helloworld.default.10.89.0.200.sslip.io
    http:
      paths:
      - splits:
        - appendHeaders:
            Knative-Serving-Namespace: default
            Knative-Serving-Revision: helloworld-00001
          percent: 100
          serviceName: helloworld-00001
          serviceNamespace: default
          servicePort: 443
    visibility: ExternalIP
  tls:
  - visibility: ExternalIP
    secretName: secret-for-external
    secretNamespace: default
  - visibility: ClusterLocal
    secretName: route-ba07ea4e-2548-4632-9187-e615c876cffc-local
    secretNamespace: default

Also, httpOption might be better to apply for local and external respectively.

@ReToCode
Copy link
Member Author

ReToCode commented Nov 15, 2023

Hm, not sure if option b) would work. Note we can have multiple entries for both visibilities with different certificates:
Here an example with tags:

apiVersion: networking.internal.knative.dev/v1alpha1
kind: Ingress
metadata:
  labels:
    serving.knative.dev/route: helloworld
    serving.knative.dev/routeNamespace: default
    serving.knative.dev/service: helloworld
  name: helloworld
  namespace: default
spec:
  httpOption: Enabled
  rules:
  - hosts:
    - helloworld.default
    - helloworld.default.svc
    - helloworld.default.svc.cluster.local
    http:
      paths:
      - splits:
        - appendHeaders:
            Knative-Serving-Namespace: default
            Knative-Serving-Revision: helloworld-00001
          percent: 100
          serviceName: helloworld-00001
          serviceNamespace: default
          servicePort: 443
    visibility: ClusterLocal
  - hosts:
    - helloworld.default.192.168.105.100.sslip.io
    http:
      paths:
      - splits:
        - appendHeaders:
            Knative-Serving-Namespace: default
            Knative-Serving-Revision: helloworld-00001
          percent: 100
          serviceName: helloworld-00001
          serviceNamespace: default
          servicePort: 443
    visibility: ExternalIP
  - hosts:
    - latest-helloworld.default
    - latest-helloworld.default.svc
    - latest-helloworld.default.svc.cluster.local
    http:
      paths:
      - splits:
        - appendHeaders:
            Knative-Serving-Namespace: default
            Knative-Serving-Revision: helloworld-00001
          percent: 100
          serviceName: helloworld-00001
          serviceNamespace: default
          servicePort: 443
    visibility: ClusterLocal
  - hosts:
    - latest-helloworld.default.192.168.105.100.sslip.io
    http:
      paths:
      - splits:
        - appendHeaders:
            Knative-Serving-Namespace: default
            Knative-Serving-Revision: helloworld-00001
          percent: 100
          serviceName: helloworld-00001
          serviceNamespace: default
          servicePort: 443
    visibility: ExternalIP
  tls:
  - hosts:
    - helloworld.default
    - helloworld.default.svc
    - helloworld.default.svc.cluster.local
    secretName: route-9f44405d-74a9-496b-a43d-effdf98bd6ca-local
    secretNamespace: default
    visibility: ClusterLocal
  - hosts:
    - latest-helloworld.default
    - latest-helloworld.default.svc
    - latest-helloworld.default.svc.cluster.local
    secretName: route-9f44405d-74a9-496b-a43d-effdf98bd6ca-147587726-local
    secretNamespace: default
    visibility: ClusterLocal

Option a) seems nice, but not sure if we want to change it that much, as this will impact all net-* implementations, regardless of their current state of implementing the new features. Also it might have a reason why it has been done that way in the first place? WDYT @dprotaso ?

@nak3 nak3 removed the lgtm Indicates that a PR is ready to be merged. label Nov 16, 2023
@nak3
Copy link
Contributor

nak3 commented Nov 16, 2023

I just realized that another concern of ths PR. Current net-* implementaitons does a simple loop against spec.TLS or len(ing.Spec.TLS) > 0. So if we added the cluster local TLS, it will break external TLS without their support of cluster local TLS?
Do you have a plan how to manage it like filter it by spec.TLS.Visiblity or we just document that "Do NOT enable (do not touch) cluster local TLS for net-{istio, contour}"?

@ReToCode
Copy link
Member Author

That is a good point @nak3 , but I think not one that we can omit without introducing a totally new field here. The flag is still marked as alpha, so I'd vote to add the hint as you say. As long as this feature is not finished, it should not be enabled in a real environment. Then the cluster-local TLS entries will not occur.

I'll add this filter changes as issues to our tracking umbrella.

@dprotaso
Copy link
Member

I think I'd like to avoid API changes to our internal Ingress resource - since we'd have to support multiple versions while we perform a migration.

Given that the TLS stanza just maps host names to a secret I think I'd rather just create helper functions in this repo that implementations can use to reduce complexity.

@ReToCode
Copy link
Member Author

/hold I'm doing some testing with kourier + serving and add a test for the new function.

@skonto
Copy link
Contributor

skonto commented Nov 17, 2023

Should we restructure the spec.tls and spec.rules at this time? For example,

I would vote for that too. It seems there is a lot of repetition of info here.

@dprotaso
Copy link
Member

I would vote for that too. It seems there is a lot of repetition of info here.

You could argue that you get more repetition if you have a TLS block within the rules block. If you didn't have wildcard certs then you'd have to repeat the entire rule many times (eg. appendHeaders)

@skonto
Copy link
Contributor

skonto commented Nov 17, 2023

You could argue that you get more repetition if you have a TLS block within the rules block.

We could have it under rules, my thinking was optimize based on what is common in practice:

spec:
  rules:
  - hosts:
    - helloworld.default
    - helloworld.default.svc
    - helloworld.default.svc.cluster.local
    tls:   

Not sure if we are describing the same thing.

@knative-prow knative-prow bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 22, 2023
@ReToCode ReToCode added kind/enhancement and removed kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API labels Nov 22, 2023
@ReToCode
Copy link
Member Author

ReToCode commented Nov 22, 2023

@skonto @dprotaso I don't think we ever have a * in king. It seems to be only in the kcert, see:

But anyway, I added GetIngressTLSForVisibility on Ingress and updated the PR description above. With this there are no changes to the API, we only need to make sure the net-* repos use the new method before one enables cluster-local-domain-tls. Full test run with kourier, net-certmanager is in Serving, see here. Can you take another look?

@ReToCode ReToCode removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 22, 2023
@dprotaso
Copy link
Member

Can you update the commit message - it doesn't match the contents of the commit


// CertificateTypeLabelKey is the label to indicate the type of Knative certificate
// used for Knative Serving encryption functionality.
CertificateTypeLabelKey = PublicGroupName + "/certificate-type"
Copy link
Member

Choose a reason for hiding this comment

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

What are the corresponding values?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a comment to link to config.CertificateType. Is there a better way to do this?

if r.Visibility == visibility {
for _, t := range i.Spec.TLS {
// Check if hosts slices are equal ignoring the order
if cmp.Diff(r.Hosts, t.Hosts, cmpopts.SortSlices(func(a, b string) bool { return a < b })) == "" {
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't be an equal comparison but tls.Hosts.Contains(host)

In theory KIngress can express different TLS certs for different hosts that are in the same rules block

Copy link
Member Author

Choose a reason for hiding this comment

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

I see, switched it to check if every host in Rules.Hosts is contained in TLS.Hosts. Also added a test case for this.

@ReToCode ReToCode force-pushed the add-encryption-config branch 2 times, most recently from 839bec7 to 467173c Compare November 23, 2023 08:31
@dprotaso
Copy link
Member

/lgtm
/approve

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label Nov 23, 2023
Copy link

knative-prow bot commented Nov 23, 2023

[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 merged commit bb18aab into knative:main Nov 23, 2023
28 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. kind/enhancement lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants