@@ -21,6 +21,7 @@ import (
21
21
"github.com/hashicorp/nomad/nomad"
22
22
"github.com/hashicorp/nomad/nomad/mock"
23
23
"github.com/hashicorp/nomad/nomad/structs"
24
+ nconfig "github.com/hashicorp/nomad/nomad/structs/config"
24
25
"github.com/hashicorp/nomad/testutil"
25
26
"github.com/mitchellh/hashstructure"
26
27
@@ -382,6 +383,98 @@ func TestClient_Drivers_WhitelistBlacklistCombination(t *testing.T) {
382
383
}
383
384
}
384
385
386
+ // TestClient_MixedTLS asserts that when a server is running with TLS enabled
387
+ // it will reject any RPC connections from clients that lack TLS. See #2525
388
+ func TestClient_MixedTLS (t * testing.T ) {
389
+ const (
390
+ cafile = "../helper/tlsutil/testdata/ca.pem"
391
+ foocert = "../helper/tlsutil/testdata/nomad-foo.pem"
392
+ fookey = "../helper/tlsutil/testdata/nomad-foo-key.pem"
393
+ )
394
+ s1 , addr := testServer (t , func (c * nomad.Config ) {
395
+ c .TLSConfig = & nconfig.TLSConfig {
396
+ EnableHTTP : true ,
397
+ EnableRPC : true ,
398
+ VerifyServerHostname : true ,
399
+ CAFile : cafile ,
400
+ CertFile : foocert ,
401
+ KeyFile : fookey ,
402
+ }
403
+ })
404
+ defer s1 .Shutdown ()
405
+ testutil .WaitForLeader (t , s1 .RPC )
406
+
407
+ c1 := testClient (t , func (c * config.Config ) {
408
+ c .Servers = []string {addr }
409
+ })
410
+ defer c1 .Shutdown ()
411
+
412
+ req := structs.NodeSpecificRequest {
413
+ NodeID : c1 .Node ().ID ,
414
+ QueryOptions : structs.QueryOptions {Region : "global" },
415
+ }
416
+ var out structs.SingleNodeResponse
417
+ deadline := time .Now ().Add (1234 * time .Millisecond )
418
+ for time .Now ().Before (deadline ) {
419
+ err := c1 .RPC ("Node.GetNode" , & req , & out )
420
+ if err == nil {
421
+ t .Fatalf ("client RPC succeeded when it should have failed:\n %+v" , out )
422
+ }
423
+ }
424
+ }
425
+
426
+ // TestClient_BadTLS asserts that when a client and server are running with TLS
427
+ // enabled -- but their certificates are signed by different CAs -- they're
428
+ // unable to communicate.
429
+ func TestClient_BadTLS (t * testing.T ) {
430
+ const (
431
+ cafile = "../helper/tlsutil/testdata/ca.pem"
432
+ foocert = "../helper/tlsutil/testdata/nomad-foo.pem"
433
+ fookey = "../helper/tlsutil/testdata/nomad-foo-key.pem"
434
+ badca = "../helper/tlsutil/testdata/ca-bad.pem"
435
+ badcert = "../helper/tlsutil/testdata/nomad-bad.pem"
436
+ badkey = "../helper/tlsutil/testdata/nomad-bad-key.pem"
437
+ )
438
+ s1 , addr := testServer (t , func (c * nomad.Config ) {
439
+ c .TLSConfig = & nconfig.TLSConfig {
440
+ EnableHTTP : true ,
441
+ EnableRPC : true ,
442
+ VerifyServerHostname : true ,
443
+ CAFile : cafile ,
444
+ CertFile : foocert ,
445
+ KeyFile : fookey ,
446
+ }
447
+ })
448
+ defer s1 .Shutdown ()
449
+ testutil .WaitForLeader (t , s1 .RPC )
450
+
451
+ c1 := testClient (t , func (c * config.Config ) {
452
+ c .Servers = []string {addr }
453
+ c .TLSConfig = & nconfig.TLSConfig {
454
+ EnableHTTP : true ,
455
+ EnableRPC : true ,
456
+ VerifyServerHostname : true ,
457
+ CAFile : badca ,
458
+ CertFile : badcert ,
459
+ KeyFile : badkey ,
460
+ }
461
+ })
462
+ defer c1 .Shutdown ()
463
+
464
+ req := structs.NodeSpecificRequest {
465
+ NodeID : c1 .Node ().ID ,
466
+ QueryOptions : structs.QueryOptions {Region : "global" },
467
+ }
468
+ var out structs.SingleNodeResponse
469
+ deadline := time .Now ().Add (1234 * time .Millisecond )
470
+ for time .Now ().Before (deadline ) {
471
+ err := c1 .RPC ("Node.GetNode" , & req , & out )
472
+ if err == nil {
473
+ t .Fatalf ("client RPC succeeded when it should have failed:\n %+v" , out )
474
+ }
475
+ }
476
+ }
477
+
385
478
func TestClient_Register (t * testing.T ) {
386
479
s1 , _ := testServer (t , nil )
387
480
defer s1 .Shutdown ()
0 commit comments