codenotary / immudb

immudb - immutable database based on zero trust, SQL/Key-Value/Document model, tamperproof, data change history
https://immudb.io
Other
8.54k stars 341 forks source link

Listing users in immugw using a token for a regular user crashes immudb #378

Closed padurean closed 4 years ago

padurean commented 4 years ago

What happened immudb crashes:

panic: runtime error: index out of range [-1]

goroutine 115 [running]:
github.com/codenotary/immudb/pkg/server.(*databaseList).GetByIndex(0xc00011ab70, 0xffffffffffffffff, 0x0)
        /Users/ogg/ws/github/immudb/pkg/server/databaselist.go:42 +0xc6
github.com/codenotary/immudb/pkg/server.(*ImmuServer).ListUsers(0xc000102600, 0x4afef40, 0xc0059b75f0, 0xc0059b7710, 0xc000102600, 0xc000438200, 0xc00045a670)
        /Users/ogg/ws/github/immudb/pkg/server/server.go:1170 +0x7f0
github.com/codenotary/immudb/pkg/api/schema._ImmuService_ListUsers_Handler.func1(0x4afef40, 0xc0059b75f0, 0x4905c80, 0xc0059b7710, 0x2, 0xc0059b23e0, 0xc00590e820, 0x47227a1)
        /Users/ogg/ws/github/immudb/pkg/api/schema/schema.pb.go:3820 +0x89
github.com/grpc-ecosystem/go-grpc-middleware.ChainUnaryServer.func1.1(0x4afef40, 0xc0059b75f0, 0x4905c80, 0xc0059b7710, 0x4af2500, 0xc0059cc660, 0xcb35008, 0xc0059cc660)
        /Users/ogg/go/pkg/mod/github.com/grpc-ecosystem/go-grpc-middleware@v1.0.0/chain.go:31 +0x114
github.com/codenotary/immudb/pkg/auth.ServerUnaryInterceptor(0x4afef40, 0xc0059b75f0, 0x4905c80, 0xc0059b7710, 0xc0059b2320, 0xc000092410, 0xc0059bac00, 0x3, 0x3, 0xcb35008)
        /Users/ogg/ws/github/immudb/pkg/auth/serverinterceptors.go:87 +0x78
github.com/grpc-ecosystem/go-grpc-middleware.ChainUnaryServer.func1.1(0x4afef40, 0xc0059b75f0, 0x4905c80, 0xc0059b7710, 0x24, 0xc0000925a0, 0xc00590e9b8, 0xc00590e958)
        /Users/ogg/go/pkg/mod/github.com/grpc-ecosystem/go-grpc-middleware@v1.0.0/chain.go:34 +0x9c
github.com/grpc-ecosystem/go-grpc-prometheus.(*ServerMetrics).UnaryServerInterceptor.func1(0x4afef40, 0xc0059b75f0, 0x4905c80, 0xc0059b7710, 0xc0059b2320, 0xc000092410, 0x49bfe01, 0xc0000ce1e8, 0xc00590ea38, 0x14)
        /Users/ogg/go/pkg/mod/github.com/grpc-ecosystem/go-grpc-prometheus@v1.2.0/server_metrics.go:107 +0xad
github.com/grpc-ecosystem/go-grpc-middleware.ChainUnaryServer.func1.1(0x4afef40, 0xc0059b75f0, 0x4905c80, 0xc0059b7710, 0x0, 0x14, 0x50, 0x48)
        /Users/ogg/go/pkg/mod/github.com/grpc-ecosystem/go-grpc-middleware@v1.0.0/chain.go:34 +0x9c
github.com/codenotary/immudb/pkg/server.(*uuidContext).UuidContextSetter(0xc0001320d0, 0x4afef40, 0xc0059b75f0, 0x4905c80, 0xc0059b7710, 0xc0059b2320, 0xc000092410, 0x50, 0x495d640, 0x1, ...)
        /Users/ogg/ws/github/immudb/pkg/server/uuid.go:104 +0x1b4
github.com/grpc-ecosystem/go-grpc-middleware.ChainUnaryServer.func1(0x4afef40, 0xc0059b75f0, 0x4905c80, 0xc0059b7710, 0xc0059b2320, 0xc0059b2360, 0xc00590eba0, 0x40f28c8, 0x49441e0, 0xc0059b75f0)
        /Users/ogg/go/pkg/mod/github.com/grpc-ecosystem/go-grpc-middleware@v1.0.0/chain.go:39 +0x155
github.com/codenotary/immudb/pkg/api/schema._ImmuService_ListUsers_Handler(0x49b4340, 0xc000102600, 0x4afef40, 0xc0059b75f0, 0xc000128540, 0xc00599a0f0, 0x4afef40, 0xc0059b75f0, 0x0, 0x0)
        /Users/ogg/ws/github/immudb/pkg/api/schema/schema.pb.go:3822 +0x14b
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000260000, 0x4b07bc0, 0xc005836900, 0xc00013e400, 0xc00599a240, 0x50b8260, 0x0, 0x0, 0x0)
        /Users/ogg/go/pkg/mod/google.golang.org/grpc@v1.29.1/server.go:1082 +0x50a
google.golang.org/grpc.(*Server).handleStream(0xc000260000, 0x4b07bc0, 0xc005836900, 0xc00013e400, 0x0)
        /Users/ogg/go/pkg/mod/google.golang.org/grpc@v1.29.1/server.go:1405 +0xccb
google.golang.org/grpc.(*Server).serveStreams.func1.1(0xc000132130, 0xc000260000, 0x4b07bc0, 0xc005836900, 0xc00013e400)
        /Users/ogg/go/pkg/mod/google.golang.org/grpc@v1.29.1/server.go:746 +0xa1
created by google.golang.org/grpc.(*Server).serveStreams.func1
        /Users/ogg/go/pkg/mod/google.golang.org/grpc@v1.29.1/server.go:744 +0xa1

What you expected to happen immudb should not crash while retrieving user list when the request is coming from immugw and the token belongs to a regular (non-admin) user.

How to reproduce it (as minimally and precisely as possible) Use immugw to login and obtain a token by loging-in with a regular user, then use the token to send a user list request to GET http://localhost:3323/v1/immurestproxy/user/list

Environment

immudb 0.6.2
Commit  : 96a9045d4ded987c82d8b508e5b4010994a683eb
Built by: 912518+padurean@users.noreply.github.com
Built at: Sun, 05 Jul 2020 17:51:09 EEST

Additional info (any other context about the problem) N/A

vchain-us-mgmt commented 4 years ago

retesting to check if still occurring

padurean commented 4 years ago

Issue is not reproducible anymore with code on master branch, after latest changes.