Skip to content

Commit defcd3d

Browse files
authored
fix: Implement Persistent OS Login Authentication for TPU SSH (GoogleCloudPlatform#1172)
This change transitions the TPU SSH connection mechanism from ephemeral key injection to a persistent OS Login architecture. By leveraging long-lived SSH keys stored in the Service Account's OS Login profile, we eliminate the race conditions (409 Conflict) frequently encountered when running multiple concurrent TPU tasks in Airflow.
1 parent 461ab55 commit defcd3d

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

xlml/utils/tpu.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,16 @@ def ssh_tpu(
374374
client.get_node(name=os.path.join(node.parent, 'nodes', node.node_id))
375375
for node in queued_resource.tpu.node_spec
376376
]
377+
node_metadata = nodes[0].metadata
378+
is_oslogin_enabled = node_metadata.get('enable-oslogin', '') == 'TRUE'
379+
380+
user = 'ml-auto-solutions'
381+
if is_oslogin_enabled:
382+
logging.info('Auto-detected OS Login enabled on node {nodes[0].name}..')
383+
# get private key from Airflow Variable
384+
user = Variable.get('os-login-ssh-user')
385+
ssh_keys.private = Variable.get('os-login-ssh-private-key')
386+
ssh_keys.public = Variable.get('os-login-ssh-public-key')
377387

378388
if all_workers:
379389
endpoints = itertools.chain.from_iterable(
@@ -397,7 +407,7 @@ def ssh_tpu(
397407
*ip_addresses,
398408
connect_kwargs={
399409
'auth_strategy': paramiko.auth_strategy.InMemoryPrivateKey(
400-
'ml-auto-solutions', pkey
410+
user, pkey
401411
),
402412
# See https://stackoverflow.com/a/59453832
403413
'banner_timeout': 200,

0 commit comments

Comments
 (0)