run.sh 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. #!/bin/sh
  2. rm -rf /tmp/m1.data /tmp/m2.data /tmp/m3.data
  3. /etc/init.d/bind9 start
  4. # get rid of hosts so go lookup won't resolve 127.0.0.1 to localhost
  5. cat /dev/null >/etc/hosts
  6. goreman -f /certs-common-name-auth/Procfile start &
  7. # TODO: remove random sleeps
  8. sleep 7s
  9. ETCDCTL_API=3 ./etcdctl \
  10. --cacert=/certs-common-name-auth/ca.crt \
  11. --cert=/certs-common-name-auth/server.crt \
  12. --key=/certs-common-name-auth/server.key.insecure \
  13. --endpoints=https://m1.etcd.local:2379 \
  14. endpoint health --cluster
  15. ETCDCTL_API=3 ./etcdctl \
  16. --cacert=/certs-common-name-auth/ca.crt \
  17. --cert=/certs-common-name-auth/server.crt \
  18. --key=/certs-common-name-auth/server.key.insecure \
  19. --endpoints=https://m1.etcd.local:2379,https://m2.etcd.local:22379,https://m3.etcd.local:32379 \
  20. put abc def
  21. ETCDCTL_API=3 ./etcdctl \
  22. --cacert=/certs-common-name-auth/ca.crt \
  23. --cert=/certs-common-name-auth/server.crt \
  24. --key=/certs-common-name-auth/server.key.insecure \
  25. --endpoints=https://m1.etcd.local:2379,https://m2.etcd.local:22379,https://m3.etcd.local:32379 \
  26. get abc
  27. sleep 1s && printf "\n"
  28. echo "Step 1. creating root role"
  29. ETCDCTL_API=3 ./etcdctl \
  30. --cacert=/certs-common-name-auth/ca.crt \
  31. --cert=/certs-common-name-auth/server.crt \
  32. --key=/certs-common-name-auth/server.key.insecure \
  33. --endpoints=https://m1.etcd.local:2379,https://m2.etcd.local:22379,https://m3.etcd.local:32379 \
  34. role add root
  35. sleep 1s && printf "\n"
  36. echo "Step 2. granting readwrite 'foo' permission to role 'root'"
  37. ETCDCTL_API=3 ./etcdctl \
  38. --cacert=/certs-common-name-auth/ca.crt \
  39. --cert=/certs-common-name-auth/server.crt \
  40. --key=/certs-common-name-auth/server.key.insecure \
  41. --endpoints=https://m1.etcd.local:2379,https://m2.etcd.local:22379,https://m3.etcd.local:32379 \
  42. role grant-permission root readwrite foo
  43. sleep 1s && printf "\n"
  44. echo "Step 3. getting role 'root'"
  45. ETCDCTL_API=3 ./etcdctl \
  46. --cacert=/certs-common-name-auth/ca.crt \
  47. --cert=/certs-common-name-auth/server.crt \
  48. --key=/certs-common-name-auth/server.key.insecure \
  49. --endpoints=https://m1.etcd.local:2379,https://m2.etcd.local:22379,https://m3.etcd.local:32379 \
  50. role get root
  51. sleep 1s && printf "\n"
  52. echo "Step 4. creating user 'root'"
  53. ETCDCTL_API=3 ./etcdctl \
  54. --cacert=/certs-common-name-auth/ca.crt \
  55. --cert=/certs-common-name-auth/server.crt \
  56. --key=/certs-common-name-auth/server.key.insecure \
  57. --endpoints=https://m1.etcd.local:2379,https://m2.etcd.local:22379,https://m3.etcd.local:32379 \
  58. --interactive=false \
  59. user add root:123
  60. sleep 1s && printf "\n"
  61. echo "Step 5. granting role 'root' to user 'root'"
  62. ETCDCTL_API=3 ./etcdctl \
  63. --cacert=/certs-common-name-auth/ca.crt \
  64. --cert=/certs-common-name-auth/server.crt \
  65. --key=/certs-common-name-auth/server.key.insecure \
  66. --endpoints=https://m1.etcd.local:2379,https://m2.etcd.local:22379,https://m3.etcd.local:32379 \
  67. user grant-role root root
  68. sleep 1s && printf "\n"
  69. echo "Step 6. getting user 'root'"
  70. ETCDCTL_API=3 ./etcdctl \
  71. --cacert=/certs-common-name-auth/ca.crt \
  72. --cert=/certs-common-name-auth/server.crt \
  73. --key=/certs-common-name-auth/server.key.insecure \
  74. --endpoints=https://m1.etcd.local:2379,https://m2.etcd.local:22379,https://m3.etcd.local:32379 \
  75. user get root
  76. sleep 1s && printf "\n"
  77. echo "Step 7. enabling auth"
  78. ETCDCTL_API=3 ./etcdctl \
  79. --cacert=/certs-common-name-auth/ca.crt \
  80. --cert=/certs-common-name-auth/server.crt \
  81. --key=/certs-common-name-auth/server.key.insecure \
  82. --endpoints=https://m1.etcd.local:2379,https://m2.etcd.local:22379,https://m3.etcd.local:32379 \
  83. auth enable
  84. sleep 1s && printf "\n"
  85. echo "Step 8. writing 'foo' with 'root:123'"
  86. ETCDCTL_API=3 ./etcdctl \
  87. --cacert=/certs-common-name-auth/ca.crt \
  88. --cert=/certs-common-name-auth/server.crt \
  89. --key=/certs-common-name-auth/server.key.insecure \
  90. --endpoints=https://m1.etcd.local:2379,https://m2.etcd.local:22379,https://m3.etcd.local:32379 \
  91. --user=root:123 \
  92. put foo bar
  93. sleep 1s && printf "\n"
  94. echo "Step 9. writing 'aaa' with 'root:123'"
  95. ETCDCTL_API=3 ./etcdctl \
  96. --cacert=/certs-common-name-auth/ca.crt \
  97. --cert=/certs-common-name-auth/server.crt \
  98. --key=/certs-common-name-auth/server.key.insecure \
  99. --endpoints=https://m1.etcd.local:2379,https://m2.etcd.local:22379,https://m3.etcd.local:32379 \
  100. --user=root:123 \
  101. put aaa bbb
  102. sleep 1s && printf "\n"
  103. echo "Step 10. writing 'foo' without 'root:123'"
  104. ETCDCTL_API=3 ./etcdctl \
  105. --cacert=/certs-common-name-auth/ca.crt \
  106. --cert=/certs-common-name-auth/server.crt \
  107. --key=/certs-common-name-auth/server.key.insecure \
  108. --endpoints=https://m1.etcd.local:2379,https://m2.etcd.local:22379,https://m3.etcd.local:32379 \
  109. put foo bar
  110. sleep 1s && printf "\n"
  111. echo "Step 11. reading 'foo' with 'root:123'"
  112. ETCDCTL_API=3 ./etcdctl \
  113. --cacert=/certs-common-name-auth/ca.crt \
  114. --cert=/certs-common-name-auth/server.crt \
  115. --key=/certs-common-name-auth/server.key.insecure \
  116. --endpoints=https://m1.etcd.local:2379,https://m2.etcd.local:22379,https://m3.etcd.local:32379 \
  117. --user=root:123 \
  118. get foo
  119. sleep 1s && printf "\n"
  120. echo "Step 12. reading 'aaa' with 'root:123'"
  121. ETCDCTL_API=3 ./etcdctl \
  122. --cacert=/certs-common-name-auth/ca.crt \
  123. --cert=/certs-common-name-auth/server.crt \
  124. --key=/certs-common-name-auth/server.key.insecure \
  125. --endpoints=https://m1.etcd.local:2379,https://m2.etcd.local:22379,https://m3.etcd.local:32379 \
  126. --user=root:123 \
  127. get aaa
  128. sleep 1s && printf "\n"
  129. echo "Step 13. creating a new user 'test-common-name:test-pass'"
  130. ETCDCTL_API=3 ./etcdctl \
  131. --cacert=/certs-common-name-auth/ca.crt \
  132. --cert=/certs-common-name-auth/server.crt \
  133. --key=/certs-common-name-auth/server.key.insecure \
  134. --endpoints=https://m1.etcd.local:2379,https://m2.etcd.local:22379,https://m3.etcd.local:32379 \
  135. --user=root:123 \
  136. --interactive=false \
  137. user add test-common-name:test-pass
  138. sleep 1s && printf "\n"
  139. echo "Step 14. creating a role 'test-role'"
  140. ETCDCTL_API=3 ./etcdctl \
  141. --cacert=/certs-common-name-auth/ca.crt \
  142. --cert=/certs-common-name-auth/server.crt \
  143. --key=/certs-common-name-auth/server.key.insecure \
  144. --endpoints=https://m1.etcd.local:2379,https://m2.etcd.local:22379,https://m3.etcd.local:32379 \
  145. --user=root:123 \
  146. role add test-role
  147. sleep 1s && printf "\n"
  148. echo "Step 15. granting readwrite 'aaa' --prefix permission to role 'test-role'"
  149. ETCDCTL_API=3 ./etcdctl \
  150. --cacert=/certs-common-name-auth/ca.crt \
  151. --cert=/certs-common-name-auth/server.crt \
  152. --key=/certs-common-name-auth/server.key.insecure \
  153. --endpoints=https://m1.etcd.local:2379,https://m2.etcd.local:22379,https://m3.etcd.local:32379 \
  154. --user=root:123 \
  155. role grant-permission test-role readwrite aaa --prefix
  156. sleep 1s && printf "\n"
  157. echo "Step 16. getting role 'test-role'"
  158. ETCDCTL_API=3 ./etcdctl \
  159. --cacert=/certs-common-name-auth/ca.crt \
  160. --cert=/certs-common-name-auth/server.crt \
  161. --key=/certs-common-name-auth/server.key.insecure \
  162. --endpoints=https://m1.etcd.local:2379,https://m2.etcd.local:22379,https://m3.etcd.local:32379 \
  163. --user=root:123 \
  164. role get test-role
  165. sleep 1s && printf "\n"
  166. echo "Step 17. granting role 'test-role' to user 'test-common-name'"
  167. ETCDCTL_API=3 ./etcdctl \
  168. --cacert=/certs-common-name-auth/ca.crt \
  169. --cert=/certs-common-name-auth/server.crt \
  170. --key=/certs-common-name-auth/server.key.insecure \
  171. --endpoints=https://m1.etcd.local:2379,https://m2.etcd.local:22379,https://m3.etcd.local:32379 \
  172. --user=root:123 \
  173. user grant-role test-common-name test-role
  174. sleep 1s && printf "\n"
  175. echo "Step 18. writing 'aaa' with 'test-common-name:test-pass'"
  176. ETCDCTL_API=3 ./etcdctl \
  177. --cacert=/certs-common-name-auth/ca.crt \
  178. --cert=/certs-common-name-auth/server.crt \
  179. --key=/certs-common-name-auth/server.key.insecure \
  180. --endpoints=https://m1.etcd.local:2379,https://m2.etcd.local:22379,https://m3.etcd.local:32379 \
  181. --user=test-common-name:test-pass \
  182. put aaa bbb
  183. sleep 1s && printf "\n"
  184. echo "Step 19. writing 'bbb' with 'test-common-name:test-pass'"
  185. ETCDCTL_API=3 ./etcdctl \
  186. --cacert=/certs-common-name-auth/ca.crt \
  187. --cert=/certs-common-name-auth/server.crt \
  188. --key=/certs-common-name-auth/server.key.insecure \
  189. --endpoints=https://m1.etcd.local:2379,https://m2.etcd.local:22379,https://m3.etcd.local:32379 \
  190. --user=test-common-name:test-pass \
  191. put bbb bbb
  192. sleep 1s && printf "\n"
  193. echo "Step 20. reading 'aaa' with 'test-common-name:test-pass'"
  194. ETCDCTL_API=3 ./etcdctl \
  195. --cacert=/certs-common-name-auth/ca.crt \
  196. --cert=/certs-common-name-auth/server.crt \
  197. --key=/certs-common-name-auth/server.key.insecure \
  198. --endpoints=https://m1.etcd.local:2379,https://m2.etcd.local:22379,https://m3.etcd.local:32379 \
  199. --user=test-common-name:test-pass \
  200. get aaa
  201. sleep 1s && printf "\n"
  202. echo "Step 21. reading 'bbb' with 'test-common-name:test-pass'"
  203. ETCDCTL_API=3 ./etcdctl \
  204. --cacert=/certs-common-name-auth/ca.crt \
  205. --cert=/certs-common-name-auth/server.crt \
  206. --key=/certs-common-name-auth/server.key.insecure \
  207. --endpoints=https://m1.etcd.local:2379,https://m2.etcd.local:22379,https://m3.etcd.local:32379 \
  208. --user=test-common-name:test-pass \
  209. get bbb
  210. sleep 1s && printf "\n"
  211. echo "Step 22. writing 'aaa' with CommonName 'test-common-name'"
  212. ETCDCTL_API=3 ./etcdctl \
  213. --cacert=/certs-common-name-auth/ca.crt \
  214. --cert=/certs-common-name-auth/server.crt \
  215. --key=/certs-common-name-auth/server.key.insecure \
  216. --endpoints=https://m1.etcd.local:2379,https://m2.etcd.local:22379,https://m3.etcd.local:32379 \
  217. put aaa ccc
  218. sleep 1s && printf "\n"
  219. echo "Step 23. reading 'aaa' with CommonName 'test-common-name'"
  220. ETCDCTL_API=3 ./etcdctl \
  221. --cacert=/certs-common-name-auth/ca.crt \
  222. --cert=/certs-common-name-auth/server.crt \
  223. --key=/certs-common-name-auth/server.key.insecure \
  224. --endpoints=https://m1.etcd.local:2379,https://m2.etcd.local:22379,https://m3.etcd.local:32379 \
  225. get aaa