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

OAuthbearer support #74

Merged
merged 1 commit into from
Jul 26, 2024
Merged

OAuthbearer support #74

merged 1 commit into from
Jul 26, 2024

Conversation

macasado86
Copy link
Contributor

Hi!

I have opened this PR to include the necessary functionality to authenticate Erlkaf consumers and producers using the OAuthbearer protocol:

  • OIDC authentication passing the required parameters to librdkafka: sasl_oauthbearer_method, sasl_oauthbearer_client_id, sasl_oauthbearer_client_secret, sasl_oauthbearer_scope sasl.oauthbearer.extensions, sasl_oauthbearer_token_endpoint_url

  • Custom refresh token callback to provide users a way to implement their retrieve access token function and pass it to librdkafka

I have needed to enable this options in order to retrieve the first token before trying to establish the connection with the brokers:

  • rd_kafka_sasl_background_callbacks_enable
  • rd_kafka_conf_enable_sasl_queue

This way, the refresh callbacks are triggered automatically by librdkafka in a background thread.

Any suggestions or changes you think I should make, please let me know.

@silviucpp
Copy link
Owner

Hello,

The implementation looks ok. But please fix the duplicate code issues I mentioned in the review.

@macasado86
Copy link
Contributor Author

Hi!

I can't see the review. Maybe you forgot to submit it.

Thanks

@silviucpp
Copy link
Owner

You cannot see the above change requests ?
Screenshot 2024-07-24 at 11 10 28

@macasado86
Copy link
Contributor Author

No, I can't. I think you have to submit the review (it's in 'pending' state)

@@ -417,3 +444,105 @@ ERL_NIF_TERM enif_produce(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])

return ATOMS.atomOk;
}

char** split_producer_extensions(const std::string extensions_str, size_t* length)
Copy link
Owner

Choose a reason for hiding this comment

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

Seems duplicate code with split_consumer_extensions . Move them into a dedicated file and include it in both consumer and producer modules.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have moved this function to a new file called erlkaf_oauthbearer.cc

return extensions;
}

void free_producer_extensions(char** extensions, size_t length)
Copy link
Owner

Choose a reason for hiding this comment

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

Same as above. duplicated code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have moved this function to a new file called erlkaf_oauthbearer.cc

}
}

ERL_NIF_TERM enif_producer_oauthbearer_set_token(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
Copy link
Owner

Choose a reason for hiding this comment

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

Lot of duplicate code with enif_consumer_oauthbearer_set_token. For sure you can refactor to have same function in both.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have moved some of this functionality (all but parsing the arguments) to a new file called erlkaf_oauthbearer.cc

}
}

ERL_NIF_TERM enif_producer_oauthbearer_set_token_failure(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
Copy link
Owner

Choose a reason for hiding this comment

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

Lot of duplicate code with enif_consumer_oauthbearer_set_token_failure. For sure you can refactor to have same function in both.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have moved some of this functionality (all but parsing the arguments) to a new file called erlkaf_oauthbearer.cc

@silviucpp
Copy link
Owner

Now you can see it ?

@silviucpp silviucpp merged commit 35daac2 into silviucpp:master Jul 26, 2024
1 check passed
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.

2 participants