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

adding client certificate and key #90

Closed
wants to merge 7 commits into from
Closed

Conversation

raoel
Copy link
Contributor

@raoel raoel commented Dec 19, 2022

hey there,

for our case we needed to add a client certificate and key to the configuration - I'd like to upstream my changes.

I hope this passes your standards - I've modified existing unit tests for configuration (I didn't do a full integration test with certificates because that would make the testing setup a lot more complex)

@CLAassistant
Copy link

CLAassistant commented Dec 19, 2022

CLA assistant check
All committers have signed the CLA.

@codebien
Copy link
Contributor

Hi @raoel,
thanks for your contribution. 🙇

Can you sign the CLA, please? We need it to accept the contribution.

@raoel
Copy link
Contributor Author

raoel commented Dec 20, 2022

Hi @raoel, thanks for your contribution. bow

Can you sign the CLA, please? We need it to accept the contribution.

had to get permission from my employer :-) should be fixed.

@codebien codebien self-requested a review December 20, 2022 10:56
@codebien
Copy link
Contributor

Hi @raoel,
can you better explain your use case and how you're configuring the remote write, please?

Are you using a self-signed certificate or an internal CA? You should not share the pair with the client but just provide the CA file. https://prometheus.io/docs/guides/tls-encryption/#testing

@raoel
Copy link
Contributor Author

raoel commented Dec 27, 2022

hello (sorry for the delay... things go slow - it's been christmas here too ;-) )

We have mutual TLS, so instead of providing the client with a username/password we need to provide the client with it's key and certificate to be able to authenticate. So, as far as I know, the client really need the pair.

Copy link
Contributor

@codebien codebien left a comment

Choose a reason for hiding this comment

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

Hey @raoel, sorry for the late reply 🙏 Thanks again for your contribution. I took a quick look and I've added some comments.

I didn't test yet it on a real setup, I will be on PTO for the rest of the week. I will do more tests on Monday.

K6_PROMETHEUS_RW_CLIENT_CERTIFICATE_KEY=client.key \
./k6 run -o xk6-prometheus-rw script.js
```

Copy link
Contributor

Choose a reason for hiding this comment

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

We should document that in the case a different CA is required then the relative operating systems' storage shouid be used for providing the custom CA.

Comment on lines 97 to +100
InsecureSkipVerify: conf.InsecureSkipTLSVerify.Bool, //nolint:gosec
}

if conf.ClientCertificate.Valid && conf.ClientCertificateKey.Valid {
Copy link
Contributor

@codebien codebien Aug 16, 2023

Choose a reason for hiding this comment

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

I would prefer if we skip the assignment if Insecure is set to true.

EDIT: this a wrong suggestion

Comment on lines +105 to +108
if conf.ClientCertificate.Valid && conf.ClientCertificateKey.Valid {
cert, _ := tls.LoadX509KeyPair(conf.ClientCertificate.String, conf.ClientCertificateKey.String)
hc.TLSConfig.Certificates = []tls.Certificate{cert}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these duplicated lines?

Comment on lines +168 to +174
if applied.ClientCertificate.Valid {
conf.ClientCertificate = applied.ClientCertificate
}

if applied.ClientCertificateKey.Valid {
conf.ClientCertificateKey = applied.ClientCertificateKey
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Are they duplicated?

}{
"JSON": {jsonRaw: json.RawMessage(`{"clientCertificate":"client.crt","clientCertificateKey":"client.key"}`)},
"Env": {env: map[string]string{"K6_PROMETHEUS_RW_CLIENT_CERTIFICATE": "client.crt", "K6_PROMETHEUS_RW_CLIENT_CERTIFICATE_KEY": "client.key"}},
//"Arg": {arg: "username=user1,password=pass1"},
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
//"Arg": {arg: "username=user1,password=pass1"},

}
}

func TestOptionClientCertificate(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Duplicated?

@codebien codebien changed the base branch from main to mtls September 20, 2023 12:49
@codebien codebien requested a review from a team as a code owner September 20, 2023 12:49
@codebien codebien requested review from olegbespalov and removed request for a team September 20, 2023 12:49
Copy link
Contributor

@codebien codebien left a comment

Choose a reason for hiding this comment

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

Hey @raoel, thanks again for the contribution. I merge this PR on a development branch where we will do some polish of the feature then we will merge on the main branch. I will make sure to preserve you as the author/contributor of your commits.

@codebien codebien mentioned this pull request Sep 21, 2023
@codebien
Copy link
Contributor

Unfortunately, this branch contains conflicts and we can't push here because the PR is generated from a fork. Going to continue the work on #143 preserving the commit history and the original author.

@codebien codebien closed this Sep 21, 2023
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.

None yet

4 participants