|
|
@@ -191,6 +191,83 @@ func TestEtcdPeerCNAuth(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// TestEtcdPeerNameAuth checks that the inter peer auth based on cert name validation is working correctly.
|
|
|
+func TestEtcdPeerNameAuth(t *testing.T) {
|
|
|
+ peers, tmpdirs := make([]string, 3), make([]string, 3)
|
|
|
+ for i := range peers {
|
|
|
+ peers[i] = fmt.Sprintf("e%d=https://127.0.0.1:%d", i, etcdProcessBasePort+i)
|
|
|
+ d, err := ioutil.TempDir("", fmt.Sprintf("e%d.etcd", i))
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+ tmpdirs[i] = d
|
|
|
+ }
|
|
|
+ ic := strings.Join(peers, ",")
|
|
|
+
|
|
|
+ procs := make([]*expect.ExpectProcess, len(peers))
|
|
|
+ defer func() {
|
|
|
+ for i := range procs {
|
|
|
+ if procs[i] != nil {
|
|
|
+ procs[i].Stop()
|
|
|
+ }
|
|
|
+ os.RemoveAll(tmpdirs[i])
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ // node 0 and 1 have a cert with the correct certificate name, node 2 doesn't
|
|
|
+ for i := range procs {
|
|
|
+ commonArgs := []string{
|
|
|
+ binDir + "/etcd",
|
|
|
+ "--name", fmt.Sprintf("e%d", i),
|
|
|
+ "--listen-client-urls", "http://0.0.0.0:0",
|
|
|
+ "--data-dir", tmpdirs[i],
|
|
|
+ "--advertise-client-urls", "http://0.0.0.0:0",
|
|
|
+ "--listen-peer-urls", fmt.Sprintf("https://127.0.0.1:%d,https://127.0.0.1:%d", etcdProcessBasePort+i, etcdProcessBasePort+len(peers)+i),
|
|
|
+ "--initial-advertise-peer-urls", fmt.Sprintf("https://127.0.0.1:%d", etcdProcessBasePort+i),
|
|
|
+ "--initial-cluster", ic,
|
|
|
+ }
|
|
|
+
|
|
|
+ var args []string
|
|
|
+ if i <= 1 {
|
|
|
+ args = []string{
|
|
|
+ "--peer-cert-file", certPath,
|
|
|
+ "--peer-key-file", privateKeyPath,
|
|
|
+ "--peer-trusted-ca-file", caPath,
|
|
|
+ "--peer-client-cert-auth",
|
|
|
+ "--peer-cert-allowed-name", "example.com",
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ args = []string{
|
|
|
+ "--peer-cert-file", certPath2,
|
|
|
+ "--peer-key-file", privateKeyPath2,
|
|
|
+ "--peer-trusted-ca-file", caPath,
|
|
|
+ "--peer-client-cert-auth",
|
|
|
+ "--peer-cert-allowed-name", "example2.com",
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ commonArgs = append(commonArgs, args...)
|
|
|
+
|
|
|
+ p, err := spawnCmd(commonArgs)
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+ procs[i] = p
|
|
|
+ }
|
|
|
+
|
|
|
+ for i, p := range procs {
|
|
|
+ var expect []string
|
|
|
+ if i <= 1 {
|
|
|
+ expect = etcdServerReadyLines
|
|
|
+ } else {
|
|
|
+ expect = []string{"remote error: tls: bad certificate"}
|
|
|
+ }
|
|
|
+ if err := waitReadyExpectProc(p, expect); err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func TestGrpcproxyAndCommonName(t *testing.T) {
|
|
|
argsWithNonEmptyCN := []string{
|
|
|
binDir + "/etcd",
|