Skip to content

Commit

Permalink
tidy: cleanup oauth metadata logging
Browse files Browse the repository at this point in the history
  • Loading branch information
tinyzimmer committed Oct 18, 2023
1 parent 7141439 commit 4adc890
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 4 additions & 0 deletions internal/metadata/client_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/webmeshproj/storage-provider-k8s/provider"
"github.com/webmeshproj/webmesh/pkg/crypto"
"github.com/webmeshproj/webmesh/pkg/storage/types"
"sigs.k8s.io/controller-runtime/pkg/log"
)

// Ensure we implement the oauth2.ClientStore interface.
Expand Down Expand Up @@ -52,7 +53,10 @@ func NewClientStore(storage *provider.Provider, keys NodeKeyResolver) *ClientSto
func (c *ClientStore) GetByID(ctx context.Context, id string) (oauth2.ClientInfo, error) {
c.mu.Lock()
defer c.mu.Unlock()
log := log.FromContext(ctx).WithName("oauth-client-store")
log.V(1).Info("Looking up client by ID", "id", id)
if c.domain == "" {
log.V(1).Info("Fetching current cluster domain")
netstate, err := c.storage.MeshDB().MeshState().GetMeshState(ctx)
if err != nil {
return nil, err
Expand Down
18 changes: 14 additions & 4 deletions internal/metadata/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"net"
"net/http"
"net/netip"
"sort"
"strings"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -95,11 +96,11 @@ func NewServer(opts Options) *Server {
srv.oauth.SetAllowGetAccessRequest(true)
srv.oauth.SetClientInfoHandler(srv.getClientInfoFromRequest)
srv.oauth.SetInternalErrorHandler(func(err error) (re *errors.Response) {
srv.log.Error(err, "Internal oauth error")
srv.log.Error(err, "Internal metadata oauth error")
return
})
srv.oauth.SetResponseErrorHandler(func(re *errors.Response) {
srv.log.Error(fmt.Errorf("oauth response error: %s", re.Error.Error()), "Oauth response error")
srv.log.Info("Metadata oauth response error", "error", re.Error.Error())
})
mux.HandleFunc("/authorize", func(w http.ResponseWriter, r *http.Request) {
err := srv.oauth.HandleAuthorizeRequest(w, r)
Expand Down Expand Up @@ -170,12 +171,21 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
s.returnError(w, err)
return
}
var keys []string
for k := range m {
fmt.Fprintln(w, k)
keys = append(keys, k)
}
// Append the privateKey key if the request is local or we have a key resolver.
if (peerInfo.Local || s.KeyResolver != nil) && !peerInfo.Remote {
fmt.Fprintln(w, "privateKey")
keys = append(keys, "privateKey")
}
// Append oauth endpoints if enabled
if s.oauth != nil {
keys = append(keys, "authorize", "token")
}
sort.Strings(keys)
for _, k := range keys {
fmt.Fprintln(w, k)
}
return
default:
Expand Down

0 comments on commit 4adc890

Please sign in to comment.