Skip to content

Commit

Permalink
debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
pawanpinjarkar committed Apr 23, 2024
1 parent 34ad1f1 commit 2ca2824
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/agentbasedinstaller/client/main.go
Expand Up @@ -133,7 +133,7 @@ func main() {
log.WithError(err).Fatalf(msg, args...)
}
}
failOnError(err, "failed to create authenticator")
failOnError(err, "failed to create agent authenticator")

h, err := restapi.Handler(restapi.Config{
AuthAgentAuth: authHandler.AuthAgentAuth,
Expand Down
7 changes: 7 additions & 0 deletions cmd/main.go
@@ -1,6 +1,7 @@
package main

import (
"bytes"
"context"
"encoding/json"
"flag"
Expand Down Expand Up @@ -289,6 +290,12 @@ func main() {
usageManager := usage.NewManager(log, notificationStream)
ocmClient := getOCMClient(log)

logrus.Infof("******* AuthType = %s", Options.Auth.AuthType)

logrus.Infof("******* ECPublicKeyPEM:\n%s", Options.Auth.ECPublicKeyPEM)
runeCount := len(bytes.Runes([]byte(Options.Auth.ECPublicKeyPEM)))
logrus.Infof("******* Length of ECPublicKeyPEM = %d", runeCount)

authHandler, err := auth.NewAuthenticator(&Options.Auth, ocmClient, log.WithField("pkg", "auth"), db)
failOnError(err, "failed to create authenticator")
authzHandler := auth.NewAuthzHandler(&Options.Auth, ocmClient, log.WithField("pkg", "authz"), db)
Expand Down
4 changes: 3 additions & 1 deletion pkg/auth/agent_local_authenticator.go
Expand Up @@ -60,6 +60,7 @@ func (a *AgentLocalAuthenticator) EnableOrgBasedFeatureGates() bool {
}

func (a *AgentLocalAuthenticator) AuthAgentAuth(token string) (interface{}, error) {
a.log.Infof(" **** token = %s, public key = %s", token, a.publicKey)
t, err := validateToken(token, a.publicKey)
if err != nil {
a.log.WithError(err).Error("failed to validate token")
Expand All @@ -73,6 +74,7 @@ func (a *AgentLocalAuthenticator) AuthAgentAuth(token string) (interface{}, erro
}

infraEnvID, infraEnvOk := claims[string(gencrypto.InfraEnvKey)].(string)
logrus.Infof("infraEnvID=%s", infraEnvID)
if !infraEnvOk {
err := errors.Errorf("claims are incorrectly formatted")
a.log.Error(err)
Expand All @@ -89,7 +91,7 @@ func (a *AgentLocalAuthenticator) AuthAgentAuth(token string) (interface{}, erro
return nil, common.NewInfraError(http.StatusUnauthorized, err)
}
}
a.log.Debugf("Authenticating infraEnv %s JWT", infraEnvID)
a.log.Infof("Authenticating infraEnv %s JWT", infraEnvID)
}

return ocm.AdminPayload(), nil
Expand Down
1 change: 1 addition & 0 deletions pkg/auth/authenticator.go
Expand Up @@ -52,6 +52,7 @@ func NewAuthenticator(cfg *Config, ocmClient *ocm.Client, log logrus.FieldLogger
case TypeLocal:
a, err = NewLocalAuthenticator(cfg, log, db)
case TypeAgentLocal:
log.Infof("About to create %s authenticator", cfg.AuthType)
a, err = NewAgentLocalAuthenticator(cfg, log, db)
default:
err = fmt.Errorf("invalid authenticator type %v", cfg.AuthType)
Expand Down
2 changes: 2 additions & 0 deletions pkg/auth/local_authenticator.go
Expand Up @@ -123,6 +123,8 @@ func (a *LocalAuthenticator) CreateAuthenticator() func(_, _ string, _ security.
}

func validateToken(token string, pub crypto.PublicKey) (*jwt.Token, error) {
logrus.Infof("**** token=%s", token)
logrus.Infof("**** pub=%s", pub)
parser := &jwt.Parser{ValidMethods: []string{jwt.SigningMethodES256.Alg()}}
parsed, err := parser.Parse(token, func(t *jwt.Token) (interface{}, error) { return pub, nil })

Expand Down

0 comments on commit 2ca2824

Please sign in to comment.