Skip to content

Commit

Permalink
feat: better error logs for identity role mapper script error (#1540)
Browse files Browse the repository at this point in the history
Co-authored-by: Moshe Immerman <[email protected]>
  • Loading branch information
adityathebe and moshloop authored Oct 25, 2024
1 parent 26d307d commit 6431e39
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion auth/kratos.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

Expand Down
7 changes: 5 additions & 2 deletions auth/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 != "" {
Expand Down
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down

0 comments on commit 6431e39

Please sign in to comment.