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

Check create topic permission on topic creation using pulsar proto clients #17411

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

KannarFr
Copy link
Contributor

@KannarFr KannarFr commented Sep 1, 2022

Fixes #17406

Motivation

Enable CREATE_TOPIC permission check on topic auto creation.

Modifications

Introduce AuthAction.create_topic for the PulsarAuthorizationProvider

Verifying this change

  • Make sure that the change passes the CI checks.

This change updated tests and can be verified as follows:

  • updated test and give create_topic permission on the namespace

Does this pull request potentially affect one of the following parts:

  • it affects permissions as currently, CREATE_TOPIC wasn't checked on the default authZ provider.

  • doc-required

@github-actions
Copy link

github-actions bot commented Sep 1, 2022

@KannarFr Please provide a correct documentation label for your PR.
Instructions see Pulsar Documentation Label Guide.

@KannarFr KannarFr changed the title Check create topic on subscription creation Check create topic permission on topic creation using pulsar proto clients Sep 2, 2022
@KannarFr KannarFr force-pushed the checkCreateTopicOnSubscriptionCreation branch from 241ccc0 to 48fe841 Compare September 2, 2022 13:38
Comment on lines 1081 to 1083
CompletableFuture<Boolean> isAuthorizedToCreateTopicFuture = isNamespaceOperationAllowed(
topicName.getNamespaceObject(),
NamespaceOperation.CREATE_TOPIC
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can add this before line 1026, and use this method isAuthorizedFuture.thenCombine(isAuthorizedToCreateTopicFuture, (isAuthorized, isAuthorizedToCreateTopic).

Copy link
Contributor Author

@KannarFr KannarFr Sep 5, 2022

Choose a reason for hiding this comment

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

This will prevent produce/consume of topic if it already exists but create_topic operation not authorized, nope?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh nvm, got it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gaoran10 done.

@KannarFr KannarFr force-pushed the checkCreateTopicOnSubscriptionCreation branch 3 times, most recently from ebfd946 to 4903905 Compare September 5, 2022 12:39
@MarvinCai MarvinCai requested a review from gaoran10 September 8, 2022 13:04
@KannarFr KannarFr force-pushed the checkCreateTopicOnSubscriptionCreation branch 5 times, most recently from 80dd5a0 to 364e212 Compare September 14, 2022 13:33
@KannarFr
Copy link
Contributor Author

@gaoran10 the failing tests are due to CI flakyness, nope?

Copy link
Member

@michaeljmarshall michaeljmarshall left a comment

Choose a reason for hiding this comment

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

This looks like a breaking change for some current use cases. @KannarFr - what do you think about making this feature an alternative to auto topic creation? Then, users can run without auto topic creation and give certain roles permission to create topics.

Copy link
Member

@michaeljmarshall michaeljmarshall left a comment

Choose a reason for hiding this comment

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

Do we also need to update the logic for ServerCnx#handleProducer?

@KannarFr KannarFr force-pushed the checkCreateTopicOnSubscriptionCreation branch from ce5d4c1 to e9f004d Compare September 23, 2022 11:59
@KannarFr KannarFr force-pushed the checkCreateTopicOnSubscriptionCreation branch from e9f004d to 8fd1301 Compare October 17, 2022 12:21
@KannarFr
Copy link
Contributor Author

@michaeljmarshall are you ok with the way I've done it in handleProducer?

Copy link
Member

@michaeljmarshall michaeljmarshall left a comment

Choose a reason for hiding this comment

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

Sorry for the my delayed review @KannarFr. This is looking good, but I think it still needs some changes. Thanks!

consumers.remove(consumerId, consumerFuture);
ctx.writeAndFlush(Commands.newError(requestId, ServerError.AuthorizationError,
msg));
return null;
Copy link
Member

Choose a reason for hiding this comment

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

I don't think returning null here will give the desired behavior unless we modify the thenAccept block. It seems like the current paradigm in this section of the code is to throw an exception, so I think it would be appropriate to do that here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did you see https://github.com/apache/pulsar/pull/17411/files#diff-1e0e8195fb5ec5a6d79acbc7d859c025a9b711f94e6ab37c94439e99b3202e84L1187-L1198 lines? It seems we are returning null and writing errors to the channel. Nope?

Copy link
Member

Choose a reason for hiding this comment

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

If we return null here, we will go to the thenAccept block and will call consumerFuture.complete(consumer). We don't want to complete the future there. I think we wnat to run the lines 1187 to 1198 that you reference. Returning a failed future ensures that we jump to the exceptionally block on 1169 that will send the error response.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, does e34524a LGTY?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @michaeljmarshall

Could you retake a look? Thanks

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 just rebased it from master.

@michaeljmarshall michaeljmarshall added type/feature The PR added a new feature or issue requested a new feature doc-required Your PR changes impact docs and you will update later. component/authorization and removed doc-label-missing labels Oct 18, 2022
@michaeljmarshall michaeljmarshall added this to the 2.12.0 milestone Oct 18, 2022
@poorbarcode poorbarcode added this to the 3.1.0 milestone Apr 10, 2023
@KannarFr KannarFr force-pushed the checkCreateTopicOnSubscriptionCreation branch from 512d053 to 4d743bb Compare April 10, 2023 17:47
@KannarFr
Copy link
Contributor Author

@poorbarcode, @michaeljmarshall looks not available, can you ping someone else? It would be cool to merge it upstream asap :D.

@github-actions github-actions bot removed the Stale label Apr 19, 2023
Copy link
Member

@michaeljmarshall michaeljmarshall left a comment

Choose a reason for hiding this comment

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

After reviewing this, here are a collection of thoughts on Pulsar's Authorization.

At it's core, I think the problem described by #17406 is that allowAutoTopicCreation is a configuration about permission/authorization.

In my view, the allowAutoTopicCreation=true says "a role with permission to produce/consume to a topic also has permission to create that topic".

This change proposes that allowAutoTopicCreation=true and produce/consumer permissions are insufficient, and that a role must also have explicit permission to create a topic.

Comment on lines +1112 to +1268
CompletableFuture<Boolean> isAuthorizedToCreateTopicFuture = isNamespaceOperationAllowed(
topicName.getNamespaceObject(),
NamespaceOperation.CREATE_TOPIC
);
Copy link
Member

Choose a reason for hiding this comment

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

As I mentioned before, this does not look backwards/forwards compatible. I don't think we can add required AuthActions without finding a way to make them compatible. The idea is that users should be able to upgrade then downgrade and things should still work. Can you confirm @KannarFr?

Copy link
Contributor Author

@KannarFr KannarFr Apr 19, 2023

Choose a reason for hiding this comment

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

That would be nice, but as I answered you am I not sure we can really do it as CREATE_TOPIC check is already performed in HTTP admin checks.

Copy link
Member

Choose a reason for hiding this comment

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

While I agree that the current design is inconsistent, I don't think we should add logic that breaks existing use cases.

@KannarFr
Copy link
Contributor Author

After reviewing this, here are a collection of thoughts on Pulsar's Authorization.

At it's core, I think the problem described by #17406 is that allowAutoTopicCreation is a configuration about permission/authorization.

Yes?

In my view, the allowAutoTopicCreation=true says "a role with permission to produce/consume to a topic also has permission to create that topic".

The HTTP admin API does not comply with this sentence. The CREATE_TOPIC operation is defined and used by HTTP admin API authz checks. I agree that this is introducing breaking changes in the permissions system and this is a problem, but there is authZ plugin provider providing this operation check and does not verify it during producer/consumer. So, I have no idea what the best answer is, but we can't stay and need to find a solution or make a decision here.

This change proposes that allowAutoTopicCreation=true and produce/consumer permissions are insufficient, and that a role must also have explicit permission to create a topic.

Well, this is the default behavior of every configurations keys in pulsar. Like namespace policies or tiered storage configurations, there is a default value that can be overridden by custom namespace policies.

@michaeljmarshall
Copy link
Member

michaeljmarshall commented Apr 19, 2023

The HTTP admin API does not comply with this sentence.

Fair point. I hadn't considered the pulsar and http endpoints together when writing that generalization.

I agree that this is introducing breaking changes in the permissions system and this is a problem, but there is authZ plugin provider providing this operation check and does not verify it during producer/consumer.

Is there another way to achieve this? Perhaps we can introduce an additional check that calls the authorization service and then we'll implement the default PulsarAuthorizationProvider in such a way that there are no breaking changes.

I think it might make sense to discuss the underlying inconsistency on the pulsar mailing list.

@KannarFr
Copy link
Contributor Author

KannarFr commented Apr 19, 2023

Perhaps we can introduce an additional check that calls the authorization service and then we'll implement the default PulsarAuthorizationProvider in such a way that there are no breaking change

This LGTM. Can you drive this discussion on the ML if you think it's required? Shall I do it?

@michaeljmarshall
Copy link
Member

Perhaps we can introduce an additional check that calls the authorization service and then we'll implement the default PulsarAuthorizationProvider in such a way that there are no breaking change

This LGTM. Can you drive this discussion on the ML if you think it's required? Shall I do it?

I won't be able to drive this discussion. Let me know if you have any questions though.

Copy link
Member

@nodece nodece left a comment

Choose a reason for hiding this comment

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

Your expectations seem reasonable, but I don't suggest we continue to add elements to AuthAction, I think we should deprecate the AuthAction.

We have NamespaceOperation and TopicOperation provides fine-grained permission control, but the provider doesn't support granting these operations to the user, perhaps we should move in this direction.

Let me know your thoughts!

@github-actions
Copy link

github-actions bot commented Jun 2, 2023

The pr had no activity for 30 days, mark with Stale label.

@github-actions github-actions bot added the Stale label Jun 2, 2023
@KannarFr
Copy link
Contributor Author

KannarFr commented Jun 2, 2023

I sent

Hi,

CREATE_TOPIC authorization check is not performed when trying to PRODUCE/CONSUME a topic, it has been referenced: #17406.

I opened a PR to fix it #17411, but Michael reported issues about backward compatibility (which is totally correct). Adding support of CREATE_TOPIC authorization as-is will break current authorization system. I noticed that HTTP Admin API verifies the CREATE_TOPIC right when creating topic, so we have inconsistencies between pulsar binary protocol and the HTTP admin API on this.

Also, the AuthorizationProvider is an interface exposing the CREATE_TOPIC feature for authZ plugins. But it is inconsistent too.

Michael suggested to fix this interface to support the CREATE_TOPIC check and adapt the pulsar's DefaultAuthzProvider to continue as-is.

I'd like to know what do you think?

Thanks,

Kannar

On the ML the 20/04/2023 and still have no answers @michaeljmarshall @nodece.

@github-actions github-actions bot removed the Stale label Jun 4, 2023
@Technoboy- Technoboy- modified the milestones: 3.1.0, 3.2.0 Jul 31, 2023
@Nowadays
Copy link

Is there any progression on this issue ?

@KannarFr
Copy link
Contributor Author

Unfortunately, no. I don't know why this is stuck @michaeljmarshall?

@KannarFr
Copy link
Contributor Author

@gaoran10 @MarvinCai

@KannarFr
Copy link
Contributor Author

KannarFr commented Oct 4, 2023

@michaeljmarshall @gaoran10 @MarvinCai, it makes sense to rebase it..?

@Nowadays
Copy link

Nowadays commented Oct 5, 2023

Is there any way to move forward with this PR ?

publishing/consuming and creating/deleting a topic are clearly different actions, and thus should require different authorization.

Why would there be an api to create/delete topics if that was not the case ?

@Technoboy- Technoboy- modified the milestones: 3.2.0, 3.3.0 Dec 22, 2023
@KannarFr
Copy link
Contributor Author

Any bumps?

@coderzc coderzc modified the milestones: 3.3.0, 3.4.0 May 8, 2024
@KannarFr KannarFr force-pushed the checkCreateTopicOnSubscriptionCreation branch from 4d743bb to da5205f Compare October 3, 2024 11:30
@lhotari lhotari modified the milestones: 4.0.0, 4.1.0 Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/authn doc-required Your PR changes impact docs and you will update later. type/feature The PR added a new feature or issue requested a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] topic auto creation does not check for CREATE_TOPIC permission