@@ -415,7 +415,7 @@ func TestProvision(t *testing.T) {
415
415
// nolint:paralleltest
416
416
func TestProvision_ExtraEnv (t * testing.T ) {
417
417
// #nosec
418
- secretValue : = "oinae3uinxase"
418
+ const secretValue = "oinae3uinxase"
419
419
t .Setenv ("TF_LOG" , "INFO" )
420
420
t .Setenv ("TF_SUPERSECRET" , secretValue )
421
421
@@ -459,3 +459,65 @@ func TestProvision_ExtraEnv(t *testing.T) {
459
459
}
460
460
require .True (t , found )
461
461
}
462
+
463
+ // nolint:paralleltest
464
+ func TestProvision_SafeEnv (t * testing.T ) {
465
+ // #nosec
466
+ const (
467
+ passedValue = "superautopets"
468
+ secretValue = "oinae3uinxase"
469
+ )
470
+ t .Setenv ("SOME_ENV" , passedValue )
471
+ // We must ensure CODER_ variables aren't passed through to avoid leaking
472
+ // control plane secrets (e.g. PG URL).
473
+ t .Setenv ("CODER_SECRET" , secretValue )
474
+
475
+ const echoResource = `
476
+ resource "null_resource" "a" {
477
+ provisioner "local-exec" {
478
+ command = "env"
479
+ }
480
+ }
481
+
482
+ `
483
+
484
+ ctx , api := setupProvisioner (t , nil )
485
+
486
+ directory := t .TempDir ()
487
+ path := filepath .Join (directory , "main.tf" )
488
+ err := os .WriteFile (path , []byte (echoResource ), 0o600 )
489
+ require .NoError (t , err )
490
+
491
+ request := & proto.Provision_Request {
492
+ Type : & proto.Provision_Request_Start {
493
+ Start : & proto.Provision_Start {
494
+ Directory : directory ,
495
+ Metadata : & proto.Provision_Metadata {
496
+ WorkspaceTransition : proto .WorkspaceTransition_START ,
497
+ },
498
+ },
499
+ },
500
+ }
501
+ response , err := api .Provision (ctx )
502
+ require .NoError (t , err )
503
+ err = response .Send (request )
504
+ require .NoError (t , err )
505
+ found := false
506
+ for {
507
+ msg , err := response .Recv ()
508
+ require .NoError (t , err )
509
+
510
+ if log := msg .GetLog (); log != nil {
511
+ t .Log (log .Level .String (), log .Output )
512
+ if strings .Contains (log .Output , passedValue ) {
513
+ found = true
514
+ }
515
+ require .NotContains (t , log .Output , secretValue )
516
+ }
517
+ if c := msg .GetComplete (); c != nil {
518
+ require .Empty (t , c .Error )
519
+ break
520
+ }
521
+ }
522
+ require .True (t , found )
523
+ }
0 commit comments