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-5764: Add toLowerCase support to sasl.kerberos.principal.to.local rule #3800

Closed
wants to merge 3 commits into from

Conversation

omkreddy
Copy link
Contributor

@omkreddy omkreddy commented Sep 6, 2017

  • Update the tests and docs

Committer Checklist (excluded from commit message)

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

@omkreddy
Copy link
Contributor Author

retest this please

@omkreddy
Copy link
Contributor Author

cc @hachikuji @ijuma pinging for review

@hachikuji
Copy link

@omkreddy Thanks for the patch. Looks like a good improvement, but I think we might need a short KIP since it changes a public API.

@omkreddy
Copy link
Contributor Author

https://cwiki.apache.org/confluence/display/KAFKA/KIP-203%3A+Add+toLowerCase+support+to+sasl.kerberos.principal.to.local+rule

@hachikuji @ijuma Can you take a look at this minor KIP-203? KIP vote thread is waiting for couple of more votes.

@omkreddy
Copy link
Contributor Author

retest this please

@hachikuji
Copy link

@omkreddy Voted. I'll see if I can get one more vote for you as well.

@omkreddy
Copy link
Contributor Author

omkreddy commented Dec 7, 2017

@hachikuji whenever you get a chance, Please review the PR

Copy link

@hachikuji hachikuji left a comment

Choose a reason for hiding this comment

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

Thanks for the patch. Left a few comments/questions.

@@ -33,7 +33,7 @@
/**
* A pattern for parsing a auth_to_local rule.
*/
private static final Pattern RULE_PARSER = Pattern.compile("((DEFAULT)|(RULE:\\[(\\d*):([^\\]]*)](\\(([^)]*)\\))?(s/([^/]*)/([^/]*)/(g)?)?))");
private static final Pattern RULE_PARSER = Pattern.compile("((DEFAULT)|(RULE:\\[(\\d*):([^\\]]*)](\\(([^)]*)\\))?(s/([^/]*)/([^/]*)/(g)?)?))/?(L)?");

Choose a reason for hiding this comment

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

Seems like "DEFAULT/L" is a valid input. Is that intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is not intentional, but i was not using "/L" in this case. Updated the regex to treat "DEFAULT/L" as invalid input.

RULE:[n:string](regexp)s/pattern/replacement/
RULE:[n:string](regexp)s/pattern/replacement/g
RULE:[n:string](regexp)s/pattern/replacement//L
RULE:[n:string](regexp)s/pattern/replacement/g/L</pre>

Choose a reason for hiding this comment

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

nit: move the end tag to the next line.

The format of <code>sasl.kerberos.principal.to.local.rules</code> is a list where each rule works in the same way as the auth_to_local in <a href="http://web.mit.edu/Kerberos/krb5-latest/doc/admin/conf_files/krb5_conf.html">Kerberos configuration file (krb5.conf)</a>. Each rules starts with RULE: and contains an expression in the format [n:string](regexp)s/pattern/replacement/g. See the kerberos documentation for more details. An example of adding a rule to properly translate user@MYDOMAIN.COM to user while also keeping the default rule in place is:
By default, the SASL user name will be the primary part of the Kerberos principal. One can change that by setting <code>sasl.kerberos.principal.to.local.rules</code> to a customized rule in broker.properties.
The format of <code>sasl.kerberos.principal.to.local.rules</code> is a list where each rule works in the same way as the auth_to_local in <a href="http://web.mit.edu/Kerberos/krb5-latest/doc/admin/conf_files/krb5_conf.html">Kerberos configuration file (krb5.conf)</a>. This also support additional lowercase rule, to force the translated result to be all lower case. This is done by adding a "/L" to the end of the rule. check below formats for syntax.
Each rules starts with RULE: and contains an expression as the following formats. See the kerberos documentation for more details.

Choose a reason for hiding this comment

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

Great to have some examples in our docs 👍 . Do you think it's worth explaining each case in a little more detail?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are few articles available on web explaining these rules. so I felt not to repeat in our docs.

@@ -182,6 +189,9 @@ String apply(String[] params) throws IOException {
if (result != null && NON_SIMPLE_PATTERN.matcher(result).find()) {
throw new NoMatchingRule("Non-simple name " + result + " after auth_to_local rule " + this);
}
if (toLowerCase && result != null) {
result = result.toLowerCase(Locale.ENGLISH);

Choose a reason for hiding this comment

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

Do you know the range of characters permitted in kerberos names?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure about the character range. I felt it is safe to set EN locale. Hadoop implementation is also using EN locale.

@rajinisivaram any thoughts here?

@omkreddy
Copy link
Contributor Author

retest this please

@omkreddy
Copy link
Contributor Author

@hachikuji pinging for review

Copy link

@hachikuji hachikuji left a comment

Choose a reason for hiding this comment

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

Thanks for the update. One comment on testing. The rest looks good.

@@ -55,4 +55,33 @@ public void testParse() throws IOException {
assertEquals("REALM.COM", name.realm());
assertEquals("user", shortNamer.shortName(name));
}

@Test
public void testToLowerCase() throws Exception {

Choose a reason for hiding this comment

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

Do we have any test cases which validate the behavior for invalid rules?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hachikuji Thanks for the review. Added a simple test case for invalid rules. Pls take a look.

Copy link

@hachikuji hachikuji left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for the KIP and the patch! Will merge assuming no issues with the builds.

@asfgit asfgit closed this in b088822 Dec 12, 2017
umaanbazhagan pushed a commit to umaanbazhagan/kafka that referenced this pull request Jun 20, 2018
…al rule (KIP-203)

Author: Manikumar Reddy <manikumar.reddy@gmail.com>

Reviewers: Jason Gustafson <jason@confluent.io>

Closes apache#3800 from omkreddy/KAFKA-5764-REGEX
@umaanbazhagan
Copy link

This is useful, can we backport this fix to Kafka 1.0? If yes, I have a PR for this: #5260

@omkreddy
Copy link
Contributor Author

@umaanbazhagan Currently Kafka 1.0.2 Release vote is going on. I am not sure if we can include this now. You can post your query on vote thread.

@omkreddy omkreddy deleted the KAFKA-5764-REGEX branch July 3, 2018 15:43
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