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

feat: Support HTTPS endpoints #1084

Merged
merged 6 commits into from
Sep 10, 2024
Merged

Conversation

ifindlay-cci
Copy link
Contributor

Checklist:

  • Have you added or updated tests to validate the changed functionality?
  • Have you added Release Notes in the docs repositories?
  • Have you followed the Conventional Commits specification?

@ifindlay-cci ifindlay-cci force-pushed the enable-opening-tls-endpoint branch 4 times, most recently from ab9839c to 5ccf512 Compare September 3, 2024 12:54
@ifindlay-cci ifindlay-cci changed the title Enable opening tls endpoint feat: Support HTTPS enpoints Sep 3, 2024
@ifindlay-cci ifindlay-cci changed the title feat: Support HTTPS enpoints feat: Support HTTPS endpoints Sep 3, 2024
When running as an app in CF we can rely on the platform to handle TLS setup, but on a VM currently there is no way to have encrypted traffic.

TPCF-26820
it is angry about  `.` imports. But we do not mind because this is not
production code.
@zucchinidev zucchinidev self-requested a review September 3, 2024 14:50
scheme := "http"
for _, envVar := range cmd.Env {
if strings.HasPrefix(envVar, "TLS_") {
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: Avoid modifying the global http.DefaultTransport directly. Instead, create a custom transport.

Copy link
Contributor

Choose a reason for hiding this comment

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

for tests?

internal/testdrive/broker_start.go Outdated Show resolved Hide resolved
internal/testdrive/broker_start.go Outdated Show resolved Hide resolved
internal/testdrive/broker_start.go Outdated Show resolved Hide resolved
caBytes, err := x509.CreateCertificate(rand.Reader, ca, ca, &caPrivKey.PublicKey, caPrivKey)
Expect(err).NotTo(HaveOccurred())

caPEM, _ := encodeKeyPair(caBytes, x509.MarshalPKCS1PrivateKey(caPrivKey))
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (non-blocking): the PEM-encoded CA certificate is not being used. The code is not necessary, by removing it, we will improve the readability and the public API of the createCAKeyPair function

Expect(err).NotTo(HaveOccurred())

certPEM, certPrivKeyPEM := encodeKeyPair(certBytes, x509.MarshalPKCS1PrivateKey(certPrivKey))
return certPEM, certPrivKeyPEM
Copy link
Contributor

@zucchinidev zucchinidev Sep 4, 2024

Choose a reason for hiding this comment

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

thoughts: I prefer to declare the variable using value semantics and return it using pointer semantic. If the body of the functions grows, the readability gets worse.

return &certPEM, ...

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I understand how the readability will get better by returning a pointer?

cmd/serve.go Outdated
tlsKey := viper.GetString(tlsKeyProp)

logger.Info("tlsCertCaBundle", lager.Data{"tlsCertCaBundle": tlsCertCaBundle})
logger.Info("tlsKey", lager.Data{"tlsKey": tlsKey})
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: we want to avoid logging sensitive data.

Copy link
Contributor

Choose a reason for hiding this comment

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

thats a path

cmd/serve.go Outdated
logger.Fatal("Failed to start broker", err)
}
} else {
_ = httpServer.ListenAndServe()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
_ = httpServer.ListenAndServe()
err := httpServer.ListenAndServe()
if err != nil {
logger.Fatal("Failed to start broker without TLS", err)
}

nouseforaname and others added 3 commits September 4, 2024 16:14
currently the broker.client is not embedding http client. It never
needed to because the broker was written as a CF app and therefore
never had to consider handling self signed certs. But since we are
changing towards supporting VM based deployment, we need to think
about how our test client will handle self signed certs. This seems
to be the path of least resistance, by embedding an http client in
the broker client struct, we can rely on setting the embedded clients
transport config to allow for "insecure" connecions.
@nouseforaname nouseforaname marked this pull request as draft September 10, 2024 09:02
@nouseforaname nouseforaname marked this pull request as ready for review September 10, 2024 09:02
@nouseforaname nouseforaname merged commit f0d0091 into main Sep 10, 2024
8 checks passed
@nouseforaname nouseforaname deleted the enable-opening-tls-endpoint branch September 10, 2024 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

4 participants