mirror of
https://gitlab.archlinux.org/archlinux/infrastructure.git
synced 2025-01-18 08:06:16 +01:00
This is meant to be used in the Hetzner cloud sandbox project, so SSH keys can be injected when a new VM is created from e.g. a CI pipeline, so that the CI pipeline can SSH to the newly created VM. The EC2 metadata service is used over the Hetzner metadata service, as it is supported by more providers (including Hetzner).
19 lines
404 B
Python
Executable File
19 lines
404 B
Python
Executable File
#!/usr/bin/python
|
|
|
|
import os
|
|
from pathlib import Path
|
|
|
|
import requests
|
|
|
|
data = requests.get("http://169.254.169.254/2009-04-04/meta-data/public-keys")
|
|
data.raise_for_status()
|
|
|
|
path = Path("/root/.ssh/authorized_keys")
|
|
path.parent.mkdir(mode=0o700, exist_ok=True)
|
|
os.chmod(path.parent, 0o700)
|
|
|
|
with open(path, "w") as file:
|
|
for key in data.json():
|
|
file.write(f"{key}\n")
|
|
os.chmod(path, 0o600)
|