Skip to content

TestTLSCertificateRotation is flakey #15276

Closed

Activity

  1. added this to the v1.15.0 milestone on May 29, 2024
  2. ReToCode commented on May 30, 2024

    @ReToCode
    Contributor
    system_internal_tls_test.go:231: Deleting secret in ingress namespace
        spoof.go:110: Spoofing tls-certificate-rotation-ehunlvfy.serving-tests.example.com -> 34.139.176.129
        system_internal_tls_test.go:249: The endpoint http://tls-certificate-rotation-ehunlvfy.serving-tests.example.com/ didn't serve the expected text "Hello World! How about some tasty noodles?": response: status: 503, body: upstream connect error or disconnect/reset before headers. reset reason: remote connection failure, transport failure reason: TLS_error:|268435581:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED:TLS_error_end:TLS_error_end, headers: map[Content-Length:[230] Content-Type:[text/plain] Date:[Wed, 29 May 2024 10:00:49 GMT] Server:[istio-envoy] Zipkin_trace_id:[4c2c44ed909af014b2d3998de2de3693]] did not pass checks: status = 503 503 Service Unavailable, want one of: [200]
    

    Seems that istio is a bit picky when deleting resources that is uses/watches 😒 We can probably either wait a bit longer for it to catch up with the changes and get to a good state or we might need to look at a "cleaner" way of forcing certificate refresh, like https://cert-manager.io/docs/usage/certificate/#reissuance-triggered-by-user-actions. Not sure if we want to add another binary to prow (and call-out to shell) for this though. Thoughts? @dprotaso @skonto @mgencur

  3. mgencur commented on May 30, 2024

    @mgencur
    Contributor

    @ReToCode I am not sure if using cmctl renew cert-1 for re-newing certificates would actually help here. There might still be some little time gap when net-istio is loading the new certificate?
    Another option would be simply to not delete the Secret in the ingress-namespace during the test (these lines). The test would be a little weaker but these lines are really testing something that is outside the Serving repository. Different ingress implementations might work a bit differently here.

  4. ReToCode commented on May 30, 2024

    @ReToCode
    Contributor

    Depends on what the tool does, IMHO, it could set the renewal periods on the cert to force cert-manager to refresh, like this. This would happen without deletion.
    But I think waiting a bit longer is fine for that test-case (as we force renewal, which would not happen this way in reality).

  5. mgencur commented on May 30, 2024

    @mgencur
    Contributor

    Sent #15280 to reduce the scope of the test.

  6. dprotaso commented on May 30, 2024

    @dprotaso
    MemberAuthor

    Few questions about the test since i've lost context

    1. Should the cert rotation be run in parallel with the other test

    2. Since we're testing rotation shouldn't we be updating an existing trust bundle? Instead of creating a new one?

    3. Why do we need to create duplicate bundles in two namespaces?

      bundleNamespaces := []string{systemNS, ingressNS}

    4. Does rotation only work when deleting the secret?

      t.Log("Deleting Secret in user namespace that is mounted by queue-proxy")
      if err := clients.KubeClient.CoreV1().Secrets(test.ServingFlags.TestNamespace).Delete(context.Background(), pkgNetworking.ServingCertName, v1.DeleteOptions{}); err != nil {
      t.Error(err)
      }

    5. What's config.ServingRoutingCertName again? And why do we need to test deleting them from the ingress & system namespace then following up with checking the endpoint is still valid?

      if err := clients.KubeClient.CoreV1().Secrets(systemNS).Delete(context.Background(), config.ServingRoutingCertName, v1.DeleteOptions{}); err != nil {

    6. Is there no reason we don't use a prober during this test? That would ensure we don't drop any traffic during this process.

  7. mgencur commented on May 31, 2024

    @mgencur
    Contributor
    1. This test verifies that the application is reachable at any time during certificate rotation so it shouldn't matter if this runs in parallel with other tests or not. Running it in parallel just speeds up the whole test suite. After taking another look, the other test TestSystemInternalTLS is quite similar as it checks logs, so maybe the new test could be slightly extended to check activator logs and the old test could be removed completely. But that's just a side note.
    2. There's no existing ConfigMap with "trust-bundle" label at the time we're creating the new one. Until creating this ConfigMap, Serving is loading the certificate from the "serving-routing-certs" Secret (the one we're deleting later). So, this new ConfigMap basically adds another place where Serving can look for certificates.
    3. We're creating duplicate bundles because ingress can run in a different namespace and it expects the ConfigMap to be in the same namespace (at least for net-kourier). But now that we don't remove the original Secret from ingress namespace, I think we don't need to create the bundle in the ingress namespace. I missed that with the recent PR.
    4. Deleting the secret is a way to enforce the cert rotation at the given time. There are other ways - like using cmctl renew cert-XY but I'm not sure how exactly it works (if it immediately issues a new certificate or there's some delay).
    5. The config.ServingRoutingCertName Secret is the place where Serving (and Ingress) is loading the certificates from. The cert-manager populates the Secret. Serving can also read the cert from a ConfigMap with "trust-bundle" label which we use in this test to ensure Serving always sees the right certificates, "old" ones and "new" ones.
    6. I guess using a prober would be another way to test it, but it would be harder to know which steps causes issues.
  8. ReToCode commented on May 31, 2024

    @ReToCode
    Contributor

    We're creating duplicate bundles because ingress can run in a different namespace and it expects the ConfigMap to be in the same namespace (at least for net-kourier). But now that we don't remove the original Secret from ingress namespace, I think we don't need to create the bundle in the ingress namespace. I missed that with the recent PR.

    I'd still keep it that way, as we should re-add this as soon as net-istio supports the trust-bundles. All components need to have the CA and I'd rather not do this cross-namespace. So it makes sense to deploy the bundle to each namespace where a component in the request-path is.

  9. mgencur commented on May 31, 2024

    @mgencur
    Contributor

    Regarding enforcing cert rotation. I was thinking about modifying the the cert-manager certificate such as the spec.duration field but it is managed by the certificates.networking.internal.knative.dev resource so any changes are reverted. See below.
    So I think using cmctl would not work either because it changes status condition here
    For the purpose of this test, I think deleting the Secret does the trick.

    oc get certificate routing-serving-certs -n knative-serving -oyaml
    apiVersion: cert-manager.io/v1
    kind: Certificate
    metadata:
      annotations:
        kubectl.kubernetes.io/last-applied-configuration: |
          {"apiVersion":"networking.internal.knative.dev/v1alpha1","kind":"Certificate","metadata":{"annotations":{"networking.knative.dev/certificate.class":"cert-manager.certificate.networking.knative.dev"},"labels":{"networking.knative.dev/certificate-type":"system-internal"},"name":"routing-serving-certs","namespace":"knative-serving","ownerReferences":[{"apiVersion":"operator.knative.dev/v1beta1","blockOwnerDeletion":true,"controller":true,"kind":"KnativeServing","name":"knative-serving","uid":"3dacb9ce-06d9-4dc8-bcd2-e3f8c73bd533"}]},"spec":{"dnsNames":["kn-routing","data-plane.knative.dev"],"secretName":"routing-serving-certs"}}
        manifestival: new
        networking.knative.dev/certificate.class: cert-manager.certificate.networking.knative.dev
      creationTimestamp: "2024-05-31T07:29:34Z"
      generation: 5
      labels:
        networking.knative.dev/certificate-type: system-internal
      name: routing-serving-certs
      namespace: knative-serving
      ownerReferences:
      - apiVersion: networking.internal.knative.dev/v1alpha1
        blockOwnerDeletion: true
        controller: true
        kind: Certificate
        name: routing-serving-certs
        uid: ceaa0504-f117-4899-8ae2-8eab8092e7a8
      resourceVersion: "1397345"
      uid: 5ea61d40-864f-451d-9eb1-b708f622c8cf
    spec:
      commonName: kn-routing
      dnsNames:
      - kn-routing
      - data-plane.knative.dev
      issuerRef:
        kind: ClusterIssuer
        name: knative-selfsigned-issuer
      secretName: routing-serving-certs
      secretTemplate:
        labels:
          networking.internal.knative.dev/certificate-uid: ceaa0504-f117-4899-8ae2-8eab8092e7a8
    status:
      conditions:
      - lastTransitionTime: "2024-05-31T07:35:16Z"
        message: Certificate is up to date and has not expired
        observedGeneration: 5
        reason: Ready
        status: "True"
        type: Ready
      notAfter: "2024-08-29T07:35:15Z"
      notBefore: "2024-05-31T07:35:15Z"
      renewalTime: "2024-07-30T07:35:15Z"
      revision: 2
    
    
  10. mgencur commented on May 31, 2024

    @mgencur
    Contributor

    Sent a test PR with Prober: #15285
    Let me know if this looks ok. Thanks.

  11. ReToCode commented on Jun 4, 2024

    @ReToCode
    Contributor

    Sent a test PR with Prober: #15285
    Let me know if this looks ok. Thanks.

    I think that is fine. @dprotaso thoughts?

  12. mgencur commented on Jun 12, 2024

    @mgencur
    Contributor

    OK. It's a different failure now: system_internal_tls_test.go:231: Failed to delete secret routing-serving-certs in ingress namespacee
    But the test doesn't log the actual error.

  13. mgencur commented on Jun 12, 2024

    @mgencur
    Contributor

    Sent #15325 to properly log errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions