Skip to content

Commit aa92c63

Browse files
committed
Address comments
1 parent 3dd3f84 commit aa92c63

2 files changed

Lines changed: 36 additions & 67 deletions

File tree

scripts/aws/entrypoint.sh

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,39 +23,46 @@ echo "Starting vsock proxy..."
2323
/app/vsockpx --config /app/proxies.nitro.yaml --daemon --workers $(( ( $(nproc) + 3 ) / 4 )) --log-level 3
2424

2525
TIME_SYNC_URL="http://127.0.0.1:27015/getCurrentTime"
26-
TIME_SYNC_INTERVAL_SECONDS="${TIME_SYNC_INTERVAL_SECONDS:-86400}"
27-
28-
sync_enclave_time() {
29-
local current_time
30-
local parent_epoch
31-
local enclave_epoch
32-
local drift_seconds
33-
if current_time=$(curl -s -f -x socks5h://127.0.0.1:3305 "${TIME_SYNC_URL}"); then
34-
parent_epoch=$(date -u -d "${current_time}" +%s 2>/dev/null || true)
35-
enclave_epoch=$(date -u +%s)
36-
if [[ -n "${parent_epoch}" ]]; then
37-
drift_seconds=$((enclave_epoch - parent_epoch))
38-
echo "Time sync: drift seconds (enclave - parent) = ${drift_seconds}"
39-
fi
40-
if ! date -u -s "${current_time}"; then
41-
echo "Time sync: failed to set enclave time from '${current_time}'"
42-
return 1
43-
fi
44-
echo "Time sync: updated enclave time to ${current_time}"
45-
else
46-
echo "Time sync: failed to fetch time from parent instance"
47-
return 1
26+
TIME_SYNC_PROXY="socks5h://127.0.0.1:3305"
27+
TIME_SYNC_INTERVAL_SECONDS="300"
28+
29+
enable_time_sync_timer() {
30+
if ! command -v systemctl >/dev/null 2>&1 || [[ ! -d /run/systemd/system ]]; then
31+
echo "Time sync: systemd not available; skipping timer setup" >&2
32+
return 0
4833
fi
49-
}
5034

51-
start_time_sync_loop() {
52-
while true; do
53-
sleep "${TIME_SYNC_INTERVAL_SECONDS}"
54-
sync_enclave_time || true
55-
done
35+
cat <<EOF >/etc/systemd/system/uid2-time-sync.service
36+
[Unit]
37+
Description=UID2 enclave time sync
38+
39+
[Service]
40+
Type=oneshot
41+
Environment=TIME_SYNC_URL=${TIME_SYNC_URL}
42+
Environment=TIME_SYNC_PROXY=${TIME_SYNC_PROXY}
43+
ExecStart=/bin/bash -c 'set -euo pipefail; curl -sSf -x "$TIME_SYNC_PROXY" "$TIME_SYNC_URL" | xargs -I{} date -u -s "{}"; echo "Time sync: updated enclave time to $current_time"'
44+
EOF
45+
46+
cat <<EOF >/etc/systemd/system/uid2-time-sync.timer
47+
[Unit]
48+
Description=UID2 enclave time sync timer
49+
50+
[Timer]
51+
OnBootSec=30s
52+
OnUnitActiveSec=${TIME_SYNC_INTERVAL_SECONDS}s
53+
Unit=uid2-time-sync.service
54+
Persistent=true
55+
AccuracySec=1s
56+
57+
[Install]
58+
WantedBy=timers.target
59+
EOF
60+
61+
systemctl daemon-reload
62+
systemctl enable --now uid2-time-sync.timer
5663
}
5764

58-
start_time_sync_loop &
65+
enable_time_sync_timer
5966

6067
build_parameterized_config() {
6168
curl -s -f -o "${PARAMETERIZED_CONFIG}" -x socks5h://127.0.0.1:3305 http://127.0.0.1:27015/getConfig

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

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,44 +19,6 @@
1919
name: nmap-ncat
2020
state: latest
2121

22-
- name: Install chrony for time sync
23-
ansible.builtin.dnf:
24-
name: chrony
25-
state: latest
26-
27-
- name: Comment out default chrony pool servers
28-
ansible.builtin.replace:
29-
path: /etc/chrony.conf
30-
regexp: '^pool\s+'
31-
replace: '# pool '
32-
33-
- name: Configure AWS Time Sync Service in chrony
34-
ansible.builtin.lineinfile:
35-
path: /etc/chrony.conf
36-
line: 'server 169.254.169.123 prefer iburst'
37-
state: present
38-
insertafter: EOF
39-
40-
- name: Enable RTC sync in chrony
41-
ansible.builtin.lineinfile:
42-
path: /etc/chrony.conf
43-
line: 'rtcsync'
44-
state: present
45-
insertafter: EOF
46-
47-
- name: Allow chrony to step clock at startup
48-
ansible.builtin.lineinfile:
49-
path: /etc/chrony.conf
50-
line: 'makestep 1.0 3'
51-
state: present
52-
insertafter: EOF
53-
54-
- name: Ensure chronyd is enabled at boot
55-
ansible.builtin.systemd:
56-
name: chronyd
57-
state: started
58-
enabled: true
59-
6022
- name: Install python
6123
ansible.builtin.dnf:
6224
name:

0 commit comments

Comments
 (0)