-
-
Notifications
You must be signed in to change notification settings - Fork 109
Create KafkaCredentialStore #530
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
Merged
bplommer
merged 19 commits into
typelevel:series/1.x
from
agustafson:certificate-loading
Apr 6, 2021
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
2f7f4f0
Create KafkaCredentialStore
agustafson e206794
Add certificates.md
agustafson 39e0330
certificates.md: add title and id
agustafson 8894492
certificates.md: fix docs using fromString methods
agustafson ffe9c4b
Add headers
agustafson 349bf03
Merge branch 'master' into certificate-loading
agustafson ee2a052
scalafmt
agustafson bcaca0a
Update docs/src/main/mdoc/certificates.md
agustafson 88cfa0b
Update certificates.md
agustafson 7af23c0
Code review comments
agustafson 7e8c6f7
Add KafkaCredentialStore.createFromStrings
agustafson 6789be1
Merge branch 'master' into certificate-loading
agustafson fc79475
Add withCredentials(credentialsStore: KafkaCredentialStore) method to…
agustafson 83aaa67
Fix certificates.md
agustafson 5815a7f
Merge branch 'master' into certificate-loading
agustafson eef3208
Revert withCredentials method on AvroSettings and SchemaRegistryClien…
agustafson 9d36955
Create PemKafkaCredentialStore
agustafson 266409c
Simplify + add tests
bplommer 53cf695
Update certificates.md
bplommer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| --- | ||
| id: security | ||
| title: Security & Certificates | ||
| --- | ||
|
|
||
| ## Security: certificates, trust stores, and passwords | ||
|
|
||
| The `KafkaCredentialStore` can be used to create the necessary trust stores and passwords to access kafka. | ||
|
|
||
| The parameters passed in are string representations of the client private key, client certificate | ||
| and service certificate. the `properties` field in `KafkaCredentialStore` can then be applied to | ||
| any of the `*Settings` classes by using the `withProperties(kafkaCredentialStore.properties)`. | ||
|
|
||
| ```scala mdoc | ||
| import cats.effect._ | ||
| import fs2.kafka._ | ||
| import fs2.kafka.security._ | ||
|
|
||
| def createKafkaProducerUsingPem[F[_]: Sync, K, V]( | ||
| caCertificate: String, | ||
| accessKey: String, | ||
| accessCertificate: String | ||
| )(implicit keySer: Serializer[F, K], valSer: Serializer[F, V]): ProducerSettings[F, K, V] = | ||
| ProducerSettings[F, K, V] | ||
| .withCredentials( | ||
| KafkaCredentialStore.fromPemStrings( | ||
| caCertificate, | ||
| accessKey, | ||
| accessCertificate | ||
| ) | ||
| ) | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
modules/core/src/main/scala/fs2/kafka/security/KafkaCredentialStore.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * Copyright 2018-2021 OVO Energy Limited | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package fs2.kafka.security | ||
|
|
||
| sealed trait KafkaCredentialStore { | ||
| def properties: Map[String, String] | ||
| } | ||
|
|
||
| object KafkaCredentialStore { | ||
| final def fromPemStrings( | ||
| caCertificate: String, | ||
| clientPrivateKey: String, | ||
| clientCertificate: String | ||
| ): KafkaCredentialStore = | ||
| new KafkaCredentialStore { | ||
| override val properties: Map[String, String] = | ||
| Map( | ||
| "security.protocol" -> "SSL", | ||
| "ssl.truststore.type" -> "PEM", | ||
| "ssl.truststore.certificates" -> caCertificate.replace("\n", ""), | ||
| "ssl.keystore.type" -> "PEM", | ||
| "ssl.keystore.key" -> clientPrivateKey.replace("\n", ""), | ||
| "ssl.keystore.certificate.chain" -> clientCertificate.replace("\n", "") | ||
| ) | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
modules/core/src/test/scala/fs2/kafka/security/KafkaCredentialStoreSpec.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package fs2.kafka.security | ||
|
|
||
| import fs2.kafka.BaseSpec | ||
|
|
||
| final class KafkaCredentialStoreSpec extends BaseSpec { | ||
| describe("KafkaCredentialStore") { | ||
| describe("fromPemStrigs") { | ||
| it("should create a KafkaCredentialStore with the expected properties") { | ||
| val caCert = | ||
| """ | ||
| |-----BEGIN CERTIFICATE----- | ||
| |RmFrZSBDQSBjZXJ0aWZpY2F0ZSBGYWtlIENBIGNlcnRpZmljYXRlIEZha2UgQ0EgY2VydGlmaWNh | ||
| |dGUgRmFrZSBDQSBjZXJ0aWZpY2F0ZQ== | ||
| |-----END CERTIFICATE----- | ||
| |""".stripMargin | ||
|
|
||
| val privateKey = | ||
| """ | ||
| |-----BEGIN PRIVATE KEY----- | ||
| |RmFrZSBwcml2YXRlIGtleSBGYWtlIHByaXZhdGUga2V5IEZha2UgcHJpdmF0ZSBrZXkgRmFrZSBw | ||
| |cml2YXRlIGtleSBGYWtlIHByaXZhdGUga2V5IA== | ||
| |-----END PRIVATE KEY----- | ||
| |""".stripMargin | ||
|
|
||
| val clientCert = | ||
| """ | ||
| |-----BEGIN CERTIFICATE----- | ||
| |RmFrZSBjbGllbnQgY2VydCBGYWtlIGNsaWVudCBjZXJ0IEZha2UgY2xpZW50IGNlcnQgRmFrZSBj | ||
| |bGllbnQgY2VydCBGYWtlIGNsaWVudCBjZXJ0IA== | ||
| |-----END CERTIFICATE----- | ||
| |""".stripMargin | ||
|
|
||
| val store = KafkaCredentialStore.fromPemStrings(caCert, privateKey, clientCert) | ||
|
|
||
| assert( | ||
| store.properties === Map( | ||
| "security.protocol" -> "SSL", | ||
| "ssl.truststore.type" -> "PEM", | ||
| "ssl.truststore.certificates" -> "-----BEGIN CERTIFICATE-----RmFrZSBDQSBjZXJ0aWZpY2F0ZSBGYWtlIENBIGNlcnRpZmljYXRlIEZha2UgQ0EgY2VydGlmaWNhdGUgRmFrZSBDQSBjZXJ0aWZpY2F0ZQ==-----END CERTIFICATE-----", | ||
| "ssl.keystore.type" -> "PEM", | ||
| "ssl.keystore.key" -> "-----BEGIN PRIVATE KEY-----RmFrZSBwcml2YXRlIGtleSBGYWtlIHByaXZhdGUga2V5IEZha2UgcHJpdmF0ZSBrZXkgRmFrZSBwcml2YXRlIGtleSBGYWtlIHByaXZhdGUga2V5IA==-----END PRIVATE KEY-----", | ||
| "ssl.keystore.certificate.chain" -> "-----BEGIN CERTIFICATE-----RmFrZSBjbGllbnQgY2VydCBGYWtlIGNsaWVudCBjZXJ0IEZha2UgY2xpZW50IGNlcnQgRmFrZSBjbGllbnQgY2VydCBGYWtlIGNsaWVudCBjZXJ0IA==-----END CERTIFICATE-----" | ||
| ) | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.