-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
base: master
Are you sure you want to change the base?
Check create topic permission on topic creation using pulsar proto clients #17411
Conversation
@KannarFr Please provide a correct documentation label for your PR. |
241ccc0
to
48fe841
Compare
CompletableFuture<Boolean> isAuthorizedToCreateTopicFuture = isNamespaceOperationAllowed( | ||
topicName.getNamespaceObject(), | ||
NamespaceOperation.CREATE_TOPIC |
There was a problem hiding this comment.
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)
.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh nvm, got it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gaoran10 done.
ebfd946
to
4903905
Compare
...common/src/main/java/org/apache/pulsar/broker/authorization/PulsarAuthorizationProvider.java
Outdated
Show resolved
Hide resolved
80dd5a0
to
364e212
Compare
@gaoran10 the failing tests are due to CI flakyness, nope? |
There was a problem hiding this 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.
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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
?
ce5d4c1
to
e9f004d
Compare
e9f004d
to
8fd1301
Compare
@michaeljmarshall are you ok with the way I've done it in handleProducer? |
There was a problem hiding this 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!
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java
Outdated
Show resolved
Hide resolved
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
Outdated
Show resolved
Hide resolved
consumers.remove(consumerId, consumerFuture); | ||
ctx.writeAndFlush(Commands.newError(requestId, ServerError.AuthorizationError, | ||
msg)); | ||
return null; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, does e34524a LGTY?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you retake a look? Thanks
There was a problem hiding this comment.
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.
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
Outdated
Show resolved
Hide resolved
512d053
to
4d743bb
Compare
@poorbarcode, @michaeljmarshall looks not available, can you ping someone else? It would be cool to merge it upstream asap :D. |
There was a problem hiding this 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.
CompletableFuture<Boolean> isAuthorizedToCreateTopicFuture = isNamespaceOperationAllowed( | ||
topicName.getNamespaceObject(), | ||
NamespaceOperation.CREATE_TOPIC | ||
); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Yes?
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.
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. |
Fair point. I hadn't considered the pulsar and http endpoints together when writing that generalization.
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. |
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. |
There was a problem hiding this 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!
The pr had no activity for 30 days, mark with Stale label. |
I sent
On the ML the 20/04/2023 and still have no answers @michaeljmarshall @nodece. |
Is there any progression on this issue ? |
Unfortunately, no. I don't know why this is stuck @michaeljmarshall? |
@michaeljmarshall @gaoran10 @MarvinCai, it makes sense to rebase it..? |
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 ? |
Any bumps? |
4d743bb
to
da5205f
Compare
Fixes #17406
Motivation
Enable CREATE_TOPIC permission check on topic auto creation.
Modifications
Introduce AuthAction.create_topic for the PulsarAuthorizationProvider
Verifying this change
This change updated tests and can be verified as follows:
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