@@ -393,6 +393,100 @@ func TestDocker(t *testing.T) {
393
393
require .True (t , recorder .ContainsLog ("Envbox startup complete!" ))
394
394
})
395
395
396
+ // This test provides backwards compatibility for older variants of envbox that may specify a
397
+ // Docker Auth config without a hostname key.
398
+ t .Run ("NoHostnameAuthConfig" , func (t * testing.T ) {
399
+ t .Parallel ()
400
+
401
+ var (
402
+ dir = integrationtest .TmpDir (t )
403
+ binds = integrationtest .DefaultBinds (t , dir )
404
+ )
405
+
406
+ pool , err := dockertest .NewPool ("" )
407
+ require .NoError (t , err )
408
+
409
+ // Create some listeners for the Docker and Coder
410
+ // services we'll be running with self signed certs.
411
+ bridgeIP := integrationtest .DockerBridgeIP (t )
412
+ coderListener , err := net .Listen ("tcp" , fmt .Sprintf ("%s:0" , bridgeIP ))
413
+ require .NoError (t , err )
414
+ defer coderListener .Close ()
415
+ coderAddr := tcpAddr (t , coderListener )
416
+
417
+ registryListener , err := net .Listen ("tcp" , fmt .Sprintf ("%s:0" , bridgeIP ))
418
+ require .NoError (t , err )
419
+ err = registryListener .Close ()
420
+ require .NoError (t , err )
421
+ registryAddr := tcpAddr (t , registryListener )
422
+
423
+ coderCert := integrationtest .GenerateTLSCertificate (t , "host.docker.internal" , coderAddr .IP .String ())
424
+ dockerCert := integrationtest .GenerateTLSCertificate (t , "host.docker.internal" , registryAddr .IP .String ())
425
+
426
+ // Startup our fake Coder "control-plane".
427
+ recorder := integrationtest .FakeBuildLogRecorder (t , coderListener , coderCert )
428
+
429
+ certDir := integrationtest .MkdirAll (t , dir , "certs" )
430
+
431
+ // Write the Coder cert disk.
432
+ coderCertPath := filepath .Join (certDir , "coder_cert.pem" )
433
+ coderKeyPath := filepath .Join (certDir , "coder_key.pem" )
434
+ integrationtest .WriteCertificate (t , coderCert , coderCertPath , coderKeyPath )
435
+ coderCertMount := integrationtest .BindMount (certDir , "/tmp/certs" , false )
436
+
437
+ // Write the Registry cert to disk.
438
+ regCertPath := filepath .Join (certDir , "registry_cert.crt" )
439
+ regKeyPath := filepath .Join (certDir , "registry_key.pem" )
440
+ integrationtest .WriteCertificate (t , dockerCert , regCertPath , regKeyPath )
441
+
442
+ username := "coder"
443
+ password := "helloworld"
444
+
445
+ // Start up the docker registry and push an image
446
+ // to it that we can reference.
447
+ image := integrationtest .RunLocalDockerRegistry (t , pool , integrationtest.RegistryConfig {
448
+ HostCertPath : regCertPath ,
449
+ HostKeyPath : regKeyPath ,
450
+ Image : integrationtest .UbuntuImage ,
451
+ TLSPort : strconv .Itoa (registryAddr .Port ),
452
+ PasswordDir : dir ,
453
+ Username : username ,
454
+ Password : password ,
455
+ })
456
+
457
+ type authConfigs struct {
458
+ Auths map [string ]dockerutil.AuthConfig `json:"auths"`
459
+ }
460
+
461
+ auths := authConfigs {
462
+ Auths : map [string ]dockerutil.AuthConfig {
463
+ "" : {Username : username , Password : password },
464
+ },
465
+ }
466
+
467
+ authStr , err := json .Marshal (auths )
468
+ require .NoError (t , err )
469
+
470
+ envs := []string {
471
+ integrationtest .EnvVar (cli .EnvAgentToken , "faketoken" ),
472
+ integrationtest .EnvVar (cli .EnvAgentURL , fmt .Sprintf ("https://%s:%d" , "host.docker.internal" , coderAddr .Port )),
473
+ integrationtest .EnvVar (cli .EnvExtraCertsPath , "/tmp/certs" ),
474
+ integrationtest .EnvVar (cli .EnvBoxPullImageSecretEnvVar , string (authStr )),
475
+ }
476
+
477
+ // Run the envbox container.
478
+ _ = integrationtest .RunEnvbox (t , pool , & integrationtest.CreateDockerCVMConfig {
479
+ Image : image .String (),
480
+ Username : "coder" ,
481
+ Envs : envs ,
482
+ OuterMounts : append (binds , coderCertMount ),
483
+ })
484
+
485
+ // This indicates we've made it all the way to end
486
+ // of the logs we attempt to push.
487
+ require .True (t , recorder .ContainsLog ("Envbox startup complete!" ))
488
+ })
489
+
396
490
// This tests the inverse of SelfSignedCerts. We assert that
397
491
// the container fails to startup since we don't have a valid
398
492
// cert for the registry. It mainly tests that we aren't
0 commit comments