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

[fftls] Allow for In-Memory or Inlined TLS Certificates #132

Merged
merged 5 commits into from
Mar 11, 2024

Conversation

onelapahead
Copy link
Contributor

Useful for configs which want to inline the certs as large PEM blocks in their config files, or when constructing TLS configs from in-memory certificates (such as certificates downloaded from a Kubernetes Secret).

@codecov-commenter
Copy link

codecov-commenter commented Mar 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.96%. Comparing base (a54fd73) to head (0a735f3).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #132   +/-   ##
=======================================
  Coverage   99.96%   99.96%           
=======================================
  Files          79       79           
  Lines        6490     6507   +17     
=======================================
+ Hits         6488     6505   +17     
  Misses          1        1           
  Partials        1        1           

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

Signed-off-by: hfuss <[email protected]>
Signed-off-by: hfuss <[email protected]>
@onelapahead
Copy link
Contributor Author

onelapahead commented Mar 11, 2024

Small example that provides some context:

cfg := &ffresty.Config{}
secretName := "mtls-config"
secret := &corev1.Secret{}
err := ctrlClient.Get(context, types.NamespacedName{Namespace: "default", Name: secretName}, secret)
if err != nil {
  return nil, err
}

tls, err := fftls.NewTLSConfig(context, &fftls.Config{
  Enabled: true,
  CA:      string(secret.Data["ca.crt"]),
  Cert:    string(secret.Data["tls.crt"]),
  Key:     string(secret.Data["tls.key"]),
}, fftls.ClientType)
if err != nil {
  return nil, err
}
cfg.TLSClientConfig = tls
// proceed to use ffresty config to make a client

@@ -24,9 +24,11 @@ import (
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"github.com/stretchr/testify/require"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a specific reason to pull in require here, as opposed to assert? I think for unit tests we typically have stuck with assert, though I am noticing that is not as true in this particular repo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So require fails the test immediately whereas assert keep runs the test if it doesn't pass. So I always use require for anything involve setup, where if it errors / is not successful, the entire things fails.

It's just syntactic sugar for:

if err != nil {
  t.Fatal(err)
}

I believe

Copy link
Contributor

@nguyer nguyer left a comment

Choose a reason for hiding this comment

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

Just a couple of minor suggestions but otherwise looks good.

@@ -23,14 +23,21 @@ import (
const (
// HTTPConfTLSCAFile the TLS certificate authority file for the HTTP server
HTTPConfTLSCAFile = "caFile"
// HTTPConfTLSCA the TLS certificate authority in PEM format
HTTPConfTLSCA = "ca"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should document (probably in this comment so it's visible to the developer) that if these are set they will take precedence over the "file" fields.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well its the opposite in that the file fields take precedence over these fields for backwards compatibility's sake.

That could be the wrong approach, but I'm updating the comments now to reflect the current behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comments updated

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right sorry. Had the switch statement backwards in my head.

Signed-off-by: hfuss <[email protected]>
@nguyer nguyer merged commit b6bcbb4 into hyperledger:main Mar 11, 2024
2 checks passed
@nguyer nguyer deleted the feature/in-memory-tls-certs branch March 11, 2024 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants