Skip to content

Commit 9683f2d

Browse files
committed
Test, add a drift on boot
1 parent 29ffb43 commit 9683f2d

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

scripts/aws/entrypoint.sh

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ echo "Starting vsock proxy..."
2424

2525
TIME_SYNC_URL="http://127.0.0.1:27015/getCurrentTime"
2626
TIME_SYNC_INTERVAL_SECONDS="${TIME_SYNC_INTERVAL_SECONDS:-300}"
27+
TIME_SYNC_OFFSET_SECONDS="${TIME_SYNC_OFFSET_SECONDS:-30}"
2728

2829
sync_enclave_time() {
2930
local current_time
@@ -48,14 +49,34 @@ sync_enclave_time() {
4849
fi
4950
}
5051

52+
sync_enclave_time_with_offset_once() {
53+
local current_time
54+
local parent_epoch
55+
if current_time=$(curl -s -f -x socks5h://127.0.0.1:3305 "${TIME_SYNC_URL}"); then
56+
parent_epoch=$(date -u -d "${current_time}" +%s 2>/dev/null || true)
57+
if [[ -n "${parent_epoch}" ]]; then
58+
parent_epoch=$((parent_epoch + TIME_SYNC_OFFSET_SECONDS))
59+
if ! date -u -s "@${parent_epoch}"; then
60+
echo "Time sync: failed to set enclave time from '${current_time}' with offset ${TIME_SYNC_OFFSET_SECONDS}s"
61+
return 1
62+
fi
63+
echo "Time sync: updated enclave time to ${current_time} + ${TIME_SYNC_OFFSET_SECONDS}s"
64+
fi
65+
else
66+
echo "Time sync: failed to fetch time from parent instance"
67+
return 1
68+
fi
69+
}
70+
71+
sync_enclave_time_with_offset_once || true
72+
5173
start_time_sync_loop() {
5274
while true; do
5375
sync_enclave_time || true
5476
sleep "${TIME_SYNC_INTERVAL_SECONDS}"
5577
done
5678
}
5779

58-
sync_enclave_time || true
5980
start_time_sync_loop &
6081

6182
build_parameterized_config() {

0 commit comments

Comments
 (0)