Skip to content

Commit 46ae1ee

Browse files
authored
UID2-3331 Update ami from al2 to al2023 (#641)
* Update AL source * Remove unnecessary arguments * Update installing aws-nitro-enclaves-cli * Use dnf instead of yum * Remove the step for installing epel * Define cut down version of syslog-ng * Update inputs for `actions/download-artifact@v4` * Copy syslog-ng-amazon23.repo to artifacts dir * Temporary change ref to use new files * Update syslog-ng-amazon23.repo path * Add steps to ensure /etc/cron.d/ folder exist * Remove disabling rsyslog * Give cron.d 0755 access * Put in scripts for logrotate under cron.daily * Update external ethernet port name * Add `df -h` to monitor disk usage * Disable DOCKER_BUILDKIT for docker build * Make Makefile.nitro run quietly * Comment out uid2 build * Use .github/workflows/publish-aws-nitro-enclave-docker.yaml for build_aws_eif * Remove --quiet mode * Update start.sh * Install libxcrypt-compat * Modify scripts/aws/entrypoint.sh to match AL2023 metadata standard * Use echo $SECURITY_CREDS to get AWS keys * Convert .github/workflows/publish-aws-nitro-enclave-docker.yaml to main
1 parent 7d2c1c6 commit 46ae1ee

File tree

11 files changed

+75
-49
lines changed

11 files changed

+75
-49
lines changed

.github/actions/build_ami/action.yaml

+1-4
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,13 @@ runs:
7171

7272
- name: Get EIF for Run ${{ inputs.operator_run_number }}
7373
id: get_eif_for_run
74-
uses: actions/download-artifact@v4
74+
uses: dawidd6/action-download-artifact@v6
7575
if: ${{ inputs.operator_release == '' }}
7676
with:
77-
github_token: ${{ inputs.github_token }}
78-
repo: IABTechLab/uid2-operator
7977
name: 'aws-${{ inputs.identity_scope }}-deployment-files-.*'
8078
name_is_regexp: true
8179
run_id: ${{ inputs.operator_run_number }}
8280
skip_unpack: true
83-
path: ./download/artifacts
8481

8582
- name: Unzip artifacts
8683
if: ${{ inputs.operator_release == '' }}

.github/actions/build_aws_eif/action.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ runs:
6868
cp ./scripts/aws/syslog-ng/syslog-ng-server.conf ${ARTIFACTS_OUTPUT_DIR}/
6969
cp ./scripts/aws/syslog-ng/server/syslog-ng-pubkey.gpg ${ARTIFACTS_OUTPUT_DIR}/
7070
cp ./scripts/aws/syslog-ng/server/syslog-ng-4.6.0-1.el7.x86_64.rpm ${ARTIFACTS_OUTPUT_DIR}/
71+
cp ./scripts/aws/syslog-ng/server/syslog-ng-amazon23.repo ${ARTIFACTS_OUTPUT_DIR}/
7172
cp ./scripts/aws/logrotate/operator-logrotate.conf ${ARTIFACTS_OUTPUT_DIR}/
7273
cp ./scripts/aws/logrotate/logrotate ${ARTIFACTS_OUTPUT_DIR}/
74+
cp ./scripts/aws/logrotate/logrotateDaily ${ARTIFACTS_OUTPUT_DIR}/
7375
7476
docker cp amazonlinux:/sockd ${ARTIFACTS_OUTPUT_DIR}/
7577
docker cp amazonlinux:/vsockpx ${ARTIFACTS_OUTPUT_DIR}/

.github/workflows/publish-aws-nitro-enclave-docker.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -302,4 +302,3 @@ jobs:
302302
${{ env.ARTIFACTS_BASE_OUTPUT_DIR }}/aws-euid-deployment-artifacts-${{ needs.start.outputs.new_version }}.zip
303303
${{ env.ARTIFACTS_BASE_OUTPUT_DIR }}/manifests/aws-uid2-enclave-id-${{ needs.start.outputs.new_version }}.txt
304304
${{ env.ARTIFACTS_BASE_OUTPUT_DIR }}/manifests/aws-euid-enclave-id-${{ needs.start.outputs.new_version }}.txt
305-

scripts/aws/entrypoint.sh

+9-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ echo "Starting syslog-ng..."
1818
# -- load env vars via proxy
1919
echo "Loading env vars via proxy..."
2020

21-
USER_DATA=$(curl -s -x socks5h://127.0.0.1:3305 http://169.254.169.254/latest/user-data)
21+
TOKEN=$(curl -x socks5h://127.0.0.1:3305 --request PUT "http://169.254.169.254/latest/api/token" --header "X-aws-ec2-metadata-token-ttl-seconds: 3600")
22+
USER_DATA=$(curl -s -x socks5h://127.0.0.1:3305 http://169.254.169.254/latest/user-data --header "X-aws-ec2-metadata-token: $TOKEN")
2223
if [ "${IDENTITY_SCOPE}" = "UID2" ]; then
2324
UID2_CONFIG_SECRET_KEY=$([[ "$(echo "${USER_DATA}" | grep UID2_CONFIG_SECRET_KEY=)" =~ ^export\ UID2_CONFIG_SECRET_KEY=\"(.*)\"$ ]] && echo "${BASH_REMATCH[1]}" || echo "uid2-operator-config-key")
2425
elif [ "${IDENTITY_SCOPE}" = "EUID" ]; then
@@ -34,17 +35,17 @@ echo "UID2_CONFIG_SECRET_KEY=${UID2_CONFIG_SECRET_KEY}"
3435
echo "CORE_BASE_URL=${CORE_BASE_URL}"
3536
echo "OPTOUT_BASE_URL=${OPTOUT_BASE_URL}"
3637

37-
export AWS_REGION_NAME=$(curl -s -x socks5h://127.0.0.1:3305 http://169.254.169.254/latest/dynamic/instance-identity/document/ | jq -r ".region")
38+
export AWS_REGION_NAME=$(curl -s -x socks5h://127.0.0.1:3305 http://169.254.169.254/latest/dynamic/instance-identity/document/ --header "X-aws-ec2-metadata-token: $TOKEN" | jq -r ".region")
3839
echo "AWS_REGION_NAME=${AWS_REGION_NAME}"
3940
echo "127.0.0.1 secretsmanager.${AWS_REGION_NAME}.amazonaws.com" >> /etc/hosts
4041

41-
IAM_ROLE=$(curl -s -x socks5h://127.0.0.1:3305 http://169.254.169.254/latest/meta-data/iam/security-credentials/)
42+
IAM_ROLE=$(curl -s -x socks5h://127.0.0.1:3305 http://169.254.169.254/latest/meta-data/iam/security-credentials/ --header "X-aws-ec2-metadata-token: $TOKEN")
4243
echo "IAM_ROLE=${IAM_ROLE}"
4344

44-
CREDS_ENDPOINT="http://169.254.169.254/latest/meta-data/iam/security-credentials/${IAM_ROLE}"
45-
export AWS_ACCESS_KEY_ID=$(curl -s -x socks5h://127.0.0.1:3305 "${CREDS_ENDPOINT}" | jq -r ".AccessKeyId")
46-
export AWS_SECRET_KEY=$(curl -s -x socks5h://127.0.0.1:3305 "${CREDS_ENDPOINT}" | jq -r ".SecretAccessKey")
47-
export AWS_SESSION_TOKEN=$(curl -s -x socks5h://127.0.0.1:3305 "${CREDS_ENDPOINT}" | jq -r ".Token")
45+
SECURITY_CREDS=$(curl -s -x socks5h://127.0.0.1:3305 "http://169.254.169.254/latest/meta-data/iam/security-credentials/${IAM_ROLE}" --header "X-aws-ec2-metadata-token: $TOKEN")
46+
export AWS_ACCESS_KEY_ID=$(echo $SECURITY_CREDS | jq -r ".AccessKeyId")
47+
export AWS_SECRET_KEY=$(echo $SECURITY_CREDS | jq -r ".SecretAccessKey")
48+
export AWS_SESSION_TOKEN=$(echo $SECURITY_CREDS | jq -r ".Token")
4849

4950
# -- load configs via proxy
5051
echo "Loading config overrides..."
@@ -95,7 +96,7 @@ fi
9596

9697
cat "${FINAL_CONFIG}"
9798

98-
HOSTNAME=$(curl -s -x socks5h://127.0.0.1:3305 http://169.254.169.254/latest/meta-data/local-hostname)
99+
HOSTNAME=$(curl -s -x socks5h://127.0.0.1:3305 http://169.254.169.254/latest/meta-data/local-hostname --header "X-aws-ec2-metadata-token: $TOKEN")
99100
echo "HOSTNAME=${HOSTNAME}"
100101

101102
# -- set pwd to /app so we can find default configs

scripts/aws/logrotate/logrotateDaily

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
/usr/sbin/logrotate -s /var/lib/logrotate/logrotate.status /etc/logrotate.conf
4+
EXITVALUE=$?
5+
if [ $EXITVALUE != 0 ]; then
6+
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
7+
fi
8+
exit 0

scripts/aws/sockd.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
internal: 127.0.0.1 port = 3306
2-
external: eth0
2+
external: ens5
33
user.notprivileged: ec2-user
44
clientmethod: none
55
socksmethod: none

scripts/aws/start.sh

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ echo "$HOSTNAME" > /etc/uid2operator/HOSTNAME
44
EIF_PATH=${EIF_PATH:-/opt/uid2operator/uid2operator.eif}
55
IDENTITY_SCOPE=${IDENTITY_SCOPE:-$(cat /opt/uid2operator/identity_scope.txt)}
66
CID=${CID:-42}
7-
AWS_REGION_NAME=$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document/ | jq -r '.region')
7+
TOKEN=$(curl --request PUT "http://169.254.169.254/latest/api/token" --header "X-aws-ec2-metadata-token-ttl-seconds: 3600")
8+
AWS_REGION_NAME=$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document/ --header "X-aws-ec2-metadata-token: $TOKEN" | jq -r '.region')
89
if [ "$IDENTITY_SCOPE" = 'UID2' ]; then
9-
UID2_CONFIG_SECRET_KEY=$([[ "$(curl -s http://169.254.169.254/latest/user-data | grep UID2_CONFIG_SECRET_KEY=)" =~ ^export\ UID2_CONFIG_SECRET_KEY=\"(.*)\" ]] && echo ${BASH_REMATCH[1]} || echo "uid2-operator-config-key")
10+
UID2_CONFIG_SECRET_KEY=$([[ "$(curl -s http://169.254.169.254/latest/user-data/ --header "X-aws-ec2-metadata-token: $TOKEN" | grep UID2_CONFIG_SECRET_KEY=)" =~ ^export\ UID2_CONFIG_SECRET_KEY=\"(.*)\" ]] && echo ${BASH_REMATCH[1]} || echo "uid2-operator-config-key")
1011
elif [ "$IDENTITY_SCOPE" = 'EUID' ]; then
11-
UID2_CONFIG_SECRET_KEY=$([[ "$(curl -s http://169.254.169.254/latest/user-data | grep EUID_CONFIG_SECRET_KEY=)" =~ ^export\ EUID_CONFIG_SECRET_KEY=\"(.*)\" ]] && echo ${BASH_REMATCH[1]} || echo "euid-operator-config-key")
12+
UID2_CONFIG_SECRET_KEY=$([[ "$(curl -s http://169.254.169.254/latest/user-data/ --header "X-aws-ec2-metadata-token: $TOKEN" | grep EUID_CONFIG_SECRET_KEY=)" =~ ^export\ EUID_CONFIG_SECRET_KEY=\"(.*)\" ]] && echo ${BASH_REMATCH[1]} || echo "euid-operator-config-key")
1213
else
1314
echo "Unrecognized IDENTITY_SCOPE $IDENTITY_SCOPE"
1415
exit 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[copr:copr.fedorainfracloud.org:czanik:syslog-ng-amazon23]
2+
name=Copr repo for syslog-ng-amazon23 owned by czanik
3+
baseurl=https://download.copr.fedorainfracloud.org/results/czanik/syslog-ng-amazon23/amazonlinux-2023-$basearch/
4+
type=rpm-md
5+
skip_if_unavailable=True
6+
gpgcheck=1
7+
gpgkey=https://download.copr.fedorainfracloud.org/results/czanik/syslog-ng-amazon23/pubkey.gpg
8+
repo_gpgcheck=0
9+
enabled=1
10+
enabled_metadata=1

scripts/aws/uid2-operator-ami/ansible/playbook.yml

+38-29
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99

1010
tasks:
1111
- name: Update all base packages
12-
ansible.builtin.yum:
12+
ansible.builtin.dnf:
1313
update_cache: yes
1414
name: '*'
1515
state: latest
1616

1717
- name: Install Netcat
18-
ansible.builtin.yum:
18+
ansible.builtin.dnf:
1919
name: nmap-ncat
2020
state: latest
2121

@@ -29,6 +29,11 @@
2929
path: /opt/uid2operator
3030
state: directory
3131

32+
- name: Install libxcrypt-compat
33+
ansible.builtin.dnf:
34+
name: libxcrypt-compat
35+
state: latest
36+
3237
- name: vsock-proxy config
3338
ansible.builtin.copy:
3439
src: /tmp/artifacts/proxies.host.yaml
@@ -115,10 +120,17 @@
115120
dest: /etc/systemd/system/uid2operator.service
116121
remote_src: yes
117122

118-
- name: Ensure nitro-cli is installed to the latest version
119-
ansible.builtin.command: amazon-linux-extras install aws-nitro-enclaves-cli
123+
- name: Install AWS Nitro Enclaves CLI
124+
ansible.builtin.dnf:
125+
name: aws-nitro-enclaves-cli
126+
state: latest
127+
128+
- name: Install AWS Nitro Enclaves Devel CLI
129+
ansible.builtin.dnf:
130+
name: aws-nitro-enclaves-cli-devel
131+
state: latest
120132

121-
- name: Ensure nitro enclave allocator is enabled at boot
133+
- name: Enable the Nitro Enclave allocator service at boot
122134
ansible.builtin.systemd:
123135
name: nitro-enclaves-allocator.service
124136
enabled: yes
@@ -133,27 +145,17 @@
133145
# ansible.builtin.systemd:
134146
# name: nitro-enclaves-allocator.service
135147
# state: restarted
136-
- name: Install EPEL
137-
ansible.builtin.command: amazon-linux-extras install epel
138148

139-
- name: Install ivykis
140-
ansible.builtin.yum:
141-
name: ivykis-0.36.2-2.el7
142-
state: present
143-
144-
- name: Install libnet
145-
ansible.builtin.yum:
146-
name: libnet-1.1.6-7.amzn2.0.2
147-
state: present
148-
149-
- name: Register Public key
150-
ansible.builtin.command: rpmkeys --import /opt/uid2operator/syslog-ng-pubkey.gpg
151-
152-
- name: Install package
153-
ansible.builtin.command: rpm -U /opt/uid2operator/syslog-ng-4.6.0-1.el7.x86_64.rpm
149+
- name: Define cutdown version of syslog-ng
150+
ansible.builtin.copy:
151+
src: /tmp/artifacts/syslog-ng-amazon23.repo
152+
dest: /etc/yum.repos.d/
153+
remote_src: yes
154154

155-
- name: unregister Public key
156-
ansible.builtin.command: rpm -e gpg-pubkey-c57846f4-65a8cf14
155+
- name: Install syslog-ng
156+
ansible.builtin.dnf:
157+
name: syslog-ng
158+
state: latest
157159

158160
- name: syslog-ng config
159161
ansible.builtin.copy:
@@ -166,6 +168,12 @@
166168
src: /tmp/artifacts/operator-logrotate.conf
167169
dest: /etc/logrotate.d/operator-logrotate.conf
168170
remote_src: yes
171+
172+
- name: Ensure /etc/cron.d/ folder exist
173+
ansible.builtin.file:
174+
path: /etc/cron.d
175+
state: directory
176+
mode: 0755
169177

170178
- name: Run logrotate under cron.d
171179
ansible.builtin.copy:
@@ -174,11 +182,12 @@
174182
mode: 0644
175183
remote_src: yes
176184

177-
- name: Ensure rsyslog is disabled at boot
178-
ansible.builtin.systemd:
179-
name: rsyslog
180-
state: stopped
181-
enabled: false
185+
- name: Run logrotate under cron.daily
186+
ansible.builtin.copy:
187+
src: /tmp/artifacts/logrotateDaily
188+
dest: /etc/cron.daily/logrotate
189+
mode: 0700
190+
remote_src: yes
182191

183192
- name: Ensure syslog-ng is enabled at boot
184193
ansible.builtin.systemd:

scripts/aws/uid2-operator-ami/build.pkr.hcl

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ build {
88

99
provisioner "ansible" {
1010
playbook_file = "./ansible/playbook.yml"
11-
extra_arguments = [ "--scp-extra-args", "'-O'", "--version", "9.6.1" ]
11+
extra_arguments = [ "--scp-extra-args", "'-O'" ]
1212
}
1313

1414
post-processor "manifest" {

scripts/aws/uid2-operator-ami/source.pkr.hcl

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ source "amazon-ebs" "linux" {
33
# source parameters
44
source_ami_filter {
55
filters = {
6-
name = "amzn2-ami-hvm-*-x86_64-ebs"
6+
name = "al2023-ami-2023*-x86_64"
77
root-device-type = "ebs"
8-
virtualization-type = "hvm"
98
}
109
most_recent = true
1110
owners = ["amazon"]

0 commit comments

Comments
 (0)