Skip to content

Commit 11e2ee6

Browse files
authored
feat: initial release (#1)
1 parent 07184b4 commit 11e2ee6

File tree

7 files changed

+199
-5
lines changed

7 files changed

+199
-5
lines changed

.github/workflows/ci.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ jobs:
1414
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
1515
restore-keys: |
1616
${{ runner.os }}-go-
17-
- name: Pull dependencies
18-
run: make build
17+
- name: Build
18+
run: make production
1919
lint:
2020
runs-on: ubuntu-latest
2121
steps:
@@ -29,5 +29,7 @@ jobs:
2929
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
3030
restore-keys: |
3131
${{ runner.os }}-go-
32-
- name: Pull dependencies
33-
run: make lint
32+
- name: Lint
33+
run: |
34+
go get -u golang.org/x/lint/golint
35+
golint -set_exit_status

Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM golang:1.14.4-alpine3.11 AS builder
2+
3+
RUN apk update && apk --no-cache add make git
4+
5+
WORKDIR /build
6+
7+
ARG GITHUB_ORGANIZATION
8+
ARG GITHUB_PAT
9+
10+
COPY go.mod go.mod
11+
COPY go.sum go.sum
12+
COPY main.go main.go
13+
COPY Makefile Makefile
14+
15+
RUN make production
16+
17+
FROM scratch
18+
19+
WORKDIR /opt
20+
21+
COPY --from=builder /build/bin/audit-org-keys audit-org-keys
22+
23+
ENTRYPOINT ["./audit-org-keys"]

Makefile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
PROJECT_NAME=audit-org-keys
2+
GOBASE=$(shell pwd)
3+
GOBIN=$(GOBASE)/bin/$(PROJECT_NAME)
4+
5+
.DEFAULT_GOAL := build
6+
7+
build:
8+
go build -o $(GOBIN)
9+
10+
build-docker:
11+
docker build \
12+
--build-arg "GITHUB_ORGANIZATION=$(GITHUB_ORGANIZATION)" \
13+
--build-arg "GITHUB_PAT=$(GITHUB_PAT)" \
14+
-t $(PROJECT_NAME):local .
15+
16+
clean:
17+
rm -rf $(GOBIN)
18+
19+
fmt:
20+
go fmt
21+
22+
hooks:
23+
cp -f .github/hooks/pre-commit .git/hooks/pre-commit
24+
25+
install:
26+
go mod download
27+
28+
production:
29+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o $(GOBIN)
30+
31+
run:
32+
make build
33+
$(GOBIN)
34+
35+
run-docker:
36+
make build-docker
37+
docker run --rm -it $(PROJECT_NAME):local
38+
39+
test:
40+
go test -v
41+
42+
vet:
43+
go vet -v

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# audit-org-keys
1+
# audit-org-keys [![ci](https://github.com/jef/audit-org-keys/workflows/ci/badge.svg)](https://github.com/jef/audit-org-keys/actions?query=workflow%3Aci)
22

33
The point of this project is to help demonstrate that users of GitHub could potentially fall victim to getting their private SSH key cracked. This based on the size and complexity of the key the user generates.
44

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/jef/audit-org-keys
2+
3+
go 1.14

go.sum

Whitespace-only changes.

main.go

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"io/ioutil"
7+
"log"
8+
"net/http"
9+
"os"
10+
)
11+
12+
const (
13+
githubURL = "https://github.com"
14+
githubOrgsAPI = "https://api.github.com/orgs"
15+
)
16+
17+
var (
18+
githubOrg = os.Getenv("GITHUB_ORGANIZATION")
19+
githubPat = os.Getenv("GITHUB_PAT")
20+
)
21+
22+
type member struct {
23+
Login string `json:"login"`
24+
}
25+
26+
func main() {
27+
fmt.Println("getting members")
28+
members := getMembers()
29+
30+
fmt.Println("getting keys")
31+
getKeys(members)
32+
}
33+
34+
func getKeys(members []member) {
35+
client := &http.Client{}
36+
37+
var membersWithNoKey []member
38+
39+
for _, member := range members {
40+
req, err := http.NewRequest(
41+
"GET",
42+
fmt.Sprintf("%s/%s.keys", githubURL, member.Login),
43+
nil,
44+
)
45+
if err != nil {
46+
log.Fatal(err)
47+
}
48+
req.Header.Add("authorization", fmt.Sprintf("token %s", githubPat))
49+
50+
res, err := client.Do(req)
51+
if err != nil {
52+
log.Fatal(err)
53+
}
54+
55+
defer res.Body.Close()
56+
57+
key, err := ioutil.ReadAll(res.Body)
58+
if err != nil {
59+
log.Fatal(err)
60+
}
61+
62+
if len(key) != 0 {
63+
fmt.Println(fmt.Sprintf("%s:\n%s", member.Login, key))
64+
fmt.Println("-------------------------------------------------------------------------------------")
65+
fmt.Println()
66+
} else {
67+
membersWithNoKey = append(membersWithNoKey, member)
68+
}
69+
}
70+
71+
fmt.Println(fmt.Sprintf("members with no keys (%d):", len(membersWithNoKey)))
72+
for _, member := range membersWithNoKey {
73+
fmt.Println(fmt.Sprintf("%s", member.Login))
74+
}
75+
}
76+
77+
func getMembers() []member {
78+
page := 1
79+
80+
var members []member
81+
82+
for {
83+
client := &http.Client{}
84+
85+
req, err := http.NewRequest(
86+
"GET",
87+
fmt.Sprintf("%s/%s/members?filter=all&page=%d", githubOrgsAPI, githubOrg, page),
88+
nil,
89+
)
90+
if err != nil {
91+
log.Fatal(err)
92+
}
93+
req.Header.Add("authorization", fmt.Sprintf("token %s", githubPat))
94+
95+
res, err := client.Do(req)
96+
if err != nil {
97+
log.Fatal(err)
98+
}
99+
100+
defer res.Body.Close()
101+
102+
body, err := ioutil.ReadAll(res.Body)
103+
if err != nil {
104+
log.Fatal(err)
105+
}
106+
107+
var ms []member
108+
109+
err = json.Unmarshal(body, &ms)
110+
if err != nil {
111+
log.Fatal(err)
112+
}
113+
114+
if len(ms) != 0 {
115+
members = append(members, ms...)
116+
page++
117+
} else {
118+
break
119+
}
120+
}
121+
122+
return members
123+
}

0 commit comments

Comments
 (0)