체인의정석

트랜잭션 서명을 위한 AWS Cloud HSM 구축하기 본문

개발/docker & linux

트랜잭션 서명을 위한 AWS Cloud HSM 구축하기

체인의정석 2025. 8. 1. 18:45
728x90

Cloud HSM을 구축해보고 그 과정을 복기하며 정리해 보았다.

https://docs.aws.amazon.com/cloudhsm/latest/userguide/getting-started.html

 

Getting started with AWS CloudHSM - AWS CloudHSM

Thanks for letting us know this page needs work. We're sorry we let you down. If you've got a moment, please tell us how we can make the documentation better.

docs.aws.amazon.com

일단 위의 가이드를 보고 진행하면 된다. 

해당 문서의 내용은 아래와 같다.

순서는 먼저 IAM, VPC 설정을 해주고 

클라우드 HSM에 대한 클러스터를 먼저 만들어 준다.

이후 HSM을 2개 이상 만들어줘야 하는데 그 이유는 2개이상이 되어야 가용성 조건에 맞기 때문이다. 서명을 하고 싶다면 무조건 최소 2개는 만들어 줘야 한다.

HSM의 경우 클러스터 화면에서 초기화 버튼을 클릭하면 되는데 초기화라는 과정에서 인증서를 만들고 업로드 하게된다.

인증서는 UI에서 다운 받은 후에 로컬에서 따로 키를 만들고 서명하여서 만든 키와 인증서를 HSM에 다시 업로드 해주게 되면 HSM의  초기화가 마무리된다.

https://docs.aws.amazon.com/cloudhsm/latest/userguide/initialize-cluster.html

 

Initialize the cluster in AWS CloudHSM - AWS CloudHSM

For a production cluster, the key you are about to create should be created in a secure manner using a trusted source of randomness. We recommend that you use a secured offsite and offline HSM or the equivalent. Store the key safely. The key establishes th

docs.aws.amazon.com

위의 링크에 있는 명렁어를 따라서 치기만 하면 쉽게 된다.

그리고 HSM은 직접 접근해서 사용하는 것이 아니다. 다른 EC2에서 접근해서 (예를 들어 HSM 서명을 해야되는 서버) 해당 서버와 cloudHSM을 부트스트랩 해주고 나면 접근이 가능해진다.

따라서, HSM에 접근할 EC2에는 모두 아래와 같이 보안그룹 수정을 통해 접근이 가능하게 열어주어야 한다.

https://docs.aws.amazon.com/cloudhsm/latest/userguide/configure-sg-client-instance.html

 

Configure the Client Amazon EC2 instance security groups for AWS CloudHSM - AWS CloudHSM

You can assign a maximum of five security groups to an Amazon EC2 instance. If you have reached the maximum limit, you must modify the default security group of the Amazon EC2 instance and the cluster security group: In the default security group, do the f

docs.aws.amazon.com

이전에 만들었던 cloudHSM cluster(최소2개의 hsm이 묶여있는 cluster)가 접근이 가능하도록 EC2에서 허용을 해주는 부분이다.

여기 까지 되었다면 일단 통신은 열리게 된다.

그리고 EC2의 OS는 HSM과 상호작용하기 위해서 스펙을 확인하고 만들어야 하는데 지금 기준 스펙은 다음과 같다.

https://docs.aws.amazon.com/cloudhsm/latest/userguide/sdk8-linux.html

 

Linux support for AWS CloudHSM Client SDK 5 - AWS CloudHSM

Thanks for letting us know this page needs work. We're sorry we let you down. If you've got a moment, please tell us how we can make the documentation better.

docs.aws.amazon.com

 

이후 cloudHSM CLI를 ec2에 설치해야 거기 안에서 키를 만들고 관리를 할 수 있다.

https://docs.aws.amazon.com/cloudhsm/latest/userguide/gs_cloudhsm_cli-install.html

 

Install and configure CloudHSM CLI - AWS CloudHSM

Install and configure CloudHSM CLI To interact with the HSM in your AWS CloudHSM cluster, you need the CloudHSM CLI. Connect to your client instance and run the following commands to download and install the AWS CloudHSM command line tools. For more inform

docs.aws.amazon.com

여기서 운영체제에 맞게 설치를 하고 EC2를 HSM 클러스터에 부트스트랩해서 연결시켜준다.

내가 하려던 것은 블록체인 서명까지 포함하기 때문에 한가지 패키지를 더 설치해주어야했다.

https://docs.aws.amazon.com/cloudhsm/latest/userguide/pkcs11-library-install.html

 

Install the PKCS #11 library for AWS CloudHSM Client SDK 5 - AWS CloudHSM

Install the PKCS #11 library for AWS CloudHSM Client SDK 5 This topic provides instructions for installing the latest version of the PKCS #11 library for the AWS CloudHSM Client SDK 5 version series. For more information about the Client SDK or PKCS #11 li

docs.aws.amazon.com

바로 PKCS #11 라이브러리였다. 이것까지 설치해주고 나면 이제 로컬에서 이전에 만들었던 인증서를 해당 ec2에 보내주어야 한다.

scp -i ./키이름.pem \
    /Users/Desktop/인증서경로/customerCA.crt \
    ec2-user@{ec2의퍼블릭IP}:/home/ec2-user/

ssh키가 잇는 경로로 들어가서 위와같이 인증서 파일 위치를 적고 ec2로 바로 업로드 시켜주면된다.

이렇게되면 

cat /opt/cloudhsm/etc/c
cloudhsm-cli.cfg     cloudhsm-pkcs11.cfg  customerCA.crt

이렇게 총 2개의 설정파일과 한개의 인증서(서명된 인증서)가 들어가있게 된다. 

https://docs.aws.amazon.com/cloudhsm/latest/userguide/activate-cluster.html

 

Activate the cluster in AWS CloudHSM - AWS CloudHSM

Before you can activate the cluster, you must first copy the issuing certificate to the default location for the platform on each EC2 instance that connects to the cluster (you create the issuing certificate when you initialize the cluster). Linux /opt/clo

docs.aws.amazon.com

이후에는 위 문서를 보고 클러스터를 활성화 시킨 후에 관리자를 추가하면 설정이 완료된다.

해당 설정이후 클라우드 hsm키를 생성하고 그 키에 대한 label값을 통해서 부트스트랩된 ec2는 개인키를 가지지않고도 서명이 가능하게 된다. 해당 과정은 아래 링크에 정리해 두었다. 

https://it-timehacker.tistory.com/564

 

Cloud HSM 구현 + go 환경에서의 트랜잭션 서명

상황 : 클라우드 HSM을 통해서 트랜잭션을 쏘는 소스를 인계받는상황에서 찾아본 내용 정리AWS Cloud HSM 작업 순서먼저 cloud hsm의 경우 IAM 사용자가 생성되어 있어야 하고, VPC와 클러스터를 생성해

it-timehacker.tistory.com

 

728x90
반응형
Comments