From 6431e3901a0d93915dd6dbca34319e9e1f3f388e Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Fri, 25 Oct 2024 17:33:06 +0545 Subject: [PATCH] feat: better error logs for identity role mapper script error (#1540) Co-authored-by: Moshe Immerman --- auth/kratos.go | 2 +- auth/middleware.go | 7 +++++-- go.mod | 8 +++++--- go.sum | 6 ++++-- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/auth/kratos.go b/auth/kratos.go index c41a743fb..d0ff40366 100644 --- a/auth/kratos.go +++ b/auth/kratos.go @@ -187,7 +187,7 @@ func (k *kratosMiddleware) Session(next echo.HandlerFunc) echo.HandlerFunc { if IdentityRoleMapper != "" { if err := mapIDsToRoles(mappingCtx, session, person); err != nil { ctx.GetSpan().RecordError(err) - mappingCtx.Errorf("error mapping ids to roles: %v", err) + mappingCtx.Error(err, "error mapping ids to roles") } } diff --git a/auth/middleware.go b/auth/middleware.go index 525d9a698..374ae6842 100644 --- a/auth/middleware.go +++ b/auth/middleware.go @@ -133,7 +133,7 @@ func mapIDsToRoles(ctx context.Context, session *client.Session, person models.P res, err := ctx.RunTemplate(gomplate.Template{Expression: IdentityRoleMapper}, env) if err != nil { - return fmt.Errorf("error running IdentityRoleMapper template: %v", err) + return fmt.Errorf("error running IdentityRoleMapper template: %w", err) } log.V(3).Infof("[%s] identity mapper returned %s", name, res) @@ -144,7 +144,10 @@ func mapIDsToRoles(ctx context.Context, session *client.Session, person models.P var result IdentityMapperExprResult if err := json.Unmarshal([]byte(res), &result); err != nil { - return err + return ctx.Oops(). + With("result", result). + Hint("https://docs.flanksource.com/reference/helm/mission-control/#identity-mapper"). + Wrapf(err, "identity role mapper did not produce a valid JSON encoded result") } if result.Role != "" { diff --git a/go.mod b/go.mod index 6b139e3ae..e89430b3a 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/casbin/gorm-adapter/v3 v3.26.0 github.com/containrrr/shoutrrr v0.8.0 github.com/fergusstrange/embedded-postgres v1.25.0 // indirect - github.com/flanksource/commons v1.29.10 + github.com/flanksource/commons v1.31.2 github.com/flanksource/duty v1.0.731 github.com/flanksource/gomplate/v3 v3.24.39 github.com/flanksource/kopper v1.0.10 @@ -151,6 +151,7 @@ require ( github.com/go-redis/redis v6.15.9+incompatible // indirect github.com/go-task/slim-sprig/v3 v3.0.0 // indirect github.com/gobwas/glob v0.2.3 // indirect + github.com/goccy/go-yaml v1.12.0 // indirect github.com/gofrs/uuid v4.2.0+incompatible // indirect github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect github.com/golang-sql/sqlexp v0.1.0 // indirect @@ -245,6 +246,7 @@ require ( golang.org/x/sync v0.8.0 // indirect golang.org/x/term v0.24.0 // indirect golang.org/x/tools v0.24.0 // indirect + golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect @@ -357,8 +359,8 @@ require ( sigs.k8s.io/yaml v1.4.0 ) -// replace github.com/flanksource/commons => /Users/moshe/go/src/github.com/flanksource/commons - // replace github.com/flanksource/duty => ../duty // replace github.com/flanksource/gomplate/v3 => ../gomplate + +// replace github.com/flanksource/commons => ../commons diff --git a/go.sum b/go.sum index 61cb97885..79d37fecc 100644 --- a/go.sum +++ b/go.sum @@ -875,8 +875,8 @@ github.com/fergusstrange/embedded-postgres v1.25.0 h1:sa+k2Ycrtz40eCRPOzI7Ry7Ttk github.com/fergusstrange/embedded-postgres v1.25.0/go.mod h1:t/MLs0h9ukYM6FSt99R7InCHs1nW0ordoVCcnzmpTYw= github.com/flanksource/artifacts v1.0.14 h1:Vv70bccsae0MwGaf/uSPp34J5V1/PyKfct9z5JYCTJU= github.com/flanksource/artifacts v1.0.14/go.mod h1:qHVCnQu5k50aWNJ5UhpcAKEl7pAzqUrFFKGSm147G70= -github.com/flanksource/commons v1.29.10 h1:T/S95Pl8kASEFvQjQ7fJjTUqeVdhxQXg1vfkULTYFJQ= -github.com/flanksource/commons v1.29.10/go.mod h1:iTbrXOSp3Spv570Nly97D/U9cQjLZoVlmWCXqWzsvRU= +github.com/flanksource/commons v1.31.2 h1:VBhmhmvk6PjhJYuaK8LL+7700E3zPCY03VV/K1BxH64= +github.com/flanksource/commons v1.31.2/go.mod h1:X2txnbNGY6fKQuKLmc7x92FMYjB2MuaqNJOR6vEWDMs= github.com/flanksource/duty v1.0.731 h1:aV3BicPMi2uK/Q7ZKBTakNKIv2uC+9EWQ/F1WOcazr4= github.com/flanksource/duty v1.0.731/go.mod h1:sZY2NytdenrkqXoMD6Gn2C8xH6dm5HsqOeE0p74Z2VE= github.com/flanksource/gomplate/v3 v3.20.4/go.mod h1:27BNWhzzSjDed1z8YShO6W+z6G9oZXuxfNFGd/iGSdc= @@ -987,6 +987,8 @@ github.com/go-test/deep v1.0.4/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3a github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= github.com/goccy/go-json v0.9.11/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/goccy/go-yaml v1.12.0 h1:/1WHjnMsI1dlIBQutrvSMGZRQufVO3asrHfTwfACoPM= +github.com/goccy/go-yaml v1.12.0/go.mod h1:wKnAMd44+9JAAnGQpWVEgBzGt3YuTaQ4uXoHvE4m7WU= github.com/gofrs/uuid v4.2.0+incompatible h1:yyYWMnhkhrKwwr8gAOcOCYxOOscHgDS9yZgBrnJfGa0= github.com/gofrs/uuid v4.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=