modules: misc: Add some authorized key work

More testing and features are needed, but this is a good start.
This commit is contained in:
James Shubin
2025-05-09 04:11:04 -04:00
parent 7c5adb1fec
commit aa4320dd5f

View File

@@ -29,8 +29,10 @@
import "golang"
import "golang/strings"
import "iter"
import "net"
import "os"
import "world/collect"
# ssh_keygen creates an ssh key pair in the user's home directory if the private
# key doesn't exist.
@@ -61,6 +63,34 @@ class ssh_keygen($user) {
mode => "u=rw,go=",
owner => $user,
}
line "${user}@${hostname}" {
#file => "", # specified on collect
#state => "exists", # specified on collect
content => os.readfilewait("${p}.ssh/id_rsa.pub"),
Meta:hidden => true,
Meta:export => ["*",],
}
}
# ssh_authorized_keys pulls down an export key for a $user, from a user@host.
class ssh_authorized_keys($user, $from) {
panic($user == "") # panic if $user is empty
$p = os.expand_home("~${user}/") # eg: ~james/
$all = collect.res("line") # []struct{name str; host str;}
$fn = func($st) {
$st->name == "${from}" and $st->host != "${hostname}"
}
$filtered = iter.filter($all, $fn)
collect line $filtered { # pull down everyone's public keys
file => "${p}.ssh/authorized_keys",
state => $const.res.file.state.exists,
Meta:hidden => false,
}
}
# network_rename takes the device with the $mac address and renames it to $dev.