HTTP Basic 인증

HTTP Basic 인증 (Authentication using HTTP basic)

기본 인증(Basic authentication)은 HTTP 프로토콜에 내장된 간단한 인증 체계로, base64로 인코딩된 사용자 이름·비밀번호 쌍을 자격 증명으로 사용해요. 이번에는 Pulsar 브로커/프록시에 HTTP basic 인증을 구성하는 방법을 함께 살펴볼게요.

출처: 문서

본문

사전 준비 (Prerequisites)

환경에 htpasswd를 설치해 사용자 이름-비밀번호 쌍을 저장하는 비밀번호 파일을 만들어요.

  • Ubuntu/Debian의 경우 다음 명령으로 htpasswd를 설치해요.
apt install apache2-utils
  • CentOS/RHEL의 경우 다음 명령으로 htpasswd를 설치해요.
yum install httpd-tools

인증 파일 만들기 (Create your authentication file)

note 현재 MD5(권장)와 CRYPT 암호화를 사용해 비밀번호를 인증할 수 있어요.

superuser/admin 사용자 계정으로 .htpasswd라는 비밀번호 파일을 만들려면 다음 방법을 사용할 수 있어요.

  • MD5 암호화 사용(권장):
htpasswd -cmb /path/to/.htpasswd superuser admin
  • CRYPT 암호화 사용:
htpasswd -cdb /path/to/.htpasswd superuser admin

다음 명령으로 비밀번호 파일의 내용을 미리 볼 수 있어요.

cat path/to/.htpasswd
superuser:$apr1$GBIYZYFZ$MzLcPrvoUky16mLcK6UtX/

브로커/프록시에서 기본 인증 활성화 (Enable basic authentication on brokers/proxies)

브로커/프록시가 basic으로 클라이언트를 인증하도록 구성하려면 conf/broker.confconf/proxy.conf 파일에 다음 파라미터를 추가해요. standalone Pulsar를 사용한다면 conf/standalone.conf 파일에 이 파라미터를 추가해야 해요.

# Configuration to enable Basic authentication
authenticationEnabled=true
authenticationProviders=org.apache.pulsar.broker.authentication.AuthenticationProviderBasic
basicAuthConf=file:///path/to/.htpasswd
# basicAuthConf=/path/to/.htpasswd
# When use the base64 format, you need to encode the .htpaswd content to bas64
# basicAuthConf=data:;base64,YOUR-BASE64
# basicAuthConf=YOUR-BASE64
# Authentication settings of the broker itself. Used when the broker connects to other brokers, or when the proxy connects to brokers, either in same or other clusters
brokerClientAuthenticationPlugin=org.apache.pulsar.client.impl.auth.AuthenticationBasic
brokerClientAuthenticationParameters={"userId":"superuser","password":"admin"}

note PULSAR_EXTRA_OPTS라는 환경 변수를 설정하고 값은 -Dpulsar.auth.basic.conf=/path/to/.htpasswd로 할 수도 있어요. Pulsar는 이 환경 변수를 읽어 HTTP basic 인증을 구현해요.

CLI 도구에서 기본 인증 구성 (Configure basic authentication in CLI tools)

커맨드라인 도구(예: Pulsar-admin, Pulsar-perf, Pulsar-client)는 Pulsar 설치의 conf/client.conf 파일을 사용해요. Pulsar CLI 도구에서 기본 인증을 구성하려면 conf/client.conf 파일에 다음 파라미터를 추가해야 해요.

authPlugin=org.apache.pulsar.client.impl.auth.AuthenticationBasic
authParams={"userId":"superuser","password":"admin"}

Pulsar 클라이언트에서 기본 인증 구성 (Configure basic authentication in Pulsar clients)

Pulsar 클라이언트에서 기본 인증을 구성하려면 아래 예제를 따라할 수 있어요.

AuthenticationBasic auth = new AuthenticationBasic();
auth.configure("{\"userId\":\"superuser\",\"password\":\"admin\"}");
PulsarClient client = PulsarClient.builder()
   .serviceUrl("pulsar://broker.example.com:6650")
   .authentication(auth)
   .build();
#include <pulsar/Client.h>
int main() {
    pulsar::ClientConfiguration config;
    AuthenticationPtr auth = pulsar::AuthBasic::create("admin", "123456")
    config.setAuth(auth);
    pulsar::Client client("pulsar://broker.example.com:6650/", config);
    return 0;
}
if __name__ == "__main__":
   client = Client("pulsar://broker.example.com:6650", authentication=AuthenticationBasic("admin", "123456"))
provider, err := pulsar.NewAuthenticationBasic("admin", "123456")
if err != nil {
	log.Fatal(err)
}
client, err := pulsar.NewClient(pulsar.ClientOptions{
	URL: "pulsar://broker.example.com:6650",
	Authentication: provider,
})

더 알아보기 (Learn more)

  • 인증의 기본 개념은 Security overview 문서에서 확인해요.
  • Pulsar 커맨드라인 도구 종류는 CLI tools 문서를 참고해요.
  • 다른 인증 방식과 함께 사용하려면 TLS transport 문서를 봐요.