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

Align configuration with Kafka Operator #36

Merged
merged 4 commits into from
Mar 27, 2020

Conversation

mstruk
Copy link
Contributor

@mstruk mstruk commented Mar 11, 2020

This PR introduces changes with regards to configuration:

  • oauth.tokens.not.jwt is now called oauth.access.token.is.jwt and has a reverse meaning
  • oauth.validation.skip.type.check is now called oauth.check.access.token.type and has a reverse meaning

Having a reverse meaning for both these configuration parameters means that the default value is true whereas before it was false, and when setting them explicitly you usually want to set them to false rather than true as it was the case before.

The old configuration parameter names still work with the old semantics, but have been marked @Deprecated and will be removed in future versions. A Warning is logged if the old parameter names are used.

mstruk added 2 commits March 10, 2020 17:48
…g change)

Previous attribute defaulted to `false`, the new one defaults to `true`.

Signed-off-by: Marko Strukelj <marko.strukelj@gmail.com>
…n.type` (Breaking change)

Previous attribute defaulted to `false`, the new one defaults to `true`.

Signed-off-by: Marko Strukelj <marko.strukelj@gmail.com>
@mstruk mstruk added this to the 0.4.0 milestone Mar 11, 2020
@tombentley
Copy link
Member

I know this is still 0.x stuff, but I don't think it's necessary to make breaking changes. I think it would be better to deprecate oauth.tokens.not.jwt (and log a warning if it's used), and error if oauth.tokens.not.jwt and oauth.tokens.is.jwt are both set. Ditto the other config. Why make life harder for your users? Let them fix their configs in their own time, and don't assume they're going to read the release notes. You can remove the deprecated configs when you hit 1.0, which is when users are more likely to actually read the release notes.

…log a warning if used.

Signed-off-by: Marko Strukelj <marko.strukelj@gmail.com>
@mstruk
Copy link
Contributor Author

mstruk commented Mar 13, 2020

@tombentley I made the change as you suggested. Old config options are still in place, working as they used to, but marked as deprecated, and a warning is logged if they are used.

…o util class

Signed-off-by: Marko Strukelj <marko.strukelj@gmail.com>
throw new RuntimeException("Custom username claim (OAUTH_USERNAME_CLAIM) not available, when tokens are configured as opaque (OAUTH_TOKENS_NOT_JWT)");
isJwt = isAccessTokenJwt(config, log, null);
if (!isJwt && usernameClaim != null) {
throw new RuntimeException("Custom username claim (OAUTH_USERNAME_CLAIM) not available, when tokens are configured as opaque (OAUTH_ACCESS_TOKEN_IS_JWT=false)");
Copy link
Member

Choose a reason for hiding this comment

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

Should we have a more specific exception type for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't handle this exception anywhere. Any exception thrown here is caught by Kafka Broker and results in broker shutting down.

I don't think there is some Kafka runtime exception that should be used here? If that were the case we should replace with it all occurrences of RuntimeException inside configure() method.

Copy link
Member

Choose a reason for hiding this comment

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

I'm just thinking that if your Kafka broker shuts down in these circumstances it's slightly nicer to see OauthConfigurationException in the logs than RuntimeException.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's very subjective. I personally don't see that as added value. But since it would require changing all RuntimeException throw statements in configure(), if we really want that, I prefer we make a new PR just for that and keep this one focused on configuration alignment. Maybe create a JIRA for the other one if you think we really should introduce a new exception.

if (legacy != null) {
log.warn("OAUTH_TOKENS_NOT_JWT is deprecated. Use OAUTH_ACCESS_TOKEN_IS_JWT (with reverse meaning) instead.");
if (config.getValue(Config.OAUTH_ACCESS_TOKEN_IS_JWT) != null) {
throw new RuntimeException((errorPrefix != null ? errorPrefix : "") + "Can't use both OAUTH_ACCESS_TOKEN_IS_JWT and OAUTH_TOKENS_NOT_JWT");
Copy link
Member

Choose a reason for hiding this comment

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

More specific exception type, maybe? Wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same answer as above.

@tombentley tombentley requested a review from ppatierno March 16, 2020 12:01
@scholzj scholzj self-requested a review March 16, 2020 13:47
Copy link
Member

@scholzj scholzj left a comment

Choose a reason for hiding this comment

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

Nice PR. I left some comments, but mostly LGTM. Do we need some CHANGELOG.md or RELEASE_NOTES.md to add the deprecations there so that we remember to mention them in the release?

if (legacy != null) {
System.out.println("[WARN] OAUTH_TOKENS_NOT_JWT is deprecated. Use OAUTH_ACCESS_TOKEN_IS_JWT (with reverse meaning) instead.");
}
return legacy != null ? !Config.isTrue(legacy) :
Copy link
Member

Choose a reason for hiding this comment

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

Is it really correct that the legacy option is prefered over the new one? Shouldn't it be the other way around? Or does it have some other reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just the ExampleConsumer CLI client - not something anyone will use for more than learning, how to use it on the client. Validation performed by it is more for the user experience than for validation.
Actual validation happens later in the workflow. If both old and new options are present, then the exception is thrown, because it's treated as a misconfiguration.
It happens in OAuth client library that actually handles this config under the hood and throws an exception.

So, if both options are present then the exception will be thrown, just a little later in the code flow.

if (legacy != null) {
System.out.println("[WARN] OAUTH_TOKENS_NOT_JWT is deprecated. Use OAUTH_ACCESS_TOKEN_IS_JWT (with reverse meaning) instead.");
}
return legacy != null ? !Config.isTrue(legacy) :
Copy link
Member

Choose a reason for hiding this comment

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

Same as above. Is it really correct that the legacy option is prefered over the new one? Shouldn't it be the other way around? Or does it have some other reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same answer.

}
}

return legacy != null ? !Config.isTrue(legacy) :
Copy link
Member

Choose a reason for hiding this comment

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

Same as above ... Is it really correct that the legacy option is prefered over the new one? Shouldn't it be the other way around? Or does it have some other reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code won't be reached if both are present. See previous lines

throw new RuntimeException("OAuth validator configuration error: can't use both OAUTH_CHECK_ACCESS_TOKEN_TYPE and OAUTH_VALIDATION_SKIP_TYPE_CHECK");
}
}
return legacy != null ? !Config.isTrue(legacy) :
Copy link
Member

Choose a reason for hiding this comment

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

Same as above ... Is it really correct that the legacy option is prefered over the new one? Shouldn't it be the other way around? Or does it have some other reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same answer - this code won't be reached if both are present.

Copy link
Member

@ppatierno ppatierno left a comment

Choose a reason for hiding this comment

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

LGTM. I left just a question.

@@ -128,7 +131,7 @@ public boolean getValueAsBoolean(String key, boolean fallback) {
}
}

private boolean isTrue(String result) {
public static boolean isTrue(String result) {
Copy link
Member

Choose a reason for hiding this comment

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

of course this was already here but why we are supporting all these possible values and not just "true/false"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only reason would be usability / user experience. Some people may in some situation prefer 'y' over 'true', or '0' over 'false'. It will be a string in input in any case, and needs to be converted to boolean somehow. This code here makes it both versatile, and specific - as we can always point to the algorithm with a url.

@ppatierno Do you see some negatives of this choice?

Copy link
Member

Choose a reason for hiding this comment

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

in general, I don't like to give too much freedom to users :-)
Anyway I can live with it.

Copy link
Contributor Author

@mstruk mstruk left a comment

Choose a reason for hiding this comment

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

Nice PR. I left some comments, but mostly LGTM. Do we need some CHANGELOG.md or RELEASE_NOTES.md to add the deprecations there so that we remember to mention them in the release?

It would be nice to mention these deprecations yes. Funny we don't have CHANGELOG.md yet or RELEASE_NOTES.md. We had no place to put the mention of the new features until now :)

We also have to be careful in strimzi-kafka-operator to not pull in the next release without an accompanying strimzi-kafka-operator PR that rewires to these new properties, so that users won't see deprecation messages in the log. I have the code ready, just didn't open the PR yet.

@scholzj
Copy link
Member

scholzj commented Mar 24, 2020

It would be nice to mention these deprecations yes. Funny we don't have CHANGELOG.md yet or RELEASE_NOTES.md. We had no place to put the mention of the new features until now :)

Yeah, so I think the point of my comment was should add it here in this PR? Or should we merge it without it. :-)

We also have to be careful in strimzi-kafka-operator to not pull in the next release without an accompanying strimzi-kafka-operator PR that rewires to these new properties, so that users won't see deprecation messages in the log. I have the code ready, just didn't open the PR yet.

I think we can do the release soon if you want - up to you.

@mstruk
Copy link
Contributor Author

mstruk commented Mar 24, 2020

Ok, I can add CHANGELOG.md, and put in it the changes for the previous releases as well.

I'm not in a hurry with the release I think - 0.17.0 train has left for this one so I don't see any hurry.

@mstruk
Copy link
Contributor Author

mstruk commented Mar 27, 2020

Instead of CHANGELOG.md I added RELEASE_NOTES.md as part of a different PR (#34, #44)

@scholzj scholzj merged commit d350a31 into strimzi:master Mar 27, 2020
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.

4 participants