feat: AWS ansible setup#24
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces an Ansible role to configure AWS Nitro Enclave environments, including setting up docker-compose, socat proxies, NFS exports, and enclave-specific configurations. The review identified several critical issues: the socat service configuration is incomplete and requires a destination address, the use of 'privileged: true' in the docker-compose file poses a security risk, and several Ansible tasks contain redundancies or suboptimal practices, such as unnecessary architecture checks, redundant binary downloads, incorrect path settings for cargo, hardcoded UIDs, and overly restrictive conditional logic that prevents configuration updates.
| After=network.target | ||
|
|
||
| [Service] | ||
| ExecStart=socat -d -d -b65536 VSOCK-LISTEN:8004,fork,keepalive,rcvbuf-late=16384,sndbuf-late=16384 |
There was a problem hiding this comment.
The socat command is incomplete. It only specifies the listening address (VSOCK-LISTEN:8004) but socat requires two addresses to establish a bidirectional stream. Based on the setup-ec2-instance.sh script in the repository context, this service is intended to proxy VSOCK traffic to the local NFS server on port 2049.
ExecStart=/usr/bin/socat -d -d -b65536 VSOCK-LISTEN:8004,fork,keepalive,rcvbuf-late=16384,sndbuf-late=16384 TCP:127.0.0.1:2049,keepalive,retry=5,interval=10
| image: # ghcr.io/espressosystems/aws-nitro-poster:<docker-tag> | ||
| devices: | ||
| - "/dev/nitro_enclaves:/dev/nitro_enclaves:rwm" | ||
| privileged: true No newline at end of file |
There was a problem hiding this comment.
Running a container with privileged: true is a significant security risk as it grants the container nearly all the same capabilities as the host. For AWS Nitro Enclaves, providing access to the device via the devices section (as done in line 5) is typically sufficient. Unless there is a specific requirement for full host privileges, this should be removed.
| - name: Get architecture | ||
| shell: uname -m | ||
| register: architecture |
| - name: Install docker-compose to plugins | ||
| get_url: | ||
| url : https://github.com/docker/compose/releases/download/v2.37.0/docker-compose-linux-x86_64 | ||
| dest: /usr/lib/docker/cli-plugins/docker-compose | ||
| mode: 'u+x,g+x' |
There was a problem hiding this comment.
This task downloads the same docker-compose binary that was already downloaded in the task at line 35. It is more efficient to copy the binary from the local path on the remote host.
- name: Install docker-compose to plugins
ansible.builtin.copy:
src: /usr/local/bin/docker-compose
dest: /usr/lib/docker/cli-plugins/docker-compose
remote_src: yes
mode: 'u+x,g+x'| - name: Install "just" Rust package | ||
| community.general.cargo: | ||
| name: just | ||
| path: /usr/local |
There was a problem hiding this comment.
The path parameter for the cargo module specifies the directory where the cargo binary is located. Since cargo was installed via dnf (line 22), it is likely located in /usr/bin. Setting it to /usr/local will cause the task to fail if the binary is not found there. It is recommended to either set it to /usr/bin or omit it entirely if cargo is in the system PATH.
path: /usr/bin| group: 1000 | ||
| mode: '0775' |
| - name: Check that enclave-allocator.yaml exists | ||
| stat: | ||
| path: /etc/nitro_enclaves/allocator.yaml | ||
| register: allocator_result | ||
|
|
||
| - name: Enclave Configuration | ||
| ansible.builtin.copy: | ||
| src: enclave-allocator.yaml | ||
| dest: /etc/nitro_enclaves/allocator.yaml | ||
| owner: root | ||
| group: root | ||
| mode: '0660' | ||
| register: enclave_conf | ||
| when: not allocator_result.stat.exists |
There was a problem hiding this comment.
The when: not allocator_result.stat.exists condition prevents Ansible from updating the configuration if the file already exists. This defeats the purpose of configuration management, as updates to enclave-allocator.yaml in the repository will not be propagated to existing servers. It is better to let the copy module manage the file state directly to ensure consistency.
Adds Ansible AWS files
Ref: https://github.com/EspressoSystems/integrations-utils/pull/16/changes