--- title: "NKS 연동" slug: "hsm-nks-vpc" updated: 2026-10-22T09:08:02Z published: 2026-10-22T09:08:02Z canonical: "guide-gov.ncloud-docs.com/hsm-nks-vpc" --- > ## Documentation Index > Fetch the complete documentation index at: https://guide-gov.ncloud-docs.com/llms.txt > Use this file to discover all available pages before exploring further. # NKS 연동 VPC 환경에서 이용 가능합니다. Ncloud Kubernetes Service(NKS)의 Pod에서 HSM에 연결하는 방법을 설명합니다. 참고 NKS 연동은 Thales 공식 문서를 기반으로 작성했습니다. 사용 가이드에서 안내하는 내용 외에 더 많은 내용을 확인하려면 [Docker Container - Integration Guide](https://cpl.thalesgroup.com/resources/encryption/docker-container-integration-guide)를 참조해 주십시오. ## 지원 환경 HSM과 NKS를 연동하기 위한 환경은 다음과 같습니다. ### 전제 조건 NKS 연동을 시작하기 전, 다음의 전제 조건을 준수해 주십시오. - [HSM 파티션의 초기설정](/docs/hsm-client-vpc#HSM%EC%B4%88%EA%B8%B0%EC%84%A4%EC%A0%95) 모두 완료 - [NKS 구성](/docs/k8s-k8sstart) 모두 완료 ## Node HSM 연결 설정 [InitScript 설정](/docs/k8s-k8suse-init-script)을 참조하여 Node에 HSM 연결을 설정합니다. 설정하는 방법은 다음과 같습니다. 1. lunaclient, HSM 연결 설정 스크립트를 실행해 주십시오. - `install_lunaclient_certs.sh` 작성 ``` #!/bin/bash sudo apt update sudo apt install -y alien set -e ### [1] Luna Client 설치 및 설정 ### result=$(curl --silent --location --request GET 'https://hardwaresecuritymodule.apigw.gov-ntruss.com/api/v1/client/configs?version=10.7.1') IFS=',' read -ra ADDR <<< "$result" DOWNLOAD_URL=${ADDR[0]} HSM1_URL=${ADDR[2]} HSM2_URL=${ADDR[3]} HSM3_URL=${ADDR[4]} WORK_DIR="$HOME" INSTALL_DIR="LunaClient_10.7.1-125_Linux" ARCHIVE_NAME="610-000397-010_SW_Linux_Luna_Client_V10.7.1_RevA.tar" cd "$WORK_DIR" || { echo "Error: Could not change to $WORK_DIR"; exit 1; } echo "[INFO] Downloading Luna Client..." wget -q "$DOWNLOAD_URL" -O "$ARCHIVE_NAME" || { echo "Error: Download failed"; exit 1; } echo "[INFO] Extracting Luna Client..." tar -xf "$ARCHIVE_NAME" || { echo "Error: Extraction failed"; exit 1; } rm -f "$ARCHIVE_NAME" cd "$INSTALL_DIR/64" || { echo "Error: Installation directory not found"; exit 1; } (echo y) | sudo sh install.sh -p network -c all || { echo "Error: Installation failed"; exit 1; } EULA_FILE="$WORK_DIR/$INSTALL_DIR/008-010068-001_EULA_HSM7_SW_revC.txt" if [[ -f "$EULA_FILE" ]]; then sudo mv "$EULA_FILE" /usr/safenet/lunaclient/ fi CERT_DIR="$WORK_DIR/$INSTALL_DIR/cert" for i in 1 2 3; do HSM_URL_VAR="HSM${i}_URL" CERT_FILE="$CERT_DIR/gov-hsm00${i}.pem" if [[ -f "$CERT_FILE" ]]; then echo "[INFO] Adding server ${!HSM_URL_VAR}" /usr/safenet/lunaclient/bin/vtl addServer -n "${!HSM_URL_VAR}" -c "$CERT_FILE" fi done cd "$WORK_DIR" rm -rf "$INSTALL_DIR" ### [2] 클라이언트 인증서 및 개인키 직접 생성 ### CLIENT_CERT_DIR="/usr/safenet/lunaclient/cert/client" mkdir -p "$CLIENT_CERT_DIR" # 개인 키 생성 cat <<'EOF' > "$CLIENT_CERT_DIR/{privateKey}.pem" -----BEGIN RSA PRIVATE KEY----- ...... -----END RSA PRIVATE KEY----- EOF # 인증서 생성 cat <<'EOF' > "$CLIENT_CERT_DIR/{certificate}.pem" -----BEGIN CERTIFICATE----- ...... -----END CERTIFICATE----- EOF chmod 600 "$CLIENT_CERT_DIR/{privateKey}.pem" chmod 644 "$CLIENT_CERT_DIR/{certificate}.pem" ### [3] /etc/Chrystoki.conf 수정 ### CHRYSTOKI_CONF="/etc/Chrystoki.conf" if grep -q "ClientPrivKeyFile" "$CHRYSTOKI_CONF"; then sed -i "s|ClientPrivKeyFile *= *.*|ClientPrivKeyFile = $CLIENT_CERT_DIR/{privateKey}.pem;|" "$CHRYSTOKI_CONF" else sed -i "/LunaSA Client = {/a\ ClientPrivKeyFile = $CLIENT_CERT_DIR/{privateKey}.pem;" "$CHRYSTOKI_CONF" fi if grep -q "ClientCertFile" "$CHRYSTOKI_CONF"; then sed -i "s|ClientCertFile *= *.*|ClientCertFile = $CLIENT_CERT_DIR/{certificate}.pem;|" "$CHRYSTOKI_CONF" else sed -i "/LunaSA Client = {/a\ ClientCertFile = $CLIENT_CERT_DIR/{certificate}.pem;" "$CHRYSTOKI_CONF" fi echo "[SUCCESS] Luna Client 설치 및 인증서 설정 완료." ``` - initScript 등록 ``` kubectl --kubeconfig=$KUBE_CONFIG apply -f https://raw.githubusercontent.com/NaverCloudPlatform/nks-examples/main/examples/initscript/gov/kr.yml ``` - daemonSet env 수정 ``` kubectl --kubeconfig=$KUBE_CONFIG set env daemonset/init-script -n kube-system STARTUP_SCRIPT=$(base64 -i install_lunaclient_certs.sh -w 0) ``` - 스크립트 내에 `{privateKey}.pem`, `{certificate}.pem`은 HSM 연결에 사용된 값으로 대체해야 합니다. 스크립트가 성공적으로 수행되면 node에서 HSM으로 접근 가능한 상태가 됩니다. 2. node의 lunaclient를 이용하여 HSM에 접근하는 pod `pod-with-lunaclient`을 생성해 주십시오. 참고 위 설정은 참고용이며 사용 환경에 따라 다른 설정 값이 추가될 수 있습니다. - `lunaclient.yaml` 작성 ``` apiVersion: v1 kind: Pod metadata: name: pod-with-lunaclient spec: containers: - name: pod-with-lunaclient image: registry.access.redhat.com/ubi8/ubi:latest # RHEL UBI 이미지 command: [ "/bin/bash", "-c", "--" ] args: [ "while true; do sleep 30; done;" ] volumeMounts: - name: lunaclient-config mountPath: /etc/Chrystoki.conf readOnly: true - name: lunaclient mountPath: /usr/safenet/lunaclient env: - name: LC_ALL value: C volumes: - name: lunaclient-config hostPath: path: /etc/Chrystoki.conf type: File - name: lunaclient hostPath: path: /usr/safenet/lunaclient type: Directory ``` - `pod-with-lunaclient` 생성 ``` kubectl --kubeconfig=$KUBE_CONFIG create -f lunaclient.yaml ``` 3. pod 의 동작을 확인하고 pod 에 접근하여 HSM 연결을 확인해 주십시오. - pod 동작 확인 ``` kubectl --kubeconfig=$KUBE_CONFIG get pods NAME READY STATUS RESTARTS AGE pod-with-lunaclient 1/1 Running 0 58s ``` - pod 접속 ``` kubectl --kubeconfig=$KUBE_CONFIG exec -it pod-with-lunaclient -- /bin/bash ``` - HSM 연결 확인 ``` [root@pod-with-lunaclient /]# cd /usr/safenet/lunaclient/ [root@pod-with-lunaclient bin]# ./vtl verify vtl (64-bit) v10.7.1-125. Copyright (c) 2024 Thales Group. All rights reserved. The following Luna SA Slots/Partitions were found: Slot Serial # Label ==== ================ ===== 0 146*******711 n*****l ``` 4. 정상적으로 접근이 되기 위해서는 아래 사항을 모두 확인할 수 있어야 합니다. - `/etc/Chrystoki.conf` 파일 존재 - `/etc/Chrystoki.conf` 파일 내 `ClientPrivKeyFile`, `ClientCertFile` 값의 파일명이 스크립트에 작성한 파일명과 동일 <예시> ``` LunaSA Client = { ... ClientPrivKeyFile = /usr/safenet/lunaclient/cert/client/testHsmKey.pem; ClientCertFile = /usr/safenet/lunaclient/cert/client/testHsm.pem; ... } ``` - `/usr/safenet/lunaclient/` 경로 존재 - `/usr/safenet/lunaclient/cert/client` 경로에 `{privateKey}.pem`, `{certificate}.pem` 파일이 있고 올바른 개인키, 인증서 내용