Skip to content

Commit

Permalink
Add multiple ssh public keys
Browse files Browse the repository at this point in the history
  • Loading branch information
rootmos committed Nov 19, 2023
1 parent 2df7f6f commit 7d6d446
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions openbsd
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,12 @@ class Autoinstall:
sets += spec.get("sets", [])
sets_directory = "sets"

post = [
"set -e",
f"rm /{mode}.site",
f"echo 'running {mode}.site'",
]

self.response_file = os.path.join(webroot, f"auto_{mode}.conf")
with open(self.response_file, "x") as f:
def line(l):
Expand All @@ -934,16 +940,25 @@ class Autoinstall:
else:
user = { "name": name }
with open(ssh_pub_key_path) as g:
user["ssh_pub_key"] = g.readlines()[0].strip()
user["ssh_pub_keys"] = [ g.readlines()[0].strip() ]

if user:
name = user['name']
name = user["name"]

pks = user.get("ssh_pub_keys", [])
if "ssh_pub_key" in user:
pks.append(user["ssh_pub_key"])
pk = pks[0]
for pk in pks[1:]:
post.append(f"echo {base64.b64encode(pk)} | b64decode | tee -a /home/{name}/.ssh/authorized_keys")

if name == "root":
line(f"Public ssh key for root account = {user['ssh_pub_key']}")
line(f"Public ssh key for root account = {pk}")
line(f"Allow root ssh login = yes")
else:
line(f"Setup a user = {name}")
line(f"Password for user {name} = {'*'*13}")
line(f"Public ssh key for user {name} = {user['ssh_pub_key']}")
line(f"Public ssh key for user {name} = {pk}")

if disklabel:
line(f"URL to autopartitioning template for disklabel = http://{http_internal_ip}/{disklabel}")
Expand Down Expand Up @@ -998,12 +1013,6 @@ class Autoinstall:
with open(__file__, "rb") as f:
self.site_file(f"{meta_dir}/installer.{ok_token}.py", mode=0o755, bytes=f.read())

post = [
"set -e",
f"rm /{mode}.site",
f"echo 'running {mode}.site'",
]

if mode == "install":
self.site_file("etc/installurl", lines(files.mirror))

Expand Down

0 comments on commit 7d6d446

Please sign in to comment.