GeezerVison is showing github.com — MINOR: Improve validation in OAuthBearerValidatorCallbackHandler (#24… · coderbruis/kafka@bc4e0b9
File treeExpand file treeCollapse file tree Open diff view settings main/java/org/apache/kafka/common test/java/org/apache/kafka/common/security/oauthbearer
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: clients/src/main/java/org/apache/kafka/common/config/SaslConfigs.java +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -157,7 +157,7 @@ public class SaslConfigs { | 157 | 157 | + "<p>The built-in <code>JwtValidator</code> implementations are:</p>" | 158 | 158 | + "<ul>" | 159 | 159 | + "<li><code>org.apache.kafka.common.security.oauthbearer.BrokerJwtValidator</code></li>" | 160 | | - + "<li><code>org.apache.kafka.common.security.oauthbearer.ClientJwtValidator</code></li>" | | 160 | + + "<li><code>org.apache.kafka.common.security.oauthbearer.ClientJwtValidator</code> (clients only, it does not verify JWT signatures and cannot be used on brokers)</li>" | 161 | 161 | + "<li><code>org.apache.kafka.common.security.oauthbearer.DefaultJwtValidator</code></li>" | 162 | 162 | + "</ul>"; | 163 | 163 |
| |
Collapse file Copy file name to clipboardExpand all lines: clients/src/main/java/org/apache/kafka/common/security/oauthbearer/OAuthBearerValidatorCallbackHandler.java +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -127,6 +127,16 @@ public void configure(Map<String, ?> configs, String saslMechanism, List<AppConf | 127 | 127 | SaslConfigs.SASL_OAUTHBEARER_JWT_VALIDATOR_CLASS)); | 128 | 128 | } | 129 | 129 |
| | 130 | + if (validator instanceof ClientJwtValidator) { | | 131 | + Utils.closeQuietly(validator, "JWT validator"); | | 132 | + throw new ConfigException(String.format( | | 133 | + "The OAuth validator for the broker cannot use \"%s\" because it does not verify JWT signatures." + | | 134 | + " Set \"%s\" to a signature-verifying validator, such as \"%s\".", | | 135 | + ClientJwtValidator.class.getName(), | | 136 | + SaslConfigs.SASL_OAUTHBEARER_JWT_VALIDATOR_CLASS, | | 137 | + BrokerJwtValidator.class.getName())); | | 138 | + } | | 139 | + | 130 | 140 | jwtValidator = validator; | 131 | 141 | } | 132 | 142 |
| |
Collapse file Copy file name to clipboardExpand all lines: clients/src/test/java/org/apache/kafka/common/security/oauthbearer/OAuthBearerValidatorCallbackHandlerTest.java +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -256,6 +256,16 @@ public void testFailsToStartWhenExpectedIssuerMissingWithJwksUrl() { | 256 | 256 | SaslConfigs.SASL_OAUTHBEARER_EXPECTED_ISSUER); | 257 | 257 | } | 258 | 258 |
| | 259 | + @Test | | 260 | + public void testFailsToStartWithClientJwtValidator() { | | 261 | + Map<String, ?> configs = getSaslConfigs(SaslConfigs.SASL_OAUTHBEARER_JWT_VALIDATOR_CLASS, | | 262 | + ClientJwtValidator.class.getName()); | | 263 | + OAuthBearerValidatorCallbackHandler handler = new OAuthBearerValidatorCallbackHandler(); | | 264 | + assertThrowsWithMessage(ConfigException.class, | | 265 | + () -> handler.configure(configs, OAUTHBEARER_MECHANISM, getJaasConfigEntries()), | | 266 | + ClientJwtValidator.class.getName()); | | 267 | + } | | 268 | + | 259 | 269 | @Test | 260 | 270 | public void testConfigureAcceptsCustomValidatorClass() { | 261 | 271 | // A custom (non-default) validator class must be accepted; the startup check only applies | |
Collapse file Copy file name to clipboardExpand all lines: docs/getting-started/upgrade.md +1Lines changed: 1 addition & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -32,6 +32,7 @@ type: docs | 32 | 32 |
| 33 | 33 | ### Notable changes in 4.5.0 | 34 | 34 |
| | 35 | + * The broker-side OAUTHBEARER JWT validator now fails at startup when `sasl.oauthbearer.jwt.validator.class` is set to `org.apache.kafka.common.security.oauthbearer.ClientJwtValidator`, because that validator does not verify JWT signatures. Use `org.apache.kafka.common.security.oauthbearer.BrokerJwtValidator` or another signature-verifying validator on brokers instead. | 35 | 36 | * `ssl.principal.mapping.rules` now builds the principal name from the same full match that is used to check the rule. Previously, a rule that is not anchored with both `^` and `$`, or that uses alternation, could build the name from a shorter match or apply the replacement twice. For example, `RULE:CN=(.*?),OU=(.*?)/$1/` mapped `CN=bob,OU=eng` to `bobeng` instead of `bob`. Rules anchored with `^` and `$`, such as the documented examples, are not affected. If you use such rules, check that ACLs, quotas and `super.users` refer to the corrected principal names before upgrading. | 36 | 37 | * The `ConsumerRebalanceListener` interface and the `Consumer#subscribe` overloads that accept it are deprecated and will be removed in Kafka 5.0. Implement `RebalanceListener` instead, whose callbacks receive a `RebalanceConsumer` exposing the operations that are safe to call during a rebalance, and register it with `Consumer#setRebalanceListener` before subscribing. For further details, please refer to [KIP-1306](https://cwiki.apache.org/confluence/spaces/KAFKA/pages/406623733/KIP-1306+Extend+ConsumerRebalanceListener+with+Consumer-Aware+methods). | 37 | 38 |
| |
|