我想编写一个使用客户端票证缓存的 Java 应用程序,而不是使用 Keytab 文件。我发现的所有示例都使用定义了 Keytab 和主体 (useTicketCache=false) 的 JAAS 配置。
我尝试使用以下JAAS内容(kafka_client.jaas):
KafkaClient {
com.sun.security.auth.module.Krb5LoginModule required
useKeyTab=false
useTicketCache=true
serviceName=kafka;
};
在我的 Java 应用程序中,我使用以下命令设置此 JAAS:
System.setProperty("java.security.auth.login.config", "kafka_client.jaas");
Properties props = new Properties();
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "my-server.de:6667");
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
props.put("security.protocol", "SASL_PLAINTEXT");
props.put("sasl.kerberos.service.name", "kafka");
KafkaProducer<String, String> kafkaProducer = new KafkaProducer<String, String>(props);
kafkaProducer.send(new ProducerRecord<String, String>("test_topic", "key", "value")).get();
这不起作用并中止,但有以下例外:
javax.security.auth.login.LoginException: Could not login: the client is being asked for a password, but the Kafka client code does not currently support obtaining a password from the user. not available to garner authentication information from the user
at com.sun.security.auth.module.Krb5LoginModule.promptForPass(Unknown Source) ~[na:1.8.0_191]
at com.sun.security.auth.module.Krb5LoginModule.attemptAuthentication(Unknown Source) ~[na:1.8.0_191]
at com.sun.security.auth.module.Krb5LoginModule.login(Unknown Source) ~[na:1.8.0_191]
[...]
如上所述,我只找到了使用principal + keytab方式的例子,没有使用ticket cache。这种方式也适用于我,但这不是我需要/想要去的方式......
是否可以在我的 Kafka 客户端 Java 应用程序中使用票证缓存?还是 keytab 方式是唯一的可能?谢谢!
貌似是Kafka Client bug或者kafka开发者不知道什么是kerberos flood。 如果您将使用 keytab 参数,那么您的 KDC(Active Directory 或 Redhat FreeIPA)基础设施将受到冗余请求的攻击。
keytab JAAS 属性不适合 Linux 和 Windows,因为 JAAS 不支持凭证缓存直接支持并且不能存储 TGS 票证。这是 Java 的热门问题。
JGSS 可以帮助您获得所有 Kerberos 功能并将身份验证速度提高 5 倍: https://docs.oracle.com/en/java/javase/11/security/accessing-native-gss-api.html 它避免使用可疑的 oracle 模块来对抗 Sun 作为经过多年验证的 RFC 兼容模块。 不要忘记为唯一用户名 ccache 导出 KRB5CCNAME,为密钥表导出 KRB5_KTNAME。