@@ -113,3 +113,80 @@ func TestEtcdUnixPeers(t *testing.T) {
113
113
t .Fatal (err )
114
114
}
115
115
}
116
+
117
+ // TestEtcdPeerCNAuth checks that the inter peer auth based on CN of cert is working correctly.
118
+ func TestEtcdPeerCNAuth (t * testing.T ) {
119
+ peers , tmpdirs := make ([]string , 3 ), make ([]string , 3 )
120
+ for i := range peers {
121
+ peers [i ] = fmt .Sprintf ("e%d=https://127.0.0.1:%d" , i , etcdProcessBasePort + i )
122
+ d , err := ioutil .TempDir ("" , fmt .Sprintf ("e%d.etcd" , i ))
123
+ if err != nil {
124
+ t .Fatal (err )
125
+ }
126
+ tmpdirs [i ] = d
127
+ }
128
+ ic := strings .Join (peers , "," )
129
+
130
+ procs := make ([]* expect.ExpectProcess , len (peers ))
131
+ defer func () {
132
+ for i := range procs {
133
+ if procs [i ] != nil {
134
+ procs [i ].Stop ()
135
+ }
136
+ os .RemoveAll (tmpdirs [i ])
137
+ }
138
+ }()
139
+
140
+ // node 0 and 1 have a cert with the correct CN, node 2 doesn't
141
+ for i := range procs {
142
+ commonArgs := []string {
143
+ binDir + "/etcd" ,
144
+ "--name" , fmt .Sprintf ("e%d" , i ),
145
+ "--listen-client-urls" , "http://0.0.0.0:0" ,
146
+ "--data-dir" , tmpdirs [i ],
147
+ "--advertise-client-urls" , "http://0.0.0.0:0" ,
148
+ "--listen-peer-urls" , fmt .Sprintf ("https://127.0.0.1:%d,https://127.0.0.1:%d" , etcdProcessBasePort + i , etcdProcessBasePort + len (peers )+ i ),
149
+ "--initial-advertise-peer-urls" , fmt .Sprintf ("https://127.0.0.1:%d" , etcdProcessBasePort + i ),
150
+ "--initial-cluster" , ic ,
151
+ }
152
+
153
+ var args []string
154
+ if i <= 1 {
155
+ args = []string {
156
+ "--peer-cert-file" , certPath ,
157
+ "--peer-key-file" , privateKeyPath ,
158
+ "--peer-trusted-ca-file" , caPath ,
159
+ "--peer-client-cert-auth" ,
160
+ "--peer-cert-allowed-cn" , "example.com" ,
161
+ }
162
+ } else {
163
+ args = []string {
164
+ "--peer-cert-file" , certPath2 ,
165
+ "--peer-key-file" , privateKeyPath2 ,
166
+ "--peer-trusted-ca-file" , caPath ,
167
+ "--peer-client-cert-auth" ,
168
+ "--peer-cert-allowed-cn" , "example2.com" ,
169
+ }
170
+ }
171
+
172
+ commonArgs = append (commonArgs , args ... )
173
+
174
+ p , err := spawnCmd (commonArgs )
175
+ if err != nil {
176
+ t .Fatal (err )
177
+ }
178
+ procs [i ] = p
179
+ }
180
+
181
+ for i , p := range procs {
182
+ var expect []string
183
+ if i <= 1 {
184
+ expect = etcdServerReadyLines
185
+ } else {
186
+ expect = []string {"(remote error: tls: bad certificate)" }
187
+ }
188
+ if err := waitReadyExpectProc (p , expect ); err != nil {
189
+ t .Fatal (err )
190
+ }
191
+ }
192
+ }
0 commit comments