Skip to content

Commit 936f95c

Browse files
author
Brian McCallister
committed
use better middlewarez for ca server
1 parent 9d05b4a commit 936f95c

File tree

7 files changed

+22
-7
lines changed

7 files changed

+22
-7
lines changed

cmd/epithet-agent/epithet-agent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func run(cc *cobra.Command, args []string) error {
7373
if err != nil {
7474
return fmt.Errorf("unable to start agent %s: %w", name, err)
7575
}
76-
log.Infof("started agent [%s] [authn=%s] [agent=%s]", name, a.ControlSocketPath(), a.AgentSocketPath())
76+
log.Infof("started agent [%s] [control=%s] [agent=%s]", name, a.ControlSocketPath(), a.AgentSocketPath())
7777
defer a.Close()
7878
}
7979

cmd/epithet-auth/epithet-auth.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"strings"
99

1010
rpc "github.com/brianm/epithet/internal/agent"
11+
"github.com/sirupsen/logrus"
1112
"github.com/spf13/cobra"
1213
)
1314

@@ -28,6 +29,7 @@ func main() {
2829
fmt.Fprintln(os.Stderr, err)
2930
os.Exit(1)
3031
}
32+
logrus.Debugf("Authenticate success")
3133
}
3234

3335
func run(cc *cobra.Command, args []string) error {
@@ -46,7 +48,7 @@ func run(cc *cobra.Command, args []string) error {
4648
if err != nil {
4749
return err
4850
}
49-
51+
logrus.Debugf("invoking Authenticate")
5052
_, err = client.Authenticate(context.Background(), &rpc.AuthnRequest{
5153
Token: token,
5254
})

cmd/epithet-ca/epithet-ca.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ import (
55
"io/ioutil"
66
"net/http"
77
"os"
8+
"time"
89

910
"github.com/brianm/epithet/pkg/ca"
1011
"github.com/brianm/epithet/pkg/caserver"
1112
"github.com/brianm/epithet/pkg/sshcert"
13+
"github.com/go-chi/chi"
14+
"github.com/go-chi/chi/middleware"
1215
log "github.com/sirupsen/logrus"
1316
"github.com/spf13/cobra"
1417
)
@@ -70,10 +73,19 @@ func run(cc *cobra.Command, args []string) error {
7073
return fmt.Errorf("unable to create CA: %w", err)
7174
}
7275

73-
handler := caserver.New(c)
76+
r := chi.NewRouter()
77+
78+
// A good base middleware stack
79+
r.Use(middleware.RequestID)
80+
r.Use(middleware.RealIP)
81+
r.Use(middleware.Logger)
82+
r.Use(middleware.Recoverer)
83+
r.Use(middleware.Timeout(60 * time.Second))
84+
85+
r.Handle("/", caserver.New(c))
7486

7587
log.Infof("starting ca at %s", address)
76-
err = http.ListenAndServe(address, handler)
88+
err = http.ListenAndServe(address, r)
7789
if err != nil {
7890
return err
7991
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require (
1111
github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc // indirect
1212
github.com/docker/go-connections v0.4.0 // indirect
1313
github.com/docker/go-units v0.3.3 // indirect
14+
github.com/go-chi/chi v4.0.2+incompatible
1415
github.com/golang/protobuf v1.3.2
1516
github.com/gotestyourself/gotestyourself v2.2.0+incompatible // indirect
1617
github.com/kr/pretty v0.1.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ github.com/docker/go-units v0.3.3 h1:Xk8S3Xj5sLGlG5g67hJmYMmUgXv5N4PhkjJHHqrwnTk
2929
github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
3030
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
3131
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
32+
github.com/go-chi/chi v4.0.2+incompatible h1:maB6vn6FqCxrpz4FqWdh4+lwpyZIQS7YEAUcHlgXVRs=
33+
github.com/go-chi/chi v4.0.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ=
3234
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
3335
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
3436
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=

pkg/caserver/caserver.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/brianm/epithet/pkg/ca"
1212
"github.com/brianm/epithet/pkg/sshcert"
1313
"github.com/sirupsen/logrus"
14-
log "github.com/sirupsen/logrus"
1514
)
1615

1716
type caServer struct {
@@ -82,7 +81,6 @@ type CreateCertResponse struct {
8281
const RequestBodySizeLimit = 8192
8382

8483
func (s *caServer) createCert(w http.ResponseWriter, r *http.Request) {
85-
log.Debug("new create cert request")
8684
ccr := CreateCertRequest{}
8785
lr := io.LimitReader(r.Body, RequestBodySizeLimit)
8886

test/example_agent.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ testing:
1010
example-co:
1111
ca_url: https://ca.example.com/ssh/
1212
hooks:
13-
need_auth: "/usr/local/bin/epithet-oidc {{control_sock}}"
13+
need_auth: "epithet-oidc -f /usr/local/etc/epithet/groupon-oidc.yml -s {{control_sock}}"

0 commit comments

Comments
 (0)