-
Notifications
You must be signed in to change notification settings - Fork 27
Type-safe Security Configuration #88
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
Type-safe Security Configuration #88
Conversation
81621d3
to
1d10d99
Compare
> Adds some of the missing properties from swift-server#46. Motivation: We were lacking some of the security protocol configuration options and want to provide them in a type-safe manner. Modifications: * add Kerberos support * add OAuthBearer support * Created a new file `KafkaConfiguration+Security.swift` * add `public struct` `SSLConfiguration` * add `public struct` `SASLMechanism` * add `public struct` `KerberosConfiguration` * add `public struct` `OAuthBearerMethod` * add `public struct` `SecurityProtocol` * integrate `KafkaConfiguration.SSLOptions` in new types * integrate `KafkaConfiguration.SASLOptions` in new types
1d10d99
to
b7d57fb
Compare
public static func keyPair( | ||
privateKey: PrivateKey, | ||
publicKeyCertificate: Key, | ||
caCertificate: Key, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should provide an easy way to use the "default" i.e. "probe" that searches for locally trusted CAs.
/// Use to configure an SSL connection. | ||
public struct SSLConfiguration: Sendable, Hashable { | ||
/// A key either located in a file or directly as a key String (PEM format). | ||
public struct Key: Sendable, Hashable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably the right term here would be Chain
as it not only contains the public key but at least one certificate and possibly multiple certificates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm... maybe even two types.
- One of them is kind of a
LeafAndIntermediates
type as the first certificate in the chain will be used as the identity of the client and the remaining, in no particular order, will be used as potential intermediate certificates and send to the broker to verify the client. - The other type could be
RootCertificates
as it is an unordered list of trusted CAs that is used by the client to verifier the identity of the broker.
publicKeyCertificate: Key, | ||
caCertificate: Key, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we might want to use different types here so we can provide a reasonable default for caCertificate
.
Modifications: * go from `KafkaConfiguration.Key` type into more specific types: * `LeafAndIntermediates` to extract the public Key * `PrivateKey` * `RootCertificate` * `RootCertificate`: add two new options * `probe` (default): probe list of standard paths and make first certificate found root default root certificate location path * `disableBrokerVerification`: disable broker verification entirely * `KafkaConfiguration+Security`: * turn `static func`s without parameters into `static let`s for our enum-like `public structs`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we allow users to modify the config dictionary? e.g. to allow users using config options the swift wrappers do not yet support?
/// Available SASL mechanisms that can be used for authentication. | ||
public struct SASLMechanism: Sendable, Hashable { | ||
/// Used to configure Kerberos. | ||
public struct KerberosConfiguration: Sendable, Hashable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is a public init missing
) | ||
|
||
/// Use the Secure Sockets Layer (SSL) protocol. | ||
public static func ssl(configuration: SSLConfiguration) -> SecurityProtocol { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Lukasa should this be called TLS instead of SSL?
Modifications: * add `public init` to `KafkaConfiguration.SASLMechanism.KerberosConfiguration`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Looks good to me
Motivation:
We were lacking some of the security protocol configuration options and
want to provide them in a type-safe manner.
Modifications:
KafkaConfiguration+Security.swift
public struct
SSLConfiguration
public struct
SASLMechanism
public struct
KerberosConfiguration
public struct
OAuthBearerMethod
public struct
SecurityProtocol
KafkaConfiguration.SSLOptions
in new typesKafkaConfiguration.SASLOptions
in new typesExample: