Skip to content

Commit f130ae0

Browse files
author
wei
committed
fix(etcd): reject ambiguous peer URL ownership
1 parent d61fd51 commit f130ae0

2 files changed

Lines changed: 53 additions & 3 deletions

File tree

addons/etcd/scripts-ut-spec/member_join_spec.sh

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,20 @@ Describe "Etcd Member Join Script Tests"
117117
'"Name" : ""' \
118118
'"PeerURL" : "http://ETCD-1.ETCD-HEADLESS.DEFAULT.SVC.CLUSTER.LOCAL.:2380"' ''
119119
;;
120+
duplicate-canonical-owners)
121+
printf '%s\n' \
122+
'"ID" : 0' \
123+
'"Name" : "etcd-0"' \
124+
'"PeerURL" : "http://etcd-0.etcd-headless.default.svc.cluster.local:2380"' \
125+
'"ClientURL" : "http://etcd-0.etcd-headless.default.svc.cluster.local:2379"' '' \
126+
'"ID" : 1' \
127+
'"Name" : "etcd-1"' \
128+
'"PeerURL" : "http://etcd-1.etcd-headless.default.svc.cluster.local:2380"' \
129+
'"ClientURL" : "http://etcd-1.etcd-headless.default.svc.cluster.local:2379"' '' \
130+
'"ID" : 2' \
131+
'"Name" : ""' \
132+
'"PeerURL" : "http://ETCD-1.ETCD-HEADLESS.DEFAULT.SVC.CLUSTER.LOCAL.:2380"' ''
133+
;;
120134
unstarted-target-only)
121135
printf '%s\n' \
122136
'"ID" : 1' \
@@ -315,6 +329,30 @@ Describe "Etcd Member Join Script Tests"
315329
The output should eq "name-conflict"
316330
End
317331

332+
It "fails closed when started and unstarted members share a canonical peer URL"
333+
write_fields \
334+
'"ID" : 1' '"Name" : "etcd-1"' \
335+
'"PeerURL" : "http://etcd-1.example:2380"' '' \
336+
'"ID" : 2' '"Name" : ""' \
337+
'"PeerURL" : "http://ETCD-1.EXAMPLE.:2380"' ''
338+
When call classify_fixture "$TEST_DIR/member-list.fields" etcd-1 \
339+
http://etcd-1.example:2380
340+
The status should be failure
341+
The output should eq ""
342+
End
343+
344+
It "fails closed when two unstarted members share a canonical peer URL"
345+
write_fields \
346+
'"ID" : 1' '"Name" : ""' \
347+
'"PeerURL" : "http://etcd-1.example:2380"' '' \
348+
'"ID" : 2' '"Name" : ""' \
349+
'"PeerURL" : "http://ETCD-1.EXAMPLE.:2380"' ''
350+
When call classify_fixture "$TEST_DIR/member-list.fields" etcd-1 \
351+
http://etcd-1.example:2380
352+
The status should be failure
353+
The output should eq ""
354+
End
355+
318356
It "classifies the same name with another URL as a name conflict"
319357
write_fields \
320358
'"ID" : 1' \
@@ -359,12 +397,13 @@ Describe "Etcd Member Join Script Tests"
359397
The output should eq "name-conflict"
360398
End
361399

362-
It "gives an exact member plus same-URL foreign-name ghost a conflict verdict"
400+
It "fails closed for exact and foreign-name owners of the same peer URL"
363401
write_fields \
364402
'"ID" : 1' '"Name" : "etcd-1"' '"PeerURL" : "http://target:2380"' '' \
365403
'"ID" : 2' '"Name" : "other"' '"PeerURL" : "http://target:2380"' ''
366404
When call classify_fixture "$TEST_DIR/member-list.fields" etcd-1 http://target:2380
367-
The output should eq "peer-conflict"
405+
The status should be failure
406+
The output should eq ""
368407
End
369408

370409
It "accepts an exact member when one of multiple peer URLs matches"
@@ -669,6 +708,16 @@ Describe "Etcd Member Join Script Tests"
669708
The contents of file "$MEMBER_JOIN_READ_COUNT" should eq "1"
670709
End
671710

711+
It "fails closed before mutation when canonical target ownership is ambiguous"
712+
set_member_states duplicate-canonical-owners
713+
When call add_member
714+
The status should be failure
715+
The error should include "phase: member-list-invalid"
716+
The error should include "next-retry-safe: no"
717+
The contents of file "$MEMBER_JOIN_CALL_LOG" should eq ""
718+
The contents of file "$MEMBER_JOIN_READ_COUNT" should eq "1"
719+
End
720+
672721
It "closes an exact replay even when the target is the only current contact"
673722
set_member_states exact-only
674723
When call add_member

addons/etcd/scripts/member-join.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ classify_member_state() {
9292
}
9393
9494
if (peer_matches) {
95+
target_owner_count++
9596
if (member_name == target_name) {
9697
exact = 1
9798
} else if (member_name == "") {
@@ -155,7 +156,7 @@ classify_member_state() {
155156
156157
END {
157158
finish_member()
158-
if (!saw_member || malformed) {
159+
if (!saw_member || malformed || target_owner_count > 1) {
159160
exit 2
160161
} else if (name_conflict) {
161162
print "name-conflict"

0 commit comments

Comments
 (0)