[英]CertificateChain is null when importing pkcs12 (.p12) client-certificate file in Java Keystore
[英]Kafka Configure PKCS12 `ssl.keystore.location=user.p12` without access to local file system
我可以成功連接到具有以下客戶端屬性的 SSL 安全 Kafka 集群:
security.protocol=SSL
ssl.truststore.type=PKCS12
ssl.truststore.location=ca.p12
ssl.truststore.password=<redacted>
ssl.keystore.type=PKCS12
ssl.keystore.location=user.p12
ssl.keystore.password=<redacted>
但是,我正在編寫一個在托管雲環境中運行的 Java 應用程序,我無法訪問文件系統。 所以我不能只給它一個本地文件路徑到.p12 文件。
是否還有其他替代方法,例如使用從 S3、memory 或 JVM 類路徑資源加載?
具體來說,這是一個運行在 Amazon 的 Kinesis Analytics Managed Flink 集群服務上的 Flink 應用程序。
當然,在將屬性 object 提供給 KafkaConsumer 之前,您可以從任何地方下載任何您想要的東西。 但是,運行 Java 進程的用戶需要訪問本地文件系統才能下載文件。
我認為將文件打包為應用程序 JAR 的一部分更有意義,但是,我不知道一種簡單的方法來引用類路徑資源,就好像它是常規文件系統路徑一樣。 如果代碼在 YARN 集群中運行,您也可以在提交時嘗試使用yarn.provided.lib.dirs
選項
我暫時使用了一種解決方法,將您的證書上傳到文件共享並讓您的應用程序在初始化期間從文件共享下載證書並將其保存到選擇的位置,例如 /home/site/ca.p12 然后 kakfa 屬性應該讀取。 .. ssl.truststore.location=/home/site/ca.p12...
這里有幾行代碼可以幫助您下載和保存您的證書。
// Create the Azure Files client.
CloudFileClient fileClient = storageAccount.createCloudFileClient();
// Get a reference to the file share
CloudFileShare share = fileClient.getShareReference("[SHARENAME]");
// Get a reference to the root directory for the share.
CloudFileDirectory rootDir = share.getRootDirectoryReference();
// Get a reference to the directory where the file to be deleted is in
CloudFileDirectory containerDir = rootDir.getDirectoryReference("[DIRECTORY]");
CloudFile file = containerDir.getFileReference("[FILENAME]");
file.downloadToFile("/home/site/ca.p12");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.