Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log panics originating from built-in plugins #5476

Merged
merged 3 commits into from
Sep 13, 2024

Conversation

azdagron
Copy link
Member

@azdagron azdagron commented Sep 6, 2024

Panics are caught and converted to an internal error by the grpc server middleware that hosts the built-in plugins. However, details about the panic, e.g., the call stack, are not swallowed, making them hard to debug.

This PR changes the panic middleware to log the panic stack to the ERROR log.

Also changed the plugintest framework to wire up a logger to the testing.T so we can observe these in tests.

ERRO[0000] Plugin panicked                               cause="oh no" external=false plugin_name=disk plugin_type=UpstreamAuthority stack="goroutine 84 [running]:\nruntime/debug.Stack()\n\t/Users/azdagron/sdk/go1.23.0/src/runtime/debug/stack.go:26 +0x64\ngithub.com/spiffe/spire/pkg/common/catalog.convertPanic({0x106b43a90, 0x1400028a8c0}, {0x1060c5900, 0x106aa42c0})\n\t/Users/azdagron/spiffe/spire/pkg/common/catalog/host.go:69 +0xb0\ngithub.com/spiffe/spire/pkg/common/catalog.newBuiltInServer.unaryPanicInterceptor.func3.1()\n\t/Users/azdagron/spiffe/spire/pkg/common/catalog/host.go:59 +0x54\npanic({0x1060c5900?, 0x106aa42c0?})\n\t/Users/azdagron/sdk/go1.23.0/src/runtime/panic.go:785 +0x124\ngithub.com/spiffe/spire/pkg/server/plugin/upstreamauthority/disk.(*Plugin).Configure(0x108b4ba80?, {0x1067789a0?, 0x106abf0f0?}, 0x14000399f80?)\n\t/Users/azdagron/spiffe/spire/pkg/server/plugin/upstreamauthority/disk/disk.go:76 +0x2c\ngithub.com/spiffe/spire-plugin-sdk/proto/spire/service/common/config/v1._Config_Configure_Handler.func1({0x106b0f3f8?, 0x14000962120?}, {0x1066e0260?, 0x14000399240?})\n\t/Users/azdagron/go/pkg/mod/github.com/spiffe/spire-plugin-sdk@v1.4.4-0.20230721151831-bf67dde4721d/proto/spire/service/common/config/v1/config_grpc.pb.go:96 +0xd0\ngithub.com/spiffe/spire/pkg/common/catalog.newBuiltInServer.unaryPanicInterceptor.func3({0x106b0f3f8?, 0x14000962120?}, {0x1066e0260?, 0x14000399240?}, 0x14000931828?, 0x102920bcc?)\n\t/Users/azdagron/spiffe/spire/pkg/common/catalog/host.go:62 +0x78\ngoogle.golang.org/grpc.getChainUnaryHandler.func1({0x106b0f3f8, 0x14000962120}, {0x1066e0260, 0x14000399240})\n\t/Users/azdagron/go/pkg/mod/google.golang.org/grpc@v1.66.0/server.go:1211 +0xa0\ngithub.com/spiffe/spire/pkg/common/catalog.(*drainHandlers).UnaryServerInterceptor(0x1400033c3b0, {0x106b0f3f8, 0x14000962120}, {0x1066e0260, 0x14000399240}, 0x0?, 0x140003992c0)\n\t/Users/azdagron/spiffe/spire/pkg/common/catalog/builtin.go:184 +0x90\ngoogle.golang.org/grpc.NewServer.chainUnaryServerInterceptors.chainUnaryInterceptors.func1({0x106b0f3f8, 0x14000962120}, {0x1066e0260, 0x14000399240}, 0x140005c8240, 0x1068e1260?)\n\t/Users/azdagron/go/pkg/mod/google.golang.org/grpc@v1.66.0/server.go:1202 +0x88\ngithub.com/spiffe/spire-plugin-sdk/proto/spire/service/common/config/v1._Config_Configure_Handler({0x1067789a0, 0x14000596780}, {0x106b0f3f8, 0x14000962120}, 0x14000938480, 0x1400039c720)\n\t/Users/azdagron/go/pkg/mod/github.com/spiffe/spire-plugin-sdk@v1.4.4-0.20230721151831-bf67dde4721d/proto/spire/service/common/config/v1/config_grpc.pb.go:98 +0x148\ngoogle.golang.org/grpc.(*Server).processUnaryRPC(0x14000924000, {0x106b0f3f8, 0x14000962090}, {0x106b21480, 0x140000fe1a0}, 0x14000394fc0, 0x1400059cde0, 0x108b4ba40, 0x0)\n\t/Users/azdagron/go/pkg/mod/google.golang.org/grpc@v1.66.0/server.go:1393 +0xb78\ngoogle.golang.org/grpc.(*Server).handleStream(0x14000924000, {0x106b21480, 0x140000fe1a0}, 0x14000394fc0)\n\t/Users/azdagron/go/pkg/mod/google.golang.org/grpc@v1.66.0/server.go:1804 +0xb20\ngoogle.golang.org/grpc.(*Server).serveStreams.func2.1()\n\t/Users/azdagron/go/pkg/mod/google.golang.org/grpc@v1.66.0/server.go:1029 +0x84\ncreated by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 81\n\t/Users/azdagron/go/pkg/mod/google.golang.org/grpc@v1.66.0/server.go:1040 +0x13c\n" subsystem_name=catalog

Panics are swallowed by the grpc server middleware that hosts the
built-in plugins, making it hard to debug.

This PR changes the panic middleware to log the panic stack to the ERROR
log.

Also changed the plugintest framework to wire up a logger to the
testing.T so we can observe these in tests.

```
ERRO[0000] Plugin panicked                               cause="oh no" external=false plugin_name=disk plugin_type=UpstreamAuthority stack="goroutine 84 [running]:\nruntime/debug.Stack()\n\t/Users/azdagron/sdk/go1.23.0/src/runtime/debug/stack.go:26 +0x64\ngithub.com/spiffe/spire/pkg/common/catalog.convertPanic({0x106b43a90, 0x1400028a8c0}, {0x1060c5900, 0x106aa42c0})\n\t/Users/azdagron/spiffe/spire/pkg/common/catalog/host.go:69 +0xb0\ngithub.com/spiffe/spire/pkg/common/catalog.newBuiltInServer.unaryPanicInterceptor.func3.1()\n\t/Users/azdagron/spiffe/spire/pkg/common/catalog/host.go:59 +0x54\npanic({0x1060c5900?, 0x106aa42c0?})\n\t/Users/azdagron/sdk/go1.23.0/src/runtime/panic.go:785 +0x124\ngithub.com/spiffe/spire/pkg/server/plugin/upstreamauthority/disk.(*Plugin).Configure(0x108b4ba80?, {0x1067789a0?, 0x106abf0f0?}, 0x14000399f80?)\n\t/Users/azdagron/spiffe/spire/pkg/server/plugin/upstreamauthority/disk/disk.go:76 +0x2c\ngithub.com/spiffe/spire-plugin-sdk/proto/spire/service/common/config/v1._Config_Configure_Handler.func1({0x106b0f3f8?, 0x14000962120?}, {0x1066e0260?, 0x14000399240?})\n\t/Users/azdagron/go/pkg/mod/github.com/spiffe/spire-plugin-sdk@v1.4.4-0.20230721151831-bf67dde4721d/proto/spire/service/common/config/v1/config_grpc.pb.go:96 +0xd0\ngithub.com/spiffe/spire/pkg/common/catalog.newBuiltInServer.unaryPanicInterceptor.func3({0x106b0f3f8?, 0x14000962120?}, {0x1066e0260?, 0x14000399240?}, 0x14000931828?, 0x102920bcc?)\n\t/Users/azdagron/spiffe/spire/pkg/common/catalog/host.go:62 +0x78\ngoogle.golang.org/grpc.getChainUnaryHandler.func1({0x106b0f3f8, 0x14000962120}, {0x1066e0260, 0x14000399240})\n\t/Users/azdagron/go/pkg/mod/google.golang.org/grpc@v1.66.0/server.go:1211 +0xa0\ngithub.com/spiffe/spire/pkg/common/catalog.(*drainHandlers).UnaryServerInterceptor(0x1400033c3b0, {0x106b0f3f8, 0x14000962120}, {0x1066e0260, 0x14000399240}, 0x0?, 0x140003992c0)\n\t/Users/azdagron/spiffe/spire/pkg/common/catalog/builtin.go:184 +0x90\ngoogle.golang.org/grpc.NewServer.chainUnaryServerInterceptors.chainUnaryInterceptors.func1({0x106b0f3f8, 0x14000962120}, {0x1066e0260, 0x14000399240}, 0x140005c8240, 0x1068e1260?)\n\t/Users/azdagron/go/pkg/mod/google.golang.org/grpc@v1.66.0/server.go:1202 +0x88\ngithub.com/spiffe/spire-plugin-sdk/proto/spire/service/common/config/v1._Config_Configure_Handler({0x1067789a0, 0x14000596780}, {0x106b0f3f8, 0x14000962120}, 0x14000938480, 0x1400039c720)\n\t/Users/azdagron/go/pkg/mod/github.com/spiffe/spire-plugin-sdk@v1.4.4-0.20230721151831-bf67dde4721d/proto/spire/service/common/config/v1/config_grpc.pb.go:98 +0x148\ngoogle.golang.org/grpc.(*Server).processUnaryRPC(0x14000924000, {0x106b0f3f8, 0x14000962090}, {0x106b21480, 0x140000fe1a0}, 0x14000394fc0, 0x1400059cde0, 0x108b4ba40, 0x0)\n\t/Users/azdagron/go/pkg/mod/google.golang.org/grpc@v1.66.0/server.go:1393 +0xb78\ngoogle.golang.org/grpc.(*Server).handleStream(0x14000924000, {0x106b21480, 0x140000fe1a0}, 0x14000394fc0)\n\t/Users/azdagron/go/pkg/mod/google.golang.org/grpc@v1.66.0/server.go:1804 +0xb20\ngoogle.golang.org/grpc.(*Server).serveStreams.func2.1()\n\t/Users/azdagron/go/pkg/mod/google.golang.org/grpc@v1.66.0/server.go:1029 +0x84\ncreated by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 81\n\t/Users/azdagron/go/pkg/mod/google.golang.org/grpc@v1.66.0/server.go:1040 +0x13c\n" subsystem_name=catalog
```

Signed-off-by: Andrew Harding <azdagron@gmail.com>
Signed-off-by: Andrew Harding <azdagron@gmail.com>
@azdagron azdagron changed the title Logs panics originating from built-in plugins Log panics originating from built-in plugins Sep 8, 2024
@amartinezfayo amartinezfayo self-assigned this Sep 10, 2024
Copy link
Member

@amartinezfayo amartinezfayo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @azdagron, looks great!

@amartinezfayo amartinezfayo added this to the 1.11.0 milestone Sep 12, 2024
@MarcosDY MarcosDY merged commit d7ca5f2 into spiffe:main Sep 13, 2024
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants