Skip to content

Commit 125e77c

Browse files
authored
Merge pull request #44 from jojimt/cc-detect
fix: improved cc detection logic
2 parents eee2983 + 38bd2df commit 125e77c

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

main.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
from kubernetes import client, config, watch
3434
from kubernetes.client.rest import ApiException
3535

36-
from cpuinfo import get_cpu_info
37-
3836
# Import gpu-admin-tools
3937
try:
4038
from nvidia_gpu_tools import Gpu
@@ -86,19 +84,23 @@ def is_host_cc_enabled() -> bool:
8684
Returns:
8785
boolean status
8886
"""
89-
try:
90-
info = get_cpu_info()
91-
except Exception as e:
92-
logger.error(f"Failed to get CPU info for CC detection: {e}")
93-
return False
94-
95-
flags = info.get('flags', [])
96-
97-
# Check for specific CoCo indicators
98-
is_sev = 'sev' in flags
99-
is_tdx = 'tdx' in flags
100-
101-
return is_sev or is_tdx
87+
# 1. Check Intel TDX Host Status
88+
# Verify kvm_intel is loaded with tdx=1 and module is initialized
89+
tdx_param = "/sys/module/kvm_intel/parameters/tdx"
90+
if os.path.exists(tdx_param):
91+
with open(tdx_param, "r") as f:
92+
if f.read().strip().lower() in ['y', '1']:
93+
return True
94+
95+
# 2. Check AMD SEV-SNP Host Status
96+
# Verify kvm_amd is loaded with sev_snp enabled
97+
snp_param = "/sys/module/kvm_amd/parameters/sev_snp"
98+
if os.path.exists(snp_param):
99+
with open(snp_param, "r") as f:
100+
if f.read().strip().lower() in ['y', '1']:
101+
return True
102+
103+
return False
102104

103105
class CCManager:
104106
"""Manages NVIDIA GPU Confidential Computing mode based on Kubernetes node labels."""

0 commit comments

Comments
 (0)