@@ -186,6 +186,7 @@ func TestGCP_Init(t *testing.T) {
186
186
args args
187
187
wantErr bool
188
188
}{
189
+ {"ok" , fields {"GCP" , "name" , nil , zero , nil }, args {config , srv .URL }, false },
189
190
{"ok" , fields {"GCP" , "name" , nil , zero , nil }, args {config , srv .URL }, false },
190
191
{"ok" , fields {"GCP" , "name" , []string {"service-account" }, zero , nil }, args {config , srv .URL }, false },
191
192
{"ok" , fields {"GCP" , "name" , []string {"service-account" }, Duration {Duration : 1 * time .Minute }, nil }, args {config , srv .URL }, false },
@@ -211,6 +212,14 @@ func TestGCP_Init(t *testing.T) {
211
212
if err := p .Init (tt .args .config ); (err != nil ) != tt .wantErr {
212
213
t .Errorf ("GCP.Init() error = %v, wantErr %v" , err , tt .wantErr )
213
214
}
215
+
216
+ if * p .DisableSSHCAUser != true {
217
+ t .Errorf ("By default DisableSSHCAUser should be true" )
218
+ }
219
+
220
+ if * p .DisableSSHCAHost != false {
221
+ t .Errorf ("By default DisableSSHCAHost should be false" )
222
+ }
214
223
})
215
224
}
216
225
}
@@ -592,6 +601,9 @@ func TestGCP_AuthorizeSSHSign(t *testing.T) {
592
601
p1 , err := generateGCP ()
593
602
assert .FatalError (t , err )
594
603
p1 .DisableCustomSANs = true
604
+ // enable ssh user CA
605
+ disableSSCAUser := false
606
+ p1 .DisableSSHCAUser = & disableSSCAUser
595
607
596
608
p2 , err := generateGCP ()
597
609
assert .FatalError (t , err )
@@ -605,6 +617,12 @@ func TestGCP_AuthorizeSSHSign(t *testing.T) {
605
617
p3 .ctl .Claimer , err = NewClaimer (p3 .Claims , globalProvisionerClaims )
606
618
assert .FatalError (t , err )
607
619
620
+ p4 , err := generateGCP ()
621
+ assert .FatalError (t , err )
622
+ // disable ssh host CA
623
+ disableSSCAHost := true
624
+ p4 .DisableSSHCAHost = & disableSSCAHost
625
+
608
626
t1 , err := generateGCPToken (p1 .ServiceAccounts [0 ],
609
627
"https://accounts.google.com" , p1 .GetID (),
610
628
"instance-id" , "instance-name" , "project-id" , "zone" ,
@@ -647,6 +665,10 @@ func TestGCP_AuthorizeSSHSign(t *testing.T) {
647
665
CertType : "host" , Principals : []string {"foo.bar" , "bar.foo" },
648
666
ValidAfter : NewTimeDuration (tm ), ValidBefore : NewTimeDuration (tm .Add (hostDuration )),
649
667
}
668
+ expectedUserOptions := & SignSSHOptions {
669
+ CertType : "user" , Principals : []string {FormatServiceAccountUsername (p1 .ServiceAccounts [0 ]), "foo@developer.gserviceaccount.com" },
670
+ ValidAfter : NewTimeDuration (tm ), ValidBefore : NewTimeDuration (tm .Add (p1 .ctl .Claimer .DefaultUserSSHCertDuration ())),
671
+ }
650
672
651
673
type args struct {
652
674
token string
@@ -664,22 +686,29 @@ func TestGCP_AuthorizeSSHSign(t *testing.T) {
664
686
}{
665
687
{"ok" , p1 , args {t1 , SignSSHOptions {}, pub }, expectedHostOptions , http .StatusOK , false , false },
666
688
{"ok-rsa2048" , p1 , args {t1 , SignSSHOptions {}, rsa2048 .Public ()}, expectedHostOptions , http .StatusOK , false , false },
667
- {"ok-type" , p1 , args {t1 , SignSSHOptions {CertType : "host" }, pub }, expectedHostOptions , http .StatusOK , false , false },
689
+ {"ok-type-host" , p1 , args {t1 , SignSSHOptions {CertType : "host" }, pub }, expectedHostOptions , http .StatusOK , false , false },
690
+ {"ok-type-user" , p1 , args {t1 , SignSSHOptions {CertType : "user" }, pub }, expectedUserOptions , http .StatusOK , false , false },
668
691
{"ok-principals" , p1 , args {t1 , SignSSHOptions {Principals : []string {"instance-name.c.project-id.internal" , "instance-name.zone.c.project-id.internal" }}, pub }, expectedHostOptions , http .StatusOK , false , false },
669
692
{"ok-principal1" , p1 , args {t1 , SignSSHOptions {Principals : []string {"instance-name.c.project-id.internal" }}, pub }, expectedHostOptionsPrincipal1 , http .StatusOK , false , false },
670
693
{"ok-principal2" , p1 , args {t1 , SignSSHOptions {Principals : []string {"instance-name.zone.c.project-id.internal" }}, pub }, expectedHostOptionsPrincipal2 , http .StatusOK , false , false },
671
694
{"ok-options" , p1 , args {t1 , SignSSHOptions {CertType : "host" , Principals : []string {"instance-name.c.project-id.internal" , "instance-name.zone.c.project-id.internal" }}, pub }, expectedHostOptions , http .StatusOK , false , false },
672
695
{"ok-custom" , p2 , args {t2 , SignSSHOptions {Principals : []string {"foo.bar" , "bar.foo" }}, pub }, expectedCustomOptions , http .StatusOK , false , false },
673
696
{"fail-rsa1024" , p1 , args {t1 , SignSSHOptions {}, rsa1024 .Public ()}, expectedHostOptions , http .StatusOK , false , true },
674
- {"fail-type" , p1 , args {t1 , SignSSHOptions {CertType : "user" }, pub }, nil , http .StatusOK , false , true },
675
697
{"fail-principal" , p1 , args {t1 , SignSSHOptions {Principals : []string {"smallstep.com" }}, pub }, nil , http .StatusOK , false , true },
676
698
{"fail-extra-principal" , p1 , args {t1 , SignSSHOptions {Principals : []string {"instance-name.c.project-id.internal" , "instance-name.zone.c.project-id.internal" , "smallstep.com" }}, pub }, nil , http .StatusOK , false , true },
677
699
{"fail-sshCA-disabled" , p3 , args {"foo" , SignSSHOptions {}, pub }, expectedHostOptions , http .StatusUnauthorized , true , false },
700
+ {"fail-type-host" , p4 , args {"foo" , SignSSHOptions {CertType : "host" }, pub }, nil , http .StatusUnauthorized , true , false },
701
+ {"fail-type-user" , p4 , args {"foo" , SignSSHOptions {CertType : "host" }, pub }, nil , http .StatusUnauthorized , true , false },
678
702
{"fail-invalid-token" , p1 , args {"foo" , SignSSHOptions {}, pub }, expectedHostOptions , http .StatusUnauthorized , true , false },
679
703
}
680
704
for _ , tt := range tests {
681
705
t .Run (tt .name , func (t * testing.T ) {
682
- got , err := tt .gcp .AuthorizeSSHSign (context .Background (), tt .args .token )
706
+ ctx := context .Background ()
707
+ if tt .args .sshOpts .CertType == SSHUserCert {
708
+ ctx = NewContextWithCertType (ctx , SSHUserCert )
709
+ }
710
+
711
+ got , err := tt .gcp .AuthorizeSSHSign (ctx , tt .args .token )
683
712
if (err != nil ) != tt .wantErr {
684
713
t .Errorf ("GCP.AuthorizeSSHSign() error = %v, wantErr %v" , err , tt .wantErr )
685
714
return
0 commit comments