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

Remove curl dependency and disable OAuth Bearer SASL mechanism #155

Merged
merged 5 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ let rdkafkaExclude = [
"./librdkafka/src/rdkafka_sasl_win32.c",
"./librdkafka/src/rdwin32.h",
"./librdkafka/src/win32_config.h",
// Remove dependency on cURL. Disabling `ENABLE_CURL` and `WITH_CURL` does
// not appear to prevent processing of the below files, so we have to exclude
// them explicitly.
"./librdkafka/src/rdkafka_sasl_oauthbearer.c",
"./librdkafka/src/rdkafka_sasl_oauthbearer_oidc.c",
"./librdkafka/src/rdhttp.c",
]

let package = Package(
Expand Down Expand Up @@ -72,7 +78,6 @@ let package = Package(
.define("_GNU_SOURCE", to: "1"), // Fix build error for Swift 5.9 onwards
],
linkerSettings: [
.linkedLibrary("curl"),
.linkedLibrary("sasl2"),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we remove this here as well then?

Copy link
Member

Choose a reason for hiding this comment

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

We can't get rid of sasl2, as that would disable the more generic SASL authentication mechanisms, like SASL/PLAIN.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay we should look into building libsassl with SwiftPM then to avoid the system dependency.

.linkedLibrary("z"), // zlib
]
Expand Down
9 changes: 4 additions & 5 deletions Sources/Crdkafka/custom/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#define ENABLE_ZSTD 1
#define ENABLE_SSL 1
#define ENABLE_GSSAPI 1
#define ENABLE_CURL 1
#define ENABLE_CURL 0
#define ENABLE_DEVEL 0
#define ENABLE_VALGRIND 0
#define ENABLE_REFCNT_DEBUG 0
Expand All @@ -35,7 +35,6 @@
#define ENABLE_ZSTD 1
#define ENABLE_SSL 1
#define ENABLE_GSSAPI 1
#define ENABLE_CURL 1
#define ENABLE_LZ4_EXT 1
#define WITH_STATIC_LINKING 1
#define MKL_APP_NAME "librdkafka"
Expand Down Expand Up @@ -136,7 +135,7 @@
// libzstd
#define WITH_ZSTD 1
// libcurl
#define WITH_CURL 1
#define WITH_CURL 0
// WITH_HDRHISTOGRAM
#define WITH_HDRHISTOGRAM 1
// WITH_SNAPPY
Expand All @@ -146,9 +145,9 @@
// WITH_SASL_SCRAM
#define WITH_SASL_SCRAM 1
// WITH_SASL_OAUTHBEARER
#define WITH_SASL_OAUTHBEARER 1
#define WITH_SASL_OAUTHBEARER 0
// WITH_OAUTHBEARER_OIDC
#define WITH_OAUTHBEARER_OIDC 1
#define WITH_OAUTHBEARER_OIDC 0
// regex
#define HAVE_REGEX 1
// strndup
Expand Down
9 changes: 5 additions & 4 deletions Sources/Kafka/Configuration/KafkaConfiguration+Security.swift
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ extension KafkaConfiguration {
}
}

public struct OAuthBearerMethod: Sendable, Hashable {
struct OAuthBearerMethod: Sendable, Hashable {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Won't it be (formally) a breaking change if anyone uses that one for auth?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it would but we haven't released a major yet so removing APIs is still possible. I would love to get the package into a state where we don't require system dependencies at all.

internal enum _OAuthBearerMethod: Sendable, Hashable {
case `default`(
configuration: String?
Expand Down Expand Up @@ -337,7 +337,7 @@ extension KafkaConfiguration {
/// For example: `principalClaimName=azp principal=admin scopeClaimName=roles scope=role1,role2 lifeSeconds=600`.
/// In addition, SASL extensions can be communicated to the broker via `extension_NAME=value`.
/// For example: `principal=admin extension_traceId=123`
public static func `default`(configuration: String? = nil) -> OAuthBearerMethod {
static func `default`(configuration: String? = nil) -> OAuthBearerMethod {
OAuthBearerMethod(_internal: .default(configuration: configuration))
}

Expand All @@ -359,7 +359,7 @@ extension KafkaConfiguration {
/// - scope: The client uses this to specify the scope of the access request to the broker.
/// - extensions: Allow additional information to be provided to the broker.
/// Comma-separated list of key=value pairs. E.g., "supportFeatureX=true,organizationId=sales-emea".
public static func oidc(
static func oidc(
configuration: String? = nil,
clientID: String,
clientSecret: String,
Expand Down Expand Up @@ -419,7 +419,8 @@ extension KafkaConfiguration {
}

/// Use the OAUTHBEARER mechanism.
public static func oAuthBearer(method: OAuthBearerMethod) -> SASLMechanism {
// This is currently disabled since it requires a curl dependency otherwise.
static func oAuthBearer(method: OAuthBearerMethod) -> SASLMechanism {
SASLMechanism(
_internal: .oAuthBearer(method: method)
)
Expand Down