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

Enable TLS for OIDC e2e tests #7551

Merged
merged 33 commits into from
Jan 18, 2024

Conversation

Leo6Leo
Copy link
Member

@Leo6Leo Leo6Leo commented Jan 8, 2024

Fixes #7496
Fixes #7544
Fixes #7545
Fixes #7546
Fixes #7547
Fixes #7548
Fixes #7549
Fixes #7558

Proposed Changes

  • EventsHub receiver/sender with enforced TLS and individual resources which deliver events with CACerts specified for Destination

Pre-review Checklist

  • At least 80% unit test coverage
  • E2E tests for any new behavior
  • Docs PR for any user-facing impact
  • Spec PR for any new API feature
  • Conformance test for any change to the spec

Release Note


Docs

Copy link

knative-prow bot commented Jan 8, 2024

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@knative-prow knative-prow bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. area/test-and-release Test infrastructure, tests or release labels Jan 8, 2024
@knative-prow knative-prow bot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 8, 2024
Copy link

codecov bot commented Jan 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (fb9be2b) 74.52% compared to head (0cf666c) 74.52%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7551   +/-   ##
=======================================
  Coverage   74.52%   74.52%           
=======================================
  Files         262      262           
  Lines       14970    14970           
=======================================
  Hits        11157    11157           
  Misses       3223     3223           
  Partials      590      590           

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

delivery.WithDeadLetterSinkFromDestination(&duckv1.Destination{
Ref: service.AsKReference(dls),
Audience: &dlsAudience,
//CACerts: eventshub.GetCaCerts(ctx),
Copy link
Member Author

Choose a reason for hiding this comment

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

@creydr Question: Do you have any idea on how should I pass the CACert here? With this line I wrote, it is causing the broker creation fail. And I can't find the error message.

Copy link
Member

Choose a reason for hiding this comment

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

When you check the created YAML for the broker with the cert, you see we have a wrong indent of the cert.
Simply add 2 more spaces in delivery.WithDeadLetterSinkFromDestination() when the newlines are replaced:

diff --git a/test/rekt/resources/delivery/delivery.go b/test/rekt/resources/delivery/delivery.go
index 8348e5647..626b62c60 100644
--- a/test/rekt/resources/delivery/delivery.go
+++ b/test/rekt/resources/delivery/delivery.go
@@ -90,7 +90,7 @@ func WithDeadLetterSinkFromDestination(dest *duckv1.Destination) manifest.CfgFn
                if dest.CACerts != nil {
                        // This is a multi-line string and should be indented accordingly.
                        // Replace "new line" with "new line + spaces".
-                       dls["CACerts"] = strings.ReplaceAll(*dest.CACerts, "\n", "\n      ")
+                       dls["CACerts"] = strings.ReplaceAll(*dest.CACerts, "\n", "\n        ")
                }
 
                if dest.Audience != nil {

test/auth/features/oidc/broker.go Show resolved Hide resolved
@Leo6Leo Leo6Leo requested a review from creydr January 9, 2024 19:27
@Leo6Leo Leo6Leo marked this pull request as ready for review January 9, 2024 19:27
Signed-off-by: Leo Li <leoli@redhat.com>
@@ -41,7 +43,7 @@ import (
"knative.dev/eventing/test/rekt/resources/sequence"
)

func TestBrokerSupportsOIDC(t *testing.T) {
func TestBrokerSupportsOIDCUnderTLS(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: Change the test name to include the keyword TLS so that prow will enable TLS for this.

Copy link
Member

Choose a reason for hiding this comment

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

I think we can keep it as TestBrokerSupportsOIDC as we're migrating all of them and we can adjust the prow config for OIDC tests too. And OIDC without TLS is "useless" anyhow

Copy link
Member

@creydr creydr left a comment

Choose a reason for hiding this comment

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

Hey @Leo6Leo,
besides of the comments, I had to do the following to get the tests run/pass:

  • enable string transport encryption (via feature flag) - we need to do this for CI too (simply adjust test/auth/config/features.yaml)
  • install the TLS manifests (config/tls, config/brokers/mt-channel-broker-tls and config/channels/in-memory-channel-tls)

@@ -41,7 +43,7 @@ import (
"knative.dev/eventing/test/rekt/resources/sequence"
)

func TestBrokerSupportsOIDC(t *testing.T) {
func TestBrokerSupportsOIDCUnderTLS(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

I think we can keep it as TestBrokerSupportsOIDC as we're migrating all of them and we can adjust the prow config for OIDC tests too. And OIDC without TLS is "useless" anyhow

test/auth/features/oidc/broker.go Show resolved Hide resolved
Comment on lines 137 to 142
// create an empty destination ref
d := service.AsDestinationRef("")
d.CACerts = eventshub.GetCaCerts(ctx)
// uri is an addressable, create a new one and put the bad uri in it
d.URI, _ = apis.ParseURL("bad://uri")
trigger.Install(triggerName, brokerName, trigger.WithSubscriberFromDestination(d))(ctx, t)
Copy link
Member

Choose a reason for hiding this comment

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

I got a failed to create resource admission webhook "validation.webhook.eventing.knative.dev" denied the request: validation failed: Absolute URI is not allowed when Ref or [apiVersion, kind, name] is present: spec.subscriber.ref, spec.subscriber.uri, spec.subscriber[apiVersion, kind, name] when running this.
So there is no need to create a destination via service.AsDestinationRef(""). You can create it directly via duckv1.Destination{} and propagate the fields then.

delivery.WithDeadLetterSinkFromDestination(&duckv1.Destination{
Ref: service.AsKReference(dls),
Audience: &dlsAudience,
//CACerts: eventshub.GetCaCerts(ctx),
Copy link
Member

Choose a reason for hiding this comment

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

When you check the created YAML for the broker with the cert, you see we have a wrong indent of the cert.
Simply add 2 more spaces in delivery.WithDeadLetterSinkFromDestination() when the newlines are replaced:

diff --git a/test/rekt/resources/delivery/delivery.go b/test/rekt/resources/delivery/delivery.go
index 8348e5647..626b62c60 100644
--- a/test/rekt/resources/delivery/delivery.go
+++ b/test/rekt/resources/delivery/delivery.go
@@ -90,7 +90,7 @@ func WithDeadLetterSinkFromDestination(dest *duckv1.Destination) manifest.CfgFn
                if dest.CACerts != nil {
                        // This is a multi-line string and should be indented accordingly.
                        // Replace "new line" with "new line + spaces".
-                       dls["CACerts"] = strings.ReplaceAll(*dest.CACerts, "\n", "\n      ")
+                       dls["CACerts"] = strings.ReplaceAll(*dest.CACerts, "\n", "\n        ")
                }
 
                if dest.Audience != nil {

@Leo6Leo
Copy link
Member Author

Leo6Leo commented Jan 12, 2024

install the TLS manifests (config/tls, config/brokers/mt-channel-broker-tls and config/channels/in-memory-channel-tls)

@creydr Regarding the way to install the TLS manifest, I saw the implementation here. Don't those config have been installed here?

ko resolve ${KO_YAML_FLAGS} -Rf config/tls/ \
-Rf config/channels/in-memory-channel-tls/ \
-Rf config/brokers/mt-channel-broker-tls/ \
| "${LABEL_YAML_CMD[@]}" > "${EVENTING_TLS_YAML}"

eventing/test/e2e-common.sh

Lines 152 to 162 in 3cbddd6

local EVENTING_TLS_REPLACES=${TMP_DIR}/${EVENTING_TLS_YAML##*/}
sed "s/namespace: ${KNATIVE_DEFAULT_NAMESPACE}/namespace: ${SYSTEM_NAMESPACE}/g" "${EVENTING_TLS_YAML}" > "${EVENTING_TLS_REPLACES}"
if [[ ! -z "${CLUSTER_SUFFIX:-}" ]]; then
sed -i "s/cluster.local/${CLUSTER_SUFFIX}/g" "${EVENTING_TLS_REPLACES}"
fi
kubectl apply \
-f "${EVENTING_TLS_REPLACES}" || return 1
UNINSTALL_LIST+=( "${EVENTING_TLS_REPLACES}" )
kubectl patch horizontalpodautoscalers.autoscaling -n "${SYSTEM_NAMESPACE}" eventing-webhook -p '{"spec": {"minReplicas": '"${REPLICAS}"'}}' || return 1

@creydr
Copy link
Member

creydr commented Jan 12, 2024

install the TLS manifests (config/tls, config/brokers/mt-channel-broker-tls and config/channels/in-memory-channel-tls)

@creydr Regarding the way to install the TLS manifest, I saw the implementation here. Don't those config have been installed here?

ko resolve ${KO_YAML_FLAGS} -Rf config/tls/ \
-Rf config/channels/in-memory-channel-tls/ \
-Rf config/brokers/mt-channel-broker-tls/ \
| "${LABEL_YAML_CMD[@]}" > "${EVENTING_TLS_YAML}"

eventing/test/e2e-common.sh

Lines 152 to 162 in 3cbddd6

local EVENTING_TLS_REPLACES=${TMP_DIR}/${EVENTING_TLS_YAML##*/}
sed "s/namespace: ${KNATIVE_DEFAULT_NAMESPACE}/namespace: ${SYSTEM_NAMESPACE}/g" "${EVENTING_TLS_YAML}" > "${EVENTING_TLS_REPLACES}"
if [[ ! -z "${CLUSTER_SUFFIX:-}" ]]; then
sed -i "s/cluster.local/${CLUSTER_SUFFIX}/g" "${EVENTING_TLS_REPLACES}"
fi
kubectl apply \
-f "${EVENTING_TLS_REPLACES}" || return 1
UNINSTALL_LIST+=( "${EVENTING_TLS_REPLACES}" )
kubectl patch horizontalpodautoscalers.autoscaling -n "${SYSTEM_NAMESPACE}" eventing-webhook -p '{"spec": {"minReplicas": '"${REPLICAS}"'}}' || return 1

Hey @Leo6Leo,

yes. Sorry for not being clear, that this is only required for local tests as it is already in CI (in contrast to the feature flag, which was not enabled that time in CI).

@Leo6Leo
Copy link
Member Author

Leo6Leo commented Jan 12, 2024

@creydr Sounds good! thanks for the explanation. Then I think I have addressed all the review comments you gave me. PTAL again when you have time!

@creydr
Copy link
Member

creydr commented Jan 12, 2024

@creydr Sounds good! thanks for the explanation. Then I think I have addressed all the review comments you gave me. PTAL again when you have time!

Can you check why the auth e2e tests fail?

@creydr
Copy link
Member

creydr commented Jan 18, 2024

/retest

Copy link
Member

@creydr creydr left a comment

Choose a reason for hiding this comment

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

Left some comments. Mostly for naming & style.

And as you included the changes for other resources besides of broker, can you rename the PR?

test/rekt/resources/sequence/sequence.go Outdated Show resolved Hide resolved
))

f.Setup("install the trigger and specify the CA cert of the destination", func(ctx context.Context, t feature.T) {
Copy link
Member

Choose a reason for hiding this comment

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

I would simply name this step install the trigger, as you do some other configuration besides the CA too. Same in the other files.

f.Setup("Broker is ready", broker.IsReady(brokerName))

// FIXME: current progress left over here. Need to figure out why trigger cannot be initialized correctly.
Copy link
Member

Choose a reason for hiding this comment

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

leftover?

test/auth/features/oidc/broker.go Outdated Show resolved Hide resolved
test/auth/features/oidc/broker.go Outdated Show resolved Hide resolved
test/auth/features/oidc/broker.go Outdated Show resolved Hide resolved

// Install broker
f.Setup("install broker", broker.Install(brokerName, broker.WithEnvConfig()...))
f.Setup("Broker is ready", broker.IsReady(brokerName))
f.Setup("Broker has HTTPS address", broker.ValidateAddress(brokerName, addressable.AssertHTTPSAddress))
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if we need this, as we have f.Prerequisite("transport encryption is strict", featureflags.TransportEncryptionStrict()). IMO this should be tested in a TLS related test 🤷

test/auth/features/oidc/parallel.go Outdated Show resolved Hide resolved
Leo6Leo and others added 6 commits January 18, 2024 11:59
Co-authored-by: Christoph Stäbler <cstabler@redhat.com>
Co-authored-by: Christoph Stäbler <cstabler@redhat.com>
Co-authored-by: Christoph Stäbler <cstabler@redhat.com>
Co-authored-by: Christoph Stäbler <cstabler@redhat.com>
Co-authored-by: Christoph Stäbler <cstabler@redhat.com>
@@ -54,7 +56,7 @@ func SequenceSendsEventWithOIDC() *feature.FeatureSet {
Name: "Sequence send events with OIDC support",
Features: []*feature.Feature{
SequenceSendsEventWithOIDCTokenToSteps(),
SequenceSendsEventWithOIDCTokenToReply(),
//SequenceSendsEventWithOIDCTokenToReply(),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
//SequenceSendsEventWithOIDCTokenToReply(),
SequenceSendsEventWithOIDCTokenToReply(),

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 was in testing it by commenting out the reply portion. I will uncomment it

@Leo6Leo Leo6Leo changed the title [WIP] Enable tls for broker OIDC test [WIP] Enable tls for all OIDC test Jan 18, 2024
Signed-off-by: Leo Li <leoli@redhat.com>
Signed-off-by: Leo Li <leoli@redhat.com>
Signed-off-by: Leo Li <leoli@redhat.com>
Signed-off-by: Leo Li <leoli@redhat.com>
@Leo6Leo Leo6Leo changed the title [WIP] Enable tls for all OIDC test Enable tls for all OIDC test Jan 18, 2024
@knative-prow knative-prow bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 18, 2024
Signed-off-by: Leo Li <leoli@redhat.com>
@Leo6Leo
Copy link
Member Author

Leo6Leo commented Jan 18, 2024

/cc @creydr

@knative-prow knative-prow bot requested a review from creydr January 18, 2024 20:42
Copy link
Member

@creydr creydr left a comment

Choose a reason for hiding this comment

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

Awesome! Thanks @Leo6Leo for your work on this!

/lgtm
/retitle Enable TLS for OIDC tests

@knative-prow knative-prow bot changed the title Enable tls for all OIDC test Enable TLS for OIDC tests Jan 18, 2024
@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label Jan 18, 2024
Copy link

knative-prow bot commented Jan 18, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: creydr, Leo6Leo

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

@creydr creydr changed the title Enable TLS for OIDC tests Enable TLS for OIDC e2e tests Jan 18, 2024
@knative-prow knative-prow bot merged commit ad51fee into knative:main Jan 18, 2024
38 of 41 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/test-and-release Test infrastructure, tests or release 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
2 participants