-
Notifications
You must be signed in to change notification settings - Fork 14.2k
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-18627:add allowed modules to JaasUtils #18683
base: trunk
Are you sure you want to change the base?
Changes from 3 commits
e2967a8
2b0c20d
d151ba5
9393507
7490422
63628e0
a57b15e
9608e0a
f0bdcd2
f68f3e9
272c638
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,13 +16,32 @@ | |
*/ | ||
package org.apache.kafka.common.security; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please revet this too. |
||
public final class JaasUtils { | ||
public static final String JAVA_LOGIN_CONFIG_PARAM = "java.security.auth.login.config"; | ||
@Deprecated | ||
public static final String DISALLOWED_LOGIN_MODULES_CONFIG = "org.apache.kafka.disallowed.login.modules"; | ||
public static final String DISALLOWED_LOGIN_MODULES_DEFAULT = | ||
"com.sun.security.auth.module.JndiLoginModule,com.sun.security.auth.module.LdapLoginModule"; | ||
public static final String ALLOWED_LOGIN_MODULES_CONFIG = "org.apache.kafka.allowed.login.modules"; | ||
public static final String ALLOWED_LOGIN_MODULES_DEFAULT = String.join(",", List.of( | ||
"org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule", | ||
"org.apache.kafka.common.security.plain.PlainLoginModule", | ||
"org.apache.kafka.connect.rest.basic.auth.extension.PropertyFileLoginModule", | ||
"org.apache.kafka.common.security.scram.ScramLoginModule", | ||
"com.sun.security.auth.module.Krb5LoginModule" | ||
)); | ||
public static final String SERVICE_NAME = "serviceName"; | ||
|
||
private JaasUtils() {} | ||
private JaasUtils() { | ||
} | ||
Comment on lines
-26
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please revert unrelated this change. |
||
|
||
public static void allowDefaultJaasAndCustomJass(String... customJaas) { | ||
List<String> jaasModules = new ArrayList<>(); | ||
jaasModules.add(ALLOWED_LOGIN_MODULES_DEFAULT); | ||
jaasModules.addAll(Arrays.asList(customJaas)); | ||
System.setProperty(org.apache.kafka.common.security.JaasUtils.ALLOWED_LOGIN_MODULES_CONFIG, String.join(",", jaasModules)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why to use full package name? |
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,9 @@ | |
import javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag; | ||
import javax.security.auth.login.Configuration; | ||
|
||
import static org.apache.kafka.common.security.JaasUtils.ALLOWED_LOGIN_MODULES_CONFIG; | ||
import static org.apache.kafka.common.security.JaasUtils.DISALLOWED_LOGIN_MODULES_CONFIG; | ||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
@@ -68,11 +70,13 @@ public void tearDown() throws Exception { | |
|
||
@Test | ||
public void testConfigNoOptions() throws Exception { | ||
System.setProperty(ALLOWED_LOGIN_MODULES_CONFIG, "test.testConfigNoOptions"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding this change means we break some compatibility ...
Additionally, we should open a jira for 5.0 to add WDYT? |
||
checkConfiguration("test.testConfigNoOptions", LoginModuleControlFlag.REQUIRED, new HashMap<>()); | ||
} | ||
|
||
@Test | ||
public void testControlFlag() throws Exception { | ||
System.setProperty(ALLOWED_LOGIN_MODULES_CONFIG, "test.testControlFlag"); | ||
LoginModuleControlFlag[] controlFlags = new LoginModuleControlFlag[] { | ||
LoginModuleControlFlag.REQUIRED, | ||
LoginModuleControlFlag.REQUISITE, | ||
|
@@ -88,13 +92,15 @@ public void testControlFlag() throws Exception { | |
|
||
@Test | ||
public void testSingleOption() throws Exception { | ||
System.setProperty(ALLOWED_LOGIN_MODULES_CONFIG, "test.testSingleOption"); | ||
Map<String, Object> options = new HashMap<>(); | ||
options.put("propName", "propValue"); | ||
checkConfiguration("test.testSingleOption", LoginModuleControlFlag.REQUISITE, options); | ||
} | ||
|
||
@Test | ||
public void testMultipleOptions() throws Exception { | ||
System.setProperty(ALLOWED_LOGIN_MODULES_CONFIG, "test.testMultipleOptions"); | ||
Map<String, Object> options = new HashMap<>(); | ||
for (int i = 0; i < 10; i++) | ||
options.put("propName" + i, "propValue" + i); | ||
|
@@ -103,6 +109,7 @@ public void testMultipleOptions() throws Exception { | |
|
||
@Test | ||
public void testQuotedOptionValue() throws Exception { | ||
System.setProperty(ALLOWED_LOGIN_MODULES_CONFIG, "test.testQuotedOptionValue"); | ||
Map<String, Object> options = new HashMap<>(); | ||
options.put("propName", "prop value"); | ||
options.put("propName2", "value1 = 1, value2 = 2"); | ||
|
@@ -112,6 +119,7 @@ public void testQuotedOptionValue() throws Exception { | |
|
||
@Test | ||
public void testQuotedOptionName() throws Exception { | ||
System.setProperty(ALLOWED_LOGIN_MODULES_CONFIG, "test.testQuotedOptionName"); | ||
Map<String, Object> options = new HashMap<>(); | ||
options.put("prop name", "propValue"); | ||
String config = "test.testQuotedOptionName required \"prop name\"=propValue;"; | ||
|
@@ -224,8 +232,8 @@ public void testDisallowedLoginModulesSystemProperty() throws Exception { | |
"SOME-MECHANISM", Collections.emptyMap())); | ||
|
||
|
||
//Remove default value for org.apache.kafka.disallowed.login.modules | ||
System.setProperty(DISALLOWED_LOGIN_MODULES_CONFIG, ""); | ||
// add allowed login modules | ||
System.setProperty(ALLOWED_LOGIN_MODULES_CONFIG, "com.sun.security.auth.module.JndiLoginModule, com.sun.security.auth.module.LdapLoginModule"); | ||
|
||
checkConfiguration("com.sun.security.auth.module.JndiLoginModule", LoginModuleControlFlag.REQUIRED, new HashMap<>()); | ||
checkConfiguration("com.sun.security.auth.module.LdapLoginModule", LoginModuleControlFlag.REQUIRED, new HashMap<>()); | ||
|
@@ -252,9 +260,34 @@ public void testDisallowedLoginModulesSystemProperty() throws Exception { | |
checkEntry(context.configurationEntries().get(0), "com.sun.security.auth.module.LdapLoginModule", | ||
LoginModuleControlFlag.REQUISITE, Collections.emptyMap()); | ||
} | ||
|
||
@Test | ||
void testAllowedLoginModulesSystemProperty() { | ||
|
||
// default | ||
String jaasConfigProp1 = "com.ibm.security.auth.module.LdapLoginModule required;"; | ||
assertThrows(IllegalArgumentException.class, () -> configurationEntry(JaasContext.Type.CLIENT, jaasConfigProp1)); | ||
|
||
String jaasConfigProp2 = "com.sun.security.auth.module.JndiLoginModule required;"; | ||
// set allow dont' set not allow | ||
System.setProperty(JaasUtils.ALLOWED_LOGIN_MODULES_CONFIG, "com.ibm.security.auth.module.LdapLoginModule"); | ||
assertDoesNotThrow(() -> configurationEntry(JaasContext.Type.CLIENT, jaasConfigProp1)); | ||
assertThrows(IllegalArgumentException.class, () -> configurationEntry(JaasContext.Type.CLIENT, jaasConfigProp2)); | ||
|
||
// set allow and set not allow | ||
System.setProperty(JaasUtils.DISALLOWED_LOGIN_MODULES_CONFIG, "com.ibm.security.auth.module.LdapLoginModule"); | ||
assertDoesNotThrow(() -> configurationEntry(JaasContext.Type.CLIENT, jaasConfigProp1)); | ||
assertThrows(IllegalArgumentException.class, () -> configurationEntry(JaasContext.Type.CLIENT, jaasConfigProp2)); | ||
|
||
// don't set allow and set not allow | ||
System.clearProperty(JaasUtils.ALLOWED_LOGIN_MODULES_CONFIG); | ||
assertThrows(IllegalArgumentException.class, () -> configurationEntry(JaasContext.Type.CLIENT, jaasConfigProp1)); | ||
assertDoesNotThrow(() -> configurationEntry(JaasContext.Type.CLIENT, jaasConfigProp2)); | ||
} | ||
|
||
@Test | ||
public void testNumericOptionWithQuotes() throws Exception { | ||
System.setProperty(ALLOWED_LOGIN_MODULES_CONFIG, "test.testNumericOptionWithQuotes"); | ||
Map<String, Object> options = new HashMap<>(); | ||
options.put("option1", "3"); | ||
String config = "test.testNumericOptionWithQuotes required option1=\"3\";"; | ||
|
@@ -263,6 +296,7 @@ public void testNumericOptionWithQuotes() throws Exception { | |
|
||
@Test | ||
public void testLoadForServerWithListenerNameOverride() throws IOException { | ||
System.setProperty(ALLOWED_LOGIN_MODULES_CONFIG, "test.LoginModuleDefault, test.LoginModuleOverride"); | ||
writeConfiguration(Arrays.asList( | ||
"KafkaServer { test.LoginModuleDefault required; };", | ||
"plaintext.KafkaServer { test.LoginModuleOverride requisite; };" | ||
|
@@ -278,6 +312,7 @@ public void testLoadForServerWithListenerNameOverride() throws IOException { | |
|
||
@Test | ||
public void testLoadForServerWithListenerNameAndFallback() throws IOException { | ||
System.setProperty(ALLOWED_LOGIN_MODULES_CONFIG, "test.LoginModule"); | ||
writeConfiguration(Arrays.asList( | ||
"KafkaServer { test.LoginModule required; };", | ||
"other.KafkaServer { test.LoginModuleOther requisite; };" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
import org.apache.kafka.common.network.ListenerName; | ||
import org.apache.kafka.common.network.NetworkTestUtils; | ||
import org.apache.kafka.common.network.NioEchoServer; | ||
import org.apache.kafka.common.security.JaasUtils; | ||
import org.apache.kafka.common.security.TestSecurityConfig; | ||
import org.apache.kafka.common.security.auth.SecurityProtocol; | ||
import org.apache.kafka.common.serialization.StringDeserializer; | ||
|
@@ -75,6 +76,7 @@ public void setup() throws Exception { | |
TestJaasConfig testJaasConfig = TestJaasConfig.createConfiguration("PLAIN", Collections.singletonList("PLAIN")); | ||
testJaasConfig.setClientOptions("PLAIN", TestJaasConfig.USERNAME, "anotherpassword"); | ||
server = createEchoServer(securityProtocol); | ||
JaasUtils.allowDefaultJaasAndCustomJass(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it does not add any other modules, so do we really need it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test case reports an error. It may be that a change to the default configuration caused the jaas tested to be rejected. |
||
} | ||
|
||
@AfterEach | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
import org.apache.kafka.common.network.NioEchoServer; | ||
import org.apache.kafka.common.network.Selector; | ||
import org.apache.kafka.common.security.JaasContext; | ||
import org.apache.kafka.common.security.JaasUtils; | ||
import org.apache.kafka.common.security.TestSecurityConfig; | ||
import org.apache.kafka.common.security.auth.SecurityProtocol; | ||
import org.apache.kafka.common.utils.LogContext; | ||
|
@@ -74,6 +75,7 @@ public void setup() throws Exception { | |
credentialCache = new CredentialCache(); | ||
SaslAuthenticatorTest.TestLogin.loginCount.set(0); | ||
startTimeMs = time.milliseconds(); | ||
JaasUtils.allowDefaultJaasAndCustomJass(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
} | ||
|
||
@AfterEach | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,6 @@ abstract class SaslEndToEndAuthorizationTest extends EndToEndAuthorizationTest { | |
producerConfig.put(SaslConfigs.SASL_JAAS_CONFIG, clientLoginContext) | ||
consumerConfig.put(SaslConfigs.SASL_JAAS_CONFIG, clientLoginContext) | ||
adminClientConfig.put(SaslConfigs.SASL_JAAS_CONFIG, clientLoginContext) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
val superuserLoginContext = jaasAdminLoginModule(kafkaClientSaslMechanism) | ||
superuserClientConfig.put(SaslConfigs.SASL_JAAS_CONFIG, superuserLoginContext) | ||
super.setUp(testInfo) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,7 +70,6 @@ class SaslSslAdminIntegrationTest extends BaseAdminIntegrationTest with SaslSetu | |
this.serverConfig.setProperty(DelegationTokenManagerConfigs.DELEGATION_TOKEN_SECRET_KEY_CONFIG, secretKey) | ||
this.serverConfig.setProperty(DelegationTokenManagerConfigs.DELEGATION_TOKEN_EXPIRY_TIME_MS_CONFIG, Long.MaxValue.toString) | ||
this.serverConfig.setProperty(DelegationTokenManagerConfigs.DELEGATION_TOKEN_MAX_LIFETIME_CONFIG, Long.MaxValue.toString) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please revert unrelated change |
||
setUpSasl() | ||
super.setUp(testInfo) | ||
setInitialAcls() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we need to consider a case if a module in disallow and allow at same time?
Maybe it will happen in the meantime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new logic is to prioritize "allow", right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make sense, thanks!