Skip to content

Commit 689117b

Browse files
committed
[#21963] YSQL: Support clockbound on other cloud providers
Summary: ### Azure PHC Issue Azure VMs have hardware clocks too. However, we haven't figured out how we can use them yet. Currently, the clockbound configuration script fatals with the following error. ``` PHC is not available on eth0 ``` **Fix:** Configure PTP only when the script runs on an AWS machine. ### Missing policycoreutils package Install policycoreutils-devel explicitly. ### Yugabyted changes clockbound can now be used on any cloud provider. So, alter users with a warning when using Azure or GCP as well. Jira: DB-10879 Test Plan: Jenkins: compile only Ran ``` sudo bash ./bin/configure_clockbound.sh ``` on AWS, Azure, and GCP Reviewers: nikhil, sanketh Reviewed By: sanketh Differential Revision: https://phorge.dev.yugabyte.com/D39224
1 parent 820d4f4 commit 689117b

File tree

2 files changed

+46
-25
lines changed

2 files changed

+46
-25
lines changed

bin/configure_clockbound.sh

+36-21
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ set -euo pipefail
2727
VERBOSE=0
2828
VALIDATE_ONLY=0
2929
OS_RELEASE=""
30+
CHRONY_CONF=""
3031
CHRONY_USER=""
32+
CLOUD_PROVIDER="unknown"
3133

3234
# Parse arguments
3335
while [[ $# -gt 0 ]]; do
@@ -277,6 +279,7 @@ require {
277279
allow bin_t chronyd_t:unix_dgram_socket sendto;
278280
allow chronyd_t unconfined_service_t:unix_dgram_socket sendto;
279281
EOF
282+
dnf install policycoreutils-devel -y
280283
checkmodule -M -m -o chrony_uds_access.mod chrony_uds_access.te
281284
semodule_package -o chrony_uds_access.pp -m chrony_uds_access.mod
282285
semodule -i chrony_uds_access.pp
@@ -309,6 +312,14 @@ install_clockbound() {
309312
fi
310313
}
311314

315+
# Function to detect cloud provider based on the chrony configuration
316+
retrieve_cloud_provider() {
317+
# Check if AWS PTP server is configured
318+
if grep -q "server\s*169.254.169.123" "${CHRONY_CONF}"; then
319+
CLOUD_PROVIDER="aws"
320+
fi
321+
}
322+
312323
configure_clockbound() {
313324
if ! systemctl is-active --quiet clockbound; then
314325
# Configure and start clockbound
@@ -325,29 +336,33 @@ configure_clockbound() {
325336
fatal "Neither 'chrony' nor '_chrony' user exists. Exiting."
326337
fi
327338

328-
# Pick ETH_DEVICE as the first non-loopback device.
329-
for iface in /sys/class/net/*; do
330-
iface=$(basename "$iface")
331-
if [[ "${iface}" != "lo" ]]; then
332-
ETH_DEVICE="${iface}"
333-
break
334-
fi
335-
done
336-
337339
EXTRA_ARGS=""
338-
if chronyc sources | grep "#.\s*PHC" > /dev/null 2>&1; then
339-
# Check if PHC is available on ETH_DEVICE.
340-
if ethtool -T "${ETH_DEVICE}" | grep -q "PTP Hardware Clock: none"; then
341-
fatal "PHC is not available on ${ETH_DEVICE}."
342-
fi
343-
344-
# Check whether a PHC source is selected.
345-
if ! chronyc sources | grep "#\*\s*PHC" > /dev/null 2>&1; then
346-
fatal "PHC source is not selected as the clock soruce."
340+
# Check for PTP only on AWS instances.
341+
retrieve_cloud_provider
342+
if [[ "${CLOUD_PROVIDER}" == "aws" ]]; then
343+
if chronyc sources | grep "#.\s*PHC" > /dev/null 2>&1; then
344+
# Pick ETH_DEVICE as the first non-loopback device.
345+
for iface in /sys/class/net/*; do
346+
iface=$(basename "$iface")
347+
if [[ "${iface}" != "lo" ]]; then
348+
ETH_DEVICE="${iface}"
349+
break
350+
fi
351+
done
352+
353+
# Check if PHC is available on ETH_DEVICE.
354+
if ethtool -T "${ETH_DEVICE}" | grep -q "PTP Hardware Clock: none"; then
355+
fatal "PHC is not available on ${ETH_DEVICE}."
356+
fi
357+
358+
# Check whether a PHC source is selected.
359+
if ! chronyc sources | grep "#\*\s*PHC" > /dev/null 2>&1; then
360+
fatal "PHC source is not selected as the clock soruce."
361+
fi
362+
363+
PHC_ID=$(chronyc sources | grep "#\*\s*PHC" | awk '{print $2}')
364+
EXTRA_ARGS="-r ${PHC_ID} -i ${ETH_DEVICE}"
347365
fi
348-
349-
PHC_ID=$(chronyc sources | grep "#\*\s*PHC" | awk '{print $2}')
350-
EXTRA_ARGS="-r ${PHC_ID} -i ${ETH_DEVICE}"
351366
fi
352367

353368
# Create the clockbound service file based on systemd version

bin/yugabyted

+10-4
Original file line numberDiff line numberDiff line change
@@ -666,14 +666,20 @@ def get_cli_title():
666666
cli_title += div_line
667667
return cli_title
668668

669-
def has_aws_time_sync_service():
669+
def using_time_sync_service():
670+
# List of recognized IP addresses and sources
671+
allow_list = ['169.254.169.123', 'metadata.google.internal', 'PHC',
672+
'aws.com', 'google.com']
673+
670674
try:
671675
# Run the chronyc sources command and capture the output
672676
result = subprocess.run(['chronyc', 'sources'], capture_output=True, text=True, timeout=1)
673677

674-
# Check if 169.254.169.123 is in the output
675-
if result.returncode == 0 and '169.254.169.123' in result.stdout:
676-
return True
678+
# Check if any allowed source is in the output
679+
if result.returncode == 0:
680+
for source in allow_list:
681+
if source in result.stdout:
682+
return True
677683
except (subprocess.TimeoutExpired, FileNotFoundError):
678684
return False
679685

0 commit comments

Comments
 (0)