├── .github └── FUNDING.yml ├── .gitignore ├── .travis.yml ├── CODEOWNERS ├── LICENSE ├── README.md ├── algo ├── cloud ├── .include │ ├── outputs.tf │ ├── terraform.tf │ └── vars.tf ├── azure │ ├── outputs.tf │ ├── resources.tf │ ├── terraform.tf │ ├── vars.tf │ └── versions.tf ├── digitalocean │ ├── outputs.tf │ ├── resources.tf │ ├── terraform.tf │ ├── vars.tf │ └── versions.tf ├── ec2 │ ├── outputs.tf │ ├── resources.tf │ ├── terraform.tf │ ├── vars.tf │ └── versions.tf └── gce │ ├── outputs.tf │ ├── resources.tf │ ├── terraform.tf │ ├── vars.tf │ └── versions.tf ├── config.auto.tfvars ├── configs └── .gitinit ├── docs ├── cloud-amazon-ec2.md ├── cloud-azure.md ├── cloud-do.md ├── cloud-gce.md ├── defaults.md ├── deploy-from-docker.md ├── deploy-from-terraform.md ├── deploy-to-unsupported-cloud.md ├── faq.md ├── index.md ├── non-interactive-authentication.md └── troubleshooting.md ├── modules ├── cloud-azure │ ├── output.tf │ ├── resources.tf │ ├── vars.tf │ └── versions.tf ├── cloud-digitalocean │ ├── output.tf │ ├── resources.tf │ ├── vars.tf │ └── versions.tf ├── cloud-ec2 │ ├── output.tf │ ├── resources.tf │ ├── vars.tf │ └── versions.tf ├── cloud-gce │ ├── output.tf │ ├── resources.tf │ ├── vars.tf │ └── versions.tf ├── cloud-hetzner │ ├── output.tf │ ├── resources.tf │ ├── vars.tf │ └── versions.tf ├── cloud-scaleway │ ├── output.tf │ ├── resources.tf │ ├── vars.tf │ └── versions.tf ├── configs │ ├── external │ │ └── read-file-ssh.sh │ ├── files │ │ ├── mobileconfig.xml │ │ ├── powershell.ps1 │ │ └── wireguard.conf │ ├── hooks.tf │ ├── mobileconfig.tf │ ├── ssh_tunneling.tf │ ├── vars.tf │ ├── versions.tf │ └── wireguard.tf ├── tls │ ├── ca.tf │ ├── clients.tf │ ├── external │ │ ├── generate-crl.sh │ │ └── generate-p12.sh │ ├── output.tf │ ├── server.tf │ ├── ssh.tf │ ├── vars.tf │ ├── versions.tf │ └── wireguard.tf └── user-data │ ├── common.tf │ ├── dns.tf │ ├── files │ ├── common │ │ ├── 001-cloud-init-start.yml │ │ ├── 099-cloud-init-end.yml │ │ ├── rules.v4 │ │ └── rules.v6 │ ├── dns │ │ ├── adblock.sh │ │ ├── cloud-init.yml │ │ ├── dnscrypt-proxy.toml │ │ ├── ip-blacklist.txt │ │ └── usr.bin.dnscrypt-proxy │ ├── ssh_tunneling │ │ └── cloud-init.yml │ ├── strongswan │ │ ├── cloud-init.yml │ │ ├── ipsec.conf │ │ └── strongswan.conf │ └── wireguard │ │ ├── cloud-init.yml │ │ └── wg0.conf │ ├── ipsec.tf │ ├── main.tf │ ├── output.tf │ ├── ssh_tunneling.tf │ ├── vars.tf │ ├── versions.tf │ └── wireguard.tf └── regions ├── azure ├── digitalocean ├── ec2 └── gce /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: algovpn 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with a single custom sponsorship URL 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.retry 2 | .idea/ 3 | configs/* 4 | !configs/openssl.cnf 5 | terraform.tfstate* 6 | inventory_users 7 | *.kate-swp 8 | env 9 | .DS_Store 10 | .terraform/* 11 | *tfstate* 12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: bash 3 | dist: xenial 4 | 5 | env: 6 | global: 7 | - TF_VAR_algo_name=algo TF_VAR_region=nil 8 | - TF_VAR_google_credentials=/dev/null GOOGLE_CREDENTIALS=/dev/null 9 | - DIGITALOCEAN_TOKEN=nil 10 | - AWS_ACCESS_KEY_ID=nil AWS_SECRET_ACCESS_KEY=nil 11 | - ARM_CLIENT_SECRET=nil ARM_TENANT_ID=nil ARM_CLIENT_ID=nil ARM_SUBSCRIPTION_ID=nil 12 | - HCLOUD_TOKEN=nil 13 | - SCW_TOKEN=nil SCALEWAY_ORGANIZATION=nil 14 | 15 | matrix: 16 | fast_finish: true 17 | 18 | script: 19 | - set -ex 20 | - wget https://releases.hashicorp.com/terraform/0.12.6/terraform_0.12.6_linux_amd64.zip -O terraform.zip -q && unzip terraform.zip 21 | - | 22 | for i in $(ls ./cloud); do 23 | export TF_VAR_algo_provider=$i 24 | ./terraform init cloud/${i} 25 | ./terraform validate cloud/${i} 26 | done 27 | - ./terraform fmt -write=false -list=true -diff=true -check=true -recursive 28 | 29 | notifications: 30 | email: false 31 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @jackivanov 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published 637 | by the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Algo VPN 2 | 3 | [![Join the chat at https://gitter.im/trailofbits/algo](https://badges.gitter.im/trailofbits/algo.svg)](https://gitter.im/trailofbits/algo?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 4 | [![Twitter](https://img.shields.io/twitter/url/https/twitter.com/fold_left.svg?style=social&label=Follow%20%40AlgoVPN)](https://twitter.com/AlgoVPN) 5 | [![TravisCI Status](https://api.travis-ci.com/trailofbits/algo-ng.svg?branch=master)](https://travis-ci.com/trailofbits/algo-ng) 6 | 7 | Algo VPN is a set of Terraform files that simplify the setup of a personal VPN. It uses the most secure defaults available, works with common cloud providers, and does not require client software on most devices. See our [release announcement](https://blog.trailofbits.com/2016/12/12/meet-algo-the-vpn-that-works/) for more information. 8 | 9 | ## Features 10 | 11 | * Supports only IKEv2 with strong crypto (AES-GCM, SHA2, and P-256) and [WireGuard](https://www.wireguard.com/) 12 | * Generates Apple profiles to auto-configure iOS and macOS devices 13 | * Includes a helper script to add and remove users 14 | * Blocks ads with a local DNS resolver (optional) 15 | * Sets up limited SSH users for tunneling traffic (optional) 16 | * Based on current versions of Ubuntu and StrongSwan 17 | * Installs to DigitalOcean, Amazon Lightsail, Amazon EC2, Microsoft Azure, Google Compute Engine, Hetzner, Scaleway 18 | 19 | ## Anti-features 20 | 21 | * Does not support legacy cipher suites or protocols like L2TP, IKEv1, or RSA 22 | * Does not install Tor, OpenVPN, or other risky servers 23 | * Does not depend on the security of [TLS](https://tools.ietf.org/html/rfc7457) 24 | * Does not require client software on most platforms 25 | * Does not claim to provide anonymity or censorship avoidance 26 | * Does not claim to protect you from the [FSB](https://en.wikipedia.org/wiki/Federal_Security_Service), [MSS](https://en.wikipedia.org/wiki/Ministry_of_State_Security_(China)), [DGSE](https://en.wikipedia.org/wiki/Directorate-General_for_External_Security), or [FSM](https://en.wikipedia.org/wiki/Flying_Spaghetti_Monster) 27 | 28 | ## Deploy the Algo Server 29 | 30 | The easiest way to get an Algo server running is to let it set up a _new_ virtual machine in the cloud for you. 31 | 32 | 1. **Setup an account on a cloud hosting provider.** Algo supports [DigitalOcean](https://m.do.co/c/4d7f4ff9cfe4) (most user friendly), [Amazon EC2](https://aws.amazon.com/), [Google Compute Engine](https://cloud.google.com/compute/), and [Microsoft Azure](https://azure.microsoft.com/). 33 | 34 | 2. **[Download Algo](https://github.com/trailofbits/algo-ng/archive/master.zip).** Unzip it in a convenient location on your local machine. 35 | 36 | 3. **Install Algo's core dependencies.** Open the Terminal. 37 | 38 | - macOS: 39 | ```bash 40 | $ brew install terraform 41 | ``` 42 | 43 | - Ubuntu (16.04 or later): 44 | ```bash 45 | $ sudo apt-get update && sudo apt-get install snapd -y \ 46 | $ sudo snap install terraform 47 | ``` 48 | 49 | - Others: **[Download Terraform binary](https://www.terraform.io/downloads.html)** 50 | 51 | 4. **List the users to create.** Open `config.auto.tfvars` in your favorite text editor. Specify the users you wish to create in the `vpn_users` list. 52 | 53 | 5. **Start the deployment.** Return to your terminal. In the Algo directory, run `./algo apply` and follow the instructions. There are several optional features available. None are required for a fully functional VPN server. 54 | 55 | That's it! You will get the message below when the server deployment process completes. You now have an Algo server on the internet. Take note of the p12 (user certificate) password in case you need it later. 56 | 57 | You can now setup clients to connect it, e.g. your iPhone or laptop. Proceed to [Configure the VPN Clients](#configure-the-vpn-clients) below. 58 | 59 | ## Configure the VPN Clients 60 | 61 | Certificates and configuration files that users will need are placed in the `configs` directory. Make sure to secure these files since many contain private keys. All files are saved under a subdirectory named with the IP address of your new Algo VPN server. 62 | 63 | ### Apple Devices 64 | 65 | **Send users their Apple Profile.** Find the corresponding mobileconfig (Apple Profile) for each user and send it to them over AirDrop or other secure means. Apple Configuration Profiles are all-in-one configuration files for iOS and macOS devices. On macOS, double-clicking a profile to install it will fully configure the VPN. On iOS, users are prompted to install the profile as soon as the AirDrop is accepted. 66 | 67 | **Turn on the VPN.** On iOS, connect to the VPN by opening Settings and clicking the toggle next to "VPN" near the top of the list. On macOS, connect to the VPN by opening System Preferences -> Network, finding Algo VPN in the left column and clicking "Connect." On macOS, check "Show VPN status in menu bar" to easily connect and disconnect from the menu bar. 68 | 69 | **Managing On-Demand VPNs.** If you enabled "On Demand", the VPN will connect automatically whenever it is able. On iOS, you can turn off "On Demand" by clicking the (i) next to the entry for Algo VPN and toggling off "Connect On Demand." On macOS, you can turn off "On Demand" by opening the Network Preferences, finding Algo VPN in the left column, and unchecking the box for "Connect on demand." 70 | 71 | ### Android Devices 72 | 73 | WireGuard is used to provide VPN services on Android. Install the [WireGuard VPN Client](https://play.google.com/store/apps/details?id=com.wireguard.android). Import the corresponding `wireguard/.conf` file to your device, then setup a new connection with it. See the [Android setup instructions](/docs/client-android.md) for more detailed walkthrough. 74 | 75 | ### Windows 76 | 77 | WireGuard is used to provide VPN services on Windows. Algo generates a WireGuard configuration file, `wireguard/.conf`, for each user defined in `config.cfg`. 78 | 79 | Install the [WireGuard VPN Client](https://www.wireguard.com/install/#windows-7-8-81-10-2012-2016-2019). Import the generated `wireguard/.conf` file to your device, then setup a new connection with it. 80 | 81 | ### Linux Network Manager Clients (e.g., Ubuntu, Debian, or Fedora Desktop) 82 | 83 | Network Manager does not support AES-GCM. In order to support Linux Desktop clients, choose the "compatible" cryptography during the deploy process and use at least Network Manager 1.4.1. See [Issue #263](https://github.com/trailofbits/algo/issues/263) for more information. 84 | 85 | ### Linux strongSwan Clients (e.g., OpenWRT, Ubuntu Server, etc.) 86 | 87 | Install strongSwan, then copy the included ipsec_user.conf, ipsec_user.secrets, user.crt (user certificate), and user.key (private key) files to your client device. These will require customization based on your exact use case. These files were originally generated with a point-to-point OpenWRT-based VPN in mind. 88 | 89 | #### Ubuntu Server example 90 | 91 | 1. `sudo apt-get install strongswan libstrongswan-standard-plugins`: install strongSwan 92 | 2. `/etc/ipsec.d/certs`: copy `.crt` from `algo-master/configs//ipsec/manual/.crt` 93 | 3. `/etc/ipsec.d/private`: copy `.key` from `algo-master/configs//ipsec/manual/.key` 94 | 4. `/etc/ipsec.d/cacerts`: copy `cacert.pem` from `algo-master/configs//ipsec/manual/cacert.pem` 95 | 5. `/etc/ipsec.secrets`: add your `user.key` to the list, e.g. ` : ECDSA .key` 96 | 6. `/etc/ipsec.conf`: add the connection from `ipsec_user.conf` and ensure `leftcert` matches the `.crt` filename 97 | 7. `sudo ipsec restart`: pick up config changes 98 | 8. `sudo ipsec up `: start the ipsec tunnel 99 | 9. `sudo ipsec down `: shutdown the ipsec tunnel 100 | 101 | One common use case is to let your server access your local LAN without going through the VPN. Set up a passthrough connection by adding the following to `/etc/ipsec.conf`: 102 | 103 | conn lan-passthrough 104 | leftsubnet=192.168.1.1/24 # Replace with your LAN subnet 105 | rightsubnet=192.168.1.1/24 # Replace with your LAN subnet 106 | authby=never # No authentication necessary 107 | type=pass # passthrough 108 | auto=route # no need to ipsec up lan-passthrough 109 | 110 | To configure the connection to come up at boot time replace `auto=add` with `auto=start`. 111 | 112 | ### Other Devices 113 | 114 | Depending on the platform, you may need one or multiple of the following files. 115 | 116 | * ipsec/manual/cacert.pem: CA Certificate 117 | * ipsec/manual/.p12: User Certificate and Private Key (in PKCS#12 format) 118 | * ipsec/manual/.conf: strongSwan client configuration 119 | * ipsec/manual/.secrets: strongSwan client configuration 120 | * ipsec/apple/.mobileconfig: Apple Profile 121 | * wireguard/.conf: WireGuard configuration profile 122 | * wireguard/.png: WireGuard configuration QR code 123 | 124 | ## Setup an SSH Tunnel 125 | 126 | If you turned on the optional SSH tunneling role, then local user accounts will be created for each user in `config.cfg` and SSH authorized_key files for them will be in the `configs` directory (user.ssh.pem). SSH user accounts do not have shell access, cannot authenticate with a password, and only have limited tunneling options (e.g., `ssh -N` is required). This ensures that SSH users have the least access required to setup a tunnel and can perform no other actions on the Algo server. 127 | 128 | Use the example command below to start an SSH tunnel by replacing `user` and `ip` with your own. Once the tunnel is setup, you can configure a browser or other application to use 127.0.0.1:1080 as a SOCKS proxy to route traffic through the Algo server. 129 | 130 | `ssh -D 127.0.0.1:1080 -f -q -C -N user@ip -i configs//ssh-tunnel/.pem` 131 | 132 | ## SSH into Algo Server 133 | 134 | Your Algo server is configured for key-only SSH access for administrative purposes. Open the Terminal app, `cd` into the `algo-master` directory where you originally downloaded Algo, and then use the command listed on the success message: 135 | 136 | `ssh -i configs/algo.pem user@ip` 137 | 138 | where `user` is either `root` or `ubuntu` as listed on the success message, and `ip` is the IP address of your Algo server. If you find yourself regularly logging into the server then it will be useful to load your Algo ssh key automatically. Add the following snippet to the bottom of `~/.bash_profile` to add it to your shell environment permanently. 139 | 140 | `ssh-add ~/.ssh/algo > /dev/null 2>&1` 141 | 142 | ## Adding or Removing Users 143 | 144 | If you chose the save the CA certificate during the deploy process, then Algo's own scripts can easily add and remove users from the VPN server. 145 | 146 | 1. Update the `vpn_users` list in your `config.auto.tfvars` 147 | 2. Open a terminal, `cd` to the algo directory, and run the command: `./algo update-users` 148 | 149 | After this process completes, the Algo VPN server will contains only the users listed in the `config.auto.tfvars` file. 150 | 151 | ## Additional Documentation 152 | * [Deployment instructions, cloud provider setup instructions, and further client setup instructions available here.](docs/index.md) 153 | * [FAQ](docs/faq.md) 154 | * [Troubleshooting](docs/troubleshooting.md) 155 | 156 | If you read all the documentation and have further questions, [join the chat on Gitter](https://gitter.im/trailofbits/algo). 157 | 158 | ## Endorsements 159 | 160 | > I've been ranting about the sorry state of VPN svcs for so long, probably about 161 | > time to give a proper talk on the subject. TL;DR: use Algo. 162 | 163 | -- [Kenn White](https://twitter.com/kennwhite/status/814166603587788800) 164 | 165 | > Before picking a VPN provider/app, make sure you do some research 166 | > https://research.csiro.au/ng/wp-content/uploads/sites/106/2016/08/paper-1.pdf ... – or consider Algo 167 | 168 | -- [The Register](https://twitter.com/TheRegister/status/825076303657177088) 169 | 170 | > Algo is really easy and secure. 171 | 172 | -- [the grugq](https://twitter.com/thegrugq/status/786249040228786176) 173 | 174 | > I played around with Algo VPN, a set of scripts that let you set up a VPN in the cloud in very little time, even if you don’t know much about development. I’ve got to say that I was quite impressed with Trail of Bits’ approach. 175 | 176 | -- [Romain Dillet](https://twitter.com/romaindillet/status/851037243728965632) for [TechCrunch](https://techcrunch.com/2017/04/09/how-i-made-my-own-vpn-server-in-15-minutes/) 177 | 178 | > If you’re uncomfortable shelling out the cash to an anonymous, random VPN provider, this is the best solution. 179 | 180 | -- [Thorin Klosowski](https://twitter.com/kingthor) for [Lifehacker](http://lifehacker.com/how-to-set-up-your-own-completely-free-vpn-in-the-cloud-1794302432) 181 | 182 | ## Support Algo VPN 183 | [![Flattr](https://button.flattr.com/flattr-badge-large.png)](https://flattr.com/submit/auto?fid=kxw60j&url=https%3A%2F%2Fgithub.com%2Ftrailofbits%2Falgo) 184 | [![PayPal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=CYZZD39GXUJ3E) 185 | [![Patreon](https://img.shields.io/badge/back_on-patreon-red.svg)](https://www.patreon.com/algovpn) 186 | [![Bountysource](https://img.shields.io/bountysource/team/trailofbits/activity.svg)](https://www.bountysource.com/teams/trailofbits) 187 | 188 | All donations support continued development. Thanks! 189 | 190 | * We accept donations via [PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=CYZZD39GXUJ3E), [Patreon](https://www.patreon.com/algovpn), and [Flattr](https://flattr.com/submit/auto?fid=kxw60j&url=https%3A%2F%2Fgithub.com%2Ftrailofbits%2Falgo). 191 | * Use our [referral code](https://m.do.co/c/4d7f4ff9cfe4) when you sign up to Digital Ocean for a $10 credit. 192 | * We also accept and appreciate contributions of new code and bugfixes via Github Pull Requests. 193 | 194 | Algo is licensed and distributed under the AGPLv3. If you want to distribute a closed-source modification or service based on Algo, then please consider purchasing an exception . As with the methods above, this will help support continued development. 195 | -------------------------------------------------------------------------------- /algo: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SENSITIVE_PROMPT="[pasted values will not be displayed]" 4 | TRUE="^(y|Y|true)$" 5 | REGIONS_PATH="./regions" 6 | 7 | describeRegions(){ 8 | index=1 9 | while IFS="," read code name default; do 10 | printf "\n%2s. %-${ALGN:-5}s %s" $index "$code" "$name" 11 | ((index++)) 12 | done < ${REGIONS_PATH}/${1} 13 | } 14 | 15 | getRegionCodeByIndex(){ 16 | sed "${2}q;d" ${REGIONS_PATH}/${1} | cut -f1 -d, 17 | } 18 | 19 | getDefaultRegion(){ 20 | index=1 21 | while IFS="," read code name default; do 22 | if [[ "$default" == "default" ]]; then 23 | default=${index} 24 | echo "$default" 25 | break 26 | fi 27 | ((index++)) 28 | done < ${REGIONS_PATH}/${1} 29 | 30 | } 31 | 32 | askForRegion(){ 33 | local default="$(getDefaultRegion ${ALGO_PROVIDER})" 34 | echo -e "\nWhat region should the server be located in?" \ 35 | "\n$(describeRegions $1)" \ 36 | "\nEnter the number of your desired region:" 37 | read -p "[${default}]: " -r region 38 | region=${region:-$default} 39 | TF_VAR_region="$(getRegionCodeByIndex "$1" $region)" 40 | } 41 | 42 | azure () { 43 | if [[ -z $ALGO_REGION && "$ALGO_COMMAND" == "apply" ]]; then 44 | askForRegion ${ALGO_PROVIDER} 45 | else 46 | TF_VAR_region="$ALGO_REGION" 47 | fi 48 | 49 | export ARM_SUBSCRIPTION_ID=$ARM_SUBSCRIPTION_ID \ 50 | ARM_CLIENT_ID=$ARM_CLIENT_ID \ 51 | ARM_CLIENT_SECRET=$ARM_CLIENT_SECRET \ 52 | ARM_TENANT_ID=$ARM_TENANT_ID \ 53 | ALGO_SERVER_NAME=${ALGO_SERVER_NAME} 54 | } 55 | 56 | digitalocean () { 57 | if [[ -z $DIGITALOCEAN_TOKEN ]]; then 58 | echo -e "\nEnter your API token. The token must have read and write permissions" \ 59 | "(https://cloud.digitalocean.com/settings/api/tokens):" \ 60 | "\n$SENSITIVE_PROMPT" 61 | read -p ": " -rs DIGITALOCEAN_TOKEN 62 | fi 63 | 64 | if [[ -z $ALGO_REGION && "$ALGO_COMMAND" == "apply" ]]; then 65 | askForRegion ${ALGO_PROVIDER} 66 | else 67 | TF_VAR_region="$ALGO_REGION" 68 | fi 69 | 70 | export DIGITALOCEAN_TOKEN=$DIGITALOCEAN_TOKEN \ 71 | ALGO_SERVER_NAME=${ALGO_SERVER_NAME} 72 | } 73 | 74 | aws () { 75 | if [[ -z $AWS_ACCESS_KEY_ID && -z $AWS_PROFILE ]]; then 76 | echo -e "\nEnter your aws_access_key (http://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html)" \ 77 | "\nNote: Make sure to use an IAM user with an acceptable policy attached (see https://github.com/trailofbits/algo/blob/master/docs/deploy-from-terraform.md)." \ 78 | "\n$SENSITIVE_PROMPT" \ 79 | "\n[AKIA...]: " 80 | read -p ": " -rs AWS_ACCESS_KEY_ID 81 | fi 82 | 83 | if [[ -z $AWS_SECRET_ACCESS_KEY && -z $AWS_PROFILE ]]; then 84 | echo -e "\n\nEnter your aws_secret_key (http://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html)" \ 85 | "\n$SENSITIVE_PROMPT" \ 86 | "\n[ABCD...]: " 87 | read -p ": " -rs AWS_SECRET_ACCESS_KEY 88 | fi 89 | 90 | if [[ -z $ALGO_REGION && "$ALGO_COMMAND" == "apply" ]]; then 91 | ALGN=15 askForRegion ${ALGO_PROVIDER} 92 | else 93 | TF_VAR_region="$ALGO_REGION" 94 | fi 95 | 96 | export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \ 97 | AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \ 98 | ALGO_SERVER_NAME=${ALGO_SERVER_NAME} 99 | } 100 | 101 | gce () { 102 | if [[ -z $GOOGLE_CREDENTIALS ]]; then 103 | echo -e "\nEnter the local path to your credentials JSON file" \ 104 | "(https://support.google.com/cloud/answer/6158849?hl=en&ref_topic=6262490#serviceaccounts)" 105 | read -p "[]: " -r GOOGLE_CREDENTIALS 106 | fi 107 | 108 | if [[ -z $ALGO_REGION && "$ALGO_COMMAND" == "apply" ]]; then 109 | ALGN=25 askForRegion ${ALGO_PROVIDER} 110 | else 111 | TF_VAR_region="$ALGO_REGION" 112 | fi 113 | 114 | export GOOGLE_CREDENTIALS=$GOOGLE_CREDENTIALS \ 115 | TF_VAR_google_credentials=$GOOGLE_CREDENTIALS \ 116 | ALGO_SERVER_NAME=${ALGO_SERVER_NAME} 117 | } 118 | 119 | algo_provisioning () { 120 | if [[ -z $ALGO_PROVIDER && "$ALGO_COMMAND" == "apply" ]]; then 121 | echo -e "\nWhat provider would you like to use?\n" \ 122 | "\n 1. DigitalOcean" \ 123 | "\n 2. Amazon EC2" \ 124 | "\n 3. Microsoft Azure" \ 125 | "\n 4. Google Compute Engine" \ 126 | "\n\nEnter the number of your desired provider" 127 | read -p ": " -r ALGO_PROVIDER 128 | fi 129 | 130 | local default=algo 131 | if [[ -z $ALGO_SERVER_NAME && "$ALGO_COMMAND" == "apply" ]]; then 132 | echo -e '\nName the vpn server:' 133 | read -p "[${default}]: " -r ALGO_SERVER_NAME 134 | fi 135 | 136 | export ALGO_SERVER_NAME=${ALGO_SERVER_NAME:-${default}} 137 | 138 | case "$ALGO_PROVIDER" in 139 | 1|digitalocean) ALGO_PROVIDER=digitalocean; digitalocean; ;; 140 | 2|ec2) ALGO_PROVIDER=ec2; aws; ;; 141 | 3|azure) ALGO_PROVIDER=azure; azure; ;; 142 | 4|gce) ALGO_PROVIDER=gce; gce; ;; 143 | *) exit 1 ;; 144 | esac 145 | 146 | export TF_CLI_ARGS_apply+=" -auto-approve -parallelism=1" \ 147 | TF_VAR_algo_name="${ALGO_SERVER_NAME}" \ 148 | TF_VAR_algo_provider="${ALGO_PROVIDER}" \ 149 | TF_VAR_region="$TF_VAR_region" 150 | 151 | 152 | if [[ "$ALGO_COMMAND" == "apply" ]]; then 153 | ${TERRAFORM_BIN} workspace select ${ALGO_PROVIDER}-${TF_VAR_region}-${ALGO_SERVER_NAME} \ 154 | || ${TERRAFORM_BIN} workspace new ${ALGO_PROVIDER}-${TF_VAR_region}-${ALGO_SERVER_NAME} 155 | ${TERRAFORM_BIN} init cloud/$ALGO_PROVIDER/ 156 | fi 157 | 158 | ${TERRAFORM_BIN} ${ALGO_COMMAND:-apply} cloud/$ALGO_PROVIDER/ 159 | } 160 | 161 | help () { 162 | echo "Usage: $0 163 | 164 | The available commands for execution are listed below. 165 | 166 | Common commands: 167 | apply Builds or changes infrastructure 168 | destroy Destroy Terraform-managed infrastructure 169 | update-users Update AlgoVPN users 170 | " 171 | exit 0 172 | } 173 | 174 | locate_terraform () { 175 | export TERRAFORM_BIN=$(which ./terraform || which terraform) 176 | if [[ "$TERRAFORM_BIN" == "" ]]; then 177 | echo " 178 | Terraform binary is not found. 179 | Please, read the readme and follow the instructions" 180 | exit 1 181 | fi 182 | } 183 | 184 | apply () { 185 | locate_terraform 186 | 187 | export ALGO_COMMAND="apply" 188 | algo_provisioning 189 | } 190 | 191 | destroyResources () { 192 | locate_terraform 193 | 194 | CURRENT_WORKSPACE="$(${TERRAFORM_BIN} workspace list | grep "^*" | awk '{print $2}')" 195 | 196 | if [[ -z $WORKSPACE ]]; then 197 | echo -e "\nWhat workspace you want to destroy?\n" \ 198 | "\n$(${TERRAFORM_BIN} workspace list)\n" \ 199 | "\nEnter the full name of the workspace: " 200 | read -p "[${CURRENT_WORKSPACE}]: " -r workspace 201 | 202 | export WORKSPACE=${workspace:-$CURRENT_WORKSPACE} 203 | fi 204 | 205 | ${TERRAFORM_BIN} workspace select "${WORKSPACE}" || exit 1 206 | 207 | export ALGO_COMMAND="destroy" 208 | export ALGO_PROVIDER=$(echo $CURRENT_WORKSPACE | cut -f1 -d-) 209 | 210 | algo_provisioning 211 | 212 | ${TERRAFORM_BIN} workspace select default 213 | ${TERRAFORM_BIN} workspace delete ${WORKSPACE} 214 | } 215 | 216 | destroy () { 217 | locate_terraform 218 | destroyResources 219 | } 220 | 221 | case "$1" in 222 | apply) apply ;; 223 | destroy) destroy ;; 224 | update-users) update-users ;; 225 | get-terraform) get_terraform ;; 226 | *) help "$@" ;; 227 | esac 228 | -------------------------------------------------------------------------------- /cloud/.include/outputs.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | wireguard_dns = { 3 | for i in values(local.config.wireguard_dns) : 4 | "WireGuard" => i... 5 | if local.config.dns.adblocking.enabled || local.config.dns.encryption.enabled 6 | } 7 | 8 | ipsec_dns = { 9 | for i in values(local.config.ipsec_dns) : 10 | "IPsec" => i... 11 | if local.config.dns.adblocking.enabled || local.config.dns.encryption.enabled 12 | } 13 | 14 | resolvers = { 15 | for i in concat(var.config.dns.resolvers.ipv4, var.config.dns.resolvers.ipv6) : 16 | "Resolvers" => i... 17 | if ! local.config.dns.adblocking.enabled && ! local.config.dns.encryption.enabled 18 | } 19 | 20 | output = { 21 | dns_resolvers = merge(local.wireguard_dns, local.ipsec_dns, local.resolvers) 22 | } 23 | } 24 | 25 | output "AlgoVPN" { 26 | value = { 27 | Config = { 28 | "Server address" = local.server_address 29 | "P12 and SSH keys password" = module.tls.client_p12_pass 30 | "Config directory" = "configs/${local.server_address}/" 31 | 32 | "On Demand" = { 33 | Cellular = local.config.ondemand.cellular 34 | WiFi = { 35 | enabled = local.config.ondemand.wifi 36 | "exclude networks" = [ 37 | for i in local.config.ondemand.wifi_exclude : 38 | i 39 | if local.config.ondemand.wifi 40 | ] 41 | } 42 | } 43 | } 44 | 45 | Components = { 46 | "IPsec" = local.config.ipsec.enabled 47 | "WireGuard" = local.config.wireguard.enabled 48 | "SSH tunneling" = local.config.ssh_tunneling 49 | 50 | "DNS" = { 51 | "Encryption" = local.config.dns.encryption.enabled 52 | "Ad blocking" = local.config.dns.adblocking.enabled 53 | "Servers" = local.output.dns_resolvers 54 | } 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /cloud/.include/terraform.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = ">= 0.12" 3 | } 4 | -------------------------------------------------------------------------------- /cloud/.include/vars.tf: -------------------------------------------------------------------------------- 1 | variable "config" {} 2 | 3 | # 4 | # Prompts 5 | # 6 | 7 | variable "algo_name" { 8 | default = "algo" 9 | description = "Name the vpn server" 10 | } 11 | 12 | variable "ondemand_cellular" { 13 | default = false 14 | description = <<-EOF 15 | Do you want macOS/iOS IPsec clients to enable 'Connect On Demand' when connected to cellular networks? 16 | [y/N] 17 | EOF 18 | } 19 | variable "ondemand_wifi" { 20 | default = false 21 | description = <<-EOF 22 | Do you want macOS/iOS IPsec clients to enable 'Connect On Demand' when connected to Wi-Fi? 23 | [y/N] 24 | EOF 25 | } 26 | 27 | variable "ondemand_wifi_exclude" { 28 | default = "no" 29 | description = <<-EOF 30 | List the names of any trusted Wi-Fi networks where macOS/iOS IPsec clients should not use 'Connect On Demand' 31 | (e.g., your home network. Comma-separated value, e.g., HomeNet,OfficeWifi,AlgoWiFi). 32 | To skip enter "no" 33 | EOF 34 | } 35 | 36 | variable "dns_adblocking" { 37 | default = false 38 | description = <<-EOF 39 | Do you want to install an ad blocking DNS resolver on this VPN server? 40 | [y/N] 41 | EOF 42 | } 43 | 44 | variable "ssh_tunneling" { 45 | default = false 46 | description = <<-EOF 47 | Do you want each user to have their own account for SSH tunneling? 48 | [y/N] 49 | EOF 50 | } 51 | 52 | # 53 | # Variables 54 | # 55 | 56 | provider "random" { 57 | version = "~> 2.1" 58 | } 59 | 60 | resource "random_integer" "local_service_ip" { 61 | min = 1 62 | max = 16777214 63 | } 64 | 65 | locals { 66 | true_exp = "/^(y|Y|true|yes)$/" 67 | 68 | exclude_networks = [ 69 | for i in split(",", var.ondemand_wifi_exclude) : 70 | i 71 | if length(i) > 0 72 | ] 73 | 74 | prompts = { 75 | dns_adblocking = replace(var.dns_adblocking, local.true_exp, "yes") == "yes" ? true : false 76 | ssh_tunneling = replace(var.ssh_tunneling, local.true_exp, "yes") == "yes" ? true : false 77 | 78 | ondemand = { 79 | cellular = replace(var.ondemand_cellular, local.true_exp, "yes") == "yes" ? true : false 80 | wifi = replace(var.ondemand_wifi, local.true_exp, "yes") == "yes" ? true : false 81 | wifi_exclude = replace(var.ondemand_wifi_exclude, "/^(no|n|N|false)$/", "no") == "no" ? [] : local.exclude_networks 82 | } 83 | } 84 | 85 | calculated = { 86 | ipsec_dns = { 87 | ipv4 = cidrhost(var.config.wireguard.ipv4, 1) 88 | ipv6 = cidrhost(var.config.wireguard.ipv6, 1) 89 | } 90 | 91 | wireguard_dns = { 92 | ipv4 = cidrhost(var.config.ipsec.ipv4, 1) 93 | ipv6 = cidrhost(var.config.ipsec.ipv6, 1) 94 | } 95 | } 96 | 97 | config = merge(local.prompts, local.calculated, var.config) 98 | } 99 | -------------------------------------------------------------------------------- /cloud/azure/outputs.tf: -------------------------------------------------------------------------------- 1 | ../.include/outputs.tf -------------------------------------------------------------------------------- /cloud/azure/resources.tf: -------------------------------------------------------------------------------- 1 | resource "azurerm_resource_group" "main" { 2 | name = var.algo_name 3 | location = var.config.clouds.azure.region 4 | 5 | tags = { 6 | Environment = "Algo" 7 | } 8 | } 9 | 10 | resource "azurerm_public_ip" "main" { 11 | name = var.algo_name 12 | location = var.config.clouds.azure.region 13 | resource_group_name = azurerm_resource_group.main.name 14 | allocation_method = "Static" 15 | 16 | tags = { 17 | Environment = "Algo" 18 | } 19 | } 20 | 21 | locals { 22 | server_address = azurerm_public_ip.main.ip_address 23 | algo_config = "${path.cwd}/configs/${local.server_address}" 24 | } 25 | 26 | module "tls" { 27 | source = "../../modules/tls/" 28 | algo_config = local.algo_config 29 | vpn_users = var.config.vpn_users 30 | server_address = local.server_address 31 | } 32 | 33 | module "user-data" { 34 | source = "../../modules/user-data/" 35 | base64_encode = true 36 | gzip = true 37 | ipv6 = false 38 | config = local.config 39 | pki = module.tls.pki 40 | } 41 | 42 | module "cloud" { 43 | source = "../../modules/cloud-azure/" 44 | region = var.config.clouds.azure.region 45 | algo_name = var.algo_name 46 | algo_ip = azurerm_public_ip.main.id 47 | ssh_public_key = module.tls.ssh_public_key 48 | user_data = module.user-data.template_cloudinit_config 49 | image = var.config.clouds.azure.image 50 | size = var.config.clouds.azure.size 51 | resource_group_name = azurerm_resource_group.main.name 52 | } 53 | 54 | module "configs" { 55 | source = "../../modules/configs/" 56 | algo_config = local.algo_config 57 | server_address = local.server_address 58 | client_p12_pass = module.tls.client_p12_pass 59 | ssh_user = module.cloud.ssh_user 60 | ssh_private_key = module.tls.ssh_private_key 61 | server_id = module.cloud.server_id 62 | pki = module.tls.pki 63 | config = local.config 64 | } 65 | -------------------------------------------------------------------------------- /cloud/azure/terraform.tf: -------------------------------------------------------------------------------- 1 | ../.include/terraform.tf -------------------------------------------------------------------------------- /cloud/azure/vars.tf: -------------------------------------------------------------------------------- 1 | ../.include/vars.tf -------------------------------------------------------------------------------- /cloud/azure/versions.tf: -------------------------------------------------------------------------------- 1 | ../../modules/cloud-azure/versions.tf -------------------------------------------------------------------------------- /cloud/digitalocean/outputs.tf: -------------------------------------------------------------------------------- 1 | ../.include/outputs.tf -------------------------------------------------------------------------------- /cloud/digitalocean/resources.tf: -------------------------------------------------------------------------------- 1 | resource "digitalocean_floating_ip" "main" { 2 | region = var.config.clouds.digitalocean.region 3 | } 4 | 5 | locals { 6 | server_address = "${digitalocean_floating_ip.main.ip_address}" 7 | algo_config = "${path.cwd}/configs/${local.server_address}" 8 | } 9 | 10 | module "tls" { 11 | source = "../../modules/tls/" 12 | algo_config = local.algo_config 13 | vpn_users = var.config.vpn_users 14 | server_address = local.server_address 15 | } 16 | 17 | module "user-data" { 18 | source = "../../modules/user-data/" 19 | base64_encode = false 20 | gzip = false 21 | ipv6 = true 22 | config = local.config 23 | pki = module.tls.pki 24 | } 25 | 26 | module "cloud" { 27 | source = "../../modules/cloud-digitalocean/" 28 | region = var.config.clouds.digitalocean.region 29 | algo_name = var.algo_name 30 | algo_ip = digitalocean_floating_ip.main.id 31 | ssh_public_key = module.tls.ssh_public_key 32 | user_data = module.user-data.template_cloudinit_config 33 | image = var.config.clouds.digitalocean.image 34 | size = var.config.clouds.digitalocean.size 35 | } 36 | 37 | module "configs" { 38 | source = "../../modules/configs/" 39 | algo_config = local.algo_config 40 | server_address = local.server_address 41 | client_p12_pass = module.tls.client_p12_pass 42 | ssh_user = module.cloud.ssh_user 43 | ssh_private_key = module.tls.ssh_private_key 44 | server_id = module.cloud.server_id 45 | pki = module.tls.pki 46 | config = local.config 47 | } 48 | -------------------------------------------------------------------------------- /cloud/digitalocean/terraform.tf: -------------------------------------------------------------------------------- 1 | ../.include/terraform.tf -------------------------------------------------------------------------------- /cloud/digitalocean/vars.tf: -------------------------------------------------------------------------------- 1 | ../.include/vars.tf -------------------------------------------------------------------------------- /cloud/digitalocean/versions.tf: -------------------------------------------------------------------------------- 1 | ../../modules/cloud-digitalocean/versions.tf -------------------------------------------------------------------------------- /cloud/ec2/outputs.tf: -------------------------------------------------------------------------------- 1 | ../.include/outputs.tf -------------------------------------------------------------------------------- /cloud/ec2/resources.tf: -------------------------------------------------------------------------------- 1 | resource "aws_eip" "algo" { 2 | vpc = true 3 | } 4 | 5 | locals { 6 | server_address = "${aws_eip.algo.public_ip}" 7 | algo_config = "${path.cwd}/configs/${local.server_address}" 8 | } 9 | 10 | module "tls" { 11 | source = "../../modules/tls/" 12 | algo_config = local.algo_config 13 | vpn_users = var.config.vpn_users 14 | server_address = local.server_address 15 | } 16 | 17 | module "user-data" { 18 | source = "../../modules/user-data/" 19 | base64_encode = true 20 | gzip = true 21 | ipv6 = true 22 | config = local.config 23 | pki = module.tls.pki 24 | } 25 | 26 | module "cloud" { 27 | source = "../../modules/cloud-ec2/" 28 | region = var.config.clouds.ec2.region 29 | algo_name = var.algo_name 30 | algo_ip = aws_eip.algo.id 31 | ssh_public_key = module.tls.ssh_public_key 32 | user_data = module.user-data.template_cloudinit_config 33 | image = var.config.clouds.ec2.image 34 | size = var.config.clouds.ec2.size 35 | encrypted = var.config.clouds.ec2.encrypted 36 | kms_key_id = var.config.clouds.ec2.kms_key_id 37 | config = var.config 38 | } 39 | 40 | module "configs" { 41 | source = "../../modules/configs/" 42 | algo_config = local.algo_config 43 | server_address = local.server_address 44 | client_p12_pass = module.tls.client_p12_pass 45 | ssh_user = module.cloud.ssh_user 46 | ssh_private_key = module.tls.ssh_private_key 47 | server_id = module.cloud.server_id 48 | pki = module.tls.pki 49 | config = local.config 50 | } 51 | -------------------------------------------------------------------------------- /cloud/ec2/terraform.tf: -------------------------------------------------------------------------------- 1 | ../.include/terraform.tf -------------------------------------------------------------------------------- /cloud/ec2/vars.tf: -------------------------------------------------------------------------------- 1 | ../.include/vars.tf -------------------------------------------------------------------------------- /cloud/ec2/versions.tf: -------------------------------------------------------------------------------- 1 | ../../modules/cloud-ec2/versions.tf -------------------------------------------------------------------------------- /cloud/gce/outputs.tf: -------------------------------------------------------------------------------- 1 | ../.include/outputs.tf -------------------------------------------------------------------------------- /cloud/gce/resources.tf: -------------------------------------------------------------------------------- 1 | variable "google_credentials" { 2 | description = "Either the path to or the contents of a service account key file in JSON format" 3 | } 4 | 5 | resource "google_compute_address" "main" { 6 | name = var.algo_name 7 | region = var.config.clouds.gce.region 8 | address_type = "EXTERNAL" 9 | } 10 | 11 | locals { 12 | server_address = "${google_compute_address.main.address}" 13 | algo_config = "${path.cwd}/configs/${local.server_address}" 14 | } 15 | 16 | module "tls" { 17 | source = "../../modules/tls/" 18 | algo_config = local.algo_config 19 | vpn_users = var.config.vpn_users 20 | server_address = local.server_address 21 | } 22 | 23 | module "user-data" { 24 | source = "../../modules/user-data/" 25 | base64_encode = false 26 | gzip = false 27 | ipv6 = false 28 | config = local.config 29 | pki = module.tls.pki 30 | } 31 | 32 | module "cloud" { 33 | source = "../../modules/cloud-gce/" 34 | region = var.config.clouds.gce.region 35 | algo_name = var.algo_name 36 | server_address = local.server_address 37 | ssh_public_key = module.tls.ssh_public_key 38 | user_data = module.user-data.template_cloudinit_config 39 | image = var.config.clouds.gce.image 40 | size = var.config.clouds.gce.size 41 | google_credentials = var.google_credentials 42 | config = var.config 43 | } 44 | 45 | module "configs" { 46 | source = "../../modules/configs/" 47 | algo_config = local.algo_config 48 | server_address = local.server_address 49 | client_p12_pass = module.tls.client_p12_pass 50 | ssh_user = module.cloud.ssh_user 51 | ssh_private_key = module.tls.ssh_private_key 52 | server_id = module.cloud.server_id 53 | pki = module.tls.pki 54 | config = local.config 55 | } 56 | -------------------------------------------------------------------------------- /cloud/gce/terraform.tf: -------------------------------------------------------------------------------- 1 | ../.include/terraform.tf -------------------------------------------------------------------------------- /cloud/gce/vars.tf: -------------------------------------------------------------------------------- 1 | ../.include/vars.tf -------------------------------------------------------------------------------- /cloud/gce/versions.tf: -------------------------------------------------------------------------------- 1 | ../../modules/cloud-gce/versions.tf -------------------------------------------------------------------------------- /config.auto.tfvars: -------------------------------------------------------------------------------- 1 | config = { 2 | # This is the list of users to generate. 3 | # Every device must have a unique username. 4 | vpn_users = [ 5 | "phone", 6 | "laptop", 7 | "desktop" 8 | ] 9 | 10 | # Deploy StrongSwan to enable IPsec support 11 | ipsec = { 12 | enabled = true 13 | ipv4 = "10.100.0.0/16" 14 | ipv6 = "fd9d:bc11:4020::/64" 15 | } 16 | 17 | # Deploy WireGuard 18 | wireguard = { 19 | enabled = true 20 | ipv4 = "10.200.0.0/16" 21 | ipv6 = "fd9d:bc11:4021::/64" 22 | port = 51820 23 | # If you're behind NAT or a firewall and you want to receive incoming connections long after network traffic has gone silent. 24 | # This option will keep the "connection" open in the eyes of NAT. 25 | # See: https://www.wireguard.com/quickstart/#nat-and-firewall-traversal-persistence 26 | persistent_keepalive = 0 27 | } 28 | 29 | dns = { 30 | adblocking = { 31 | enabled = true 32 | 33 | lists = [ 34 | "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts", 35 | "https://hosts-file.net/ad_servers.txt" 36 | ] 37 | } 38 | 39 | encryption = { 40 | # Enable DNS encryption. 41 | # If 'false', resolvers should be specified below. 42 | # Can not be disable if adblocking is enabled 43 | enabled = true 44 | 45 | # DNS servers which will be used if dns encryption is enabled. Multiple 46 | # providers may be specified, but avoid mixing providers that filter results 47 | # (like Cisco) with those that don't (like Cloudflare) or you could get 48 | # inconsistent results. The list of available public providers can be found 49 | # here: 50 | # https://github.com/DNSCrypt/dnscrypt-resolvers/blob/master/v2/public-resolvers.md 51 | servers = { 52 | ipv4 = [ 53 | "cloudflare" 54 | ] 55 | ipv6 = [ 56 | "cloudflare-ipv6" 57 | ] 58 | } 59 | } 60 | 61 | # DNS resolvers which will be used if dns encryption is disabled 62 | # The default is to use Cloudflare. 63 | resolvers = { 64 | ipv4 = [ 65 | "1.1.1.1", 66 | "1.0.0.1" 67 | ] 68 | 69 | ipv6 = [ 70 | "2606:4700:4700::1111", 71 | "2606:4700:4700::1001" 72 | ] 73 | } 74 | } 75 | 76 | ssh_tunneling = true 77 | 78 | # MSS is the TCP Max Segment Size 79 | # Setting the 'max_mss' variable can solve some issues related to packet fragmentation 80 | # This appears to be necessary on (at least) Google Cloud, 81 | # however, some routers also require a change to this parameter 82 | # See also: 83 | # - https://github.com/trailofbits/algo/issues/216 84 | # - https://github.com/trailofbits/algo/issues?utf8=%E2%9C%93&q=is%3Aissue%20mtu 85 | # - https://serverfault.com/questions/601143/ssh-not-working-over-ipsec-tunnel-strongswan 86 | # max_mss = 1316 87 | max_mss = 0 88 | 89 | # Block traffic between connected clients 90 | drop_traffic_between_clients = true 91 | 92 | # StrongSwan log level 93 | # https://wiki.strongswan.org/projects/strongswan/wiki/LoggerConfiguration 94 | strongswan_log_level = "2" 95 | 96 | # Your Algo server will automatically install security updates. Some updates 97 | # require a reboot to take effect but your Algo server will not reboot itself 98 | # automatically unless you change 'enabled' below from 'false' to 'true', in 99 | # which case a reboot will take place if necessary at the time specified (as 100 | # HH:MM) in the time zone of your Algo server. The default time zone is UTC. 101 | unattended_reboot = { 102 | enabled = false 103 | time = "06:00" 104 | } 105 | 106 | # TODO: delete ssh authorized keys 107 | unmanaged = false 108 | 109 | # Upgrade the system during the deployment 110 | system_upgrade = true 111 | 112 | ciphers = { 113 | ipsec = { 114 | ike = "aes256gcm16-prfsha512-ecp384!" 115 | esp = "aes256gcm16-ecp384!" 116 | } 117 | } 118 | 119 | clouds = { 120 | azure = { 121 | image = "19.04" 122 | size = "Standard_B1S" 123 | region = "eastus" 124 | } 125 | 126 | digitalocean = { 127 | image = "ubuntu-19-04-x64" 128 | size = "s-1vcpu-1gb" 129 | region = "nyc1" 130 | } 131 | 132 | ec2 = { 133 | # Change the encrypted flag to "true" to enable AWS volume encryption, for encryption of data at rest. 134 | encrypted = true 135 | kms_key_id = "" 136 | image = "ubuntu-disco-19.04" 137 | size = "t2.micro" 138 | region = "us-east-1" 139 | } 140 | 141 | gce = { 142 | image = "ubuntu-os-cloud/ubuntu-1904" 143 | size = "f1-micro" 144 | region = "us-east1" 145 | } 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /configs/.gitinit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trailofbits/algo-ng/718fa4d82233a95b6f095f235bb61890f2d7a139/configs/.gitinit -------------------------------------------------------------------------------- /docs/cloud-amazon-ec2.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trailofbits/algo-ng/718fa4d82233a95b6f095f235bb61890f2d7a139/docs/cloud-amazon-ec2.md -------------------------------------------------------------------------------- /docs/cloud-azure.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trailofbits/algo-ng/718fa4d82233a95b6f095f235bb61890f2d7a139/docs/cloud-azure.md -------------------------------------------------------------------------------- /docs/cloud-do.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trailofbits/algo-ng/718fa4d82233a95b6f095f235bb61890f2d7a139/docs/cloud-do.md -------------------------------------------------------------------------------- /docs/cloud-gce.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trailofbits/algo-ng/718fa4d82233a95b6f095f235bb61890f2d7a139/docs/cloud-gce.md -------------------------------------------------------------------------------- /docs/defaults.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trailofbits/algo-ng/718fa4d82233a95b6f095f235bb61890f2d7a139/docs/defaults.md -------------------------------------------------------------------------------- /docs/deploy-from-docker.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trailofbits/algo-ng/718fa4d82233a95b6f095f235bb61890f2d7a139/docs/deploy-from-docker.md -------------------------------------------------------------------------------- /docs/deploy-from-terraform.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trailofbits/algo-ng/718fa4d82233a95b6f095f235bb61890f2d7a139/docs/deploy-from-terraform.md -------------------------------------------------------------------------------- /docs/deploy-to-unsupported-cloud.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trailofbits/algo-ng/718fa4d82233a95b6f095f235bb61890f2d7a139/docs/deploy-to-unsupported-cloud.md -------------------------------------------------------------------------------- /docs/faq.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trailofbits/algo-ng/718fa4d82233a95b6f095f235bb61890f2d7a139/docs/faq.md -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trailofbits/algo-ng/718fa4d82233a95b6f095f235bb61890f2d7a139/docs/index.md -------------------------------------------------------------------------------- /docs/non-interactive-authentication.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trailofbits/algo-ng/718fa4d82233a95b6f095f235bb61890f2d7a139/docs/non-interactive-authentication.md -------------------------------------------------------------------------------- /docs/troubleshooting.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trailofbits/algo-ng/718fa4d82233a95b6f095f235bb61890f2d7a139/docs/troubleshooting.md -------------------------------------------------------------------------------- /modules/cloud-azure/output.tf: -------------------------------------------------------------------------------- 1 | output "server_id" { 2 | value = "${azurerm_virtual_machine.algo.id}" 3 | } 4 | 5 | output "ssh_user" { 6 | value = "ubuntu" 7 | } 8 | -------------------------------------------------------------------------------- /modules/cloud-azure/resources.tf: -------------------------------------------------------------------------------- 1 | resource "azurerm_network_security_group" "algo" { 2 | name = var.algo_name 3 | location = var.region 4 | resource_group_name = var.resource_group_name 5 | 6 | dynamic "security_rule" { 7 | iterator = rule 8 | for_each = [ 9 | "0:*:ICMP", 10 | "22:Tcp:SSH", 11 | "500,4500:Udp:IPsec", 12 | "${var.wireguard_network["port"]}:Udp:WireGuard" 13 | ] 14 | 15 | content { 16 | name = "Allow-${split(":", rule.value)[2]}" 17 | priority = "10${rule.key}" 18 | direction = "Inbound" 19 | access = "Allow" 20 | protocol = split(":", rule.value)[1] 21 | source_port_range = "*" 22 | source_address_prefix = "*" 23 | destination_address_prefix = "*" 24 | destination_port_ranges = [ 25 | for i in split(",", split(":", rule.value)[0]) : 26 | i 27 | ] 28 | } 29 | } 30 | 31 | tags = { 32 | Environment = "Algo" 33 | } 34 | } 35 | 36 | resource "azurerm_virtual_network" "algo" { 37 | name = var.algo_name 38 | location = var.region 39 | resource_group_name = var.resource_group_name 40 | address_space = ["10.10.0.0/16"] 41 | 42 | tags = { 43 | Environment = "Algo" 44 | } 45 | } 46 | 47 | resource "azurerm_subnet" "algo" { 48 | name = var.algo_name 49 | resource_group_name = var.resource_group_name 50 | virtual_network_name = azurerm_virtual_network.algo.name 51 | address_prefix = "10.10.0.0/24" 52 | } 53 | 54 | resource "azurerm_network_interface" "algo" { 55 | name = var.algo_name 56 | location = var.region 57 | resource_group_name = var.resource_group_name 58 | network_security_group_id = azurerm_network_security_group.algo.id 59 | 60 | ip_configuration { 61 | name = var.algo_name 62 | subnet_id = azurerm_subnet.algo.id 63 | private_ip_address_allocation = "dynamic" 64 | public_ip_address_id = var.algo_ip 65 | } 66 | } 67 | 68 | resource "azurerm_virtual_machine" "algo" { 69 | name = var.algo_name 70 | location = var.region 71 | resource_group_name = var.resource_group_name 72 | network_interface_ids = [azurerm_network_interface.algo.id] 73 | vm_size = var.size 74 | delete_os_disk_on_termination = true 75 | delete_data_disks_on_termination = true 76 | 77 | storage_image_reference { 78 | publisher = "Canonical" 79 | offer = "UbuntuServer" 80 | sku = var.image 81 | version = "latest" 82 | } 83 | 84 | storage_os_disk { 85 | name = var.algo_name 86 | caching = "ReadWrite" 87 | create_option = "FromImage" 88 | managed_disk_type = "Standard_LRS" 89 | } 90 | 91 | os_profile { 92 | computer_name = var.algo_name 93 | admin_username = "ubuntu" 94 | custom_data = var.user_data 95 | } 96 | 97 | os_profile_linux_config { 98 | disable_password_authentication = true 99 | 100 | ssh_keys { 101 | path = "/home/ubuntu/.ssh/authorized_keys" 102 | key_data = var.ssh_public_key 103 | } 104 | } 105 | 106 | tags = { 107 | Environment = "Algo" 108 | } 109 | 110 | lifecycle { 111 | create_before_destroy = true 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /modules/cloud-azure/vars.tf: -------------------------------------------------------------------------------- 1 | variable "region" {} 2 | variable "algo_name" {} 3 | variable "ssh_public_key" {} 4 | variable "user_data" {} 5 | variable "resource_group_name" {} 6 | variable "algo_ip" {} 7 | 8 | variable "wireguard_network" { 9 | type = map(string) 10 | 11 | default = { 12 | ipv4 = "10.19.49.0/24" 13 | ipv6 = "fd9d:bc11:4021::/48" 14 | port = 51820 15 | } 16 | } 17 | 18 | variable "image" { 19 | default = "18.04-LTS" 20 | } 21 | 22 | variable "size" { 23 | default = "Basic_A0" 24 | } 25 | 26 | variable "ipv6" { 27 | default = false 28 | } 29 | -------------------------------------------------------------------------------- /modules/cloud-azure/versions.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = "~> 0.12" 3 | 4 | required_providers { 5 | azurerm = "~> 1.32" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /modules/cloud-digitalocean/output.tf: -------------------------------------------------------------------------------- 1 | output "server_id" { 2 | value = "${digitalocean_droplet.main.id}" 3 | } 4 | 5 | output "ssh_user" { 6 | value = "root" 7 | } 8 | -------------------------------------------------------------------------------- /modules/cloud-digitalocean/resources.tf: -------------------------------------------------------------------------------- 1 | resource "digitalocean_ssh_key" "main" { 2 | name = "${var.algo_name}" 3 | public_key = "${var.ssh_public_key}" 4 | } 5 | 6 | resource "digitalocean_tag" "main" { 7 | name = "Environment:Algo" 8 | } 9 | 10 | resource "digitalocean_droplet" "main" { 11 | name = "${var.algo_name}" 12 | image = "${var.image}" 13 | size = "${var.size}" 14 | region = "${var.region}" 15 | user_data = "${var.user_data}" 16 | tags = ["${digitalocean_tag.main.id}"] 17 | ssh_keys = ["${digitalocean_ssh_key.main.id}"] 18 | ipv6 = true 19 | 20 | lifecycle { 21 | create_before_destroy = true 22 | } 23 | } 24 | 25 | resource "digitalocean_floating_ip_assignment" "foobar" { 26 | ip_address = "${var.algo_ip}" 27 | droplet_id = "${digitalocean_droplet.main.id}" 28 | } 29 | 30 | resource "digitalocean_firewall" "main" { 31 | name = "${var.algo_name}" 32 | droplet_ids = ["${digitalocean_droplet.main.id}"] 33 | 34 | dynamic "inbound_rule" { 35 | iterator = rule 36 | for_each = [ 37 | "22:tcp", 38 | "500:udp", 39 | "4500:udp", 40 | "${var.wireguard_network["port"]}:udp" 41 | ] 42 | 43 | content { 44 | source_addresses = ["0.0.0.0/0", "::/0"] 45 | protocol = split(":", rule.value)[1] 46 | port_range = split(":", rule.value)[0] 47 | } 48 | } 49 | 50 | dynamic "outbound_rule" { 51 | iterator = rule 52 | for_each = [ 53 | "tcp", 54 | "udp", 55 | ] 56 | 57 | content { 58 | protocol = rule.value 59 | port_range = "1-65535" 60 | destination_addresses = [ 61 | "0.0.0.0/0", 62 | "::/0" 63 | ] 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /modules/cloud-digitalocean/vars.tf: -------------------------------------------------------------------------------- 1 | variable "region" {} 2 | variable "algo_name" {} 3 | variable "ssh_public_key" {} 4 | variable "user_data" {} 5 | 6 | variable "wireguard_network" { 7 | type = map(string) 8 | 9 | default = { 10 | ipv4 = "10.19.49.0/24" 11 | ipv6 = "fd9d:bc11:4021::/48" 12 | port = 51820 13 | } 14 | } 15 | 16 | variable "image" { 17 | default = "ubuntu-19-04-x64" 18 | } 19 | 20 | variable "size" { 21 | default = "s-1vcpu-1gb" 22 | } 23 | 24 | variable "ipv6" { 25 | default = true 26 | } 27 | 28 | variable "algo_ip" {} 29 | -------------------------------------------------------------------------------- /modules/cloud-digitalocean/versions.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = "~> 0.12" 3 | 4 | required_providers { 5 | digitalocean = "~> 1.3" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /modules/cloud-ec2/output.tf: -------------------------------------------------------------------------------- 1 | output "server_id" { 2 | value = "${aws_instance.main.id}" 3 | } 4 | 5 | output "ssh_user" { 6 | value = "ubuntu" 7 | } 8 | -------------------------------------------------------------------------------- /modules/cloud-ec2/resources.tf: -------------------------------------------------------------------------------- 1 | data "aws_ami_ids" "main" { 2 | owners = ["099720109477"] 3 | 4 | filter { 5 | name = "name" 6 | 7 | values = [ 8 | "ubuntu/images/hvm-ssd/${var.image}-amd64-server-*", 9 | ] 10 | } 11 | } 12 | 13 | resource "aws_vpc" "main" { 14 | cidr_block = "172.16.0.0/16" 15 | instance_tenancy = "default" 16 | assign_generated_ipv6_cidr_block = true 17 | 18 | tags = { 19 | Environment = "Algo" 20 | } 21 | } 22 | 23 | resource "aws_internet_gateway" "main" { 24 | vpc_id = "${aws_vpc.main.id}" 25 | 26 | tags = { 27 | Environment = "Algo" 28 | } 29 | } 30 | 31 | resource "aws_subnet" "main" { 32 | vpc_id = "${aws_vpc.main.id}" 33 | cidr_block = "172.16.254.0/23" 34 | ipv6_cidr_block = "${cidrsubnet(aws_vpc.main.ipv6_cidr_block, 8, 1)}" 35 | 36 | tags = { 37 | Environment = "Algo" 38 | } 39 | } 40 | 41 | resource "aws_route_table" "default" { 42 | vpc_id = "${aws_vpc.main.id}" 43 | 44 | route { 45 | cidr_block = "0.0.0.0/0" 46 | gateway_id = "${aws_internet_gateway.main.id}" 47 | } 48 | 49 | route { 50 | ipv6_cidr_block = "::/0" 51 | gateway_id = "${aws_internet_gateway.main.id}" 52 | } 53 | 54 | tags = { 55 | Environment = "Algo" 56 | } 57 | } 58 | 59 | resource "aws_route_table_association" "default" { 60 | subnet_id = "${aws_subnet.main.id}" 61 | route_table_id = "${aws_route_table.default.id}" 62 | } 63 | 64 | resource "aws_security_group" "main" { 65 | description = "Enable SSH and IPsec" 66 | vpc_id = "${aws_vpc.main.id}" 67 | tags = { 68 | Environment = "Algo" 69 | } 70 | 71 | dynamic "ingress" { 72 | for_each = [ 73 | "-1:icmp", 74 | "22:tcp", 75 | "500:udp", 76 | "4500:udp", 77 | "${var.wireguard_network["port"]}:udp" 78 | ] 79 | 80 | content { 81 | cidr_blocks = ["0.0.0.0/0"] 82 | ipv6_cidr_blocks = ["::/0"] 83 | from_port = split(":", ingress.value)[0] 84 | to_port = split(":", ingress.value)[0] 85 | protocol = split(":", ingress.value)[1] 86 | } 87 | } 88 | 89 | egress { 90 | from_port = 0 91 | to_port = 0 92 | protocol = "-1" 93 | cidr_blocks = ["0.0.0.0/0"] 94 | ipv6_cidr_blocks = ["::/0"] 95 | } 96 | } 97 | 98 | resource "aws_key_pair" "main" { 99 | key_name_prefix = "algo-" 100 | public_key = "${var.ssh_public_key}" 101 | } 102 | 103 | resource "aws_instance" "main" { 104 | ami = data.aws_ami_ids.main.ids[0] 105 | instance_type = "${var.size}" 106 | instance_initiated_shutdown_behavior = "terminate" 107 | key_name = "${aws_key_pair.main.key_name}" 108 | vpc_security_group_ids = ["${aws_security_group.main.id}"] 109 | subnet_id = "${aws_subnet.main.id}" 110 | user_data = "${var.user_data}" 111 | ipv6_address_count = 1 112 | 113 | root_block_device { 114 | volume_size = 8 115 | delete_on_termination = true 116 | encrypted = var.encrypted 117 | kms_key_id = var.kms_key_id 118 | } 119 | 120 | tags = { 121 | Environment = "Algo" 122 | } 123 | 124 | volume_tags = { 125 | Environment = "Algo" 126 | } 127 | 128 | lifecycle { 129 | create_before_destroy = true 130 | } 131 | } 132 | 133 | resource "aws_eip_association" "main" { 134 | instance_id = "${aws_instance.main.id}" 135 | allocation_id = var.algo_ip 136 | } 137 | -------------------------------------------------------------------------------- /modules/cloud-ec2/vars.tf: -------------------------------------------------------------------------------- 1 | variable "region" {} 2 | variable "algo_name" {} 3 | variable "ssh_public_key" {} 4 | variable "user_data" {} 5 | variable "config" {} 6 | 7 | variable "wireguard_network" { 8 | type = map(string) 9 | 10 | default = { 11 | ipv4 = "10.19.49.0/24" 12 | ipv6 = "fd9d:bc11:4021::/48" 13 | port = 51820 14 | } 15 | } 16 | 17 | variable "image" { 18 | default = "ubuntu-disco-19.04" 19 | } 20 | 21 | variable "size" { 22 | default = "t2.micro" 23 | } 24 | 25 | variable "ipv6" { 26 | default = true 27 | } 28 | 29 | variable "encrypted" { 30 | default = true 31 | } 32 | 33 | variable "kms_key_id" { 34 | default = "" 35 | } 36 | 37 | variable "algo_ip" {} 38 | -------------------------------------------------------------------------------- /modules/cloud-ec2/versions.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = "~> 0.12" 3 | 4 | required_providers { 5 | aws = "~> 2.22" 6 | } 7 | } 8 | 9 | provider "aws" { 10 | region = var.config.clouds.ec2.region 11 | } 12 | -------------------------------------------------------------------------------- /modules/cloud-gce/output.tf: -------------------------------------------------------------------------------- 1 | output "server_id" { 2 | value = "${google_compute_instance.algo.instance_id}" 3 | } 4 | 5 | output "ssh_user" { 6 | value = "ubuntu" 7 | } 8 | -------------------------------------------------------------------------------- /modules/cloud-gce/resources.tf: -------------------------------------------------------------------------------- 1 | resource "random_id" "name" { 2 | byte_length = 3 3 | 4 | keepers = { 5 | region_name = "${var.region}/${var.algo_name}" 6 | user_data = "${var.user_data}" 7 | } 8 | } 9 | 10 | locals { 11 | name = "${var.algo_name}-${random_id.name.hex}" 12 | } 13 | 14 | resource "google_compute_network" "main" { 15 | name = "${local.name}" 16 | description = "${var.algo_name}" 17 | auto_create_subnetworks = false 18 | } 19 | 20 | resource "google_compute_subnetwork" "main" { 21 | name = "${local.name}" 22 | ip_cidr_range = "10.2.0.0/16" 23 | network = "${google_compute_network.main.self_link}" 24 | } 25 | 26 | resource "google_compute_firewall" "ingress" { 27 | name = "${local.name}" 28 | description = "${var.algo_name}" 29 | network = "${google_compute_network.main.name}" 30 | 31 | dynamic "allow" { 32 | for_each = [ 33 | ":icmp", 34 | "22:tcp", 35 | "500,4500,${var.wireguard_network["port"]}:udp" 36 | ] 37 | 38 | content { 39 | ports = [ 40 | for i in split(",", split(":", allow.value)[0]) : 41 | i 42 | if length(i) > 0 43 | ] 44 | protocol = split(":", allow.value)[1] 45 | } 46 | } 47 | } 48 | 49 | data "google_compute_zones" "available" {} 50 | 51 | resource "random_shuffle" "az" { 52 | input = data.google_compute_zones.available.names 53 | result_count = 1 54 | } 55 | 56 | resource "google_compute_instance" "algo" { 57 | name = "${var.algo_name}" 58 | description = "${var.algo_name}" 59 | machine_type = "${var.size}" 60 | zone = "${random_shuffle.az.result[0]}" 61 | can_ip_forward = true 62 | 63 | boot_disk { 64 | auto_delete = true 65 | 66 | initialize_params { 67 | image = "${var.image}" 68 | } 69 | } 70 | 71 | network_interface { 72 | network = "${google_compute_network.main.name}" 73 | subnetwork = "${google_compute_subnetwork.main.name}" 74 | 75 | access_config { 76 | nat_ip = "${var.server_address}" 77 | } 78 | } 79 | 80 | metadata = { 81 | sshKeys = "ubuntu:${var.ssh_public_key}" 82 | user-data = "${var.user_data}" 83 | } 84 | 85 | labels = { 86 | "environment" = "algo" 87 | } 88 | 89 | lifecycle { 90 | create_before_destroy = true 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /modules/cloud-gce/vars.tf: -------------------------------------------------------------------------------- 1 | variable "region" {} 2 | variable "algo_name" {} 3 | variable "ssh_public_key" {} 4 | variable "user_data" {} 5 | variable "server_address" {} 6 | variable "config" {} 7 | 8 | variable "wireguard_network" { 9 | type = map(string) 10 | 11 | default = { 12 | ipv4 = "10.19.49.0/24" 13 | ipv6 = "fd9d:bc11:4021::/48" 14 | port = 51820 15 | } 16 | } 17 | 18 | variable "google_credentials" {} 19 | 20 | variable "image" { 21 | default = "ubuntu-os-cloud/ubuntu-1904" 22 | } 23 | 24 | variable "size" { 25 | default = "f1-micro" 26 | } 27 | 28 | variable "ipv6" { 29 | default = false 30 | } 31 | -------------------------------------------------------------------------------- /modules/cloud-gce/versions.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = "~> 0.12" 3 | 4 | required_providers { 5 | google = "~> 2.6" 6 | } 7 | } 8 | 9 | provider "google" { 10 | region = var.config.clouds.gce.region 11 | project = jsondecode(file(var.google_credentials))["project_id"] 12 | } 13 | -------------------------------------------------------------------------------- /modules/cloud-hetzner/output.tf: -------------------------------------------------------------------------------- 1 | output "server_id" { 2 | value = "${hcloud_server.main.id}" 3 | } 4 | 5 | output "ssh_user" { 6 | value = "root" 7 | } 8 | -------------------------------------------------------------------------------- /modules/cloud-hetzner/resources.tf: -------------------------------------------------------------------------------- 1 | resource "random_id" "name" { 2 | byte_length = 3 3 | 4 | keepers = { 5 | region_name = "${var.region}/${var.algo_name}" 6 | user_data = "${var.user_data}" 7 | } 8 | } 9 | 10 | locals { 11 | algo_name = "${var.algo_name}-${random_id.name.hex}" 12 | } 13 | 14 | resource "hcloud_ssh_key" "main" { 15 | name = "${var.algo_name}" 16 | public_key = "${var.ssh_public_key}" 17 | } 18 | 19 | resource "hcloud_server" "main" { 20 | name = "${local.algo_name}" 21 | image = "${var.image}" 22 | server_type = "${var.size}" 23 | location = "${var.region}" 24 | user_data = var.user_data 25 | ssh_keys = ["${hcloud_ssh_key.main.id}"] 26 | backups = false 27 | labels = { 28 | "Environment" = "Algo" 29 | } 30 | lifecycle { 31 | create_before_destroy = true 32 | } 33 | } 34 | 35 | resource "hcloud_floating_ip_assignment" "main" { 36 | floating_ip_id = var.algo_ip 37 | server_id = "${hcloud_server.main.id}" 38 | } 39 | -------------------------------------------------------------------------------- /modules/cloud-hetzner/vars.tf: -------------------------------------------------------------------------------- 1 | variable "region" {} 2 | variable "algo_name" {} 3 | variable "ssh_public_key" {} 4 | variable "user_data" {} 5 | variable "server_address" {} 6 | 7 | variable "wireguard_network" { 8 | type = map(string) 9 | 10 | default = { 11 | ipv4 = "10.19.49.0/24" 12 | ipv6 = "fd9d:bc11:4021::/48" 13 | port = 51820 14 | } 15 | } 16 | 17 | variable "image" { 18 | default = "ubuntu-18.04" 19 | } 20 | 21 | variable "size" { 22 | default = "cx11" 23 | } 24 | 25 | variable "ipv6" { 26 | default = true 27 | } 28 | 29 | variable "algo_ip" {} 30 | -------------------------------------------------------------------------------- /modules/cloud-hetzner/versions.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = "~> 0.12" 3 | } 4 | 5 | provider "hcloud" { 6 | version = "~> 1.10" 7 | } 8 | -------------------------------------------------------------------------------- /modules/cloud-scaleway/output.tf: -------------------------------------------------------------------------------- 1 | output "server_id" { 2 | value = "${scaleway_server.main.id}" 3 | } 4 | 5 | output "ssh_user" { 6 | value = "root" 7 | } 8 | -------------------------------------------------------------------------------- /modules/cloud-scaleway/resources.tf: -------------------------------------------------------------------------------- 1 | data "scaleway_image" "main" { 2 | architecture = "x86_64" 3 | name = "${var.image}" 4 | } 5 | 6 | locals { 7 | authorized_key = chomp(replace(var.ssh_public_key, " ", "_")) 8 | } 9 | 10 | resource "scaleway_server" "main" { 11 | name = "${var.algo_name}" 12 | image = "${data.scaleway_image.main.id}" 13 | type = "${var.size}" 14 | boot_type = "local" 15 | enable_ipv6 = true 16 | public_ip = "${var.server_address}" 17 | state = "running" 18 | cloudinit = "${var.user_data}" 19 | tags = [ 20 | "Environment:Algo", 21 | "AUTHORIZED_KEY=${local.authorized_key}" 22 | ] 23 | 24 | lifecycle { 25 | create_before_destroy = true 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /modules/cloud-scaleway/vars.tf: -------------------------------------------------------------------------------- 1 | variable "region" {} 2 | variable "algo_name" {} 3 | variable "ssh_public_key" {} 4 | variable "user_data" {} 5 | 6 | variable "wireguard_network" { 7 | type = map(string) 8 | 9 | default = { 10 | ipv4 = "10.19.49.0/24" 11 | ipv6 = "fd9d:bc11:4021::/48" 12 | port = 51820 13 | } 14 | } 15 | 16 | variable "image" { 17 | default = "Ubuntu Bionic" 18 | } 19 | 20 | variable "size" { 21 | default = "START1-S" 22 | } 23 | 24 | variable "ipv6" { 25 | default = true 26 | } 27 | 28 | variable "server_address" {} 29 | -------------------------------------------------------------------------------- /modules/cloud-scaleway/versions.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = "~> 0.12" 3 | } 4 | 5 | provider "scaleway" { 6 | region = "${var.region}" 7 | version = "~> 1.10" 8 | } 9 | -------------------------------------------------------------------------------- /modules/configs/external/read-file-ssh.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -ex 4 | 5 | SSH="$(which ssh)" 6 | SSH_ARGS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" 7 | ADDRESS="$1" 8 | KEY="$2" 9 | FILE="$3" 10 | WAIT="${4:-false}" 11 | 12 | connect() { 13 | $SSH -i "${KEY}" ${SSH_ARGS} ${ADDRESS} $1 14 | } 15 | 16 | wait() { 17 | connect "until test -f ${FILE}; do sleep 5; done" 18 | } 19 | 20 | read() { 21 | FILE=$(connect "cat ${FILE} || echo null") 22 | } 23 | 24 | if [[ "${WAIT}" == "wait" ]]; then 25 | wait 26 | fi 27 | 28 | read 29 | 30 | printf '{"result": "%s"}\n' "$FILE" 31 | -------------------------------------------------------------------------------- /modules/configs/files/mobileconfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PayloadContent 6 | 7 | 8 | IKEv2 9 | 10 | OnDemandEnabled 11 | ${var.ondemand.wifi || var.ondemand.cellular ? 1 : 0} 12 | OnDemandRules 13 | 14 | 15 | %{ if length(var.ondemand.wifi_exclude) > 0 && var.ondemand.wifi == true } 16 | Action 17 | Disconnect 18 | InterfaceTypeMatch 19 | WiFi 20 | SSIDMatch 21 | 22 | %{ for i in var.ondemand.wifi_exclude ~} 23 | ${i} 24 | %{ endfor } 25 | 26 | %{ endif } 27 | 28 | %{ if var.ondemand.wifi == true } 29 | 30 | Action 31 | Connect 32 | InterfaceTypeMatch 33 | WiFi 34 | URLStringProbe 35 | http://captive.apple.com/hotspot-detect.html 36 | 37 | %{ endif } 38 | %{ if var.ondemand.cellular == true } 39 | 40 | Action 41 | Connect 42 | InterfaceTypeMatch 43 | Cellular 44 | URLStringProbe 45 | http://captive.apple.com/hotspot-detect.html 46 | 47 | %{ endif } 48 | 49 | AuthenticationMethod 50 | Certificate 51 | ChildSecurityAssociationParameters 52 | 53 | DiffieHellmanGroup 54 | 20 55 | EncryptionAlgorithm 56 | AES-256-GCM 57 | IntegrityAlgorithm 58 | SHA2-512 59 | LifeTimeInMinutes 60 | 20 61 | 62 | DeadPeerDetectionRate 63 | Medium 64 | DisableMOBIKE 65 | 0 66 | DisableRedirect 67 | 1 68 | EnableCertificateRevocationCheck 69 | 0 70 | EnablePFS 71 | 72 | IKESecurityAssociationParameters 73 | 74 | DiffieHellmanGroup 75 | 20 76 | EncryptionAlgorithm 77 | AES-256-GCM 78 | IntegrityAlgorithm 79 | SHA2-512 80 | LifeTimeInMinutes 81 | 20 82 | 83 | LocalIdentifier 84 | ${var.vpn_users[index]} 85 | PayloadCertificateUUID 86 | ${var.PayloadIdentifier_pkcs12} 87 | CertificateType 88 | ECDSA384 89 | ServerCertificateIssuerCommonName 90 | ${var.server_address} 91 | RemoteAddress 92 | ${var.server_address} 93 | RemoteIdentifier 94 | algo.vpn 95 | UseConfigurationAttributeInternalIPSubnet 96 | 0 97 | 98 | IPv4 99 | 100 | OverridePrimary 101 | 1 102 | 103 | PayloadDescription 104 | Configures VPN settings 105 | PayloadDisplayName 106 | VPN 107 | PayloadIdentifier 108 | com.apple.vpn.managed.${var.PayloadIdentifier_vpn} 109 | PayloadType 110 | com.apple.vpn.managed 111 | PayloadUUID 112 | ${var.PayloadIdentifier_vpn} 113 | PayloadVersion 114 | 1 115 | Proxies 116 | 117 | HTTPEnable 118 | 0 119 | HTTPSEnable 120 | 0 121 | 122 | UserDefinedName 123 | Algo VPN ${var.server_address} IKEv2 124 | VPNType 125 | IKEv2 126 | 127 | 128 | Password 129 | ${var.Password_pkcs12} 130 | PayloadCertificateFileName 131 | ${var.vpn_users[index]}.p12 132 | PayloadContent 133 | 134 | ${pki.ipsec.pkcs12[index]} 135 | 136 | PayloadDescription 137 | Adds a PKCS#12-formatted certificate 138 | PayloadDisplayName 139 | ${var.vpn_users[index]}.p12 140 | PayloadIdentifier 141 | com.apple.security.pkcs12.${var.PayloadIdentifier_pkcs12} 142 | PayloadType 143 | com.apple.security.pkcs12 144 | PayloadUUID 145 | ${var.PayloadIdentifier_pkcs12} 146 | PayloadVersion 147 | 1 148 | 149 | 150 | PayloadCertificateFileName 151 | ca.crt 152 | PayloadContent 153 | 154 | ${var.PayloadContentCA} 155 | 156 | PayloadDescription 157 | Adds a CA root certificate 158 | PayloadDisplayName 159 | ${var.server_address} 160 | PayloadIdentifier 161 | com.apple.security.root.${var.PayloadIdentifier_ca} 162 | PayloadType 163 | com.apple.security.root 164 | PayloadUUID 165 | ${var.PayloadIdentifier_ca} 166 | PayloadVersion 167 | 1 168 | 169 | 170 | PayloadDisplayName 171 | ${var.server_address} IKEv2 172 | PayloadIdentifier 173 | donut.local.${var.PayloadIdentifier_conf} 174 | PayloadRemovalDisallowed 175 | 176 | PayloadType 177 | Configuration 178 | PayloadUUID 179 | ${var.PayloadIdentifier_conf} 180 | PayloadVersion 181 | 1 182 | 183 | 184 | -------------------------------------------------------------------------------- /modules/configs/files/powershell.ps1: -------------------------------------------------------------------------------- 1 | #Requires -RunAsAdministrator 2 | 3 | <# 4 | .SYNOPSIS 5 | Add or remove the Algo VPN 6 | 7 | .DESCRIPTION 8 | Add or remove the Algo VPN 9 | See the examples for more information 10 | 11 | .PARAMETER Add 12 | Add the VPN to the local system 13 | 14 | .PARAMETER Remove 15 | Remove the VPN from the local system 16 | 17 | .PARAMETER GetInstalledCerts 18 | Retrieve Algo certs, if any, from the system certificate store 19 | 20 | .PARAMETER SaveCerts 21 | Save the Algo certs embedded in this file 22 | 23 | .PARAMETER OutputDirectory 24 | When saving the Algo certs, save to this directory 25 | 26 | .PARAMETER Pkcs12DecryptionPassword 27 | The decryption password for the user's PKCS12 certificate, sometimes called the "p12 password". 28 | Note that this must be passed in as a SecureString, not a regular string. 29 | You can create a secure string with the `Read-Host -AsSecureString` cmdlet. 30 | See the examples for more information. 31 | 32 | .EXAMPLE 33 | client_USER.ps1 -Add 34 | 35 | Adds the Algo VPN 36 | 37 | .EXAMPLE 38 | $$p12pass = Read-Host -AsSecureString; client_USER.ps1 -Add -Pkcs12DecryptionPassword $$p12pass 39 | 40 | Create a variable containing the PKCS12 decryption password, then use it when adding the VPN. 41 | This can be especially useful when troubleshooting, because you can use the same variable with 42 | multiple calls to client_USER.ps1, rather than having to type the PKCS12 password each time. 43 | 44 | .EXAMPLE 45 | client_USER.ps1 -Remove 46 | 47 | Removes the Algo VPN if installed. 48 | 49 | .EXAMPLE 50 | client_USER.ps1 -GetIntalledCerts 51 | 52 | Show the Algo VPN's installed certificates, if any. 53 | 54 | .EXAMPLE 55 | client_USER.ps1 -SaveCerts -OutputDirectory $$Home\Downloads 56 | 57 | Save the embedded CA cert and encrypted user PKCS12 file. 58 | #> 59 | [CmdletBinding(DefaultParameterSetName="Add")] Param( 60 | [Parameter(ParameterSetName="Add")] 61 | [Switch] $$Add, 62 | 63 | [Parameter(ParameterSetName="Add")] 64 | [SecureString] $$Pkcs12DecryptionPassword, 65 | 66 | [Parameter(Mandatory, ParameterSetName="Remove")] 67 | [Switch] $$Remove, 68 | 69 | [Parameter(Mandatory, ParameterSetName="GetInstalledCerts")] 70 | [Switch] $$GetInstalledCerts, 71 | 72 | [Parameter(Mandatory, ParameterSetName="SaveCerts")] 73 | [Switch] $$SaveCerts, 74 | 75 | [Parameter(ParameterSetName="SaveCerts")] 76 | [string] $$OutputDirectory = "$$PWD" 77 | ) 78 | 79 | $$ErrorActionPreference = "Stop" 80 | 81 | $$VpnServerAddress = "${var.server_address}" 82 | $$VpnName = "Algo VPN ${var.server_address} IKEv2" 83 | $$VpnUser = "${var.vpn_users[index]}" 84 | $$CaCertificateBase64 = "${var.CaCertificateBase64}" 85 | $$UserPkcs12Base64 = '${pki.ipsec.pkcs12[index]}' 86 | 87 | if ($$PsCmdlet.ParameterSetName -eq "Add" -and -not $$Pkcs12DecryptionPassword) { 88 | $$Pkcs12DecryptionPassword = Read-Host -AsSecureString -Prompt "Pkcs12DecryptionPassword" 89 | } 90 | 91 | <# 92 | .SYNOPSIS 93 | Create a temporary directory 94 | #> 95 | function New-TemporaryDirectory { 96 | [CmdletBinding()] Param() 97 | do { 98 | $$guid = New-Guid | Select-Object -ExpandProperty Guid 99 | $$newTempDirPath = Join-Path -Path $$env:TEMP -ChildPath $$guid 100 | } while (Test-Path -Path $$newTempDirPath) 101 | New-Item -ItemType Directory -Path $$newTempDirPath 102 | } 103 | 104 | <# 105 | .SYNOPSIS 106 | Retrieve any installed Algo VPN certificates 107 | #> 108 | function Get-InstalledAlgoVpnCertificates { 109 | [CmdletBinding()] Param() 110 | Get-ChildItem -LiteralPath Cert:\LocalMachine\Root | 111 | Where-Object { 112 | $$_.Subject -match "^CN=$${VpnServerAddress}$$" -and $$_.Issuer -match "^CN=$${VpnServerAddress}$$" 113 | } 114 | Get-ChildItem -LiteralPath Cert:\LocalMachine\My | 115 | Where-Object { 116 | $$_.Subject -match "^CN=$${VpnUser}$$" -and $$_.Issuer -match "^CN=$${VpnServerAddress}$$" 117 | } 118 | } 119 | 120 | function Save-AlgoVpnCertificates { 121 | [CmdletBinding()] Param( 122 | [String] $$OutputDirectory = $$PWD 123 | ) 124 | $$caCertPath = Join-Path -Path $$OutputDirectory -ChildPath "cacert.pem" 125 | $$userP12Path = Join-Path -Path $$OutputDirectory -ChildPath "$$VpnUser.p12" 126 | # NOTE: We cannot use ConvertFrom-Base64 here because it is not designed for binary data 127 | [IO.File]::WriteAllBytes( 128 | $$caCertPath, 129 | [Convert]::FromBase64String($$CaCertificateBase64)) 130 | [IO.File]::WriteAllBytes( 131 | $$userP12Path, 132 | [Convert]::FromBase64String($$UserPkcs12Base64)) 133 | return New-Object -TypeName PSObject -Property @{ 134 | CaPem = $$caCertPath 135 | UserPkcs12 = $$userP12Path 136 | } 137 | } 138 | 139 | function Add-AlgoVPN { 140 | [Cmdletbinding()] Param() 141 | 142 | $$workDir = New-TemporaryDirectory 143 | 144 | try { 145 | $$certs = Save-AlgoVpnCertificates -OutputDirectory $$workDir 146 | $$importPfxCertParams = @{ 147 | Password = $$Pkcs12DecryptionPassword 148 | FilePath = $$certs.UserPkcs12 149 | CertStoreLocation = "Cert:\LocalMachine\My" 150 | } 151 | Import-PfxCertificate @importPfxCertParams 152 | $$importCertParams = @{ 153 | FilePath = $$certs.CaPem 154 | CertStoreLocation = "Cert:\LocalMachine\Root" 155 | } 156 | Import-Certificate @importCertParams 157 | } finally { 158 | Remove-Item -Recurse -Force -LiteralPath $$workDir 159 | } 160 | 161 | $$addVpnParams = @{ 162 | Name = $$VpnName 163 | ServerAddress = $$VpnServerAddress 164 | TunnelType = "IKEv2" 165 | AuthenticationMethod = "MachineCertificate" 166 | EncryptionLevel = "Required" 167 | } 168 | Add-VpnConnection @addVpnParams 169 | 170 | $$setVpnParams = @{ 171 | ConnectionName = $$VpnName 172 | AuthenticationTransformConstants = "GCMAES256" 173 | CipherTransformConstants = "GCMAES256" 174 | EncryptionMethod = "AES256" 175 | IntegrityCheckMethod = "SHA384" 176 | DHGroup = "ECP384" 177 | PfsGroup = "ECP384" 178 | Force = $$true 179 | } 180 | Set-VpnConnectionIPsecConfiguration @setVpnParams 181 | } 182 | 183 | function Remove-AlgoVPN { 184 | [CmdletBinding()] Param() 185 | Get-InstalledAlgoVpnCertificates | Remove-Item -Force 186 | Remove-VpnConnection -Name $$VpnName -Force 187 | } 188 | 189 | switch ($$PsCmdlet.ParameterSetName) { 190 | "Add" { Add-AlgoVPN } 191 | "Remove" { Remove-AlgoVPN } 192 | "GetInstalledCerts" { Get-InstalledAlgoVpnCertificates } 193 | "SaveCerts" { 194 | $$certs = Save-AlgoVpnCertificates -OutputDirectory $$OutputDirectory 195 | Get-Item -LiteralPath $$certs.UserPkcs12, $$certs.CaPem 196 | } 197 | default { throw "Unknown parameter set: '$$($$PsCmdlet.ParameterSetName)'" } 198 | } 199 | -------------------------------------------------------------------------------- /modules/configs/files/wireguard.conf: -------------------------------------------------------------------------------- 1 | [Interface] 2 | PrivateKey = ${vars.private_key} 3 | Address = ${vars.address} 4 | DNS = ${vars.dns} 5 | 6 | [Peer] 7 | PublicKey = ${vars.peer.publickey} 8 | AllowedIPs = 0.0.0.0/0, ::/0 9 | Endpoint = ${vars.peer.endpoint} 10 | PersistentKeepalive = ${vars.peer.persistent_keepalive} 11 | -------------------------------------------------------------------------------- /modules/configs/hooks.tf: -------------------------------------------------------------------------------- 1 | resource "null_resource" "wait-until-deploy-finished" { 2 | triggers = { 3 | server_id = var.server_id 4 | } 5 | 6 | connection { 7 | host = var.server_address 8 | user = var.ssh_user 9 | private_key = var.ssh_private_key 10 | } 11 | 12 | provisioner "remote-exec" { 13 | inline = [ 14 | "until test -f /tmp/booted; do sleep 5; done", 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /modules/configs/mobileconfig.tf: -------------------------------------------------------------------------------- 1 | resource "random_uuid" "PayloadIdentifier" { 2 | count = 4 3 | } 4 | 5 | locals { 6 | mobileconfig = { 7 | ondemand = var.config.ondemand 8 | vpn_users = var.config.vpn_users 9 | server_address = var.server_address 10 | algo_config = var.algo_config 11 | PayloadContentCA = base64encode(var.pki.ipsec.ca_cert) 12 | Password_pkcs12 = var.client_p12_pass 13 | PayloadIdentifier_vpn = upper(random_uuid.PayloadIdentifier.0.result) 14 | PayloadIdentifier_pkcs12 = upper(random_uuid.PayloadIdentifier.1.result) 15 | PayloadIdentifier_ca = upper(random_uuid.PayloadIdentifier.2.result) 16 | PayloadIdentifier_conf = upper(random_uuid.PayloadIdentifier.3.result) 17 | } 18 | } 19 | 20 | resource "local_file" "mobileconfig" { 21 | count = length(var.config.vpn_users) 22 | content = templatefile("${path.module}/files/mobileconfig.xml", { var = local.mobileconfig, index = count.index, pki = var.pki }) 23 | filename = "${var.algo_config}/ipsec/apple/${var.config.vpn_users[count.index]}.mobileconfig" 24 | } 25 | -------------------------------------------------------------------------------- /modules/configs/ssh_tunneling.tf: -------------------------------------------------------------------------------- 1 | resource "local_file" "user_ssh_private_keys" { 2 | count = var.config.ssh_tunneling ? 0 : length(var.config.vpn_users) 3 | content = var.pki.ssh.private_keys[count.index] 4 | filename = "${var.algo_config}/ssh_tunneling/${var.config.vpn_users[count.index]}.pem" 5 | } 6 | -------------------------------------------------------------------------------- /modules/configs/vars.tf: -------------------------------------------------------------------------------- 1 | variable "algo_config" {} 2 | variable "server_address" {} 3 | variable "client_p12_pass" {} 4 | variable "ssh_private_key" {} 5 | variable "server_id" {} 6 | variable "pki" {} 7 | variable "config" {} 8 | 9 | variable "ipv6" { 10 | default = false 11 | } 12 | 13 | variable "ssh_user" { 14 | default = "ubuntu" 15 | } 16 | -------------------------------------------------------------------------------- /modules/configs/versions.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_providers { 3 | local = "~> 1.2" 4 | external = "~> 1.1" 5 | null = "~> 2.1" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /modules/configs/wireguard.tf: -------------------------------------------------------------------------------- 1 | data "external" "wg-server-pub" { 2 | depends_on = [null_resource.wait-until-deploy-finished] 3 | 4 | program = [ 5 | "${path.module}/external/read-file-ssh.sh", 6 | "${var.ssh_user}@${var.server_address}", 7 | "${var.algo_config}/algo.pem", 8 | "/etc/wireguard/.wg-server.pub", 9 | ] 10 | } 11 | 12 | resource "local_file" "wireguard" { 13 | count = var.config.wireguard.enabled ? length(var.config.vpn_users) : 0 14 | filename = "${var.algo_config}/wireguard/${var.config.vpn_users[count.index]}.conf" 15 | 16 | content = templatefile("${path.module}/files/wireguard.conf", { 17 | vars = { 18 | private_key = base64encode(var.pki.wireguard.client_private_keys[count.index]) 19 | address = "${cidrhost(var.config.wireguard.ipv4, 2 + count.index)}/32${var.ipv6 == 0 ? "" : ",${cidrhost(var.config.wireguard.ipv6, 2 + count.index)}/128"}" 20 | dns = join(",", (var.config.dns.encryption.enabled || var.config.dns.adblocking.enabled ? values(var.config.wireguard_dns) : concat(var.config.dns.resolvers.ipv4, var.ipv6 ? var.config.dns.resolvers.ipv6 : []))) 21 | peer = { 22 | publickey = var.config.wireguard.enabled 23 | endpoint = "${var.server_address}:${var.config.wireguard.port}" 24 | persistent_keepalive = var.config.wireguard.persistent_keepalive > 0 ? var.config.wireguard.persistent_keepalive : 0 25 | } 26 | } 27 | } 28 | ) 29 | } 30 | -------------------------------------------------------------------------------- /modules/tls/ca.tf: -------------------------------------------------------------------------------- 1 | resource "tls_private_key" "ca" { 2 | algorithm = "ECDSA" 3 | ecdsa_curve = "P384" 4 | } 5 | 6 | resource "tls_self_signed_cert" "ca" { 7 | key_algorithm = "ECDSA" 8 | private_key_pem = tls_private_key.ca.private_key_pem 9 | validity_period_hours = 87600 10 | is_ca_certificate = true 11 | 12 | subject { 13 | common_name = var.server_address 14 | } 15 | 16 | allowed_uses = [ 17 | "cert_signing", 18 | "crl_signing", 19 | ] 20 | } 21 | 22 | resource "local_file" "ca_cert" { 23 | content = tls_self_signed_cert.ca.cert_pem 24 | filename = "${var.algo_config}/ipsec/manual/ca.crt.pem" 25 | 26 | provisioner "local-exec" { 27 | command = "chmod 0600 ${var.algo_config}/ipsec/manual/ca.crt.pem" 28 | } 29 | } 30 | 31 | resource "local_file" "ca_key" { 32 | content = tls_private_key.ca.private_key_pem 33 | filename = "${var.algo_config}/ipsec/manual/ca.key.pem" 34 | 35 | provisioner "local-exec" { 36 | command = "chmod 0600 ${var.algo_config}/ipsec/manual/ca.key.pem" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /modules/tls/clients.tf: -------------------------------------------------------------------------------- 1 | resource "tls_private_key" "client" { 2 | count = length(var.vpn_users) 3 | algorithm = "ECDSA" 4 | ecdsa_curve = "P384" 5 | } 6 | 7 | resource "tls_cert_request" "client" { 8 | count = length(var.vpn_users) 9 | key_algorithm = "ECDSA" 10 | private_key_pem = tls_private_key.client.*.private_key_pem[count.index] 11 | dns_names = [var.vpn_users[count.index]] 12 | 13 | subject { 14 | common_name = var.vpn_users[count.index] 15 | } 16 | } 17 | 18 | resource "tls_locally_signed_cert" "client" { 19 | count = length(var.vpn_users) 20 | cert_request_pem = tls_cert_request.client.*.cert_request_pem[count.index] 21 | ca_key_algorithm = "ECDSA" 22 | ca_private_key_pem = tls_private_key.ca.private_key_pem 23 | ca_cert_pem = tls_self_signed_cert.ca.cert_pem 24 | validity_period_hours = 87600 25 | 26 | allowed_uses = [ 27 | "client_auth", 28 | "server_auth", 29 | "key_encipherment", 30 | "digital_signature", 31 | ] 32 | } 33 | 34 | resource "local_file" "user_private_keys" { 35 | count = length(var.vpn_users) 36 | content = tls_private_key.client.*.private_key_pem[count.index] 37 | filename = "${var.algo_config}/ipsec/manual/${var.vpn_users[count.index]}.key.pem" 38 | } 39 | 40 | resource "local_file" "user_certs" { 41 | count = length(var.vpn_users) 42 | content = tls_locally_signed_cert.client.*.cert_pem[count.index] 43 | filename = "${var.algo_config}/ipsec/manual/${var.vpn_users[count.index]}.crt.pem" 44 | 45 | provisioner "local-exec" { 46 | interpreter = ["/bin/bash", "-ec"] 47 | working_dir = "${var.algo_config}/ipsec/manual/" 48 | when = create 49 | command = <<-EOF 50 | mkdir .for_crl/ || true 51 | cp -f ${var.vpn_users[count.index]}.crt.pem \ 52 | .for_crl/${var.vpn_users[count.index]}.crt.pem 53 | EOF 54 | } 55 | } 56 | 57 | data "local_file" "user_certs" { 58 | depends_on = [local_file.user_certs] 59 | count = length(var.vpn_users) 60 | filename = "${var.algo_config}/ipsec/manual/${var.vpn_users[count.index]}.crt.pem" 61 | } 62 | 63 | resource "random_id" "client_p12_pass" { 64 | byte_length = 6 65 | } 66 | 67 | data "external" "pkcs12" { 68 | count = length(var.vpn_users) 69 | program = ["${path.cwd}/${path.module}/external/generate-p12.sh"] 70 | 71 | query = { 72 | user = var.vpn_users[count.index] 73 | cert = tls_locally_signed_cert.client.*.cert_pem[count.index] 74 | key = tls_private_key.client.*.private_key_pem[count.index] 75 | pass = random_id.client_p12_pass.hex 76 | } 77 | } 78 | 79 | data "external" "crl" { 80 | program = ["${path.cwd}/${path.module}/external/generate-crl.sh"] 81 | working_dir = "${var.algo_config}/ipsec/manual/" 82 | 83 | query = { 84 | users = join("\n", var.vpn_users) 85 | ca_cert = tls_self_signed_cert.ca.cert_pem 86 | ca_key = tls_private_key.ca.private_key_pem 87 | users_certs = md5(join(",", data.local_file.user_certs.*.content)) 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /modules/tls/external/generate-crl.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -uxo pipefail 4 | 5 | umask 077 6 | 7 | eval "$(jq -r '@sh "USERS=\(.users) CA_CERT=\(.ca_cert) CA_KEY=\(.ca_key)"')" 8 | 9 | OPENSSLCNF="[ ca ] 10 | default_ca=CA_default 11 | [ CA_default ] 12 | database=index.txt 13 | crlnumber=crlnumber 14 | default_days=3650 15 | default_crl_days=3650 16 | default_md=default 17 | preserve=no 18 | crl_extensions=crl_ext 19 | [ crl_ext ] 20 | authorityKeyIdentifier=keyid:always,issuer:always" 21 | 22 | 23 | [ -f index.txt ] || touch index.txt 24 | [ -f crlnumber ] || echo 00 > crlnumber 25 | [ -f crl.pem ] || openssl ca -gencrl -keyfile <(echo "$CA_KEY") -cert <(echo "$CA_CERT") -out crl.pem -config <(echo "$OPENSSLCNF") 26 | 27 | cp -f users.txt users.txt.old || true 28 | echo "$USERS" > users.txt 29 | 30 | cat users.txt.old | while read userOld; do 31 | if grep -Ew "^${userOld}$" users.txt >/dev/null; then 32 | : 33 | else 34 | openssl ca -gencrl \ 35 | -config <(echo "$OPENSSLCNF") \ 36 | -keyfile <(echo "$CA_KEY") \ 37 | -cert <(echo "$CA_CERT") \ 38 | -revoke .for_crl/$userOld.crt.pem \ 39 | -out .for_crl/$userOld.crt.pem_revoked 40 | openssl ca -gencrl \ 41 | -config <(echo "$OPENSSLCNF") \ 42 | -keyfile <(echo "$CA_KEY") \ 43 | -cert <(echo "$CA_CERT") \ 44 | -out crl.pem 45 | fi 46 | done 47 | 48 | jq -n --arg crl "$(cat crl.pem)\n$CA_CERT" '{"crl":$crl}' 49 | -------------------------------------------------------------------------------- /modules/tls/external/generate-p12.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | umask 077; 6 | 7 | eval "$(jq -r '@sh "USER=\(.user) CERT=\(.cert) KEY=\(.key) PASS=\(.pass)"')" 8 | 9 | base64encode () { 10 | if PY=$(which python2) >/dev/null; then 11 | $PY -c "import base64,sys; base64.encode(sys.stdin,sys.stdout)" 12 | elif PY=$(which python3) >/dev/null; then 13 | $PY -c "import base64,sys; print(base64.b64encode(sys.stdin.buffer.read()).decode('ascii'))" 14 | else 15 | echo "Python not found" 16 | exit 1 17 | fi 18 | } 19 | 20 | PKCS12=$(openssl pkcs12 \ 21 | -in <(echo "${CERT}") \ 22 | -inkey <(echo "${KEY}") \ 23 | -export \ 24 | -name ${USER} \ 25 | -passout pass:"${PASS}" | base64encode) 26 | 27 | jq -n --arg pkcs12 "$PKCS12" '{"pkcs12":$pkcs12}' 28 | -------------------------------------------------------------------------------- /modules/tls/output.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | pki = { 3 | ipsec = { 4 | server_cert = tls_locally_signed_cert.server.cert_pem 5 | server_key = tls_private_key.server.private_key_pem 6 | ca_cert = tls_self_signed_cert.ca.cert_pem 7 | pkcs12 = data.external.pkcs12.*.result.pkcs12 8 | crl = data.external.crl.result.crl 9 | } 10 | 11 | wireguard = { 12 | client_private_keys = random_string.wg_client_private_key.*.result 13 | server_private_key = random_string.wg_server_private_key.result 14 | } 15 | 16 | ssh = { 17 | public_keys = tls_private_key.client.*.public_key_openssh 18 | private_keys = tls_private_key.client.*.private_key_pem 19 | } 20 | } 21 | } 22 | 23 | output "pki" { 24 | value = local.pki 25 | } 26 | 27 | output "client_p12_pass" { 28 | value = random_id.client_p12_pass.hex 29 | } 30 | 31 | output "ssh_public_key" { 32 | value = tls_private_key.algo_ssh.public_key_openssh 33 | } 34 | 35 | output "ssh_private_key" { 36 | value = tls_private_key.algo_ssh.private_key_pem 37 | } 38 | -------------------------------------------------------------------------------- /modules/tls/server.tf: -------------------------------------------------------------------------------- 1 | resource "tls_private_key" "server" { 2 | algorithm = "ECDSA" 3 | ecdsa_curve = "P384" 4 | } 5 | 6 | resource "tls_cert_request" "server" { 7 | key_algorithm = "ECDSA" 8 | private_key_pem = tls_private_key.server.private_key_pem 9 | ip_addresses = [var.server_address] 10 | dns_names = ["algo.vpn"] 11 | 12 | subject { 13 | common_name = "algo.vpn" 14 | } 15 | } 16 | 17 | resource "tls_locally_signed_cert" "server" { 18 | cert_request_pem = tls_cert_request.server.cert_request_pem 19 | ca_key_algorithm = "ECDSA" 20 | ca_private_key_pem = tls_private_key.ca.private_key_pem 21 | ca_cert_pem = tls_self_signed_cert.ca.cert_pem 22 | validity_period_hours = 87600 23 | 24 | allowed_uses = [ 25 | "key_encipherment", 26 | "digital_signature", 27 | "server_auth", 28 | "client_auth", 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /modules/tls/ssh.tf: -------------------------------------------------------------------------------- 1 | resource "tls_private_key" "algo_ssh" { 2 | algorithm = var.ssh_key_algorithm 3 | rsa_bits = var.ssh_key_rsa_bits 4 | } 5 | 6 | resource "local_file" "ssh_private_key" { 7 | content = tls_private_key.algo_ssh.private_key_pem 8 | filename = "${var.algo_config}/algo.pem" 9 | 10 | provisioner "local-exec" { 11 | command = "chmod 0600 ${var.algo_config}/algo.pem" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /modules/tls/vars.tf: -------------------------------------------------------------------------------- 1 | variable "server_address" {} 2 | variable "algo_config" {} 3 | variable "vpn_users" {} 4 | 5 | variable "ssh_key_algorithm" { 6 | default = "RSA" 7 | } 8 | 9 | variable "ssh_key_rsa_bits" { 10 | default = "2048" 11 | } 12 | -------------------------------------------------------------------------------- /modules/tls/versions.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = ">= 0.12" 3 | } 4 | 5 | provider "tls" { 6 | version = "~> 2.0" 7 | } 8 | 9 | provider "local" { 10 | version = "~> 1.2" 11 | } 12 | 13 | provider "null" { 14 | version = "~> 2.1" 15 | } 16 | 17 | provider "random" { 18 | version = "~> 2.1" 19 | } 20 | 21 | provider "external" { 22 | version = "~> 1.1" 23 | } 24 | -------------------------------------------------------------------------------- /modules/tls/wireguard.tf: -------------------------------------------------------------------------------- 1 | # TODO: revise the way we generate private keys for WireGuard 2 | # EdDSA/Ed25519 is not implemented in Terraform yet 3 | # https://github.com/terraform-providers/terraform-provider-tls/issues/26 4 | resource "random_string" "wg_server_private_key" { 5 | length = 32 6 | special = true 7 | } 8 | 9 | resource "random_string" "wg_client_private_key" { 10 | count = length(var.vpn_users) 11 | length = 32 12 | special = true 13 | } 14 | -------------------------------------------------------------------------------- /modules/user-data/common.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | unmanaged = "until test -f /root/.terraform_complete; do echo 'Waiting for terraform to complete..'; sleep 5 ; done" 3 | 4 | iptables = { 5 | common = { 6 | mss_fix = var.config.max_mss >= 1000 ? "-A FORWARD -s ${var.config.ipsec.ipv4},${var.config.wireguard.ipv4} -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss ${var.config.max_mss}" : "" 7 | wireguard_port = var.config.wireguard.port 8 | drop_traffic_between_clients = var.config.drop_traffic_between_clients == true ? "DROP" : "ACCEPT" 9 | } 10 | 11 | v4 = { 12 | wireguard_network = var.config.wireguard.ipv4 13 | ipsec_network = var.config.ipsec.ipv4 14 | dns = [ 15 | var.config.wireguard_dns.ipv4, 16 | var.config.ipsec_dns.ipv4, 17 | ] 18 | } 19 | 20 | v6 = { 21 | wireguard_network = var.config.wireguard.ipv6 22 | ipsec_network = var.config.ipsec.ipv6 23 | dns = [ 24 | var.config.wireguard_dns.ipv6, 25 | var.config.ipsec_dns.ipv6, 26 | ] 27 | } 28 | } 29 | 30 | common_start = { 31 | rules_v4 = templatefile("${path.module}/files/common/rules.v4", { vars = local.iptables }) 32 | rules_v6 = templatefile("${path.module}/files/common/rules.v6", { vars = local.iptables }) 33 | system_upgrade = var.config.system_upgrade == true ? "true" : "false" 34 | unattended_reboot = var.config.unattended_reboot.enabled == true ? "true" : "false" 35 | unattended_reboot_time = var.config.unattended_reboot.time 36 | } 37 | 38 | common_end = { 39 | additional_tasks = var.config.unmanaged == true ? local.unmanaged : "true" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /modules/user-data/dns.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | dnscrypt_proxy_toml = { 3 | server_names = concat(var.config.dns.encryption.servers.ipv4, var.ipv6 ? var.config.dns.encryption.servers.ipv6 : []) 4 | ipv6 = var.ipv6 ? "true" : "false" 5 | blacklist_file = var.config.dns.adblocking.enabled ? "blacklist_file = 'blacklist.txt'" : "" 6 | } 7 | 8 | dns = { 9 | encryption = { 10 | apparmor_dnscrypt-proxy = file("${path.module}/files/dns/usr.bin.dnscrypt-proxy") 11 | dnscrypt_proxy_toml = templatefile("${path.module}/files/dns/dnscrypt-proxy.toml", { vars = local.dnscrypt_proxy_toml }) 12 | ip-blacklist = file("${path.module}/files/dns/ip-blacklist.txt") 13 | adblock_sh = file("${path.module}/files/dns/adblock.sh") 14 | adblock_lists = join("\n", var.config.dns.adblocking.lists) 15 | wireguard_dns_address = values(var.config.wireguard_dns) 16 | ipsec_dns_address = values(var.config.ipsec_dns) 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /modules/user-data/files/common/001-cloud-init-start.yml: -------------------------------------------------------------------------------- 1 | #cloud-config 2 | output: {all: '| tee -a /var/log/cloud-init-output.log'} 3 | 4 | groups: 5 | - algo 6 | 7 | users: 8 | - default 9 | 10 | package_update: true 11 | package_upgrade: ${vars.system_upgrade} 12 | 13 | packages: 14 | - unattended-upgrades 15 | - git 16 | - screen 17 | - apparmor-utils 18 | - uuid-runtime 19 | - coreutils 20 | - iptables-persistent 21 | - cgroup-tools 22 | - openssl 23 | - linux-headers-generic 24 | - cfget 25 | 26 | write_files: 27 | - path: /etc/apt/apt.conf.d/50unattended-upgrades 28 | permissions: '0644' 29 | content: | 30 | Unattended-Upgrade::Automatic-Reboot "${vars.unattended_reboot}"; 31 | Unattended-Upgrade::Automatic-Reboot-Time "${vars.unattended_reboot_time}"; 32 | Unattended-Upgrade::Allowed-Origins { 33 | "$${distro_id}:$${distro_codename}-security"; 34 | "$${distro_id}:$${distro_codename}-updates"; 35 | }; 36 | 37 | - path: /etc/apt/apt.conf.d/10periodic 38 | permissions: '0644' 39 | content: | 40 | APT::Periodic::Update-Package-Lists "1"; 41 | APT::Periodic::Download-Upgradeable-Packages "1"; 42 | APT::Periodic::AutocleanInterval "7"; 43 | APT::Periodic::Unattended-Upgrade "1"; 44 | 45 | - path: /etc/sysctl.d/10-algo.conf 46 | permissions: '0644' 47 | content: | 48 | net.ipv4.ip_forward=1 49 | net.ipv4.conf.all.forwarding=1 50 | net.ipv6.conf.all.forwarding=1 51 | 52 | - path: /etc/iptables/rules.v4 53 | permissions: '0644' 54 | content: ${jsonencode(vars.rules_v4)} 55 | 56 | - path: /etc/iptables/rules.v6 57 | permissions: '0644' 58 | content: ${jsonencode(vars.rules_v6)} 59 | 60 | runcmd: 61 | - set -x 62 | - echo BEGIN >> /tmp/pipeline 63 | - ln -sf /bin/bash /bin/sh 64 | - apt install linux-headers-$(uname -r) -y 65 | - apt remove resolvconf -y 66 | - sysctl -p /etc/sysctl.d/10-algo.conf 67 | - systemctl enable systemd-networkd systemd-resolved netfilter-persistent 68 | - systemctl restart systemd-networkd systemd-resolved netfilter-persistent 69 | - printf '%s\n' '#!/bin/bash' '/usr/bin/touch /tmp/booted' | sudo tee -a /etc/rc.local 70 | - chmod +x /etc/rc.local 71 | -------------------------------------------------------------------------------- /modules/user-data/files/common/099-cloud-init-end.yml: -------------------------------------------------------------------------------- 1 | #cloud-config 2 | 3 | runcmd: 4 | - echo "Run additional tasks"; ${vars.additional_tasks} 5 | - echo END >> /tmp/pipeline 6 | - touch /tmp/booted && sleep 20 7 | - '[ -f /var/run/reboot-required ] && shutdown -r now "Algo updates triggered" || true' 8 | -------------------------------------------------------------------------------- /modules/user-data/files/common/rules.v4: -------------------------------------------------------------------------------- 1 | #### The mangle table 2 | # This table allows us to modify packet headers 3 | # Packets enter this table first 4 | # 5 | *mangle 6 | 7 | :PREROUTING ACCEPT [0:0] 8 | :INPUT ACCEPT [0:0] 9 | :FORWARD ACCEPT [0:0] 10 | :OUTPUT ACCEPT [0:0] 11 | :POSTROUTING ACCEPT [0:0] 12 | 13 | ${vars.common.mss_fix} 14 | 15 | COMMIT 16 | 17 | 18 | #### The nat table 19 | # This table enables Network Address Translation 20 | # (This is technically a type of packet mangling) 21 | # 22 | *nat 23 | 24 | :PREROUTING ACCEPT [0:0] 25 | :POSTROUTING ACCEPT [0:0] 26 | 27 | # Allow traffic from the VPN network to the outside world, and replies 28 | -A POSTROUTING -s ${vars.v4.ipsec_network},${vars.v4.wireguard_network} -m policy --pol none --dir out -j MASQUERADE 29 | 30 | 31 | COMMIT 32 | 33 | 34 | #### The filter table 35 | # The default ipfilter table 36 | # 37 | *filter 38 | 39 | # By default, drop packets that are destined for this server 40 | :INPUT DROP [0:0] 41 | # By default, drop packets that request to be forwarded by this server 42 | :FORWARD DROP [0:0] 43 | # By default, accept any packets originating from this server 44 | :OUTPUT ACCEPT [0:0] 45 | 46 | # Accept packets destined for localhost 47 | -A INPUT -i lo -j ACCEPT 48 | # Accept any packet from an open TCP connection 49 | -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 50 | # Accept packets using the encapsulation protocol 51 | -A INPUT -p esp -j ACCEPT 52 | -A INPUT -p ah -j ACCEPT 53 | # rate limit ICMP traffic per source 54 | -A INPUT -p icmp --icmp-type echo-request -m hashlimit --hashlimit-upto 5/s --hashlimit-mode srcip --hashlimit-srcmask 32 --hashlimit-name icmp-echo-drop -j ACCEPT 55 | # Accept IPSEC traffic to ports 500 (IPSEC) and 4500 (MOBIKE aka IKE + NAT traversal) 56 | -A INPUT -p udp -m multiport --dports 500,4500,${vars.common.wireguard_port} -j ACCEPT 57 | # Allow new traffic to port 22 (SSH) 58 | -A INPUT -p tcp --dport 22 -m conntrack --ctstate NEW -j ACCEPT 59 | # Allow any traffic from the VPN 60 | -A INPUT -p ipencap -m policy --dir in --pol ipsec --proto esp -j ACCEPT 61 | 62 | # Accept DNS traffic to the local DNS resolver 63 | -A INPUT -d ${join(",", vars.v4.dns)} -p udp --dport 53 -j ACCEPT 64 | 65 | # Drop traffic between VPN clients 66 | -A FORWARD -s ${vars.v4.ipsec_network},${vars.v4.wireguard_network} -d ${vars.v4.ipsec_network},${vars.v4.wireguard_network} -j ${vars.common.drop_traffic_between_clients} 67 | 68 | # Drop traffic to VPN clients from SSH tunnels 69 | -A OUTPUT -d ${vars.v4.ipsec_network},${vars.v4.wireguard_network} -m owner --gid-owner algo -j ${vars.common.drop_traffic_between_clients} 70 | 71 | # Drop traffic to the link-local network 72 | -A FORWARD -s ${vars.v4.ipsec_network},${vars.v4.wireguard_network} -d 169.254.0.0/16 -j DROP 73 | 74 | # Drop traffic to the link-local network from SSH tunnels 75 | -A OUTPUT -d 169.254.0.0/16 -m owner --gid-owner algo -j DROP 76 | 77 | # Forward any packet that's part of an established connection 78 | -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 79 | # Drop SMB/CIFS traffic that requests to be forwarded 80 | -A FORWARD -p tcp --dport 445 -j DROP 81 | # Drop NETBIOS trafic that requests to be forwarded 82 | -A FORWARD -p udp -m multiport --ports 137,138 -j DROP 83 | -A FORWARD -p tcp -m multiport --ports 137,139 -j DROP 84 | 85 | # Forward any IPSEC traffic from the VPN network 86 | -A FORWARD -m conntrack --ctstate NEW -s ${vars.v4.ipsec_network} -m policy --pol ipsec --dir in -j ACCEPT 87 | 88 | # Forward any traffic from the WireGuard VPN network 89 | -A FORWARD -m conntrack --ctstate NEW -s ${vars.v4.wireguard_network} -m policy --pol none --dir in -j ACCEPT 90 | 91 | COMMIT 92 | -------------------------------------------------------------------------------- /modules/user-data/files/common/rules.v6: -------------------------------------------------------------------------------- 1 | #### The mangle table 2 | # This table allows us to modify packet headers 3 | # Packets enter this table first 4 | # 5 | *mangle 6 | 7 | :PREROUTING ACCEPT [0:0] 8 | :INPUT ACCEPT [0:0] 9 | :FORWARD ACCEPT [0:0] 10 | :OUTPUT ACCEPT [0:0] 11 | :POSTROUTING ACCEPT [0:0] 12 | 13 | ${vars.common.mss_fix} 14 | 15 | COMMIT 16 | 17 | 18 | #### The nat table 19 | # This table enables Network Address Translation 20 | # (This is technically a type of packet mangling) 21 | # 22 | *nat 23 | 24 | :PREROUTING ACCEPT [0:0] 25 | :POSTROUTING ACCEPT [0:0] 26 | 27 | # Allow traffic from the VPN network to the outside world, and replies 28 | -A POSTROUTING -s ${vars.v6.ipsec_network},${vars.v6.wireguard_network} -m policy --pol none --dir out -j MASQUERADE 29 | 30 | 31 | COMMIT 32 | 33 | 34 | #### The filter table 35 | # The default ipfilter table 36 | # 37 | *filter 38 | 39 | # By default, drop packets that are destined for this server 40 | :INPUT DROP [0:0] 41 | # By default, drop packets that request to be forwarded by this server 42 | :FORWARD DROP [0:0] 43 | # By default, accept any packets originating from this server 44 | :OUTPUT ACCEPT [0:0] 45 | 46 | # Create the ICMPV6-CHECK chain and its log chain 47 | # These chains are used later to prevent a type of bug that would 48 | # allow malicious traffic to reach over the server into the private network 49 | # An instance of such a bug on Cisco software is described here: 50 | # https://www.insinuator.net/2016/05/cve-2016-1409-ipv6-ndp-dos-vulnerability-in-cisco-software/ 51 | # other software implementations might be at least as broken as the one in CISCO gear. 52 | :ICMPV6-CHECK - [0:0] 53 | :ICMPV6-CHECK-LOG - [0:0] 54 | 55 | # Accept packets destined for localhost 56 | -A INPUT -i lo -j ACCEPT 57 | # Accept any packet from an open TCP connection 58 | -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 59 | # Accept packets using the encapsulation protocol 60 | -A INPUT -p esp -j ACCEPT 61 | -A INPUT -m ah -j ACCEPT 62 | # rate limit ICMP traffic per source 63 | -A INPUT -p icmpv6 --icmpv6-type echo-request -m hashlimit --hashlimit-upto 5/s --hashlimit-mode srcip --hashlimit-srcmask 32 --hashlimit-name icmp-echo-drop -j ACCEPT 64 | # Accept IPSEC traffic to ports 500 (IPSEC) and 4500 (MOBIKE aka IKE + NAT traversal) 65 | -A INPUT -p udp -m multiport --dports 500,4500,${vars.common.wireguard_port} -j ACCEPT 66 | # Allow new traffic to port 22 (SSH) 67 | -A INPUT -p tcp --dport 22 -m conntrack --ctstate NEW -j ACCEPT 68 | 69 | # Accept properly formatted Neighbor Discovery Protocol packets 70 | -A INPUT -p icmpv6 --icmpv6-type router-advertisement -m hl --hl-eq 255 -j ACCEPT 71 | -A INPUT -p icmpv6 --icmpv6-type neighbor-solicitation -m hl --hl-eq 255 -j ACCEPT 72 | -A INPUT -p icmpv6 --icmpv6-type neighbor-advertisement -m hl --hl-eq 255 -j ACCEPT 73 | -A INPUT -p icmpv6 --icmpv6-type redirect -m hl --hl-eq 255 -j ACCEPT 74 | 75 | # DHCP in AWS 76 | -A INPUT -m conntrack --ctstate NEW -m udp -p udp --dport 546 -d fe80::/64 -j ACCEPT 77 | 78 | # TODO: 79 | # The IP of the resolver should be bound to a DUMMY interface. 80 | # DUMMY interfaces are the proper way to install IPs without assigning them any 81 | # particular virtual (tun,tap,...) or physical (ethernet) interface. 82 | 83 | # Accept DNS traffic to the local DNS resolver 84 | -A INPUT -d ${join(",", vars.v6.dns)} -p udp --dport 53 -j ACCEPT 85 | 86 | -A FORWARD -j ICMPV6-CHECK 87 | -A FORWARD -p tcp --dport 445 -j DROP 88 | -A FORWARD -p udp -m multiport --ports 137,138 -j DROP 89 | -A FORWARD -p tcp -m multiport --ports 137,139 -j DROP 90 | -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 91 | 92 | # Forward any IPSEC traffic from the VPN network 93 | -A FORWARD -m conntrack --ctstate NEW -s ${vars.v6.ipsec_network} -m policy --pol ipsec --dir in -j ACCEPT 94 | 95 | # Forward any traffic from the WireGuard VPN network 96 | -A FORWARD -m conntrack --ctstate NEW -s ${vars.v6.wireguard_network} -m policy --pol none --dir in -j ACCEPT 97 | 98 | # Use the ICMPV6-CHECK chain, described above 99 | -A ICMPV6-CHECK -p icmpv6 -m hl ! --hl-eq 255 --icmpv6-type router-solicitation -j ICMPV6-CHECK-LOG 100 | -A ICMPV6-CHECK -p icmpv6 -m hl ! --hl-eq 255 --icmpv6-type router-advertisement -j ICMPV6-CHECK-LOG 101 | -A ICMPV6-CHECK -p icmpv6 -m hl ! --hl-eq 255 --icmpv6-type neighbor-solicitation -j ICMPV6-CHECK-LOG 102 | -A ICMPV6-CHECK -p icmpv6 -m hl ! --hl-eq 255 --icmpv6-type neighbor-advertisement -j ICMPV6-CHECK-LOG 103 | -A ICMPV6-CHECK-LOG -j LOG --log-prefix "ICMPV6-CHECK-LOG DROP " 104 | -A ICMPV6-CHECK-LOG -j DROP 105 | 106 | COMMIT 107 | -------------------------------------------------------------------------------- /modules/user-data/files/dns/adblock.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Block ads, malware, etc.. 3 | 4 | TEMP="$(mktemp)" 5 | TEMP_SORTED="$(mktemp)" 6 | WHITELIST="/etc/dnscrypt-proxy/white.list" 7 | BLACKLIST="/etc/dnscrypt-proxy/black.list" 8 | BLOCKHOSTS="{{ config_prefix|default('/') }}etc/dnscrypt-proxy/blacklist.txt" 9 | BLOCKLIST_URLS="/etc/default/adblock" 10 | 11 | #Delete the old block.hosts to make room for the updates 12 | rm -f $BLOCKHOSTS 13 | 14 | echo 'Downloading hosts lists...' 15 | #Download and process the files needed to make the lists (enable/add more, if you want) 16 | while read url; do 17 | wget --timeout=2 --tries=3 -qO- "$url" | grep -Ev "(localhost)" | grep -Ew "(0.0.0.0|127.0.0.1)" | awk '{sub(/\r$/,"");print $2}' >> "$TEMP" 18 | done < $BLOCKLIST_URLS 19 | 20 | #Add black list, if non-empty 21 | if [ -s "$BLACKLIST" ] 22 | then 23 | echo 'Adding blacklist...' 24 | cat $BLACKLIST >> "$TEMP" 25 | fi 26 | 27 | #Sort the download/black lists 28 | awk '/^[^#]/ { print $1 }' "$TEMP" | sort -u > "$TEMP_SORTED" 29 | 30 | #Filter (if applicable) 31 | if [ -s "$WHITELIST" ] 32 | then 33 | #Filter the blacklist, suppressing whitelist matches 34 | # This is relatively slow =-( 35 | echo 'Filtering white list...' 36 | grep -v -E "^[[:space:]]*$" $WHITELIST | awk '/^[^#]/ {sub(/\r$/,"");print $1}' | grep -vf - "$TEMP_SORTED" > $BLOCKHOSTS 37 | else 38 | cat "$TEMP_SORTED" > $BLOCKHOSTS 39 | fi 40 | 41 | echo 'Restarting dns service...' 42 | #Restart the dns service 43 | systemctl restart dnscrypt-proxy.service 44 | 45 | exit 0 46 | -------------------------------------------------------------------------------- /modules/user-data/files/dns/cloud-init.yml: -------------------------------------------------------------------------------- 1 | #cloud-config 2 | apt: 3 | sources: 4 | shevchuk-ubuntu-dnscrypt-proxy.list: 5 | source: ppa:shevchuk/dnscrypt-proxy 6 | 7 | packages: 8 | - dnscrypt-proxy 9 | 10 | write_files: 11 | - path: /etc/apparmor.d/usr.bin.dnscrypt-proxy 12 | permissions: '0644' 13 | content: ${jsonencode(vars.apparmor_dnscrypt-proxy)} 14 | 15 | - path: /etc/systemd/system/dnscrypt-proxy.service.d/99-capabilities.conf 16 | permissions: '0644' 17 | content: | 18 | [Service] 19 | AmbientCapabilities=CAP_NET_BIND_SERVICE 20 | 21 | - path: /etc/dnscrypt-proxy/ip-blacklist.txt 22 | permissions: '0644' 23 | content: ${jsonencode(vars.ip-blacklist)} 24 | 25 | - path: /etc/dnscrypt-proxy/dnscrypt-proxy.toml 26 | permissions: '0644' 27 | content: ${jsonencode(vars.dnscrypt_proxy_toml)} 28 | 29 | - path: /etc/default/adblock 30 | permissions: '0644' 31 | content: ${jsonencode(vars.adblock_lists)} 32 | 33 | - path: /usr/local/sbin/adblock.sh 34 | permissions: '0755' 35 | content: ${jsonencode(vars.adblock_sh)} 36 | 37 | - path: /etc/cron.d/adblock 38 | permissions: '0644' 39 | content: | 40 | 10 2 * * * root /usr/local/sbin/adblock.sh 41 | 42 | - path: /etc/systemd/system/dnscrypt-proxy.socket.d/algo.conf 43 | permissions: '0644' 44 | content: | 45 | [Socket] 46 | FreeBind=yes 47 | %{ for i in vars.ipsec_dns_address ~} 48 | ListenDatagram=${i}:53 49 | ListenStream=${i}:53 50 | %{ endfor } 51 | %{ for i in vars.wireguard_dns_address ~} 52 | ListenDatagram=${i}:53 53 | ListenStream=${i}:53 54 | %{ endfor } 55 | 56 | runcmd: 57 | - aa-enforce /etc/apparmor.d/usr.bin.dnscrypt-proxy 58 | - systemctl daemon-reload 59 | - systemctl restart dnscrypt-proxy 60 | - systemctl enable dnscrypt-proxy 61 | -------------------------------------------------------------------------------- /modules/user-data/files/dns/dnscrypt-proxy.toml: -------------------------------------------------------------------------------- 1 | server_names = [ '${join("', '", vars.server_names)}' ] 2 | listen_addresses = [ '127.0.0.1:53' ] 3 | max_clients = 250 4 | ipv4_servers = true 5 | ipv6_servers = ${vars.ipv6} 6 | dnscrypt_servers = true 7 | doh_servers = true 8 | require_dnssec = true 9 | require_nolog = true 10 | require_nofilter = true 11 | force_tcp = false 12 | timeout = 2500 13 | keepalive = 30 14 | lb_strategy = 'p2' 15 | log_level = 2 16 | use_syslog = true 17 | cert_refresh_delay = 240 18 | dnscrypt_ephemeral_keys = true 19 | tls_disable_session_tickets = true 20 | fallback_resolver = '127.0.0.53:53' 21 | ignore_system_dns = true 22 | log_files_max_size = 10 23 | log_files_max_age = 7 24 | log_files_max_backups = 1 25 | block_ipv6 = false 26 | cache = true 27 | cache_size = 512 28 | cache_min_ttl = 600 29 | cache_max_ttl = 86400 30 | cache_neg_min_ttl = 60 31 | cache_neg_max_ttl = 600 32 | refused_code_in_responses = false 33 | netprobe_timeout = 60 34 | netprobe_address = "1.1.1.1:53" 35 | [query_log] 36 | format = 'tsv' 37 | [nx_log] 38 | format = 'tsv' 39 | [blacklist] 40 | ${vars.blacklist_file} 41 | [ip_blacklist] 42 | blacklist_file = 'ip-blacklist.txt' 43 | [whitelist] 44 | [schedules] 45 | [sources] 46 | [sources.'public-resolvers'] 47 | urls = ['https://raw.githubusercontent.com/DNSCrypt/dnscrypt-resolvers/master/v2/public-resolvers.md', 'https://download.dnscrypt.info/resolvers-list/v2/public-resolvers.md'] 48 | cache_file = 'public-resolvers.md' 49 | minisign_key = 'RWQf6LRCGA9i53mlYecO4IzT51TGPpvWucNSCh1CBM0QTaLn73Y7GFO3' 50 | refresh_delay = 72 51 | prefix = '' 52 | [static] 53 | -------------------------------------------------------------------------------- /modules/user-data/files/dns/ip-blacklist.txt: -------------------------------------------------------------------------------- 1 | 0.0.0.0 2 | 10.* 3 | 127.* 4 | 169.254.* 5 | 172.16.* 6 | 172.17.* 7 | 172.18.* 8 | 172.19.* 9 | 172.20.* 10 | 172.21.* 11 | 172.22.* 12 | 172.23.* 13 | 172.24.* 14 | 172.25.* 15 | 172.26.* 16 | 172.27.* 17 | 172.28.* 18 | 172.29.* 19 | 172.30.* 20 | 172.31.* 21 | 192.168.* 22 | ::ffff:0.0.0.0 23 | ::ffff:10.* 24 | ::ffff:127.* 25 | ::ffff:169.254.* 26 | ::ffff:172.16.* 27 | ::ffff:172.17.* 28 | ::ffff:172.18.* 29 | ::ffff:172.19.* 30 | ::ffff:172.20.* 31 | ::ffff:172.21.* 32 | ::ffff:172.22.* 33 | ::ffff:172.23.* 34 | ::ffff:172.24.* 35 | ::ffff:172.25.* 36 | ::ffff:172.26.* 37 | ::ffff:172.27.* 38 | ::ffff:172.28.* 39 | ::ffff:172.29.* 40 | ::ffff:172.30.* 41 | ::ffff:172.31.* 42 | ::ffff:192.168.* 43 | fd00::* 44 | fe80::* 45 | -------------------------------------------------------------------------------- /modules/user-data/files/dns/usr.bin.dnscrypt-proxy: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /usr/{s,}bin/dnscrypt-proxy flags=(attach_disconnected) { 4 | #include 5 | #include 6 | #include 7 | 8 | capability chown, 9 | capability dac_override, 10 | capability net_bind_service, 11 | capability setgid, 12 | capability setuid, 13 | capability sys_resource, 14 | 15 | /etc/dnscrypt-proxy/** r, 16 | /usr/bin/dnscrypt-proxy mr, 17 | /tmp/public-resolvers.md* rw, 18 | 19 | /tmp/*.tmp w, 20 | owner /tmp/*.tmp r, 21 | 22 | /run/systemd/notify rw, 23 | /lib/x86_64-linux-gnu/ld-*.so mr, 24 | @{PROC}/sys/kernel/hostname r, 25 | @{PROC}/sys/net/core/somaxconn r, 26 | /etc/ld.so.cache r, 27 | /usr/local/lib/{@{multiarch}/,}libldns.so* mr, 28 | /usr/local/lib/{@{multiarch}/,}libsodium.so* mr, 29 | } 30 | -------------------------------------------------------------------------------- /modules/user-data/files/ssh_tunneling/cloud-init.yml: -------------------------------------------------------------------------------- 1 | #cloud-config 2 | groups: 3 | - algo 4 | 5 | users: 6 | %{ for index, user in vars.vpn_users ~} 7 | - name: ${user} 8 | shell: /bin/false 9 | primary_group: algo 10 | lock_passwd: true 11 | ssh_authorized_keys: 12 | - ${vars.ssh_keys[index]} 13 | %{ endfor ~} 14 | 15 | write_files: 16 | - path: /etc/ssh/sshd_config 17 | append: true 18 | content: | 19 | 20 | Match Group algo 21 | AllowTcpForwarding local 22 | AllowAgentForwarding no 23 | AllowStreamLocalForwarding no 24 | PermitTunnel no 25 | X11Forwarding no 26 | 27 | runcmd: 28 | - systemctl reload sshd 29 | -------------------------------------------------------------------------------- /modules/user-data/files/strongswan/cloud-init.yml: -------------------------------------------------------------------------------- 1 | #cloud-config 2 | 3 | packages: 4 | - strongswan 5 | 6 | write_files: 7 | - path: /etc/strongswan.conf 8 | permissions: '0400' 9 | content: ${jsonencode(vars.strongswan_conf)} 10 | 11 | - path: /etc/ipsec.conf 12 | permissions: '0400' 13 | content: ${jsonencode(vars.ipsec_conf)} 14 | 15 | - path: /etc/ipsec.secrets 16 | permissions: '0400' 17 | content: ': ECDSA server.pem' 18 | 19 | - path: /etc/ipsec.d/cacerts/ca.pem 20 | permissions: '0400' 21 | content: ${jsonencode(vars.pki.ipsec.ca_cert)} 22 | 23 | - path: /etc/ipsec.d/certs/server.pem 24 | permissions: '0400' 25 | content: ${jsonencode(vars.pki.ipsec.server_cert)} 26 | 27 | - path: /etc/ipsec.d/private/server.pem 28 | permissions: '0400' 29 | content: ${jsonencode(vars.pki.ipsec.server_key)} 30 | 31 | - path: /etc/ipsec.d/crls/crl.pem 32 | permissions: '0400' 33 | content: ${jsonencode(vars.pki.ipsec.crl)} 34 | 35 | - path: /etc/apparmor.d/local/usr.lib.ipsec.charon 36 | content: ' capability setpcap,' 37 | runcmd: 38 | # just because of `write_files` runs before `users` we need to change the owner with this workaround 39 | - bash -c 'chown strongswan:root /etc/ipsec.d/{cacerts/ca,certs/server,private/server}.pem /etc/{strongswan.conf,ipsec.conf,ipsec.secrets}' 40 | - aa-enforce /etc/apparmor.d/usr.lib.ipsec.charon 41 | - systemctl restart strongswan ; systemctl enable strongswan 42 | -------------------------------------------------------------------------------- /modules/user-data/files/strongswan/ipsec.conf: -------------------------------------------------------------------------------- 1 | config setup 2 | uniqueids=never 3 | charondebug="ike ${vars.strongswan_log_level}, knl ${vars.strongswan_log_level}, cfg ${vars.strongswan_log_level}, net ${vars.strongswan_log_level}, esp ${vars.strongswan_log_level}, dmn ${vars.strongswan_log_level}, mgr ${vars.strongswan_log_level}" 4 | 5 | conn %default 6 | fragmentation=yes 7 | rekey=no 8 | dpdaction=clear 9 | keyexchange=ikev2 10 | compress=yes 11 | dpddelay=35s 12 | 13 | ike=${vars.ike} 14 | esp=${vars.esp} 15 | 16 | left=%any 17 | leftid=algo.vpn 18 | leftauth=pubkey 19 | leftcert=server.pem 20 | leftsendcert=always 21 | leftsubnet=0.0.0.0/0,::/0 22 | 23 | right=%any 24 | rightauth=pubkey 25 | rightsourceip=${join(",", compact(vars.rightsourceip))} 26 | rightdns=${join(",", compact(vars.rightdns))} 27 | 28 | conn ikev2-pubkey 29 | auto=add 30 | -------------------------------------------------------------------------------- /modules/user-data/files/strongswan/strongswan.conf: -------------------------------------------------------------------------------- 1 | charon { 2 | load_modular = yes 3 | plugins { 4 | include strongswan.d/charon/*.conf 5 | } 6 | user = strongswan 7 | group = nogroup 8 | } 9 | 10 | include strongswan.d/*.conf 11 | -------------------------------------------------------------------------------- /modules/user-data/files/wireguard/cloud-init.yml: -------------------------------------------------------------------------------- 1 | #cloud-config 2 | apt: 3 | sources: 4 | wireguard-ubuntu-wireguard-bionic.list: 5 | source: deb http://ppa.launchpad.net/wireguard/wireguard/ubuntu bionic main 6 | keyid: AE33835F504A1A25 7 | 8 | packages: 9 | - wireguard 10 | - wireguard-dkms 11 | 12 | write_files: 13 | - path: /etc/wireguard/wg0.conf 14 | permissions: '0600' 15 | content: ${jsonencode(vars.wg_conf)} 16 | 17 | runcmd: 18 | %{ for index, user in vars.vpn_users ~} 19 | - bash -c 'sed s~::${user}::~$(echo '${base64encode(vars.private_keys[index])}' | wg pubkey)~ -i /etc/wireguard/wg0.conf' 20 | %{ endfor ~} 21 | - echo '${base64encode(vars.server_private_key)}' | wg pubkey > /etc/wireguard/.wg-server.pub 22 | - systemctl restart wg-quick@wg0 ; systemctl enable wg-quick@wg0 23 | -------------------------------------------------------------------------------- /modules/user-data/files/wireguard/wg0.conf: -------------------------------------------------------------------------------- 1 | [Interface] 2 | Address = ${join(",", compact(vars.InterfaceAddress))} 3 | ListenPort = ${vars.InterfaceListenPort} 4 | PrivateKey = ${base64encode(vars.InterfacePrivateKey)} 5 | 6 | %{ for index, user in vars.vpn_users } 7 | [Peer] 8 | # ${user} 9 | PublicKey = ::${user}:: 10 | AllowedIPs = ${cidrhost(vars.wireguard.ipv4, 2 + index)}/32,${cidrhost(vars.wireguard.ipv6, 2 + index)}/128 11 | %{ endfor } 12 | -------------------------------------------------------------------------------- /modules/user-data/ipsec.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | ipsec_conf = { 3 | ike = var.config.ciphers.ipsec.ike 4 | esp = var.config.ciphers.ipsec.esp 5 | strongswan_log_level = var.config.strongswan_log_level 6 | rightsourceip = ["${cidrhost(var.config.ipsec.ipv4, 2)}-${cidrhost(var.config.ipsec.ipv4, -2)},${cidrhost(var.config.ipsec.ipv6, 2)}-${cidrhost(var.config.ipsec.ipv6, 9223372036854775807)}"] 7 | rightdns = var.config.dns.encryption.enabled || var.config.dns.adblocking.enabled ? values(var.config.ipsec_dns) : concat(var.config.dns.resolvers.ipv4, var.ipv6 ? var.config.dns.resolvers.ipv6 : []) 8 | } 9 | 10 | strongswan = { 11 | strongswan_conf = file("${path.module}/files/strongswan/strongswan.conf") 12 | ipsec_conf = templatefile("${path.module}/files/strongswan/ipsec.conf", { vars = local.ipsec_conf }) 13 | pki = var.pki 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /modules/user-data/main.tf: -------------------------------------------------------------------------------- 1 | data "template_cloudinit_config" "cloud_init" { 2 | gzip = var.gzip 3 | base64_encode = var.base64_encode 4 | 5 | part { 6 | filename = "common_start" 7 | content = templatefile("${path.module}/files/common/001-cloud-init-start.yml", { vars = local.common_start }) 8 | merge_type = "list(append)+dict(recurse_array)+str()" 9 | } 10 | 11 | part { 12 | filename = "cloud_specific" 13 | content = var.cloud_specific 14 | merge_type = "list(append)+dict(recurse_array)+str()" 15 | } 16 | 17 | part { 18 | filename = "ssh_tunneling" 19 | content = var.config.ssh_tunneling ? templatefile("${path.module}/files/ssh_tunneling/cloud-init.yml", { vars = local.ssh_tunneling }) : "" 20 | merge_type = "list(append)+dict(recurse_array)+str()" 21 | } 22 | 23 | part { 24 | filename = "strongswan" 25 | content = var.config.ipsec.enabled ? templatefile("${path.module}/files/strongswan/cloud-init.yml", { vars = local.strongswan }) : "" 26 | merge_type = "list(append)+dict(recurse_array)+str()" 27 | } 28 | 29 | part { 30 | filename = "wireguard" 31 | content = var.config.wireguard.enabled ? templatefile("${path.module}/files/wireguard/cloud-init.yml", { vars = local.wireguard }) : "" 32 | merge_type = "list(append)+dict(recurse_array)+str()" 33 | } 34 | 35 | part { 36 | filename = "dns" 37 | content = var.config.dns.encryption.enabled ? templatefile("${path.module}/files/dns/cloud-init.yml", { vars = local.dns.encryption }) : "" 38 | merge_type = "list(append)+dict(recurse_array)+str()" 39 | } 40 | 41 | part { 42 | filename = "common_end" 43 | content = templatefile("${path.module}/files/common/099-cloud-init-end.yml", { vars = local.common_end }) 44 | merge_type = "list(append)+dict(recurse_array)+str()" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /modules/user-data/output.tf: -------------------------------------------------------------------------------- 1 | output "template_cloudinit_config" { 2 | value = data.template_cloudinit_config.cloud_init.rendered 3 | } 4 | -------------------------------------------------------------------------------- /modules/user-data/ssh_tunneling.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | ssh_tunneling = { 3 | ssh_keys = var.pki.ssh.public_keys 4 | vpn_users = var.config.vpn_users 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /modules/user-data/vars.tf: -------------------------------------------------------------------------------- 1 | variable "gzip" {} 2 | variable "base64_encode" {} 3 | variable "ipv6" {} 4 | variable "pki" {} 5 | variable "config" {} 6 | variable "cloud_specific" { 7 | default = "" 8 | } 9 | -------------------------------------------------------------------------------- /modules/user-data/versions.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = ">= 0.12" 3 | } 4 | 5 | provider "template" { 6 | version = "~> 2.1" 7 | } 8 | 9 | provider "random" { 10 | version = "~> 2.1" 11 | } 12 | -------------------------------------------------------------------------------- /modules/user-data/wireguard.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | wg_conf = { 3 | InterfaceAddress = [cidrhost(var.config.wireguard.ipv4, 1), var.ipv6 ? cidrhost(var.config.wireguard.ipv6, 1) : ""] 4 | InterfaceListenPort = var.config.wireguard.port 5 | InterfacePrivateKey = var.pki.wireguard.server_private_key 6 | vpn_users = var.config.vpn_users 7 | ipv6 = var.ipv6 8 | wireguard = { 9 | ipv4 = var.config.wireguard.ipv4 10 | ipv6 = var.config.wireguard.ipv6 11 | } 12 | } 13 | 14 | wireguard = { 15 | wg_conf = templatefile("${path.module}/files/wireguard/wg0.conf", { vars = local.wg_conf }) 16 | private_keys = var.pki.wireguard.client_private_keys 17 | server_private_key = var.pki.wireguard.server_private_key 18 | vpn_users = var.config.vpn_users 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /regions/azure: -------------------------------------------------------------------------------- 1 | australiacentral,Australia Central, 2 | australiacentral2,Australia Central 2, 3 | australiaeast,Australia East, 4 | australiasoutheast,Australia Southeast, 5 | brazilsouth,Brazil South, 6 | canadacentral,Canada Central, 7 | canadaeast,Canada East, 8 | centralindia,Central India, 9 | centralus,Central US, 10 | eastasia,East Asia, 11 | eastus,East US,default 12 | eastus2,East US 2, 13 | francecentral,France Central, 14 | francesouth,France South, 15 | japaneast,Japan East, 16 | japanwest,Japan West, 17 | koreacentral,Korea Central, 18 | koreasouth,Korea South, 19 | northcentralus,North Central US, 20 | northeurope,North Europe, 21 | southafricanorth,South Africa North, 22 | southafricawest,South Africa West, 23 | southcentralus,South Central US, 24 | southeastasia,Southeast Asia, 25 | southindia,South India, 26 | uksouth,UK South, 27 | ukwest,UK West, 28 | westcentralus,West Central US, 29 | westeurope,West Europe, 30 | westindia,West India, 31 | westus,West US, 32 | westus2,West US 2, 33 | -------------------------------------------------------------------------------- /regions/digitalocean: -------------------------------------------------------------------------------- 1 | ams3,Amsterdam 3 2 | blr1,Bangalore 1 3 | fra1,Frankfurt 1 4 | lon1,London 1 5 | nyc1,New York 1,default 6 | nyc3,New York 3 7 | sfo2,San Francisco 2 8 | sgp1,Singapore 1 9 | tor1,Toronto 1 10 | -------------------------------------------------------------------------------- /regions/ec2: -------------------------------------------------------------------------------- 1 | ap-northeast-1,Tokyo 2 | ap-northeast-2,Seoul 3 | ap-south-1,Mumbai 4 | ap-southeast-1,Singapore 5 | ap-southeast-2,Sydney 6 | ca-central-1,Montreal 7 | eu-central-1,Frankfurt 8 | eu-north-1,Stockholm 9 | eu-west-1,Ireland 10 | eu-west-2,London 11 | eu-west-3,Paris 12 | sa-east-1,São Paulo 13 | us-east-1,Virginia,default 14 | us-east-2,California 15 | us-west-e,Oregon 16 | us-west-2,Oregon 17 | -------------------------------------------------------------------------------- /regions/gce: -------------------------------------------------------------------------------- 1 | asia-east1,Changhua County 2 | asia-east2,Hong Kong 3 | asia-northeast1,Tokyo 4 | asia-south1,Mumbai 5 | asia-southeast1,Jurong West 6 | australia-southeast1,Sydney 7 | europe-north1,Hamina 8 | europe-west1,St. Ghislain 9 | europe-west2,London 10 | europe-west3,Frankfurt 11 | europe-west4,Eemshaven 12 | northamerica-northeast1,Montréal 13 | southamerica-east1,São Paulo 14 | us-central1,Iowa 15 | us-east1,South Carolina 16 | us-east4,Virginia,default 17 | us-west1,Oregon 18 | us-west2,California 19 | --------------------------------------------------------------------------------