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

feat: Add segmentio/kafka-go Mechanism implementation for SASL/Plain with GCP OAuth Tokens. #30

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

benjamin-maynard
Copy link

Internal Note: This depends on a rollout of cl/712634153.

This package provides an implementation of the sasl.Mechanism interface from segmentio/kafka-go that handles authentication to Google Managed Kafka using OAuth Tokens from Application Default Credentials.

It allows you to use Authorization Tokens with SASL/Plain in segmentio/kafka-go, without requiring OAuthBearer support in the library.

This is useful for GMK customers that use this library for Kafka - who cannot use OAuthBearer authentication due to lack of support.

@benjamin-maynard benjamin-maynard requested a review from a team as a code owner January 7, 2025 17:46
@benjamin-maynard benjamin-maynard changed the title Add saslplainoauthmechanism package for OAuth Token SASL/Plain Add package for segmentio/kafka-go Mechanism implementation for SASL/Plain with OAuth Tokens. Jan 7, 2025
@benjamin-maynard benjamin-maynard changed the title Add package for segmentio/kafka-go Mechanism implementation for SASL/Plain with OAuth Tokens. feat: Add segmentio/kafka-go Mechanism implementation for SASL/Plain with GCP OAuth Tokens. Jan 7, 2025
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd remove this file

Copy link
Author

Choose a reason for hiding this comment

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

Happy to remove - would you mind expanding on why it should be removed?

sasl-plain-access-token/saslplainoauthmechanism/README.md Outdated Show resolved Hide resolved
sasl-plain-access-token/README.md Outdated Show resolved Hide resolved
sasl-plain-access-token/saslplainoauthmechanism/README.md Outdated Show resolved Hide resolved
sasl-plain-access-token/saslplainoauthmechanism/go.mod Outdated Show resolved Hide resolved
return "PLAIN"
}

func (m *Mechanism) Start(ctx context.Context) (sasl.StateMachine, []byte, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

how does segmentio io knows it has to refresh the token?

Copy link
Author

Choose a reason for hiding this comment

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

It doesn't know it has to refresh the token - but it calls Start¹ for every new Kafka broker connection and uses the returned token for authenticating the connection.

The TokenSource in the Mechanism always returns a valid token at the point it is called, and the token is only validated on the broker at the point of connection establishment, so as long as it is valid at the point the connection is established, then we no longer care about expiry for that connection.

[1] Each time the Dialer connects to a Kafka Broker, it calls Dialer.authenticateSASL if there is a non nil SASLMechanism, which in turn calls the Start receiver function on the Mechanism. The encoded username and password (token) is then used for authentication to the broker.

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