You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pulsar.apache.org by yush1ga <gi...@git.apache.org> on 2017/06/26 17:56:05 UTC

[GitHub] incubator-pulsar pull request #530: Support wildcard in permitted role name

GitHub user yush1ga opened a pull request:

    https://github.com/apache/incubator-pulsar/pull/530

    Support wildcard in permitted role name

    This PR is resolving conflicts of #494 as I commented when closing it.
    
    ### Motivation
    
    Please refer to #469.
    
    ### Modifications
    
    Fix AuthorizationManger to check by wildcard matching after normal authorization check.
    This process is executed when `wildcardRoleNamePermittedActions` in `ServiceConfiguration` is set.
    
    ### Result
    
    Wildcard is valid in heads or tails of permission's role names.
    I'm going to add document after this  PR is merged.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/yush1ga/pulsar wildcard

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-pulsar/pull/530.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #530
    
----

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-pulsar pull request #530: Support wildcard in permitted role name

Posted by saandrews <gi...@git.apache.org>.
Github user saandrews commented on a diff in the pull request:

    https://github.com/apache/incubator-pulsar/pull/530#discussion_r124101111
  
    --- Diff: pulsar-broker/src/test/java/org/apache/pulsar/broker/auth/AuthorizationTest.java ---
    @@ -94,6 +96,46 @@ void simple() throws Exception {
             assertEquals(auth.canProduce(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my-role"), true);
             assertEquals(auth.canConsume(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my-role"), true);
     
    +        // test for wildcard
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my.role.1"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my.role.2"), false);
    +        assertEquals(auth.canProduce(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my.role.1"), false);
    +        assertEquals(auth.canConsume(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my.role.1"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "other.role.1"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "other.role.2"), false);
    +
    +        admin.namespaces().grantPermissionOnNamespace("p1/c1/ns1", "my.role.*", EnumSet.of(AuthAction.produce));
    +        waitForChange();
    +
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my.role.1"), true);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my.role.2"), true);
    +        assertEquals(auth.canProduce(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my.role.1"), true);
    +        assertEquals(auth.canConsume(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my.role.1"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "other.role.1"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "other.role.2"), false);
    +
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "1.role.my"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "2.role.my"), false);
    +        assertEquals(auth.canProduce(DestinationName.get("persistent://p1/c1/ns1/ds1"), "1.role.my"), false);
    +        assertEquals(auth.canConsume(DestinationName.get("persistent://p1/c1/ns1/ds1"), "1.role.my"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "2.role.other"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "2.role.other"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds2"), "1.role.my"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds2"), "2.role.my"), false);
    +
    +        admin.persistentTopics().grantPermission("persistent://p1/c1/ns1/ds1", "*.my",
    --- End diff --
    
    We need to add a case to cover prefix match as well?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-pulsar pull request #530: Support wildcard in permitted role name

Posted by yush1ga <gi...@git.apache.org>.
Github user yush1ga commented on a diff in the pull request:

    https://github.com/apache/incubator-pulsar/pull/530#discussion_r124403361
  
    --- Diff: conf/broker.conf ---
    @@ -140,6 +140,10 @@ authenticationProviders=
     # Enforce authorization
     authorizationEnabled=false
     
    +# Actions that can be authorized by using permitted role name which contains wildcard
    +# e.g. pulsar.service.*
    +wildcardInPermittedRoleNameEnabled=false
    --- End diff --
    
    Fixed.
    I was worried about this name.
    Thanks for your comment:)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-pulsar pull request #530: Support wildcard in permitted role name

Posted by rdhabalia <gi...@git.apache.org>.
Github user rdhabalia commented on a diff in the pull request:

    https://github.com/apache/incubator-pulsar/pull/530#discussion_r124121140
  
    --- Diff: pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/AuthorizationManager.java ---
    @@ -177,6 +190,29 @@ private boolean checkCluster(DestinationName destination) {
             return permissionFuture;
         }
     
    +    private Boolean checkWildcardPermission(String checkedRole, AuthAction checkedAction,
    +            Map<String, Set<AuthAction>> permissionMap) {
    +        for (Map.Entry<String, Set<AuthAction>> permissionData : permissionMap.entrySet()) {
    +            String permittedRole = permissionData.getKey();
    +            Set<AuthAction> permittedActions = permissionData.getValue();
    +
    +            // Prefix match
    +            if (permittedRole.charAt(permittedRole.length() - 1) == '*'
    +                    && checkedRole.startsWith(permittedRole.substring(0, permittedRole.length() - 1))
    +                    && permittedActions.contains(checkedAction)) {
    +                return true;
    +            }
    +
    +            // Suffix match
    +            if (permittedRole.charAt(0) == '*'
    --- End diff --
    
    as we just check Prefix and  suffix so, it seems it will not support wild-card character for usecase:
    checkedRole = `abcd` 
    and permittedRole = `ab*d`
    So, instead can we use regex-pattern to validate it.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-pulsar pull request #530: Support wildcard in permitted role name

Posted by yush1ga <gi...@git.apache.org>.
Github user yush1ga commented on a diff in the pull request:

    https://github.com/apache/incubator-pulsar/pull/530#discussion_r124128740
  
    --- Diff: pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/AuthorizationManager.java ---
    @@ -177,6 +190,29 @@ private boolean checkCluster(DestinationName destination) {
             return permissionFuture;
         }
     
    +    private Boolean checkWildcardPermission(String checkedRole, AuthAction checkedAction,
    +            Map<String, Set<AuthAction>> permissionMap) {
    +        for (Map.Entry<String, Set<AuthAction>> permissionData : permissionMap.entrySet()) {
    +            String permittedRole = permissionData.getKey();
    +            Set<AuthAction> permittedActions = permissionData.getValue();
    +
    +            // Prefix match
    +            if (permittedRole.charAt(permittedRole.length() - 1) == '*'
    +                    && checkedRole.startsWith(permittedRole.substring(0, permittedRole.length() - 1))
    +                    && permittedActions.contains(checkedAction)) {
    +                return true;
    +            }
    +
    +            // Suffix match
    +            if (permittedRole.charAt(0) == '*'
    --- End diff --
    
    Thanks for your advice.
    I will state it explicitly in the document that I'm going to make after merging this PR :)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-pulsar pull request #530: Support wildcard in permitted role name

Posted by yush1ga <gi...@git.apache.org>.
Github user yush1ga commented on a diff in the pull request:

    https://github.com/apache/incubator-pulsar/pull/530#discussion_r124128153
  
    --- Diff: pulsar-broker/src/test/java/org/apache/pulsar/broker/auth/AuthorizationTest.java ---
    @@ -94,6 +96,46 @@ void simple() throws Exception {
             assertEquals(auth.canProduce(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my-role"), true);
             assertEquals(auth.canConsume(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my-role"), true);
     
    +        // test for wildcard
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my.role.1"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my.role.2"), false);
    +        assertEquals(auth.canProduce(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my.role.1"), false);
    +        assertEquals(auth.canConsume(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my.role.1"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "other.role.1"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "other.role.2"), false);
    +
    +        admin.namespaces().grantPermissionOnNamespace("p1/c1/ns1", "my.role.*", EnumSet.of(AuthAction.produce));
    +        waitForChange();
    +
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my.role.1"), true);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my.role.2"), true);
    +        assertEquals(auth.canProduce(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my.role.1"), true);
    +        assertEquals(auth.canConsume(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my.role.1"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "other.role.1"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "other.role.2"), false);
    +
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "1.role.my"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "2.role.my"), false);
    +        assertEquals(auth.canProduce(DestinationName.get("persistent://p1/c1/ns1/ds1"), "1.role.my"), false);
    +        assertEquals(auth.canConsume(DestinationName.get("persistent://p1/c1/ns1/ds1"), "1.role.my"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "2.role.other"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "2.role.other"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds2"), "1.role.my"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds2"), "2.role.my"), false);
    +
    +        admin.persistentTopics().grantPermission("persistent://p1/c1/ns1/ds1", "*.my",
    --- End diff --
    
    I separated tests for wildcard into 4 parts.
    - prefix match (my.role.*) for namespace
    - suffix match (*.role.my) for namespace
    - prefix match (my.*) for destination
    - suffix match (*.my) for destination


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-pulsar pull request #530: Support wildcard in permitted role name

Posted by merlimat <gi...@git.apache.org>.
Github user merlimat commented on a diff in the pull request:

    https://github.com/apache/incubator-pulsar/pull/530#discussion_r124104761
  
    --- Diff: pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/AuthorizationManager.java ---
    @@ -177,6 +190,29 @@ private boolean checkCluster(DestinationName destination) {
             return permissionFuture;
         }
     
    +    private Boolean checkWildcardPermission(String checkedRole, AuthAction checkedAction,
    --- End diff --
    
    return `boolean` instead of `Boolean`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-pulsar pull request #530: Support wildcard in permitted role name

Posted by merlimat <gi...@git.apache.org>.
Github user merlimat commented on a diff in the pull request:

    https://github.com/apache/incubator-pulsar/pull/530#discussion_r124104535
  
    --- Diff: conf/broker.conf ---
    @@ -140,6 +140,10 @@ authenticationProviders=
     # Enforce authorization
     authorizationEnabled=false
     
    +# Actions that can be authorized by using permitted role name which contains wildcard
    +# e.g. pulsar.service.*
    +# wildcardRoleNamePermittedActions=produce,consume
    --- End diff --
    
    I would prefer to keep a single flag here (enabled/disabled)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-pulsar pull request #530: Support wildcard in permitted role name

Posted by saandrews <gi...@git.apache.org>.
Github user saandrews commented on a diff in the pull request:

    https://github.com/apache/incubator-pulsar/pull/530#discussion_r124126013
  
    --- Diff: pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/AuthorizationManager.java ---
    @@ -177,6 +190,29 @@ private boolean checkCluster(DestinationName destination) {
             return permissionFuture;
         }
     
    +    private Boolean checkWildcardPermission(String checkedRole, AuthAction checkedAction,
    +            Map<String, Set<AuthAction>> permissionMap) {
    +        for (Map.Entry<String, Set<AuthAction>> permissionData : permissionMap.entrySet()) {
    +            String permittedRole = permissionData.getKey();
    +            Set<AuthAction> permittedActions = permissionData.getValue();
    +
    +            // Prefix match
    +            if (permittedRole.charAt(permittedRole.length() - 1) == '*'
    +                    && checkedRole.startsWith(permittedRole.substring(0, permittedRole.length() - 1))
    +                    && permittedActions.contains(checkedAction)) {
    +                return true;
    +            }
    +
    +            // Suffix match
    +            if (permittedRole.charAt(0) == '*'
    --- End diff --
    
    Do we really needs to support regex use case? Even though it's a nice feature, I think * at the beginning or end should address most use cases for auth. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-pulsar pull request #530: Support wildcard in permitted role name

Posted by yush1ga <gi...@git.apache.org>.
Github user yush1ga commented on a diff in the pull request:

    https://github.com/apache/incubator-pulsar/pull/530#discussion_r124128740
  
    --- Diff: pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/AuthorizationManager.java ---
    @@ -177,6 +190,29 @@ private boolean checkCluster(DestinationName destination) {
             return permissionFuture;
         }
     
    +    private Boolean checkWildcardPermission(String checkedRole, AuthAction checkedAction,
    +            Map<String, Set<AuthAction>> permissionMap) {
    +        for (Map.Entry<String, Set<AuthAction>> permissionData : permissionMap.entrySet()) {
    +            String permittedRole = permissionData.getKey();
    +            Set<AuthAction> permittedActions = permissionData.getValue();
    +
    +            // Prefix match
    +            if (permittedRole.charAt(permittedRole.length() - 1) == '*'
    +                    && checkedRole.startsWith(permittedRole.substring(0, permittedRole.length() - 1))
    +                    && permittedActions.contains(checkedAction)) {
    +                return true;
    +            }
    +
    +            // Suffix match
    +            if (permittedRole.charAt(0) == '*'
    --- End diff --
    
    Thanks for your advice.
    I will state it explicitly in the document that I'm going to make after merging this PR :)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-pulsar pull request #530: Support wildcard in permitted role name

Posted by yush1ga <gi...@git.apache.org>.
Github user yush1ga commented on a diff in the pull request:

    https://github.com/apache/incubator-pulsar/pull/530#discussion_r124128272
  
    --- Diff: conf/broker.conf ---
    @@ -140,6 +140,10 @@ authenticationProviders=
     # Enforce authorization
     authorizationEnabled=false
     
    +# Actions that can be authorized by using permitted role name which contains wildcard
    +# e.g. pulsar.service.*
    +# wildcardRoleNamePermittedActions=produce,consume
    --- End diff --
    
    I changed it into `boolean wildcardInPermittedRoleNameEnabled`.



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-pulsar pull request #530: Support wildcard in permitted role name

Posted by saandrews <gi...@git.apache.org>.
Github user saandrews commented on a diff in the pull request:

    https://github.com/apache/incubator-pulsar/pull/530#discussion_r124100809
  
    --- Diff: pulsar-broker/src/test/java/org/apache/pulsar/broker/auth/AuthorizationTest.java ---
    @@ -94,6 +96,46 @@ void simple() throws Exception {
             assertEquals(auth.canProduce(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my-role"), true);
             assertEquals(auth.canConsume(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my-role"), true);
     
    +        // test for wildcard
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my.role.1"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my.role.2"), false);
    +        assertEquals(auth.canProduce(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my.role.1"), false);
    +        assertEquals(auth.canConsume(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my.role.1"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "other.role.1"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "other.role.2"), false);
    +
    +        admin.namespaces().grantPermissionOnNamespace("p1/c1/ns1", "my.role.*", EnumSet.of(AuthAction.produce));
    --- End diff --
    
    Don't we have to cover the case with *.my for namespace as well?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-pulsar pull request #530: Support wildcard in permitted role name

Posted by merlimat <gi...@git.apache.org>.
Github user merlimat commented on a diff in the pull request:

    https://github.com/apache/incubator-pulsar/pull/530#discussion_r124366536
  
    --- Diff: conf/broker.conf ---
    @@ -140,6 +140,10 @@ authenticationProviders=
     # Enforce authorization
     authorizationEnabled=false
     
    +# Actions that can be authorized by using permitted role name which contains wildcard
    +# e.g. pulsar.service.*
    +wildcardInPermittedRoleNameEnabled=false
    --- End diff --
    
    Last comment on this :) 
    
    What about renaming it to something like `authorizationAllowWildcardsMatching` ?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-pulsar pull request #530: Support wildcard in permitted role name

Posted by yush1ga <gi...@git.apache.org>.
Github user yush1ga commented on a diff in the pull request:

    https://github.com/apache/incubator-pulsar/pull/530#discussion_r124128308
  
    --- Diff: pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/AuthorizationManager.java ---
    @@ -177,6 +190,29 @@ private boolean checkCluster(DestinationName destination) {
             return permissionFuture;
         }
     
    +    private Boolean checkWildcardPermission(String checkedRole, AuthAction checkedAction,
    --- End diff --
    
    I fixed it.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-pulsar pull request #530: Support wildcard in permitted role name

Posted by rdhabalia <gi...@git.apache.org>.
Github user rdhabalia commented on a diff in the pull request:

    https://github.com/apache/incubator-pulsar/pull/530#discussion_r124126966
  
    --- Diff: pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/AuthorizationManager.java ---
    @@ -177,6 +190,29 @@ private boolean checkCluster(DestinationName destination) {
             return permissionFuture;
         }
     
    +    private Boolean checkWildcardPermission(String checkedRole, AuthAction checkedAction,
    +            Map<String, Set<AuthAction>> permissionMap) {
    +        for (Map.Entry<String, Set<AuthAction>> permissionData : permissionMap.entrySet()) {
    +            String permittedRole = permissionData.getKey();
    +            Set<AuthAction> permittedActions = permissionData.getValue();
    +
    +            // Prefix match
    +            if (permittedRole.charAt(permittedRole.length() - 1) == '*'
    +                    && checkedRole.startsWith(permittedRole.substring(0, permittedRole.length() - 1))
    +                    && permittedActions.contains(checkedAction)) {
    +                return true;
    +            }
    +
    +            // Suffix match
    +            if (permittedRole.charAt(0) == '*'
    --- End diff --
    
    Ok. So, then should we document it that wild-card only works with prefix and suffix. because user may expect wild-card works in any position.



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-pulsar pull request #530: Support wildcard in permitted role name

Posted by merlimat <gi...@git.apache.org>.
Github user merlimat commented on a diff in the pull request:

    https://github.com/apache/incubator-pulsar/pull/530#discussion_r124366536
  
    --- Diff: conf/broker.conf ---
    @@ -140,6 +140,10 @@ authenticationProviders=
     # Enforce authorization
     authorizationEnabled=false
     
    +# Actions that can be authorized by using permitted role name which contains wildcard
    +# e.g. pulsar.service.*
    +wildcardInPermittedRoleNameEnabled=false
    --- End diff --
    
    Last comment on this :) 
    
    What about renaming it to something like `authorizationAllowWildcardsMatching` ?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-pulsar pull request #530: Support wildcard in permitted role name

Posted by yush1ga <gi...@git.apache.org>.
Github user yush1ga commented on a diff in the pull request:

    https://github.com/apache/incubator-pulsar/pull/530#discussion_r124128153
  
    --- Diff: pulsar-broker/src/test/java/org/apache/pulsar/broker/auth/AuthorizationTest.java ---
    @@ -94,6 +96,46 @@ void simple() throws Exception {
             assertEquals(auth.canProduce(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my-role"), true);
             assertEquals(auth.canConsume(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my-role"), true);
     
    +        // test for wildcard
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my.role.1"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my.role.2"), false);
    +        assertEquals(auth.canProduce(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my.role.1"), false);
    +        assertEquals(auth.canConsume(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my.role.1"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "other.role.1"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "other.role.2"), false);
    +
    +        admin.namespaces().grantPermissionOnNamespace("p1/c1/ns1", "my.role.*", EnumSet.of(AuthAction.produce));
    +        waitForChange();
    +
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my.role.1"), true);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my.role.2"), true);
    +        assertEquals(auth.canProduce(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my.role.1"), true);
    +        assertEquals(auth.canConsume(DestinationName.get("persistent://p1/c1/ns1/ds1"), "my.role.1"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "other.role.1"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "other.role.2"), false);
    +
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "1.role.my"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "2.role.my"), false);
    +        assertEquals(auth.canProduce(DestinationName.get("persistent://p1/c1/ns1/ds1"), "1.role.my"), false);
    +        assertEquals(auth.canConsume(DestinationName.get("persistent://p1/c1/ns1/ds1"), "1.role.my"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "2.role.other"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds1"), "2.role.other"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds2"), "1.role.my"), false);
    +        assertEquals(auth.canLookup(DestinationName.get("persistent://p1/c1/ns1/ds2"), "2.role.my"), false);
    +
    +        admin.persistentTopics().grantPermission("persistent://p1/c1/ns1/ds1", "*.my",
    --- End diff --
    
    I separated tests for wildcard into 4 parts.
    - prefix match (my.role.*) for namespace
    - suffix match (*.role.my) for namespace
    - prefix match (my.*) for destination
    - suffix match (*.my) for destination


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---