aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitch Riedstra <mitch@riedstra.us>2019-02-18 16:33:04 -0500
committerMitch Riedstra <mitch@riedstra.us>2019-02-18 16:33:04 -0500
commit9f0c6e30cfea1c1b9f24fe0ee5811ace24d304b6 (patch)
tree7107476dc1e62b0145e2a71a37cd050d2a8ec54a
downloadsshauth-9f0c6e30cfea1c1b9f24fe0ee5811ace24d304b6.tar.gz
sshauth-9f0c6e30cfea1c1b9f24fe0ee5811ace24d304b6.tar.xz
Initial
-rw-r--r--gogs.patch17
-rwxr-xr-xgogsSSHAuthbin0 -> 6404231 bytes
-rw-r--r--main.go51
-rw-r--r--readme.md43
4 files changed, 111 insertions, 0 deletions
diff --git a/gogs.patch b/gogs.patch
new file mode 100644
index 0000000..e326f95
--- /dev/null
+++ b/gogs.patch
@@ -0,0 +1,17 @@
+diff --git a/routes/api/v1/api.go b/routes/api/v1/api.go
+index d73f57f3..a1658ac3 100644
+--- a/routes/api/v1/api.go
++++ b/routes/api/v1/api.go
+@@ -182,6 +182,11 @@ func RegisterRoutes(m *macaron.Macaron) {
+ m.Group("/users", func() {
+ m.Group("/:username", func() {
+ m.Get("/keys", user.ListPublicKeys)
++ })
++ })
++
++ m.Group("/users", func() {
++ m.Group("/:username", func() {
+
+ m.Get("/followers", user.ListFollowers)
+ m.Group("/following", func() {
+
diff --git a/gogsSSHAuth b/gogsSSHAuth
new file mode 100755
index 0000000..97838f5
--- /dev/null
+++ b/gogsSSHAuth
Binary files differ
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..5edfd64
--- /dev/null
+++ b/main.go
@@ -0,0 +1,51 @@
+package main
+
+import (
+ "encoding/json"
+ "flag"
+ "fmt"
+ "io/ioutil"
+ "log"
+ "net/http"
+)
+
+var (
+ endpoint = flag.String("e", "https://gogs.example.com/api/v1",
+ "Gogs server endpoint, possibly github e.g. https://api.github.com")
+ user = flag.String("u", "", "Username to look for")
+)
+
+type Key struct {
+ Key string `json: key`
+}
+
+func (k Key) String() string {
+ return k.Key
+}
+
+func errDie(err error) {
+ if err != nil {
+ log.Fatal(err)
+ }
+}
+
+func main() {
+ flag.Parse()
+
+ str := fmt.Sprintf("%s/users/%s/keys", *endpoint, *user)
+ resp, err := http.Get(str)
+ errDie(err)
+
+ defer resp.Body.Close()
+ b, err := ioutil.ReadAll(resp.Body)
+ errDie(err)
+
+ keyList := []Key{}
+
+ err = json.Unmarshal(b, &keyList)
+ errDie(err)
+
+ for _, k := range keyList {
+ fmt.Println(k)
+ }
+}
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..eb87175
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,43 @@
+# SSH Auth to Gogs or Github
+
+Small program to call out to a (patched) Gogs server and pull SSH keys
+from the API.
+
+This should work for Github as well with the endpoint adjusted.
+
+The main utility of this program is to be used to provide SSH keys to a Unix
+server without the need to manually place them on it.
+
+
+## Installing
+
+```
+go get git.stridet.com/Stridet/sshauth
+```
+
+```
+sudo install -m 555 -o root -g bin $GOPATH/bin/sshauth /usr/local/bin/
+```
+
+And then in `/etc/ssh/sshd_config`
+```
+AuthorizedKeysCommand sshauth -e https://git.stridet.com/api/v1 -u %u
+```
+
+See: http://man.openbsd.org/sshd_config#AuthorizedKeysCommand for more
+information.
+
+## Gogs Patch
+
+Used on commit `2c3e2b701e012294d457937e6bfbffd63dd8ae4f` it should work
+as expected with `git apply` and `go build`
+
+## Notes
+
+This obviously requires that your server have a working internet connection.
+Without it it'll just time out and you'll be locked out. This usually isn't
+a problem if you're using SSH though.
+
+If you have a highly restrictive firewall you're going to want to be sure to
+set up a special user and allow outbound network access.
+