Skip to content

Commit

Permalink
rpc: add a /health endpoint verifying KMS (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrislav committed Feb 29, 2024
1 parent 8645216 commit 2ca1d56
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
12 changes: 6 additions & 6 deletions rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,13 @@ func (s *RPC) Handler() http.Handler {
r.Use(middleware.PageRoute("/status", http.HandlerFunc(s.statusHandler)))
r.Use(middleware.PageRoute("/favicon.ico", http.HandlerFunc(emptyHandler)))

userRouter := r.Group(func(r chi.Router) {
// Generate attestation document
r.Use(attestation.Middleware(s.Enclave))
// Generate attestation document
r.Use(attestation.Middleware(s.Enclave))

// Healthcheck
r.Use(middleware.PageRoute("/health", http.HandlerFunc(s.healthHandler)))

userRouter := r.Group(func(r chi.Router) {
// Find and decrypt tenant data
r.Use(tenant.Middleware(s.Tenants, s.Config.KMS.TenantKeys))
})
Expand All @@ -203,9 +206,6 @@ func (s *RPC) Handler() http.Handler {
adminRouter := r.Group(func(r chi.Router) {
// Validate admin JWTs
r.Use(access.JWTAuthMiddleware(s.Config.Admin))

// Generate attestation document
r.Use(attestation.Middleware(s.Enclave))
})
adminRouter.Handle("/rpc/WaasAuthenticatorAdmin/*", proto.NewWaasAuthenticatorAdminServer(s))

Expand Down
11 changes: 11 additions & 0 deletions rpc/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

waasauthenticator "github.com/0xsequence/waas-authenticator"
"github.com/0xsequence/waas-authenticator/proto"
"github.com/0xsequence/waas-authenticator/rpc/attestation"
)

func (s *RPC) Version(ctx context.Context) (*proto.Version, error) {
Expand Down Expand Up @@ -46,3 +47,13 @@ func (s *RPC) statusHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
_ = json.NewEncoder(w).Encode(status)
}

func (s *RPC) healthHandler(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
att := attestation.FromContext(ctx)
if _, err := att.GenerateDataKey(ctx, s.Config.KMS.TenantKeys[0]); err != nil {
w.WriteHeader(http.StatusServiceUnavailable)
return
}
w.WriteHeader(http.StatusOK)
}

0 comments on commit 2ca1d56

Please sign in to comment.