1
1
mirror of https://gitlab.archlinux.org/archlinux/infrastructure.git synced 2025-01-18 08:06:16 +01:00
infrastructure/roles/install_arch/files/ec2-public-keys
Kristian Klausen 645b1a003c
Add small script to fetch SSH keys from the EC2 metadata service
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).
2023-08-19 22:02:13 +02:00

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)