Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

[improve] Pass group ID to authorizer when using OAuth #1926

Conversation

Demogorgon314
Copy link
Member

@Demogorgon314 Demogorgon314 commented Jun 28, 2023

Motivation

Currently, the KoP only supports checking the topic permission when doing the consume authorization, but Kafka support checking the topic and group ID permission.

Before introducing this change, let's understand why KoP can't check group ID permission.

When Kafka does the consume authorization check, it will first check the group ID permission in handleJoinGroupRequest method, then it will check the topic permission in the handleFetchRequest method.

However, Pulsar is using another way to check consume permission. See the org.apache.pulsar.broker.authorization.AuthorizationService#canConsumeAsync method, it requires passing the topic name and subscription to check both permissions in the same place, and the topic name is required param.

public CompletableFuture<Boolean> canConsumeAsync(TopicName topicName, String role, AuthenticationDataSource authenticationData,String subscription)

If we follow the Kafka way to check the consumer permission, we can't get the topic name when joining a group since the join group request does not contain the topic name. So we have to authorize permission in the fetch request.

However, to authorization consume permission in the fetch request, we can only get the topic name in this request. In this case, we can't authorize the group ID.

Modifications

Since we can't get group ID when handling fetch requests, we need to find a way to pass through group ID when doing the authentication.

In OAuth, we have a credentials_file.json file that needs to be config, for example:

{
	"client_id": "my-id",
	"client_secret": "my-secret",
	"tenant": "my-tenant"
}

Here we can add a new parameter into the config:

{
	"client_id": "my-id",
	"client_secret": "my-secret",
	"tenant": "my-tenant",
        "group_id": "my-group-id"
}

Then we can add these parameters to SaslExtensions, and send it to the broker.

Documentation

Check the box below.

Need to update docs?

  • doc-required

    (If you need help on updating docs, create a doc issue)

  • no-need-doc

    (Please explain why)

  • doc

    (If this PR contains doc changes)

@Demogorgon314 Demogorgon314 self-assigned this Jun 28, 2023
@github-actions github-actions bot added the doc-required This pr needs a document label Jun 28, 2023
@codecov
Copy link

codecov bot commented Jun 28, 2023

Codecov Report

Merging #1926 (a0566e8) into master (24180bb) will decrease coverage by 0.10%.
The diff coverage is 9.37%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1926      +/-   ##
============================================
- Coverage     17.94%   17.85%   -0.10%     
- Complexity      745      752       +7     
============================================
  Files           194      195       +1     
  Lines         13957    14061     +104     
  Branches       1291     1308      +17     
============================================
+ Hits           2505     2511       +6     
- Misses        11271    11368      +97     
- Partials        181      182       +1     
Impacted Files Coverage Δ
...ative/pulsar/handlers/kop/KafkaRequestHandler.java 1.06% <0.00%> (-0.02%) ⬇️
...ive/pulsar/handlers/kop/SchemaRegistryManager.java 0.00% <0.00%> (ø)
...e/pulsar/handlers/kop/security/KafkaPrincipal.java 0.00% <0.00%> (ø)
.../pulsar/handlers/kop/security/PlainSaslServer.java 45.00% <0.00%> (-1.56%) ⬇️
...ulsar/handlers/kop/security/SaslAuthenticator.java 0.00% <0.00%> (ø)
...ulsar/handlers/kop/security/auth/ResourceType.java 0.00% <0.00%> (ø)
...andlers/kop/security/auth/SimpleAclAuthorizer.java 0.00% <0.00%> (ø)
...s/kop/security/oauth/KopOAuthBearerSaslServer.java 0.00% <0.00%> (ø)
.../security/oauth/OauthValidatorCallbackHandler.java 0.00% <0.00%> (ø)
.../kop/security/oauth/OauthLoginCallbackHandler.java 0.00% <0.00%> (ø)
... and 4 more

@Demogorgon314 Demogorgon314 marked this pull request as ready for review June 29, 2023 07:05
@BewareMyPower BewareMyPower added release/2.11 release/2.10.4 release/3.0 type/enhancement Indicates an improvement to an existing feature labels Jun 30, 2023
Copy link
Collaborator

@BewareMyPower BewareMyPower left a comment

Choose a reason for hiding this comment

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

We need to prevent consumers from subscribing group-B if they have configured the permission for group-A.

@Demogorgon314 Demogorgon314 force-pushed the Demogorgon314/pass-groupid-when-use-oauth branch from 3aa978d to 591c45b Compare June 30, 2023 05:35
Comment on lines 41 to 47
/**
* {@code SaslServer} implementation for SASL/OAUTHBEARER in Kafka. An instance
* of {@link OAuthBearerToken} is available upon successful authentication via
* the negotiated property "{@code OAUTHBEARER.token}"; the token could be used
* in a custom authorizer (to authorize based on JWT claims rather than ACLs,
* for example).
*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you just copy the Java docs from Kafka? It might be misleading here. It's better to remove them. For example, {@code SaslServer} and {@code OAUTHBEARER.token} never link correctly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated.

@BewareMyPower
Copy link
Collaborator

@Demogorgon314 Could you resolve the conflicts?

@Demogorgon314 Demogorgon314 force-pushed the Demogorgon314/pass-groupid-when-use-oauth branch from e159653 to dc9f1d7 Compare July 4, 2023 13:52
@Demogorgon314
Copy link
Member Author

@BewareMyPower Resolved.

@BewareMyPower BewareMyPower merged commit e108e44 into streamnative:master Jul 5, 2023
17 of 19 checks passed
@Demogorgon314 Demogorgon314 deleted the Demogorgon314/pass-groupid-when-use-oauth branch July 5, 2023 09:39
Demogorgon314 added a commit to Demogorgon314/kop that referenced this pull request Jul 5, 2023
…1926)

### Motivation
Currently, the KoP only supports checking the topic permission when
doing the consume authorization, but Kafka support checking the topic
and group ID permission.

Before introducing this change, let's understand why KoP can't check
group ID permission.

When Kafka does the consume authorization check, it will first check the
group ID permission in `handleJoinGroupRequest` method, then it will
check the topic permission in the `handleFetchRequest` method.

However, Pulsar is using another way to check consume permission. See
the
`org.apache.pulsar.broker.authorization.AuthorizationService#canConsumeAsync`
method, it requires passing the topic name and subscription to check
both permissions in the same place, and the topic name is required
param.
```
public CompletableFuture<Boolean> canConsumeAsync(TopicName topicName, String role, AuthenticationDataSource authenticationData,String subscription)
```

If we follow the Kafka way to check the consumer permission, we can't
get the topic name when joining a group since the join group request
does not contain the topic name. So we have to authorize permission in
the fetch request.

However, to authorization consume permission in the fetch request, we
can only get the topic name in this request. In this case, we can't
authorize the group ID.

### Modifications
Since we can't get group ID when handling fetch requests, we need to
find a way to pass through group ID when doing the authentication.

In OAuth, we have a `credentials_file.json` file that needs to be
config, for example:
```
{
	"client_id": "my-id",
	"client_secret": "my-secret",
	"tenant": "my-tenant"
}
```
Here we can add a new parameter into the config:
```
{
	"client_id": "my-id",
	"client_secret": "my-secret",
	"tenant": "my-tenant",
        "group_id": "my-group-id"
}
```
Then we can add these parameters to `SaslExtensions`, and send it to the
broker.

(cherry picked from commit e108e44)
Demogorgon314 added a commit to Demogorgon314/kop that referenced this pull request Jul 5, 2023
…1926)

### Motivation
Currently, the KoP only supports checking the topic permission when
doing the consume authorization, but Kafka support checking the topic
and group ID permission.

Before introducing this change, let's understand why KoP can't check
group ID permission.

When Kafka does the consume authorization check, it will first check the
group ID permission in `handleJoinGroupRequest` method, then it will
check the topic permission in the `handleFetchRequest` method.

However, Pulsar is using another way to check consume permission. See
the
`org.apache.pulsar.broker.authorization.AuthorizationService#canConsumeAsync`
method, it requires passing the topic name and subscription to check
both permissions in the same place, and the topic name is required
param.
```
public CompletableFuture<Boolean> canConsumeAsync(TopicName topicName, String role, AuthenticationDataSource authenticationData,String subscription)
```

If we follow the Kafka way to check the consumer permission, we can't
get the topic name when joining a group since the join group request
does not contain the topic name. So we have to authorize permission in
the fetch request.

However, to authorization consume permission in the fetch request, we
can only get the topic name in this request. In this case, we can't
authorize the group ID.

### Modifications
Since we can't get group ID when handling fetch requests, we need to
find a way to pass through group ID when doing the authentication.

In OAuth, we have a `credentials_file.json` file that needs to be
config, for example:
```
{
	"client_id": "my-id",
	"client_secret": "my-secret",
	"tenant": "my-tenant"
}
```
Here we can add a new parameter into the config:
```
{
	"client_id": "my-id",
	"client_secret": "my-secret",
	"tenant": "my-tenant",
        "group_id": "my-group-id"
}
```
Then we can add these parameters to `SaslExtensions`, and send it to the
broker.

(cherry picked from commit e108e44)
BewareMyPower pushed a commit that referenced this pull request Jul 6, 2023
…#1926) (#1945)

### Motivation
Currently, the KoP only supports checking the topic permission when
doing the consume authorization, but Kafka support checking the topic
and group ID permission.

Before introducing this change, let's understand why KoP can't check
group ID permission.

When Kafka does the consume authorization check, it will first check the
group ID permission in `handleJoinGroupRequest` method, then it will
check the topic permission in the `handleFetchRequest` method.

However, Pulsar is using another way to check consume permission. See
the

`org.apache.pulsar.broker.authorization.AuthorizationService#canConsumeAsync`
method, it requires passing the topic name and subscription to check
both permissions in the same place, and the topic name is required
param.
```
public CompletableFuture<Boolean> canConsumeAsync(TopicName topicName, String role, AuthenticationDataSource authenticationData,String subscription)
```

If we follow the Kafka way to check the consumer permission, we can't
get the topic name when joining a group since the join group request
does not contain the topic name. So we have to authorize permission in
the fetch request.

However, to authorization consume permission in the fetch request, we
can only get the topic name in this request. In this case, we can't
authorize the group ID.

### Modifications
Since we can't get group ID when handling fetch requests, we need to
find a way to pass through group ID when doing the authentication.

In OAuth, we have a `credentials_file.json` file that needs to be
config, for example:
```
{
	"client_id": "my-id",
	"client_secret": "my-secret",
	"tenant": "my-tenant"
}
```
Here we can add a new parameter into the config:
```
{
	"client_id": "my-id",
	"client_secret": "my-secret",
	"tenant": "my-tenant",
        "group_id": "my-group-id"
}
```
Then we can add these parameters to `SaslExtensions`, and send it to the
broker.

(cherry picked from commit e108e44)
BewareMyPower pushed a commit that referenced this pull request Jul 31, 2023
### Motivation
#1728 Introduced tenant for
OAuth, and #1926 introduced
group ID for OAuth, we should add docs.
Demogorgon314 added a commit to Demogorgon314/kop that referenced this pull request Aug 14, 2023
…1926)

### Motivation
Currently, the KoP only supports checking the topic permission when
doing the consume authorization, but Kafka support checking the topic
and group ID permission.

Before introducing this change, let's understand why KoP can't check
group ID permission.

When Kafka does the consume authorization check, it will first check the
group ID permission in `handleJoinGroupRequest` method, then it will
check the topic permission in the `handleFetchRequest` method.

However, Pulsar is using another way to check consume permission. See
the
`org.apache.pulsar.broker.authorization.AuthorizationService#canConsumeAsync`
method, it requires passing the topic name and subscription to check
both permissions in the same place, and the topic name is required
param.
```
public CompletableFuture<Boolean> canConsumeAsync(TopicName topicName, String role, AuthenticationDataSource authenticationData,String subscription)
```

If we follow the Kafka way to check the consumer permission, we can't
get the topic name when joining a group since the join group request
does not contain the topic name. So we have to authorize permission in
the fetch request.

However, to authorization consume permission in the fetch request, we
can only get the topic name in this request. In this case, we can't
authorize the group ID.

### Modifications
Since we can't get group ID when handling fetch requests, we need to
find a way to pass through group ID when doing the authentication.

In OAuth, we have a `credentials_file.json` file that needs to be
config, for example:
```
{
	"client_id": "my-id",
	"client_secret": "my-secret",
	"tenant": "my-tenant"
}
```
Here we can add a new parameter into the config:
```
{
	"client_id": "my-id",
	"client_secret": "my-secret",
	"tenant": "my-tenant",
        "group_id": "my-group-id"
}
```
Then we can add these parameters to `SaslExtensions`, and send it to the
broker.

(cherry picked from commit e108e44)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
doc-required This pr needs a document release/2.10.4 release/2.11 release/3.0 type/enhancement Indicates an improvement to an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants