Skip to content

Add support for sending events to HTTPS endpoints in Eventshub#526

Merged
knative-prow[bot] merged 9 commits intoknative-extensions:mainfrom
Rahul-Kumar-prog:Rahulkumar6840
Jul 4, 2023
Merged

Add support for sending events to HTTPS endpoints in Eventshub#526
knative-prow[bot] merged 9 commits intoknative-extensions:mainfrom
Rahul-Kumar-prog:Rahulkumar6840

Conversation

@Rahul-Kumar-prog
Copy link
Copy Markdown
Contributor

@Rahul-Kumar-prog Rahul-Kumar-prog commented May 16, 2023

Signing-off by : Rahul Kumar rahulkumarrsde@gmail.com

Fixes knative/eventing#6840

  • Add support for sending events to HTTPS endpoints

Release Note

Add support for sending events to HTTPS endpoints

Docs


@knative-prow
Copy link
Copy Markdown

knative-prow bot commented May 16, 2023

@Rahul-Kumar-prog: The label(s) kind/<kind> cannot be applied, because the repository doesn't have them.

Details

In response to this:

Signing-off by : Rahul Kumar rahulkumarrsde@gmail.com

  • Add support for sending events to HTTPS endpoints

/kind

Fixes #6840

Release Note


Docs


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.

@knative-prow knative-prow bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label May 16, 2023
@knative-prow
Copy link
Copy Markdown

knative-prow bot commented May 16, 2023

Hi @Rahul-Kumar-prog. Thanks for your PR.

I'm waiting for a knative-sandbox member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

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.

@knative-prow knative-prow bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label May 16, 2023
Copy link
Copy Markdown
Member

@pierDipi pierDipi left a comment

Choose a reason for hiding this comment

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

we need to solve the requirement number 2 on the issue.
This is just for an idea, in my PR I added another env variable to enforce TLS and the sender would check and enforce TLS regardless of the "is HTTPS sink", see #527

In addition, we need functions to configure the sender with CA Certs, similar to https://github.com/knative-sandbox/reconciler-test/blob/7e6edebb371797610b06b117670ba9bd22b6dbcc/pkg/eventshub/options.go#L62-L94

@Rahul-Kumar-prog
Copy link
Copy Markdown
Contributor Author

Rahul-Kumar-prog commented May 19, 2023

@pierDipi
Let me explain myself whether I understand or not.

  1. step i need to create a function that configure the sender with CA certs.
  2. step is i need to enforce TLS sender would check and enforce TLS regardless of the "is HTTPS sink"
    Right and
    One question : i have to do both function implementation in sender.go file? Right!

@pierDipi
Copy link
Copy Markdown
Member

pierDipi commented May 22, 2023

@pierDipi Let me explain myself whether I understand or not.

  1. step i need to create a function that configure the sender with CA certs.
  2. step is i need to enforce TLS sender would check and enforce TLS regardless of the "is HTTPS sink"
    Right and
    One question : i have to do both function implementation in sender.go file? Right!

No, I sent you the reference on where to do point 1 (options.go), point 2 is in sender.go

For point 1, we're trying to offer a way to use the new feature you have implemented, when we implement a new feature, we need to think about "how users will use such feature?" and "how are users using similar features?"; that's what point 2 is trying to address, does that make sense?

@vishal-chdhry
Copy link
Copy Markdown

Hi @Rahul-Kumar-prog! Do you need any help, are the requirements clear to you?

@Rahul-Kumar-prog
Copy link
Copy Markdown
Contributor Author

Hey @vishal-chdhry yes I need help. I will contact with you on slack for some doubts. Please have a look

@pierDipi
Copy link
Copy Markdown
Member

@Rahul-Kumar-prog do you have any updates on this?

@pierDipi
Copy link
Copy Markdown
Member

How can we help you?

@Rahul-Kumar-prog
Copy link
Copy Markdown
Contributor Author

Hey @pierDipi i have talk to vishal and I got solution just little more time and I will be commit with the solution.

@pierDipi
Copy link
Copy Markdown
Member

Thank you both!

@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 Jun 6, 2023
}

func StartsenderTLS(sinkSvc string) EventsHubOption {
return compose(envAdditive(EventGeneratorsEnv, "CACerts"), func(ctx context.Context, envs map[string]string) error {
Copy link
Copy Markdown
Member

@pierDipi pierDipi Jun 6, 2023

Choose a reason for hiding this comment

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

EventGeneratorsEnv set to CACerts is not a valid generator, we need to set this to sender


func StartsenderTLS(sinkSvc string) EventsHubOption {
return compose(envAdditive(EventGeneratorsEnv, "CACerts"), func(ctx context.Context, envs map[string]string) error {
envs["SINK"] = "https://" + network.GetServiceHostname(sinkSvc, environment.FromContext(ctx).Namespace())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is SINK env variable enough to make an HTTPS request? do we need CA certs?

if u == nil {
return fmt.Errorf("resource %v named %s is not addressable", gvr, name)
}
envs["SINK"] = "https://" + u.String()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is SINK env variable enough to make an HTTPS request? do we need CA certs?


func StartSenderURLTLS(sink string) EventsHubOption {
return compose(envAdditive(EventGeneratorsEnv, "CACerts"), func(ctx context.Context, envs map[string]string) error {
envs["SINK"] = "https://" + sink
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is SINK env variable enough to make an HTTPS request? do we need CA certs?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ohh i miss this sorry?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No need to be sorry

Comment on lines +89 to +115
func StartsenderTLS(sinkSvc string) EventsHubOption {
return compose(envAdditive(EventGeneratorsEnv, "CACerts"), func(ctx context.Context, envs map[string]string) error {
envs["SINK"] = "https://" + network.GetServiceHostname(sinkSvc, environment.FromContext(ctx).Namespace())
return nil
})
}

func StartSenderToResourceTLS(gvr schema.GroupVersionResource, name string) EventsHubOption {
return compose(envAdditive(EventGeneratorsEnv, "CACerts"), func(ctx context.Context, envs map[string]string) error {
u, err := k8s.Address(ctx, gvr, name)
if err != nil {
return err
}
if u == nil {
return fmt.Errorf("resource %v named %s is not addressable", gvr, name)
}
envs["SINK"] = "https://" + u.String()
return nil
})
}

func StartSenderURLTLS(sink string) EventsHubOption {
return compose(envAdditive(EventGeneratorsEnv, "CACerts"), func(ctx context.Context, envs map[string]string) error {
envs["SINK"] = "https://" + sink
return nil
})
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For each new *TLS function we need to also set ENFORCE_TLS to true so that eventshub can enforce TLS

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

var startsender EventsHubOption = envAdditive(EventGeneratorsEnv, "sender")

var StartSendertls EventsHubOption = compose(startsender,envAdditive(EnforceTLS, "True"))

like this ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Have you tried it? the current startSender is different from what you posted above, so I'm not sure that would work

To each compose function we need to add

envAdditive(EnforceTLS, "true")

as argument

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i made a commit recently for these changes have you check those @pierDipi

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I saw it, I don't think it's correct

Comment on lines +148 to +174
server := &https.Server{addr: ":8080", Handler: handler}
serverTLS := &http.Server{
Addr: ":8443",
TLSConfig: &tls.Config{
MinVersion: tls.VersionTLS12,
},
Handler: handler,
}

var httpErr error
go func() {
httpErr = server.ListenAndServe()
}()
var httpsErr error
if env.EnforceTLS {
go func() {
httpsErr = serverTLS.ListenAndServe("/etc/tls/certificates/tls.crt", "/etc/tls/certifcates/tls.key")
}()
defer serverTLS.Close()
}

if httpErr != nil {
return fmt.Errorf("error while starting the HTTP server: %w", httpErr)
}
if httpsErr != nil {
return fmt.Errorf("error while starting the HTTPS server: %w", httpsErr)
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't get why we need the servers, this is a sender, which means it acts as HTTP(s) client

}

httpClient := &nethttp.Client{}
if isHTTPSSink(env.Sink) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if isHTTPSSink(env.Sink) {
if env.EnforceTLS {

Comment on lines +203 to +208
if isHTTPSSink(env.Sink) {
if _, err := httpClient.Do(req); err != nil {
logging.FromContext(ctx).Error(zap.Error(err))
return false, nil
}
} else if _, err := nethttp.DefaultClient.Do(req); err != nil {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if isHTTPSSink(env.Sink) {
if _, err := httpClient.Do(req); err != nil {
logging.FromContext(ctx).Error(zap.Error(err))
return false, nil
}
} else if _, err := nethttp.DefaultClient.Do(req); err != nil {
if _, err := httpClient.Do(req); err != nil {

return fmt.Errorf("error while starting the HTTPS server: %w", httpsErr)
}

httpClient := &nethttp.Client{}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
httpClient := &nethttp.Client{}
httpClient := nethttp.DefaultClient

@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 6, 2023
@Rahul-Kumar-prog
Copy link
Copy Markdown
Contributor Author

@pierDipi have a look.

Comment on lines +55 to +56
var Startsender EventsHubOption = envAdditive(EventGeneratorsEnv, "sender")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
var Startsender EventsHubOption = envAdditive(EventGeneratorsEnv, "sender")

We don't need this, there is already StartSender

Comment on lines +57 to +60
// StartSendertls starts the sender in the eventshub with TLS enforcement.
// It requires cert-manager operator to be able to create TLS Certificate.const
// To get the CA certificate used you can use GetCAcerts
var StartSendertls EventsHubOption = compose(Startsender, envAdditive(EnforceTLS, "true"))
Copy link
Copy Markdown
Member

@pierDipi pierDipi Jun 12, 2023

Choose a reason for hiding this comment

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

Suggested change
// StartSendertls starts the sender in the eventshub with TLS enforcement.
// It requires cert-manager operator to be able to create TLS Certificate.const
// To get the CA certificate used you can use GetCAcerts
var StartSendertls EventsHubOption = compose(Startsender, envAdditive(EnforceTLS, "true"))
// StartSenderTLS starts the sender in the eventshub with TLS enforcement.
func StartSenderTLS(sinkSvc string, caCerts *caCerts) EventsHubOption {
return compose(StartSender(sinkSvc), envAdditive(EnforceTLS, "true"), func(ctx context.Context, envs map[string]string) error {
if caCerts != nil {
envs["CA_CERTS"] = *caCerts
}
return nil
})
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is the idea for StartSenderTLS function


func StartSenderTLS(sinkSvc string) EventsHubOption {
return compose(envAdditive(EventGeneratorsEnv, "sender"), func(ctx context.Context, envs map[string]string) error {
envs["CACerts"] = "https://" + network.GetServiceHostname(sinkSvc, environment.FromContext(ctx).Namespace())
Copy link
Copy Markdown
Member

@pierDipi pierDipi Jun 12, 2023

Choose a reason for hiding this comment

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

I left a comment earlier to challenge CA certs set to a URL, if we set CACerts env variabe to a URL, would that work for the updated code you've implmented in pkg/eventshub/sender/sender.go? is that the expected behavior?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think so. what you say?

Copy link
Copy Markdown
Member

@pierDipi pierDipi Jun 20, 2023

Choose a reason for hiding this comment

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

how would that work if CACerts is not used anywhere?

given the PR change:


	// CACert is the certificate for enabling HTTPS in Sink URL
	CACerts string `envconfig:"CA_CERTS"`

	// EnforceTLS is used to enforce TLS.
	EnforceTLS bool `envconfig:"ENFORCE_TLS" default:"false"`

I don't see where CACerts is used, nor how setting CACerts to an HTTP address has a meaning.

In addition, the PR is setting CACerts to a URL that should be set as SINK.

See this comment: #526 (comment)

Copy link
Copy Markdown
Contributor Author

@Rahul-Kumar-prog Rahul-Kumar-prog Jun 20, 2023

Choose a reason for hiding this comment

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

@pierDipi You mean in startsendertls function I have to set env as sink right ?
If we set env as a sink then how can start sender tls with Cacerts ?

@pierDipi
Copy link
Copy Markdown
Member

pierDipi commented Jun 16, 2023

@Rahul-Kumar-prog this is blocking progress on bunch of other tasks, so we need to move forward.

  • are the task and comments clear?
  • by when can we get a solution done?
  • if you don't have capacity because you're busy, that's ok, we can have other contributors taking your initial great work and bring it to completion, but please be clear about that

@Rahul-Kumar-prog
Copy link
Copy Markdown
Contributor Author

Rahul-Kumar-prog commented Jun 18, 2023

Sorry @pierDipi i get sick past few days. I understand your comments. Give me some time I will push a commit with the solution/changes.

And again sorry for blocking

@Rahul-Kumar-prog Rahul-Kumar-prog force-pushed the Rahulkumar6840 branch 2 times, most recently from 81ac3b1 to e7498e2 Compare June 21, 2023 18:26
@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 21, 2023
@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 Jun 21, 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 Jun 21, 2023
Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
@pierDipi
Copy link
Copy Markdown
Member

@Rahul-Kumar-prog I've sent a PR to your branch Rahul-Kumar-prog#1, please merge it

@knative-prow knative-prow bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 30, 2023
@pierDipi
Copy link
Copy Markdown
Member

/ok-to-test

@knative-prow knative-prow bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 30, 2023
Copy link
Copy Markdown
Member

@pierDipi pierDipi left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@knative-prow knative-prow bot added lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jun 30, 2023
Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
@knative-prow knative-prow bot removed the lgtm Indicates that a PR is ready to be merged. label Jul 4, 2023
Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
@pierDipi
Copy link
Copy Markdown
Member

pierDipi commented Jul 4, 2023

/lgtm
/approve

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

knative-prow bot commented Jul 4, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: pierDipi, Rahul-Kumar-prog

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

The pull request process is described here

Details 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 4c1226f into knative-extensions:main Jul 4, 2023
knative-prow bot pushed a commit to knative/eventing that referenced this pull request Jul 6, 2023
Manual update since there are a few braking chanages with
knative-extensions/reconciler-test#526

first commit upgrade deps and vendor, the rest fixes the issues.

---------

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
vishal-chdhry pushed a commit to vishal-chdhry/eventing that referenced this pull request Jul 6, 2023
Manual update since there are a few braking chanages with
knative-extensions/reconciler-test#526

first commit upgrade deps and vendor, the rest fixes the issues.

---------

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
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. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. 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.

Eventing TLS: support sending events to HTTPS endpoints in eventshub

4 participants