Added source code

This commit is contained in:
Jan Christian Grünhage 2017-04-10 18:04:54 +02:00
parent 110ab9e4b0
commit 29cbbd67d4
Signed by: jcgruenhage
GPG Key ID: 321A67D9EE8BC3E1
3 changed files with 64 additions and 1 deletions

View File

@ -1,2 +1,10 @@
# borg-gen-auth-keys
### Generate an authorized_keys file:
When working with borg serve in an automated environment, you should use an authorized_keys file that restricts the ssh sessions to use only borg, and only in the directory where the repo they should use lies in. This binary takes in a json file specifying the needed info and prints out the wanted authorized_keys file.
To generate that file, do this (assuming you have set up everything needed for go get, and $GOPATH/bin is in your $PATH):
```bash
go get git.jcg.re/jcgruenhage/borg-gen-auth-keys
borg-gen-auth-keys yourjsonfile.json > ~/.ssh/authorized_keys
```

13
example.json Normal file
View File

@ -0,0 +1,13 @@
{
"Folder": "/mnt/backupmount",
"Hosts":[
{
"Name": "host1",
"SSHKey": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQC7ZvLoWZgh5eMDQXLEdWobkt/B8mnM2osEynF0boorifRNwztQHY3bKXTHjUlMnnWH+UvZ3aXH16M1QmyuNi4kLUTSMu4GSVsXMfknHRjgJ927Y/j5TCGXfOcfB0B4pcgHS3fVi1VMXXiZ1S/X8cbt1llXHfEC5eKutDeJkRer3w== SSH_KEY"
},
{
"Name": "host2",
"SSHKey": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDIgm31x6ETn4HwxBthe3m14s1Bp9p8sT5kC/XSijN6uPpUmuF2ciRGc5QLzsBJR6MAD45zg6Q9nLBZGBnSIZDNfSGA5sqAeoZVHm4vjQWxenqG7dlNFXlC1DIHzMxxDsDUPneyXGBemAvVwL9h4HEC4xhMQIAJfaZqSWuNzzqYWw== SSH_KEY"
}
]
}

42
main.go Normal file
View File

@ -0,0 +1,42 @@
package main
import (
"os"
"io/ioutil"
"encoding/json"
"fmt"
)
type Host struct {
Name string
SSHKey string
}
type HostList struct {
Folder string
Hosts []Host
}
func main() {
inputFilePath := os.Args[1]
dat, err := ioutil.ReadFile(inputFilePath)
check(err)
var hosts HostList
err = json.Unmarshal(dat, &hosts)
check(err)
for i := 0; i < len(hosts.Hosts); i++ {
fmt.Print("command=\"borg serve --restrict-to-path ")
fmt.Print(hosts.Folder)
fmt.Print("/")
fmt.Print(hosts.Hosts[i].Name)
fmt.Print("\",no-pty,no-agent-forwarding,no-port-forwarding,no-X11-forwarding,no-user-rc ")
fmt.Print(hosts.Hosts[i].SSHKey)
fmt.Print("\n")
}
}
func check(e error) {
if e != nil {
panic(e)
}
}