cloud-init.tpl.toomuch 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. #cloud-config
  2. preserve_hostname: false
  3. hostname: ${hostname}
  4. fqdn: ${fqdn}
  5. # A lot of this could be done via salt. But for simplicity, i'm presently keeping it out.
  6. yum_repos:
  7. epel-release:
  8. baseurl: http://download.fedoraproject.org/pub/epel/7/$basearch
  9. enabled: true
  10. failovermethod: priority
  11. gpgcheck: true
  12. gpgkey: http://download.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7
  13. name: Extra Packages for Enterprise Linux 7 - Release
  14. packages:
  15. - strongswan
  16. - quagga
  17. - ntp
  18. - vim
  19. package_update: true # Always patch
  20. growpart:
  21. mode: auto
  22. devices: [ '/' ]
  23. ignore_growroot_disabled: false
  24. write_files:
  25. - path: /etc/strongswan/strongswan.conf
  26. content: |
  27. # strongswan.conf - strongSwan configuration file
  28. #
  29. # Refer to the strongswan.conf(5) manpage for details
  30. #
  31. # Configuration changes should be made in the included files
  32. charon {
  33. plugins {
  34. include strongswan.d/charon/*.conf
  35. }
  36. load_modular = yes
  37. filelog {
  38. charon {
  39. path = /var/log/charon.log
  40. time_format = %b %e %T
  41. ike_name = yes
  42. append = yes
  43. }
  44. }
  45. }
  46. owner: root
  47. group: root
  48. permissions: '0600'
  49. - path: /etc/strongswan/ipsec.conf
  50. content: |
  51. conn %default
  52. leftauth=psk
  53. rightauth=psk
  54. ike=aes256-sha256-modp2048s256,aes128-sha1-modp1024!
  55. ikelifetime=28800s
  56. aggressive=no
  57. esp=aes128-sha256-modp2048s256,aes128-sha1-modp1024!
  58. lifetime=3600s
  59. type=tunnel
  60. dpddelay=10s
  61. dpdtimeout=30s
  62. keyexchange=ikev1
  63. rekey=yes
  64. reauth=no
  65. dpdaction=restart
  66. closeaction=restart
  67. left=%defaultroute
  68. leftsubnet=0.0.0.0/0,::/0
  69. rightsubnet=0.0.0.0/0,::/0
  70. leftupdown=/etc/strongswan/ipsec-vti.sh
  71. installpolicy=yes
  72. compress=no
  73. mobike=no
  74. conn AWS-VPC-TUNNEL-1
  75. left=%any
  76. right=TODO-pTunnel1VgwOutsideIpAddress
  77. auto=start
  78. mark=100
  79. conn AWS-VPC-TUNNEL-2
  80. left=%any
  81. right=TODO-pTunnel2VgwOutsideIpAddress
  82. auto=start
  83. mark=200
  84. owner: root
  85. group: root
  86. permissions: '0600'
  87. - path: /etc/strongswan/ipsec-vti.sh
  88. content: |
  89. #!/bin/bash
  90. #@ /etc/strongswan/ipsec-vti.sh (Centos) or /etc/strongswan.d/ipsec-vti.sh (Ubuntu)
  91. # AWS VPC Hardware VPN Strongswan updown Script
  92. # Usage Instructions:
  93. # Add "install_routes = no" to /etc/strongswan/strongswan.d/charon.conf or /etc/strongswan.d/charon.conf
  94. # Add "install_virtual_ip = no" to /etc/strongswan/strongswan.d/charon.conf or /etc/strongswan.d/charon.conf
  95. # For Ubuntu: Add "leftupdown=/etc/strongswan.d/ipsec-vti.sh" to /etc/ipsec.conf
  96. # For RHEL/Centos: Add "leftupdown=/etc/strongswan/ipsec-vti.sh" to /etc/strongswan/ipsec.conf
  97. # For RHEL/Centos 6 and below: git clone git://git.kernel.org/pub/scm/linux/kernel/git/shemminger/iproute2.git && cd iproute2 && make && cp ./ip/ip /usr/local/sbin/ip
  98. # Adjust the below according to the Generic Gateway Configuration file provided to you by AWS.
  99. # Sample: http://docs.aws.amazon.com/AmazonVPC/latest/NetworkAdminGuide/GenericConfig.html
  100. IP=$(which ip)
  101. IPTABLES=$(which iptables)
  102. PLUTO_MARK_OUT_ARR=($${!PLUTO_MARK_OUT//// })
  103. PLUTO_MARK_IN_ARR=($${!PLUTO_MARK_IN//// })
  104. case "$PLUTO_CONNECTION" in
  105. AWS-VPC-TUNNEL-1)
  106. VTI_INTERFACE=vti1
  107. VTI_LOCALADDR=TODO_pTunnel1CgwInsideCidr
  108. VTI_REMOTEADDR=TODO_pTunnel1VgwInsideCidr
  109. ;;
  110. AWS-VPC-TUNNEL-2)
  111. VTI_INTERFACE=vti2
  112. VTI_LOCALADDR=TODO_pTunnel2CgwInsideCidr
  113. VTI_REMOTEADDR=TODO_pTunnel2VgwInsideCidr
  114. ;;
  115. esac
  116. case "$${!PLUTO_VERB}" in
  117. up-client)
  118. #$IP tunnel add $${!VTI_INTERFACE} mode vti local $${!PLUTO_ME} remote $${!PLUTO_PEER} okey $${!PLUTO_MARK_OUT_ARR[0]} ikey $${!PLUTO_MARK_IN_ARR[0]}
  119. $IP link add $${!VTI_INTERFACE} type vti local $${!PLUTO_ME} remote $${!PLUTO_PEER} okey $${!PLUTO_MARK_OUT_ARR[0]} ikey $${!PLUTO_MARK_IN_ARR[0]}
  120. sysctl -w net.ipv4.conf.$${!VTI_INTERFACE}.disable_policy=1
  121. sysctl -w net.ipv4.conf.$${!VTI_INTERFACE}.rp_filter=2 || sysctl -w net.ipv4.conf.$${!VTI_INTERFACE}.rp_filter=0
  122. $IP addr add $${!VTI_LOCALADDR} remote $${!VTI_REMOTEADDR} dev $${!VTI_INTERFACE}
  123. $IP link set $${!VTI_INTERFACE} up mtu 1436
  124. $IPTABLES -t mangle -I FORWARD -o $${!VTI_INTERFACE} -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
  125. $IPTABLES -t mangle -I INPUT -p esp -s $${!PLUTO_PEER} -d $${!PLUTO_ME} -j MARK --set-xmark $${!PLUTO_MARK_IN}
  126. $IP route flush table 220
  127. #/etc/init.d/bgpd reload || /etc/init.d/quagga force-reload bgpd
  128. ;;
  129. down-client)
  130. #$IP tunnel del $${!VTI_INTERFACE}
  131. $IP link del $${!VTI_INTERFACE}
  132. $IPTABLES -t mangle -D FORWARD -o $${!VTI_INTERFACE} -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
  133. $IPTABLES -t mangle -D INPUT -p esp -s $${!PLUTO_PEER} -d $${!PLUTO_ME} -j MARK --set-xmark $${!PLUTO_MARK_IN}
  134. ;;
  135. esac
  136. mode: '000700'
  137. owner: root
  138. group: root
  139. - path: /etc/strongswan/ipsec.secrets
  140. content: |
  141. TODO_pTunnel1VgwOutsideIpAddress : PSK "TODO_pTunnel1Psk"
  142. TODO_pTunnel2VgwOutsideIpAddress : PSK "TODO_Tunnel2Psk"
  143. mode: '000600'
  144. owner: root
  145. group: root
  146. - path: /etc/quagga/zebra.conf
  147. content: |
  148. hostname {HOSTNAME}
  149. password zebra
  150. enable password zebra
  151. !
  152. log file /var/log/quagga/zebra.log
  153. !
  154. ! Configure interfaces
  155. interface lo
  156. ! Change preferred source ip address of received routes
  157. route-map RM_SET_SRC permit 10
  158. set src {PRIVATE_IP}
  159. ip protocol bgp route-map RM_SET_SRC
  160. !
  161. line vty
  162. mode: '000644'
  163. owner: root
  164. group: root
  165. - path: /etc/quagga/bgpd.conf
  166. content: |
  167. hostname bgpd
  168. password zebra
  169. enable password zebra
  170. !
  171. log file /var/log/quagga/bgpd.log
  172. !
  173. debug bgp events
  174. debug bgp filters
  175. debug bgp fsm
  176. debug bgp keepalives
  177. debug bgp updates
  178. !
  179. router bgp TODO_pLocalBgpAsn
  180. bgp router-id {PRIVATE_IP}
  181. network TODO_pVpcCidr
  182. neighbor TODO_pTunnel1BgpNeighborIpAddress} remote-as TODO_pTunnel1BgpAsn}
  183. neighbor TODO_pTunnel2BgpNeighborIpAddress} remote-as TODO_pTunnel2BgpAsn}
  184. neighbor TODO_pTunnel2BgpNeighborIpAddress} route-map RM_LOWER_PRIORITY out
  185. !
  186. route-map RM_LOWER_PRIORITY permit 10
  187. set as-path prepend TODO_pLocalBgpAsn} TODO_pLocalBgpAsn} TODO_pLocalBgpAsn}
  188. !
  189. line vty
  190. mode: '000644'
  191. owner: root
  192. group: root
  193. - path: /etc/sysctl.conf
  194. content: |
  195. # sysctl settings are defined through files in
  196. # /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
  197. #
  198. # Vendors settings live in /usr/lib/sysctl.d/.
  199. # To override a whole file, create a new file with the same in
  200. # /etc/sysctl.d/ and put new settings there. To override
  201. # only specific settings, add a file with a lexically later
  202. # name in /etc/sysctl.d/ and put new settings there.
  203. #
  204. # For more information, see sysctl.conf(5) and sysctl.d(5).
  205. net.ipv4.ip_forward = 1
  206. net.ipv4.conf.all.send_redirects = 0
  207. net.ipv4.conf.default.send_redirects = 0
  208. net.ipv4.tcp_max_syn_backlog = 1280
  209. net.ipv4.icmp_echo_ignore_broadcasts = 1
  210. net.ipv4.conf.all.accept_source_route = 0
  211. net.ipv4.conf.all.accept_redirects = 0
  212. net.ipv4.conf.all.secure_redirects = 0
  213. net.ipv4.conf.all.log_martians = 1
  214. net.ipv4.conf.default.accept_source_route = 0
  215. net.ipv4.conf.default.accept_redirects = 0
  216. net.ipv4.conf.default.secure_redirects = 0
  217. net.ipv4.icmp_echo_ignore_broadcasts = 1
  218. net.ipv4.icmp_ignore_bogus_error_responses = 1
  219. net.ipv4.tcp_syncookies = 1
  220. net.ipv4.conf.all.rp_filter = 1
  221. net.ipv4.conf.default.rp_filter = 1
  222. net.ipv4.tcp_mtu_probing = 1
  223. mode: '000600'
  224. owner: root
  225. group: root
  226. runcmd:
  227. - echo "${fqdn}" > /etc/salt/minion_id
  228. - /bin/systemctl restart salt-minion
  229. - /bin/systemctl enable salt-minion
  230. - /bin/systemctl start amazon-ssm-agent
  231. - /bin/systemctl enable amazon-ssm-agent
  232. - /usr/sbin/aide --update --verbose=0
  233. - /bin/cp /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz
  234. # Since we reboot, either final message or power state, but probably not both
  235. #final_message: "The system is up after $UPTIME seconds"
  236. #power_state:
  237. # delay: "+30"
  238. # mode: reboot
  239. # message: "System configured after $UPTIME seconds"
  240. # timeout: 300
  241. # condition: true