Skip to content

Commit ee2cdd9

Browse files
committed
Fix time drift for private operator
1 parent bf4ba4e commit ee2cdd9

3 files changed

Lines changed: 73 additions & 0 deletions

File tree

scripts/aws/config-server/app.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from flask import Flask
2+
from datetime import datetime, timezone
23
import json
34
import os
45

@@ -14,5 +15,12 @@ def get_config():
1415
except Exception as e:
1516
return str(e), 500
1617

18+
@app.route('/getCurrentTime', methods=['GET'])
19+
def get_time():
20+
try:
21+
return datetime.now(timezone.utc).isoformat(timespec="seconds")
22+
except Exception as e:
23+
return str(e), 500
24+
1725
if __name__ == '__main__':
1826
app.run(processes=8)

scripts/aws/entrypoint.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,33 @@ ifconfig lo 127.0.0.1
2222
echo "Starting vsock proxy..."
2323
/app/vsockpx --config /app/proxies.nitro.yaml --daemon --workers $(( ( $(nproc) + 3 ) / 4 )) --log-level 3
2424

25+
TIME_SYNC_URL="http://127.0.0.1:27015/getCurrentTime"
26+
TIME_SYNC_INTERVAL_SECONDS="${TIME_SYNC_INTERVAL_SECONDS:-300}"
27+
28+
sync_enclave_time() {
29+
local current_time
30+
if current_time=$(curl -s -f -x socks5h://127.0.0.1:3305 "${TIME_SYNC_URL}"); then
31+
if ! date -u -s "${current_time}"; then
32+
echo "Time sync: failed to set enclave time from '${current_time}'"
33+
return 1
34+
fi
35+
echo "Time sync: updated enclave time to ${current_time}"
36+
else
37+
echo "Time sync: failed to fetch time from parent instance"
38+
return 1
39+
fi
40+
}
41+
42+
start_time_sync_loop() {
43+
while true; do
44+
sync_enclave_time || true
45+
sleep "${TIME_SYNC_INTERVAL_SECONDS}"
46+
done
47+
}
48+
49+
sync_enclave_time || true
50+
start_time_sync_loop &
51+
2552
build_parameterized_config() {
2653
curl -s -f -o "${PARAMETERIZED_CONFIG}" -x socks5h://127.0.0.1:3305 http://127.0.0.1:27015/getConfig
2754
REQUIRED_KEYS=("optout_base_url" "core_base_url" "core_api_token" "optout_api_token" "environment" "uid_instance_id_prefix")

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,44 @@
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+
2260
- name: Install python
2361
ansible.builtin.dnf:
2462
name:

0 commit comments

Comments
 (0)