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

KAFKA-7010: Rename ResourceNameType to PatternType #5205

Merged
merged 7 commits into from
Jun 14, 2018

Conversation

big-andy-coates
Copy link
Contributor

@big-andy-coates big-andy-coates commented Jun 12, 2018

Fix for KAFKA-7010.

The initial PR for KIP-290 #5117 added a new ResourceNameType, which was initially a field on Resource and ResourceFilter. However, follow on PRs have now moved the name type fields to new ResourcePattern and ResourcePatternFilter classes. This means the old name is no longer valid and may be confusing. The PR looks to rename the class to a more intuitive resource.PatternType.

@cmccabe also requested that the current ANY value for this class be renamed to avoid confusion. PatternType.ANY currently causes ResourcePatternFilter to bring back all ACLs that would affect the supplied resource, i.e. it brings back literal, wildcard ACLs, and also does pattern matching to work out which prefix acls would affect the resource. This is very different from the behaviour of ResourceType.ANY, which just means the filter ignores the type of resources.

ANY is to be renamed to MATCH to disambiguate it from other ANY filter types. A new ANY will be added that works in the same way as others, i.e. it will cause the filter to ignore the pattern type, (but won't do any pattern matching).

cc @junrao

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

Copy link
Contributor

@junrao junrao left a comment

Choose a reason for hiding this comment

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

@big-andy-coates : Thanks for the patch. LGTM. Just a few minor comments below.

*/
ANY((byte) 1),

/**
* In a filter, matches any resource pattern type.
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, this has to be different from the comment for ANY?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Classic cut & paste error - how embarrassing. :)

@@ -345,11 +346,11 @@ object AclCommand extends Logging {
.describedAs("delegation-token")
.ofType(classOf[String])

val resourceNameType = parser.accepts("resource-name-type", "The type of the resource name, or any.")
val resourcePatternType = parser.accepts("resource-pattern-type", "The type of the resource pattern, or any.")
Copy link
Contributor

Choose a reason for hiding this comment

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

We want to add MATCH in the description and explain its meaning.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added more detail

<li><b>Prefixed</b> Match any resource whose name starts with the prefix.</li>
<li><b>All</b> (list|remove only) Matching any name type, including the Wildcard name.</li>
<li><b>Literal (default):</b> a pattern that only matches a resource if the name is an exact match, or, in the case of the Wildcard name '*', matches all resources.
All operations, (add, remove, list), will only affect or return acls on literal resource patterns with the exact supplied name.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Erm... yes...?

Happy to replace if you can word it better :D

All operations, (add, remove, list), will only affect or return acls on literal resource patterns with the exact supplied name.
</li>
<li><b>Prefixed:</b> a pattern that will match a resource whose name starts with the supplied name.
All operations, (add, remove, list), will only affect or return acls on prefixed resource patterns with the exact supplied name.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As above, yes.

</li>
<li><b>Prefixed:</b> a pattern that will match a resource whose name starts with the supplied name.
All operations, (add, remove, list), will only affect or return acls on prefixed resource patterns with the exact supplied name.
<li><b>All</b> (list|remove only)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this All or Any?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any - updated.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be MATCH, as per our earlier discussion?

* Version 1 adds RESOURCE_NAME_TYPE.
* Also, when the quota is violated, brokers will respond to a version 1 or later request before throttling.
* Version 1 adds RESOURCE_PATTERN_TYPE, to support more than just literal resource patterns.
* For more info, see {@link PatternType}.
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the JavaDoc work without the full class path?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unlike ScalaDoc, yes, as long as the type is imported, which it is.

*/
UNKNOWN((byte) 0),

/**
* In a filter, matches any resource name type.
* In a filter, matches any resource pattern type.
*/
ANY((byte) 1),
Copy link
Contributor

Choose a reason for hiding this comment

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

We should rename this to "MATCH" as per our earlier discussion, since its behavior doesn't match the other "ANY" fields

Copy link
Contributor Author

Choose a reason for hiding this comment

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

MATCH is the next one down.

@big-andy-coates
Copy link
Contributor Author

Hi @junrao, @cmccabe, I've pushed changes, as requested by @junrao, and also spent some time overhauling security.html to slightly introduce the user to the concept of resource patterns, and then refer them to KIP-290. I think this page now hangs together better.

Let me know what you think, or merge if you're happy.

@big-andy-coates
Copy link
Contributor Author

Test failure is unrelated DeleteConsumerGroupTest.testConsumptionOnRecreatedTopicAfterTopicWideDeleteInZK

Copy link
Contributor

@junrao junrao left a comment

Choose a reason for hiding this comment

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

@big-andy-coates : Thanks for the updated PR. LGTM. Just a few minor typos listed below.

@@ -345,11 +346,16 @@ object AclCommand extends Logging {
.describedAs("delegation-token")
.ofType(classOf[String])

val resourceNameType = parser.accepts("resource-name-type", "The type of the resource name, or any.")
val resourcePatternType = parser.accepts("resource-pattern-type", "The type of the resource pattern or pattern filter. " +
"When adding acls, this should a specific pattern type, e.g. 'literal' or 'prefixed'. " +
Copy link
Contributor

Choose a reason for hiding this comment

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

this should a =>this should be a

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

val resourceNameType = parser.accepts("resource-name-type", "The type of the resource name, or any.")
val resourcePatternType = parser.accepts("resource-pattern-type", "The type of the resource pattern or pattern filter. " +
"When adding acls, this should a specific pattern type, e.g. 'literal' or 'prefixed'. " +
"When listing or removing acls, a specific pattern type can be used to remove acls from specific resource patterns, " +
Copy link
Contributor

Choose a reason for hiding this comment

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

to remove => to list or remove ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@@ -1009,7 +1009,7 @@ <h3><a id="security_sasl" href="#security_sasl">7.3 Authentication using SASL</a
<h3><a id="security_authz" href="#security_authz">7.4 Authorization and ACLs</a></h3>
Kafka ships with a pluggable Authorizer and an out-of-box authorizer implementation that uses zookeeper to store all the acls. The Authorizer is configured by setting <code>authorizer.class.name</code> in server.properties. To enable the out of the box implementation use:
<pre>authorizer.class.name=kafka.security.auth.SimpleAclAuthorizer</pre>
Kafka acls are defined in the general format of "Principal P is [Allowed/Denied] Operation O From Host H On Resource R". You can read more about the acl structure on KIP-11. In order to add, remove or list acls you can use the Kafka authorizer CLI. By default, if a Resource R has no associated acls, no one other than super users is allowed to access R. If you want to change that behavior, you can include the following in server.properties.
Kafka acls are defined in the general format of "Principal P is [Allowed/Denied] Operation O From Host H On Any Resoure R matching ResourcePattern RP". You can read more about the acl structure in KIP-11 and resource patterns in KIP-290. In order to add, remove or list acls you can use the Kafka authorizer CLI. By default, if no ResourcePatterns match a specific Resource R, then R has no associated acls, and therefore no one other than super users is allowed to access R. If you want to change that behavior, you can include the following in server.properties.
Copy link
Contributor

Choose a reason for hiding this comment

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

Any => any ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@@ -1070,31 +1070,30 @@ <h4><a id="security_authz_cli" href="#security_authz_cli">Command Line Interface
</tr>
<tr>
<td>--cluster</td>
<td>Specifies cluster as resource.</td>
<td>Indicates to the script tha the user is trying to interact with acls on the singular cluster resource.</td>
Copy link
Contributor

Choose a reason for hiding this comment

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

tha => that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

</tr>
<tr>
<td>--topic [topic-name]</td>
<td>Specifies the topic as resource.</td>
<td>Indicates to the script tha the user is trying to interact with acls on topic resource pattern(s).</td>
Copy link
Contributor

Choose a reason for hiding this comment

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

tha => that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

You can add acls on any resource of a certain type, e.g. suppose you wanted to add an acl "Principal User:Peter is allowed to produce to any Topic from IP 198.51.200.0"
You can do that by using the wildcard resource '*', e.g. by executing the CLI with following options:
<pre class="brush: bash;">bin/kafka-acls.sh --authorizer-properties zookeeper.connect=localhost:2181 --add --allow-principal User:Peter --allow-host 198.51.200.1 --producer --topic *</pre>
You can add acls on resources matching a certain prefix, e.g. suppose you want to add an acl "Principal User:Jane is allowed to produce to any Topic whose name is prefixed with 'Test-' from any host".
You can add acls on prefixed resource patterns, e.g. suppose you want to add an acl "Principal User:Jane is allowed to produce to any Topic whose name is starts with 'Test-' from any host".
Copy link
Contributor

Choose a reason for hiding this comment

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

is starts => starts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

<pre class="brush: bash;">bin/kafka-acls.sh --authorizer-properties zookeeper.connect=localhost:2181 --list --topic *</pre>
However, it is not necessarily possible to explicitly query for acls on prefixed resource patterns that match Test-topic as the name of such patterns may not be known.
We can list <i>all</i> acls affecting Test-topic by using '--resource-pattern-type match', e.g.
<pre class="brush: bash;">bin/kafka-acls.sh --authorizer-properties zookeeper.connect=localhost:2181 --list --topic Test-topic --resource-pattern-type any</pre>
Copy link
Contributor

Choose a reason for hiding this comment

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

--resource-pattern-type any => --resource-pattern-type match

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@big-andy-coates
Copy link
Contributor Author

test this please

@junrao junrao merged commit 642a977 into apache:trunk Jun 14, 2018
junrao pushed a commit that referenced this pull request Jun 14, 2018
The initial PR for KIP-290 #5117 added a new `ResourceNameType`, which was initially a field on `Resource` and `ResourceFilter`. However, follow on PRs have now moved the name type fields to new `ResourcePattern` and `ResourcePatternFilter` classes. This means the old name is no longer valid and may be confusing. The PR looks to rename the class to a more intuitive `resource.PatternType`.

@cmccabe also requested that the current `ANY` value for this class be renamed to avoid confusion. `PatternType.ANY` currently causes `ResourcePatternFilter` to bring back all ACLs that would affect the supplied resource, i.e. it brings back literal, wildcard ACLs, and also does pattern matching to work out which prefix acls would affect the resource.  This is very different from the behaviour of `ResourceType.ANY`, which just means the filter ignores the type of resources.

 `ANY` is to be renamed to `MATCH` to disambiguate it from other `ANY` filter types. A new `ANY` will be added that works in the same way as others, i.e. it will cause the filter to ignore the pattern type, (but won't do any pattern matching).

Reviewers: Colin Patrick McCabe <colin@cmccabe.xyz>, Jun Rao <junrao@gmail.com>
@big-andy-coates big-andy-coates deleted the pattern_type branch June 14, 2018 21:09
ying-zheng pushed a commit to ying-zheng/kafka that referenced this pull request Jul 6, 2018
The initial PR for KIP-290 apache#5117 added a new `ResourceNameType`, which was initially a field on `Resource` and `ResourceFilter`. However, follow on PRs have now moved the name type fields to new `ResourcePattern` and `ResourcePatternFilter` classes. This means the old name is no longer valid and may be confusing. The PR looks to rename the class to a more intuitive `resource.PatternType`.

@cmccabe also requested that the current `ANY` value for this class be renamed to avoid confusion. `PatternType.ANY` currently causes `ResourcePatternFilter` to bring back all ACLs that would affect the supplied resource, i.e. it brings back literal, wildcard ACLs, and also does pattern matching to work out which prefix acls would affect the resource.  This is very different from the behaviour of `ResourceType.ANY`, which just means the filter ignores the type of resources. 

 `ANY` is to be renamed to `MATCH` to disambiguate it from other `ANY` filter types. A new `ANY` will be added that works in the same way as others, i.e. it will cause the filter to ignore the pattern type, (but won't do any pattern matching).

Reviewers: Colin Patrick McCabe <colin@cmccabe.xyz>, Jun Rao <junrao@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants