使用 dotnet 5 访问 GCP 机密管理器的问题

时间:2021-03-27 07:55:40

标签: c# asp.net-core .net-core google-cloud-platform google-secret-manager

我在我的 .NET 5 aspnet 核心应用程序中使用 Google.Cloud.SecretManager.V1。我正在容器化应用程序以在 GCP Cloud run 上作为 linux 容器运行。创建 SecretManagerServiceClient 时出现以下异常

//call SDK
SecretManagerServiceClient client = SecretManagerServiceClient.Create();


System.DllNotFoundException: Unable to load shared library 'libdl.so' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibdl.so: cannot open shared object file: No such file or directory
   at Grpc.Core.Internal.UnmanagedLibrary.Linux.dlopen(String filename, Int32 flags)
   at Grpc.Core.Internal.UnmanagedLibrary.LoadLibraryPosix(Func`3 dlopenFunc, Func`1 dlerrorFunc, String libraryPath, String& errorMsg)
   at Grpc.Core.Internal.UnmanagedLibrary.PlatformSpecificLoadLibrary(String libraryPath, String& errorMsg)
   at Grpc.Core.Internal.UnmanagedLibrary..ctor(String[] libraryPathAlternatives)
   at Grpc.Core.Internal.NativeExtension.LoadUnmanagedLibrary()
   at Grpc.Core.Internal.NativeExtension.LoadNativeMethods()
   at Grpc.Core.Internal.NativeExtension..ctor()
   at Grpc.Core.Internal.NativeExtension.Get()
   at Grpc.Core.Internal.NativeMethods.Get()
   at Grpc.Core.GrpcEnvironment.GrpcNativeInit()
   at Grpc.Core.GrpcEnvironment..ctor()
   at Grpc.Core.GrpcEnvironment.AddRef()
   at Grpc.Core.Channel..ctor(String target, ChannelCredentials credentials, IEnumerable`1 options)
   at Google.Api.Gax.Grpc.GrpcCore.GrpcCoreAdapter.CreateChannelImpl(String endpoint, ChannelCredentials credentials, GrpcChannelOptions options)
   at Google.Api.Gax.Grpc.GrpcAdapter.CreateChannel(String endpoint, ChannelCredentials credentials, GrpcChannelOptions options)
   at Google.Api.Gax.Grpc.ChannelPool.GetChannel(GrpcAdapter grpcAdapter, String endpoint, GrpcChannelOptions channelOptions, ChannelCredentials credentials)
   at Google.Api.Gax.Grpc.ChannelPool.GetChannel(GrpcAdapter grpcAdapter, String endpoint, GrpcChannelOptions channelOptions)
   at Google.Api.Gax.Grpc.ClientBuilderBase`1.CreateCallInvoker()
   at Google.Cloud.SecretManager.V1.SecretManagerServiceClientBuilder.BuildImpl()
   at Google.Cloud.SecretManager.V1.SecretManagerServiceClientBuilder.Build()
   at Google.Cloud.SecretManager.V1.SecretManagerServiceClient.Create()

如果我使用 aspnetcore 3.1 图像,同样的代码工作正常。 NET 5 应该是 .NET core 3.1 的升级和向后兼容。所以,我很好奇可以做些什么来使这段代码在 .NET 5 上运行

1 个答案:

答案 0 :(得分:1)

我发布此答案是为了使评论部分中的解决方案更加明显。

正如 @John Hanley 所建议并由 @SmartCoder 确认的,这个问题已通过添加到下面的 Docker 文件行来解决:

RUN apt-get update -y 
RUN apt-get install -y libc6-dev