...
- Principal “user2” has access to all topics that start with “com.company.product1.”.
- Principal “user1” has access to all consumer groups that start with “com.company.client1.”.
This support Support for adding ACLs to such 'prefixed resource patterns' will greatly simplify ACL operational story in a multi-tenant environment.
Public Interfaces
Summary of changes
- Add new field 'ResourceNameType' to Resource, and ResourceFilter classes to distinguish between literal and prefixed resource names.
- ResourceNameType is an enum to support more types in the future.
- ResourceNameType will include an 'ANY' type for use in filters
- ResourceNameType will default to literal, to maintain backwards compatibility with existing clients.
- Create new
ResourcePattern
class ino.a.k.common.resource
. This will be used to represent the resource pattern that ACLs can be attached to. This will be used within the AdminClient implementation and server side code for create requests and in list and remove responses. This will replace the use of the current Resource class. - Create new
ResourcePatternFilter
class ino.a.k.common.resource
. This will be used within the AdminClient implementation and server side code for list and remove requests. This will replace the use of the current ResourceFilter. - Create new
PatternType
enumeration ino.a.k.common.resource
. This be used inResourcePattern
andResourcePatternFilter
to define the type of pattern they represent. With values of:- LITERAL: meaning the pattern's name is treated literally. The pattern will only match a resource with the same name. The exception to this is a pattern with the wildcard '*' name, which for backwards compatibility reasons must also be of type literal, and which matches a resource of any name.
- PREFIXED: meaning the pattern's name is treated as a prefix. The pattern will match any resource with a name that starts with the patterns name.
- ANY: (For use in filters only) meaning the filter will ignore the pattern's type.
- MATCH: (For use in filters only) meaning the filter will match any pattern that would match the filters name, e.g. given a filter with name 'payments.received', it would match a literal pattern with the exact same name or the wildcard name and would match a prefixed pattern with a name such as 'payments.'. This value cane be used to select all resource patterns that match a specific resource.
- Update the SimpleAclAuthorizer to support prefixed resource patterns
- The
kafka.auth.Resource
class will have a newPatternType
field added, but the class will rejectPatternType.ANY
orPatternType.MATCH
.
- The contract of existing CRUD operations on the SimpleAclAuthorizer will remain the same: they will only return ACLs for the resources that exact matches the ones passed in.
- The CRUD operations will accept literal and prefixed resources.The authorize(...) method, which currently calls getAcls(resource) and getAcls('*') to get all the matching ACLs today, will instead now look for all matching literal and prefixed ACLs.
- To avoid resource pattern name clashes in ZK, non-literal ACLs will be stored under a new ZK path: '/kafka-acl-extended/<pattern-type>' and change events to such ACLs will be stored under: '/kafka-acl-extended-changes'.
- ACL change events stored under the new '/kafka-acl-extended-changes' path in ZK will have a JSON value value.
- ACL change events stored under the existing '/kafka-acl-changes' path in ZK will continue to use a colon separated value.
- The
- Change the command line tool class AclCommand.scala, (the code behind the
kafka-acls.sh
script).Changes to command line tool class https://github.com/apache/kafka/blob/trunk/core/src/main/scala/kafka/admin/AclCommand.scala- Expose a '--resource-namepattern-type' flagswitch, which can be set to literal, prefixed, any or anymatch, e.g.
bin/kafka-acls.sh --authorizer-properties zookeeper.connect=localhost:2181 --add --allow-principal User:Bob --operation Read --group my-app-
*--resource-
namepattern-type prefixed
- The flag pattern-type will default to 'literal', meaning the commands will return only the ACLs they previously returned, even if prefixed ACLs exists for the resource.
- Users can now set the flag to 'allmatch' to retrieve/delete all ACLs affecting the supplied ACLs resource(s).
- Expose a '--resource-namepattern-type' flagswitch, which can be set to literal, prefixed, any or anymatch, e.g.
- Changes to the admin client to support prefixed ACLs.
- New schema version for
CreateAclsRequest
/ DeleteAclsRequest / DescribeAclsRequest,DescribeAclsRequest
,DeleteAclsRequest
, and associated responses, which will have a new byte field in schemas to distinguish literals vs prefixed resource namescontaining the pattern type. - The
CreateAclRequest
will will only accept prefixed or literal ResourceNameTypespatterns. - The DeleteAclRequest and DescribeAclRequests will also accept a ResourceNameType of 'all', which will delete/describe all ACLs affecting the resource, including the literal wildcard ACL '*', if present
The
DeleteAclRequest and DescribeAclRequests will accept prefixed or literal, and will return delete/describe only ACLs exactly matching the resources. i.e. no pattern matching will be performedDescribeAclsRequest and DeleteAcl
Request
will accept allPattternType
s. The use ofLITERAL
andPREFIXED
will mean only ACLs on those exact resource patterns will be affected. The use ofANY
will be synonymous with issuing separate commands for bothLITERAL
andPREFIXED
. The use ofMATCH
will mean the command performs pattern matching, returning / removing all ACLs that affect the supplied resource, including any wildcard patterns.
- New schema version for
AdminClient changes
The examples below should help demonstrate the purposed functionality:
...
Each call retrieves ACLs stored in one path in ZK:adminClient.describeAcls(... TOPIC, "foobar" ...)
-> would return only ACLs from '/kafka-aclsacl/Topic/foobar' pathadminClient.describeAcls(... TOPIC, "*" ...)
-> would return only ACLs from '/kafka-aclsacl/Topic/*' path
New functionality
...
Legacy constructors default resourceNameType to Literal and maintains existing contract:adminClient.describeAcls(... TOPIC, "foobar" ...)
-> still returns only ACLs from '/kafka-aclsacl/Topic/foobar' pathadminClient.describeAcls(... TOPIC, "*" ...)
-> still returns only ACLs from '/kafka-aclsacl/Topic/*' path
Using constructors with explicit resourceNameType
The user needs to know, up front, which prefixed resource paths exist to be able to query them:adminClient.describeAcls(... TOPIC, "foobar", Literal LITERAL ...)
-> will return only ACLs from '/kafka-aclsacl/Topic/foobar' pathadminClient.describeAcls(... TOPIC, "*", Literal LITERAL ...)
-> will return only ACLs from '/kafka-aclsacl/Topic/*' pathadminClient.describeAcls(... TOPIC, "foo", Prefixed PREFIXED ...)
-> will return only ACLs from '/kafka-acl-extended/prefixed-acls/Topic/foo' path
Using 'ANY' resource name type
adminClient.describeAcls(... TOPIC, "foo", ANY ...)
-> will return ACLs from both '/kafka-acl/Topic/foobar' and '/kafka-acl-extended/prefixed/Topic/foo' path
Using '
...
MATCH' resource name type
This allows will perform pattern matching to allow user to discover all the ACLs affecting a specific resource:adminClient.describeAcls(... TOPIC, "foobar", Any MATCH ...)
-> will return all ACLs affecting topic "foobar", including any prefixed and wildcard ACLs.
The return value from describeAcls
will contain the resourceNameType field pattern type for each ACL, so the user can determine if it is literal or prefixed.
...
Solution
The proposal is to enhance the SimpleAclAuthorizer
, AdminClient
and AclCommand
classes to support prefixed ACLs.
This means that it will be possible to create ACLs of type: User:clientA has READ access on any topic prefixed whose name starts with the prefix 'orgA' from 'hostA', i.e clientA has READ access to all topics that start with `orgA` from hostA.
Currently ACLs are stored against a Resource
in ZK, i.e. a resource-type and name. This is insufficient to represent prefixes.The solution will introduce the concept of prefixed a ResourcePattern
and ACLs in ZK will be applicable only to resource namesstored against such patterns.
Storage model
Currently, ACLs are stored on ZK under path /kafka-acl/<resource-type>/<resource-name>.
For example:
ACLs for topic topicName topic 'topicName' will be stored under '/kafka-acl/Topic/topicName'.
ACLs for consumer group groupId group 'group:Id' will be stored under '/kafka-acl/Group/groupId.
An example ACL definition looks like:
$ get group:Id'.
ACLs for the wildcard topic '*' will be stored under '/kafka-acl/Topic/topicName
{"version":1,"acls":[{"principal":"User:clientA","permissionType":"Allow","operation":"Read","host":"*"},{"principal":"User:clientA","permissionType":"Allow","operation":"Write","host":"*"},{"principal":"clientB","permissionType":"Allow","operation":"Write","host":"host1"}]}
Current supported resource names are either full resource names like topicName or a special wildcard '*'.
$ get /kafka-acl/Topic/*
{"version":1,"acls":[{"principal":"User:clientA","permissionType":"Allow","operation":"Read","host":"*"}]}
which means that clientA has read access to all topics from all hosts.
The challenge here is that there can be both literal and prefixed resource paths with the same name. Some resources like consumer groups don't have any defined naming convention, so can include any characters in their name. It is therefore not possible to prepend/append a 'special character' to prefixed names to distinguish them from literal ones.
*'.
As some resource types, e.g. consumer groups, have freeform topic names it is not possible to store prefixed resource patterns under the same ZK root, as there is no viable encoding of the pattern type into the path that does not have the potential of name clashes with existing or future literal patterns. e.g. consider encoding prefixed patterns using paths such as '/kafka-acl/Group/prefixed/my-group' or '/kafka-acl/Group/prefixed:my-group' - both can clash with potential existing paths: the first would match a group named 'prefixed/my-group' and the second one named 'prefixed:my-group', both of which are valid group names.
To work around the free-form nature of some resource types, ACLs for the new prefixed resource patterns will be stored under a second root in ZK: '/kafka-acl-extended/prefixed'. Changes will first be stored under '/kafka-acl-extended-changes'. We will also take the opportunity to store change events as JSON under the new path, allowing for easier enhancements in the future.
We extend the same storage model to store prefixed ACLs in a different location 'kafka-prefixed-acl'. Changes will first be stored at 'kafka-prefixed-acl-changes'. Literal resources, including the wildcard resource '*', will continue to be stored in their original location.
Access will be allowed if there is at least one ALLOW matching acl and no DENY matching ACL (current behaviour is maintained). Note that the length of the prefix doesn't play any role here.
Extended ACL storage
$ get /kafka-prefixedextended-acl/prefixed/Topic/teamAorgName
{"version":1,"acls":[{"principal":"User:clientA","permissionType":"Allow","operation":"Read","host":"*"}]}
ACLs write path
Write to a new location 'kafka-prefixed-acl'.
Extended ACL change event storage
$ get /kafka-acl-prefixedextended-acl/Topic/orgNamechanges/acl_changes_0000
{"version":1, "aclsresourceType":[{"principal":"User:clientA"Topic", "permissionTypename":"AlloworgName", "operationpatternType":"Read","host":"*"}]}
ACLs read path
On read path, we look for all matching ACLs when authorize() is called.
Access will be allowed if there is at least one ALLOW matching acl and no DENY matching ACL (current behaviour is maintained). Note that the length of the prefix doesn't play any role here.PREFIXED"}
Compatibility, Deprecation, and Migration Plan
...