LoginSignup
3
0

AWS Nitro Enclaves 試してみた

Last updated at Posted at 2023-11-28

AWS Nitro Enclaves を試してみました.
https://aws.amazon.com/jp/ec2/nitro/nitro-enclaves/

やってみる

まずは, Nitro Enclaves を有効化した EC2 インスタンスを作成します.

  InstanceKeyPair:
    Type: AWS::EC2::KeyPair
    Properties:
      KeyName: aws-nitro-enclave-test-instance-key-pair
      KeyType: rsa
      KeyFormat: pem

  Instance:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: ami-070bc45386687dd29 # Amazon Linux 2 LTS Arm64 Kernel 5.10 AMI 2.0.20231101.0 arm64 HVM gp2
      InstanceType: m6g.large # AWS Nitro に対応したインスタンスタイプを選択する必要があります https://docs.aws.amazon.com/enclaves/latest/user/nitro-enclave.html#nitro-enclave-reqs
      KeyName: !Ref InstanceKeyPair
      EnclaveOptions:
        Enabled: true # AWS Nitro Enclaves を有効化
      UserData:
        Fn::Base64: !Sub
          - |
            #!/bin/bash
            # Nitro Enclave を管理するための  Nitro Enclaves CLI をインストールします. ここでは UserData に記載しインスタンス起動時に自動でセットアップされるようにしていますが, インスタンスに接続し手動でインストールしても構いません
            # 参考: https://docs.aws.amazon.com/enclaves/latest/user/nitro-enclave-cli-install.html
            amazon-linux-extras install aws-nitro-enclaves-cli -y
            yum install aws-nitro-enclaves-cli-devel -y            
            usermod -aG ne ec2-user
            usermod -aG docker ec2-user
            
            sed -i 's/cpu_count: 2/cpu_count: 1/g' /etc/nitro_enclaves/allocator.yaml
            systemctl enable --now nitro-enclaves-allocator.service
            systemctl enable --now docker
      Tags:
        - Key: Name
          Value: aws-nitro-enclave-test-instance

下記, インスタンスに接続して作業を行います.
参考: https://docs.aws.amazon.com/enclaves/latest/user/getting-started.html

# Enclave Image File(.eif) を構築していきます
$ docker build /usr/share/nitro_enclaves/examples/hello -t hello
Sending build context to Docker daemon   5.12kB
Step 1/4 : FROM arm64v8/busybox
latest: Pulling from arm64v8/busybox
8a0af25e8c2e: Pull complete 
Digest: sha256:1fa89c01cd0473cedbd1a470abb8c139eeb80920edf1bc55de87851bfb63ea11
Status: Downloaded newer image for arm64v8/busybox:latest
 ---> fc9db2894f4e
Step 2/4 : ENV HELLO="Hello from the enclave side!"
 ---> Running in a347c10690e8
Removing intermediate container a347c10690e8
 ---> 579ea867330f
Step 3/4 : COPY hello.sh /bin/hello.sh
 ---> 312e5eefcd6c
Step 4/4 : CMD ["/bin/hello.sh"]
 ---> Running in 5fe8ef001a45
Removing intermediate container 5fe8ef001a45
 ---> 9e53acb5127e
Successfully built 9e53acb5127e
Successfully tagged hello:latest

# Docker Image を EIF に変換します
$ nitro-cli build-enclave --docker-uri hello:latest --output-file hello.eif
Start building the Enclave Image...
Using the locally available Docker image...
Enclave Image successfully created.
{
  "Measurements": {
    "HashAlgorithm": "Sha384 { ... }",
    "PCR0": "...",
    "PCR1": "...",
    "PCR2": "..."
  }
}

# Enclave を起動し, アプリケーションを実行させます
$ nitro-cli run-enclave --cpu-count 1 --memory 512 --enclave-cid 16 --eif-path hello.eif --debug-mode
Start allocating memory...
Started enclave with enclave-cid: 16, memory: 512 MiB, cpu-ids: [1]
{
  "EnclaveName": "hello",
  "EnclaveID": "i-HOGE-encFOO",
  "ProcessID": 2218,
  "EnclaveCID": 16,
  "NumberOfCPUs": 1,
  "CPUIDs": [
    1
  ],
  "MemoryMiB": 512
}

# Enclave のコンソール出力を表示させ, アプリケーションの実行を確認します
$ nitro-cli console --enclave-id i-HOGE-encFOO
Connecting to the console for enclave 16...
Successfully connected to the console.
...
[   1] Hello from the enclave side!
[   2] Hello from the enclave side!
[   3] Hello from the enclave side!
[   4] Hello from the enclave side!
[   5] Hello from the enclave side!
[   6] Hello from the enclave side!
[   7] Hello from the enclave side!
[   8] Hello from the enclave side!
[   9] Hello from the enclave side!
[  10] Hello from the enclave side!
...

# Enclave を停止します
$ nitro-cli terminate-enclave --enclave-id i-HOGE-encFOO
Successfully terminated enclave i-HOGE-encFOO.
{
  "EnclaveName": "hello",
  "EnclaveID": "i-HOGE-encFOO",
  "Terminated": true
}

Enclave 内で Hello Enclave アプリケーションが実行されていることを確認できました.

最後に

簡単ではありますが, AWS Nitro Enclaves を試してみました.
機密性の高いデータを処理する場合, AWS Nitro Enclaves の利用を検討してみてもいいかもしれませんね.

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0