-
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
[PIP-167][Authorization] Make it Configurable to Require Subscription Permission #15576
[PIP-167][Authorization] Make it Configurable to Require Subscription Permission #15576
Conversation
4c56cf8
to
52438cc
Compare
@@ -42,6 +42,10 @@ public final class AuthPoliciesImpl implements AuthPolicies { | |||
@JsonProperty("subscription_auth_roles") | |||
private Map<String, Set<String>> subscriptionAuthentication = new TreeMap<>(); | |||
|
|||
// Default value is set in the builder | |||
@JsonProperty(value = "implicit_subscription_auth") | |||
private boolean implicitSubscriptionAuth; |
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.
adding a field with default value "true" is problematic, thinking to the upgrade path.
This is because on storage (ZK) all the old Policies do not have this field, but we are considering it "true" if it is not present.
This may make us fall into some subtle problems with clusters upgraded to the latest version.
I suggest to go down these ways:
- use Boolean (nullable boolean) and deal explicitly with the case "unknown"
- negate the flag, this way the default will be "false" and this value will also be applied in case of null/non existing field (so old cluster upgraded, or updates happening during rolling upgrades of the cluster
I prefer 2) as it is easier to deal with both code changes and also with the migration
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.
Good points Enrico. Yes this should be addressed.
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.
Thank you for the review, @eolivelli. My preference is also 2. I'll replace implicit
with explicit
for the whole PR/PIP.
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.
@eolivelli - on second thought, are you suggesting that I need to update the variable names or just that the stored metadata needs to default to false? The semantics of "granting permission" on the API will be different if we change the endpoint names to align with a default value where "false" means additional permission is granted roles. For example, an alternate name for the /implicitPermissionOnSubscription
endpoint is /permissionOnSubscriptionRequired
. In that case, granting permission would use a PUT
/POST
to set the value to false, which seems counter intuitive.
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.
The main point is that the default value must be 'false' or null because this is what is on existing data.
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 makes sense. I think the likely alternative name is permissionOnSubscriptionRequired
. If someone has a better name, though, I'll use that.
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.
@eolivelli - I updating the naming by using permissionOnSubscriptionRequired
. Please let me know what you think about the name.
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.
works for me
@PUT | ||
@Path("/{property}/{cluster}/{namespace}/implicitPermissionOnSubscription") | ||
@ApiOperation(hidden = true, value = "Allow a consumer's role to have implicit permission to consume from a" | ||
+ " subscription.") | ||
@ApiResponses(value = {@ApiResponse(code = 403, message = "Don't have admin permission"), | ||
@ApiResponse(code = 404, message = "Property or cluster or namespace doesn't exist"), | ||
@ApiResponse(code = 409, message = "Concurrent modification"), | ||
@ApiResponse(code = 501, message = "Authorization is not enabled")}) | ||
public void grantImplicitPermissionOnSubscription( | ||
@PathParam("property") String property, @PathParam("cluster") String cluster, | ||
@PathParam("namespace") String namespace) { | ||
validateNamespaceName(property, cluster, namespace); | ||
internalSetImplicitPermissionOnSubscription(true); | ||
} | ||
|
||
@DELETE | ||
@Path("/{property}/{cluster}/{namespace}/implicitPermissionOnSubscription") | ||
@ApiOperation(hidden = true, value = "Require a consumer's role to have explicit permission to consume from a" | ||
+ " subscription.") | ||
@ApiResponses(value = {@ApiResponse(code = 403, message = "Don't have admin permission"), | ||
@ApiResponse(code = 404, message = "Property or cluster or namespace doesn't exist"), | ||
@ApiResponse(code = 409, message = "Concurrent modification"), | ||
@ApiResponse(code = 501, message = "Authorization is not enabled")}) | ||
public void revokeImplicitPermissionOnSubscription( | ||
@PathParam("property") String property, @PathParam("cluster") String cluster, | ||
@PathParam("namespace") String namespace) { | ||
validateNamespaceName(property, cluster, namespace); | ||
internalSetImplicitPermissionOnSubscription(false); | ||
} | ||
|
||
@GET | ||
@Path("/{property}/{cluster}/{namespace}/implicitPermissionOnSubscription") | ||
@ApiOperation(value = "Get permission on subscription required for namespace.") | ||
@ApiResponses(value = {@ApiResponse(code = 403, message = "Don't have admin permission"), | ||
@ApiResponse(code = 404, message = "Property or cluster or namespace doesn't exist"), | ||
@ApiResponse(code = 409, message = "Namespace is not empty")}) | ||
public boolean getImplicitPermissionOnSubscription(@PathParam("property") String property, | ||
@PathParam("cluster") String cluster, | ||
@PathParam("namespace") String namespace) { | ||
validateNamespaceName(property, cluster, namespace); | ||
return getImplicitPermissionOnSubscription(); | ||
} | ||
|
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.
Does this have to be added to the v1 API at all?
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.
Good question, I'm not sure. I don't know how we're approaching new features like this. I'm open to removing it, if that's the consensus.
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/Namespaces.java
Outdated
Show resolved
Hide resolved
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/Namespaces.java
Outdated
Show resolved
Hide resolved
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java
Outdated
Show resolved
Hide resolved
@@ -42,6 +42,10 @@ public final class AuthPoliciesImpl implements AuthPolicies { | |||
@JsonProperty("subscription_auth_roles") | |||
private Map<String, Set<String>> subscriptionAuthentication = new TreeMap<>(); | |||
|
|||
// Default value is set in the builder | |||
@JsonProperty(value = "implicit_subscription_auth") | |||
private boolean implicitSubscriptionAuth; |
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.
Good points Enrico. Yes this should be addressed.
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.
+1
(there are some TODOs, but I don't think we can address them with this work, maybe you can remove the TODO, or at least like a GH issue near the TODO)
The pr had no activity for 30 days, mark with Stale label. |
@michaeljmarshall do you continue this work? cc @nodece |
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.
Makes sense.
Signed-off-by: tison <[email protected]>
This reverts commit 96be50c.
Signed-off-by: tison <[email protected]>
33001f4
to
c6a4b3a
Compare
Codecov Report
@@ Coverage Diff @@
## master #15576 +/- ##
============================================
+ Coverage 46.34% 47.82% +1.47%
- Complexity 10394 11213 +819
============================================
Files 703 763 +60
Lines 68838 73640 +4802
Branches 7379 7915 +536
============================================
+ Hits 31905 35217 +3312
- Misses 33324 34557 +1233
- Partials 3609 3866 +257
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Merging... Thanks for your all efforts. |
@michaeljmarshall @eolivelli @nodece @lhotari Although, I noticed that this proposal didn't pass a formal PIP vote yet, while there is a thread without objection. I suggest you continue that thread to make a formal resolution. |
Hi @michaeljmarshall, do you have any updates for adding the docs? |
@momo-jun this PR was reverted, so no docs are needed. |
Fixes: #15597
Motivation
See PIP-167 for more detail. At a high level, this PR seeks to make it possible to configure whether subscription level permission is required to consume from a subscription in a namespace where a subscription does not have any permission defined.
Modifications
PulsarAuthorizationProvider#canConsume
logic so that when subscription permission is required, it will reject all roles that do not explicitly have permission to consume from a subscription in the subscription permission map for the namespace.AuthPolicies
and theAuthPoliciesImpl
classes to store a new boolean field namedsubscription_auth_required
.Verifying this change
Once the design is solidified, I will add tests to the
pulsar-broker/src/test/java/org/apache/pulsar/client/api/AuthorizationProducerConsumerTest.java
class.Does this pull request potentially affect one of the following parts:
This change adds a new feature discussed in the associated PIP.
Documentation
doc-required
I will add docs as a part of this work, but I haven't yet because the design isn't solidified.