mTLS 인증
mTLS 인증 (Authentication using mTLS)
mTLS 인증 개요 (mTLS authentication overview)
상호 TLS(mTLS)는 상호 인증 메커니즘이에요. 서버만 클라이언트가 서버의 신원을 검증하는 데 사용하는 키와 인증서를 갖는 것이 아니라, 클라이언트도 서버가 클라이언트의 신원을 검증하는 데 사용하는 키와 인증서를 가져요. 이번에는 Pulsar에서 클라이언트와 서버 사이의 mTLS 인증을 구성하는 방법을 함께 살펴볼게요.
출처: 문서
본문
아래 그림은 Pulsar가 클라이언트와 서버 사이의 mTLS 인증을 처리하는 방식을 보여줘요.
브로커에서 mTLS 인증 활성화 (Enable mTLS authentication on brokers)
브로커가 mTLS로 클라이언트를 인증하도록 구성하려면 conf/broker.conf에 다음 파라미터를 추가해요. standalone Pulsar를 사용한다면 conf/standalone.conf 파일에 이 파라미터를 추가해야 해요.
# enable authentication
authenticationEnabled=true
# set mTLS authentication provider
authenticationProviders=org.apache.pulsar.broker.authentication.AuthenticationProviderTls
# configure TLS for client to connect brokers
brokerClientTlsEnabled=true
brokerClientTrustCertsFilePath=/path/to/ca.cert.pem
brokerClientAuthenticationPlugin=org.apache.pulsar.client.impl.auth.AuthenticationTls
brokerClientAuthenticationParameters={"tlsCertFile":"/path/to/broker_client.cert.pem","tlsKeyFile":"/path/to/broker_client.key-pk8.pem"}
# configure TLS ports
brokerServicePortTls=6651
webServicePortTls=8081
# configure CA certificate
tlsTrustCertsFilePath=/path/to/ca.cert.pem
# configure server certificate
tlsCertificateFilePath=/path/to/server.cert.pem
# configure server's private key
tlsKeyFilePath=/path/to/server.key-pk8.pem
# enable mTLS
tlsRequireTrustedClientCertOnConnect=true
tlsAllowInsecureConnection=false
# Tls cert refresh duration in seconds (set 0 to check on every new connection)
tlsCertRefreshCheckDurationSec=300
프록시에서 mTLS 인증 활성화 (Enable mTLS authentication on proxies)
프록시가 mTLS로 클라이언트를 인증하도록 구성하려면 conf/proxy.conf 파일에 다음 파라미터를 추가해요.
# enable authentication
authenticationEnabled=true
# set mTLS authentication provider
authenticationProviders=org.apache.pulsar.broker.authentication.AuthenticationProviderTls
# configure TLS for client to connect proxies
tlsEnabledWithBroker=true
brokerClientTrustCertsFilePath=/path/to/ca.cert.pem
brokerClientAuthenticationPlugin=org.apache.pulsar.client.impl.auth.AuthenticationTls
brokerClientAuthenticationParameters={"tlsCertFile":"/path/to/proxy.cert.pem","tlsKeyFile":"/path/to/proxy.key-pk8.pem"}
# configure TLS ports
brokerServicePortTls=6651
webServicePortTls=8081
# configure CA certificate
tlsTrustCertsFilePath=/path/to/ca.cert.pem
# configure server certificate
tlsCertificateFilePath=/path/to/server.cert.pem
# configure server's private key
tlsKeyFilePath=/path/to/server.key-pk8.pem
# enable mTLS
tlsRequireTrustedClientCertOnConnect=true
tlsAllowInsecureConnection=false
Pulsar 클라이언트에서 mTLS 인증 구성 (Configure mTLS authentication in Pulsar clients)
mTLS 인증을 사용할 때 클라이언트는 TLS 전송으로 연결돼요. 클라이언트가 웹 서비스 URL에는 https://와 8443 포트를, 브로커 서비스 URL에는 pulsar+ssl://와 6651 포트를 사용하도록 구성해야 해요.
- Java
- Python
- C++
- Node.js
- Go
- C#
Java:
import org.apache.pulsar.client.api.PulsarClient;
PulsarClient client = PulsarClient.builder()
.serviceUrl("pulsar+ssl://broker.example.com:6651/")
.tlsTrustCertsFilePath("/path/to/ca.cert.pem")
.authentication("org.apache.pulsar.client.impl.auth.AuthenticationTls",
"tlsCertFile:/path/to/client.cert.pem,tlsKeyFile:/path/to/client.key-pk8.pem")
.build();
Python:
from pulsar import Client, AuthenticationTLS
auth = AuthenticationTLS("/path/to/client.cert.pem", "/path/to/client.key-pk8.pem")
client = Client("pulsar+ssl://broker.example.com:6651/",
tls_trust_certs_file_path="/path/to/ca.cert.pem",
tls_allow_insecure_connection=False,
authentication=auth)
C++:
#include <pulsar/Client.h>
pulsar::ClientConfiguration config;
config.setUseTls(true);
config.setTlsTrustCertsFilePath("/path/to/ca.cert.pem");
config.setTlsAllowInsecureConnection(false);
pulsar::AuthenticationPtr auth = pulsar::AuthTls::create("/path/to/client.cert.pem",
"/path/to/client.key-pk8.pem")
config.setAuth(auth);
pulsar::Client client("pulsar+ssl://broker.example.com:6651/", config);
Node.js:
const Pulsar = require('pulsar-client');
(async () => {
const auth = new Pulsar.AuthenticationTls({
certificatePath: '/path/to/client.cert.pem',
privateKeyPath: '/path/to/client.key-pk8.pem',
});
const client = new Pulsar.Client({
serviceUrl: 'pulsar+ssl://broker.example.com:6651/',
authentication: auth,
tlsTrustCertsFilePath: '/path/to/ca.cert.pem',
});
})();
Go:
client, err := pulsar.NewClient(ClientOptions{
URL: "pulsar+ssl://broker.example.com:6651/",
TLSTrustCertsFilePath: "/path/to/ca.cert.pem",
Authentication: pulsar.NewAuthenticationTLS("/path/to/client.cert.pem", "/path/to/client.key-pk8.pem"),
})
C#:
var clientCertificate = new X509Certificate2("admin.pfx");
var client = PulsarClient.Builder()
.AuthenticateUsingClientCertificate(clientCertificate)
.Build();
CLI 도구에서 mTLS 인증 구성 (Configure mTLS authentication in CLI tools)
pulsar-admin, pulsar-perf, pulsar-client 같은 커맨드라인 도구는 Pulsar 설치의 conf/client.conf 구성 파일을 사용해요.
Pulsar의 CLI 도구와 mTLS 인증을 사용하려면 mTLS 암호화 활성화 구성과 함께 conf/client.conf 파일에 다음 파라미터를 추가해야 해요.
webServiceUrl=https://localhost:8081/
brokerServiceUrl=pulsar+ssl://localhost:6651/
authPlugin=org.apache.pulsar.client.impl.auth.AuthenticationTls
authParams=tlsCertFile:/path/to/admin.cert.pem,tlsKeyFile:/path/to/admin.key-pk8.pem
KeyStore로 mTLS 인증 구성 (Configure mTLS authentication with KeyStore)
Apache Pulsar는 클라이언트와 Apache Pulsar 서비스 사이의 TLS 암호화와 mTLS 인증을 지원해요. 기본적으로 PEM 형식 파일 구성을 사용해요.
KeyStore로 mTLS 인증을 구성하려면 다음 단계를 완료해요.
1단계: 브로커 구성 (Step 1: Configure brokers)
broker.conf 파일을 다음과 같이 구성해요.
# Configuration to enable authentication
authenticationEnabled=true
authenticationProviders=org.apache.pulsar.broker.authentication.AuthenticationProviderTls
# Enable KeyStore type
tlsEnabledWithKeyStore=true
# key store
tlsKeyStoreType=JKS
tlsKeyStore=/var/private/tls/broker.keystore.jks
tlsKeyStorePassword=brokerpw
# trust store
tlsTrustStoreType=JKS
tlsTrustStore=/var/private/tls/broker.truststore.jks
tlsTrustStorePassword=brokerpw
# internal client/admin-client config
brokerClientTlsEnabled=true
brokerClientTlsEnabledWithKeyStore=true
brokerClientTlsTrustStoreType=JKS
brokerClientTlsTrustStore=/var/private/tls/client.truststore.jks
brokerClientTlsTrustStorePassword=clientpw
# internal auth config
brokerClientAuthenticationPlugin=org.apache.pulsar.client.impl.auth.AuthenticationKeyStoreTls
brokerClientAuthenticationParameters={"keyStoreType":"JKS","keyStorePath":"/var/private/tls/client.keystore.jks","keyStorePassword":"clientpw"}
tlsRequireTrustedClientCertOnConnect=true
tlsAllowInsecureConnection=false
2단계: 클라이언트 구성 (Step 2: Configure clients)
TLS 암호화 구성 외에, 클라이언트 역할로 유효한 CN을 포함하는 KeyStore를 클라이언트에 구성해야 해요.
예를 들어:
pulsar-admin,pulsar-perf,pulsar-client같은 커맨드라인 도구의 경우 Pulsar 설치의conf/client.conf파일을 설정해요.
webServiceUrl=https://broker.example.com:8443/
brokerServiceUrl=pulsar+ssl://broker.example.com:6651/
useKeyStoreTls=true
tlsTrustStoreType=JKS
tlsTrustStorePath=/var/private/tls/client.truststore.jks
tlsTrustStorePassword=clientpw
authPlugin=org.apache.pulsar.client.impl.auth.AuthenticationKeyStoreTls
authParams={"keyStoreType":"JKS","keyStorePath":"/var/private/tls/client.keystore.jks","keyStorePassword":"clientpw"}
- Java 클라이언트의 경우
import org.apache.pulsar.client.api.PulsarClient;
PulsarClient client = PulsarClient.builder()
.serviceUrl("pulsar+ssl://broker.example.com:6651/")
.useKeyStoreTls(true)
.tlsTrustStorePath("/var/private/tls/client.truststore.jks")
.tlsTrustStorePassword("clientpw")
.allowTlsInsecureConnection(false)
.enableTlsHostnameVerification(false)
.authentication(
"org.apache.pulsar.client.impl.auth.AuthenticationKeyStoreTls",
"keyStoreType:JKS,keyStorePath:/var/private/tls/client.keystore.jks,keyStorePassword:clientpw")
.build();
- Java admin 클라이언트의 경우
PulsarAdmin amdin = PulsarAdmin.builder().serviceHttpUrl("https://broker.example.com:8443")
.useKeyStoreTls(true)
.tlsTrustStorePath("/var/private/tls/client.truststore.jks")
.tlsTrustStorePassword("clientpw")
.allowTlsInsecureConnection(false)
.enableTlsHostnameVerification(false)
.authentication(
"org.apache.pulsar.client.impl.auth.AuthenticationKeyStoreTls",
"keyStoreType:JKS,keyStorePath:/var/private/tls/client.keystore.jks,keyStorePassword:clientpw")
.build();
note
useKeyStoreTls를true로 설정할 때는tlsTrustStorePath를 구성해요.
더 알아보기 (Learn more)
- 전송 계층 암호화 구성은 TLS transport 문서를 참고해요.
- 인증의 기본 개념은 Security overview 문서를 봐요.
- CLI 도구 종류는 CLI tools 문서를 살펴봐요.