diff --git a/cmd/keyfetch/format_test.go b/cmd/keyfetch/format_test.go deleted file mode 100644 index 4d5b9d1..0000000 --- a/cmd/keyfetch/format_test.go +++ /dev/null @@ -1,45 +0,0 @@ -package main - -import "testing" - -func TestFormatKeyData(t *testing.T) { - tests := []struct { - name string - repoguardPath string - data map[string]string - want string - }{ - { - name: "single user", - repoguardPath: "/usr/bin/repoguard", - data: map[string]string{ - "user1": "ssh-rsa AAAA...", - }, - want: `command="/usr/bin/repoguard -base-dir /home/git -user user1 -log-path /home/git/log ",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa AAAA...` + "\n", - }, - { - name: "multiple users", - repoguardPath: "/usr/bin/repoguard", - data: map[string]string{ - "user1": "ssh-rsa AAAA...", - "user2": "ssh-rsa BBBB...", - }, - want: `command="/usr/bin/repoguard -base-dir /home/git -user user1 -log-path /home/git/log ",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa AAAA...` + "\n" + - `command="/usr/bin/repoguard -base-dir /home/git -user user2 -log-path /home/git/log ",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa BBBB...` + "\n", - }, - { - name: "empty data", - repoguardPath: "/usr/bin/repoguard", - data: map[string]string{}, - want: "", - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := formatKeyData(tt.repoguardPath, tt.data); got != tt.want { - t.Errorf("formatKeyData() = %v, want %v", got, tt.want) - } - }) - } -} diff --git a/cmd/knotserver/main.go b/cmd/knotserver/main.go index 362f8ab..6d59598 100644 --- a/cmd/knotserver/main.go +++ b/cmd/knotserver/main.go @@ -2,7 +2,6 @@ package main import ( "context" - "fmt" "net/http" "github.com/sotangled/tangled/knotserver" @@ -46,16 +45,13 @@ func main() { l.Error("failed to setup server", "error", err) return } - addr := fmt.Sprintf("%s:%d", c.Server.Host, c.Server.Port) - imux := knotserver.Internal(ctx, db, e) - iaddr := fmt.Sprintf("%s:%d", c.Server.Host, c.Server.InternalPort) - l.Info("starting internal server", "address", iaddr) - go http.ListenAndServe(iaddr, imux) + l.Info("starting internal server", "address", c.Server.InternalListenAddr) + go http.ListenAndServe(c.Server.InternalListenAddr, imux) - l.Info("starting main server", "address", addr) - l.Error("server error", "error", http.ListenAndServe(addr, mux)) + l.Info("starting main server", "address", c.Server.ListenAddr) + l.Error("server error", "error", http.ListenAndServe(c.Server.ListenAddr, mux)) return } diff --git a/knotserver/config/config.go b/knotserver/config/config.go index ca3ecc0..cb5f828 100644 --- a/knotserver/config/config.go +++ b/knotserver/config/config.go @@ -13,11 +13,12 @@ type Repo struct { } type Server struct { - Host string `env:"HOST, default=0.0.0.0"` - Port int `env:"PORT, default=5555"` - InternalPort int `env:"PORT, default=5444"` - Secret string `env:"SECRET, required"` - DBPath string `env:"DB_PATH, default=knotserver.db"` + ListenAddr string `env:"LISTEN_ADDR, default=0.0.0.0:5555"` + InternalListenAddr string `env:"INTERNAL_LISTEN_ADDR, default=0.0.0.0:5444"` + Secret string `env:"SECRET, required"` + DBPath string `env:"DB_PATH, default=knotserver.db"` + Hostname string `env:"HOSTNAME, required"` + // This disables signature verification so use with caution. Dev bool `env:"DEV, default=false"` } diff --git a/knotserver/jetstream.go b/knotserver/jetstream.go index 4ad3c80..ebb11e7 100644 --- a/knotserver/jetstream.go +++ b/knotserver/jetstream.go @@ -110,6 +110,12 @@ func (h *Handle) fetchAndAddKeys(ctx context.Context, did string) error { func (h *Handle) processKnotMember(ctx context.Context, did string, record map[string]interface{}) error { l := log.FromContext(ctx) + + if record["domain"] != h.c.Server.Hostname { + l.Error("domain mismatch", "domain", record["domain"], "expected", h.c.Server.Hostname) + return fmt.Errorf("domain mismatch: %s != %s", record["domain"], h.c.Server.Hostname) + } + ok, err := h.e.E.Enforce(did, ThisServer, ThisServer, "server:invite") if err != nil || !ok { l.Error("failed to add member", "did", did)