Skip to content

[Bug]: InvalidCastException when running with docker with TLS #813

@mciezczak312

Description

@mciezczak312

Testcontainers version

2.4.0

Using the latest Testcontainers version?

Yes

Host OS

Linux

Host arch

amd64

.NET version

6.0.400

Docker version

Client:
 Version:           20.10.18
 API version:       1.41
 Go version:        go1.18.6
 Git commit:        b40c2f6
 Built:             Thu Sep  8 23:05:51 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.23
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.10
  Git commit:       6051f14
  Built:            Thu Jan 19 17:36:08 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.6.15
  GitCommit:        5b842e528e99d4d4c1686467debf2bd4b88ecd86
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d1
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Docker info

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  compose: Docker Compose (Docker Inc., v2.5.0)

Server:
 Containers: 1
  Running: 0
  Paused: 0
  Stopped: 1
 Images: 3
 Server Version: 20.10.23
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: false
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 5b842e528e99d4d4c1686467debf2bd4b88ecd86
 runc version: v1.1.4-0-g5fd4c4d1
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.15.0-1031-azure
 Operating System: Alpine Linux v3.17 (containerized)
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 31.35GiB
 Name: github-runner-k8s-0
 ID: T5DM:5SLM:M75B:TI64:LUIN:SVSU:ZGEZ:GJVS:TXPU:B4IM:5XC4:UUA3
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

What happened?

I have a simple integration tests that spin up a docker container with SQL database. Everything seems to be working perfectly when running locally, but when the integration tests run on the GitHub agent with docker TLS enabled, I am just getting this InvalidCastException. Could it be something wrong with the docker setup on that build agent? Starting same SQL container 'manually' from the agent works just fine as well.

Relevant log output

Error Message:
   System.AggregateException : One or more errors occurred. (The type initializer for 'DotNet.Testcontainers.Configurations.TestcontainersSettings' threw an exception.) (The following constructor parameters did not have matching fixture data: SqlDbTestContainer testContainer)
---- System.TypeInitializationException : The type initializer for 'DotNet.Testcontainers.Configurations.TestcontainersSettings' threw an exception.
-------- System.InvalidCastException : Unable to cast object of type 'Org.BouncyCastle.Crypto.Parameters.RsaPrivateCrtKeyParameters' to type 'Org.BouncyCastle.Crypto.AsymmetricCipherKeyPair'.
---- The following constructor parameters did not have matching fixture data: SqlDbTestContainer testContainer
  Stack Trace:
  
----- Inner Stack Trace #1 (System.TypeInitializationException) -----
   at DotNet.Testcontainers.Configurations.TestcontainersSettings.get_SettingsInitialized()
   at DotNet.Testcontainers.Builders.AbstractBuilder`4..ctor(TConfigurationEntity dockerResourceConfiguration)
   at DotNet.Testcontainers.Builders.ContainerBuilder`3..ctor(TConfigurationEntity dockerResourceConfiguration)
   at DotNet.Testcontainers.Builders.ContainerBuilder`1..ctor(IContainerConfiguration dockerResourceConfiguration)
   at DotNet.Testcontainers.Builders.ContainerBuilder`1..ctor()
   at DotNet.Testcontainers.Builders.TestcontainersBuilder`1..ctor()
   at {...}IntegrationTests.SqlDbTestContainer..ctor() in /home/docker/actions-runner/_work/{...}/SqlDbTestContainer.cs:line 24
----- Inner Stack Trace -----
   at DotNet.Testcontainers.Builders.MTlsEndpointAuthenticationProvider.CreateFromPemFile(String certPemFilePath, String keyPemFilePath)
   at DotNet.Testcontainers.Builders.MTlsEndpointAuthenticationProvider.GetClientCertificate()
   at DotNet.Testcontainers.Builders.MTlsEndpointAuthenticationProvider.GetAuthConfig()
   at DotNet.Testcontainers.Builders.DockerEndpointAuthenticationProvider.IsAvailable()
   at DotNet.Testcontainers.Configurations.TestcontainersSettings.<>c.<.cctor>b__2_2(IDockerEndpointAuthenticationProvider authProvider)
   at System.Linq.Utilities.<>c__DisplayClass1_0`1.<CombinePredicates>b__0(TSource x)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Boolean& found)
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
   at DotNet.Testcontainers.Configurations.TestcontainersSettings..cctor()


### Additional information

_No response_

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions