├── .gitignore ├── LICENSE ├── README.md ├── aws ├── README.md ├── prepareEnvironment │ └── quorum-prepare-environment.cfn.yml ├── templates │ ├── _terraform_init │ │ ├── main.tf │ │ ├── outputs.tf │ │ └── variables.tf │ ├── bastion.tf │ ├── container_definition_bootstrap.tf │ ├── container_definitions.tf │ ├── container_definitions_constellation.tf │ ├── container_definitions_quorum.tf │ ├── container_definitions_tessera.tf │ ├── ecs.tf │ ├── iam.tf │ ├── logging.tf │ ├── main.tf │ ├── outputs.tf │ ├── security_groups.tf │ └── variables.tf └── utils │ ├── cleanup.sh │ └── nuke-config.tpl.yml └── travis ├── 4nodes ├── clique-genesis.json ├── clique-init.sh ├── clique-start.sh ├── constellation-start.sh ├── genesis.json ├── init.sh ├── istanbul-genesis.json ├── istanbul-init.sh ├── istanbul-start.sh ├── keys │ ├── key1 │ ├── key2 │ ├── key3 │ ├── key4 │ ├── tm1.key │ ├── tm1.pub │ ├── tm1a.key │ ├── tm1a.pub │ ├── tm2.key │ ├── tm2.pub │ ├── tm2a.key │ ├── tm2a.pub │ ├── tm3.key │ ├── tm3.pub │ ├── tm3a.key │ ├── tm3a.pub │ ├── tm4.key │ ├── tm4.pub │ ├── tm4a.key │ └── tm4a.pub ├── passwords.txt ├── permissioned-nodes.json ├── raft-init.sh ├── raft-start.sh ├── raft │ ├── nodekey1 │ ├── nodekey2 │ ├── nodekey3 │ └── nodekey4 ├── start.sh ├── stop.sh ├── stop_all.sh ├── tessera-init.sh └── tessera-start.sh └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, build with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | 14 | *.iml 15 | .idea/ 16 | target/ 17 | 18 | **/terraform.tfstate* 19 | **/.terraform* 20 | **/terraform.auto.* 21 | **/*.tfplan 22 | **/*.tfvars 23 | **/quorum-*.pem 24 | **/generated-*.sh 25 | **/qdata -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2018 JP Morgan Chase & Co. 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Quorum Cloud 2 | 3 | ## ⚠️ Project Deprecation Notice ⚠️ 4 | 5 | Quorum-Cloud has been deprecated, and we are no longer supporting the project. 6 | 7 | It has been replaced by [quorum-terraform](https://github.com/ConsenSys/quorum-terraform) and [quorum-kubernetes](https://github.com/ConsenSys/quorum-kubernetes) that offers wider compatibility with Quorum products and cloud providers 8 | 9 | We encourage all users with active projects to migrate to [quorum-terraform](https://github.com/ConsenSys/quorum-terraform) or [quorum-kubernetes](https://github.com/ConsenSys/quorum-kubernetes) 10 | 11 | If you have any questions or concerns, please reach out to the ConsenSys protocol engineering team on [#Discord](https://chat.consensys.net) or by [email](mailto:quorum@consensys.net). 12 | 13 | > Quorum Cloud **should not be used for production deployments**. It is intended to be used for experimenting with, and testing, Quorum 14 | 15 | Quorum Cloud can be used to bootstrap a Quorum network in the cloud. The currently supported platforms are AWS and Travis CI. 16 | 17 | ### Getting Started 18 | * [AWS](aws/README.md): Deploy a 7nodes network on AWS 19 | * [Travis CI](travis/README.md): Deploy a 4nodes network within a Travis container 20 | -------------------------------------------------------------------------------- /aws/README.md: -------------------------------------------------------------------------------- 1 | ## Quorum Cloud: AWS 2 | 3 | Deploy a Quorum Network in AWS using [Terraform](https://terraform.io). 4 | 5 | > AWS Fargate is only available in certain regions, see [AWS Region Table](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/) for more details. 6 | 7 | > AWS Fargate has default limits which might impact the provisioning, see [Amazon ECS Service Limits](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service_limits.html) for more details. 8 | 9 | ## What will this create? 10 | This will create a Quorum network (with 7 nodes by default) using AWS ECS Fargate, S3 and an EC2. The network can be configured to use either Raft or Istanbul consensus and either Tessera or Constellation privacy managers. 11 | 12 | ### Overview 13 | 14 | ``` 15 | +----- Public Subnet -----+ +----- Private Subnet(s) ---+ 16 | | | | | 17 | Internet <--- [NAT Gateway] [Bastion] ---------->| [ECS] [ECS] [ECS] .... | 18 | ^ | | | | 19 | | +-------------------------+ +-------------.-------------+ 20 | | | 21 | +------------------- Routable --------------------+ 22 | ``` 23 | 24 | #### Node containers (ECS Fargate) 25 | 26 | Each Quorum/privacy manager node pair is run in a separate AWS ECS (Elastic Container Service) Service. 27 | 28 | Each ECS Service contains the following Tasks to bootstrap and start the node pair: 29 | ``` 30 | node-key-bootstrap 31 | ^ 32 | | 33 | metadata-bootstrap 34 | ^ 35 | / \ 36 | / \ 37 | quorum-run --> {tx-privacy-engine}-run 38 | 39 | ``` 40 | * `node-key-bootstrap`: run `bootnode` to generate a node key and marshall to node id, store them in shared folder 41 | * `metadata-bootstrap`: prepare IP list and enode list 42 | * `{tx-privacy-engine}-run`: start the privacy manager 43 | * `quorum-run`: start Quorum 44 | 45 | #### Bastion node 46 | 47 | The Bastion is publically accessible and enables `geth attach` to each Quorum node in the private subnet. Additionally it exposes `ethstats` to more easily view activity on the network. 48 | 49 | ## Prerequisites 50 | > Terraform v0.12 introduced significant configuration language changes and so is not currently supported 51 | * Install Terraform v0.11 52 | * From [HashiCorp website](https://www.terraform.io/downloads.html) 53 | * MacOS: `brew install terraform@0.11` 54 | * Install AWS CLI 55 | * MacOS: https://docs.aws.amazon.com/cli/latest/userguide/install-macos.html 56 | * Linux: https://docs.aws.amazon.com/cli/latest/userguide/install-linux.html 57 | * Configure AWS CLI 58 | ```bash 59 | aws configure 60 | ``` 61 | Follow the prompts to provide credentials and preferences for the AWS CLI 62 | * Create an AWS VPC with Subnets if one does not already exist 63 | * Create a VPC with a public and private subnet and corresponding networking as visualised in the above diagram 64 | * For more help see the [AWS documentation](https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Scenario2.html) 65 | 66 | ## Getting Started 67 | 68 | ### Step 1: Prepare environment 69 | 70 | This will create an AWS environment with the resources required for deployment. 71 | 72 | This has to be run once **per region and per AWS Account**. 73 | 74 | ```bash 75 | aws cloudformation create-stack --stack-name quorum-prepare-environment --template-body file://./quorum-prepare-environment.cfn.yml 76 | ``` 77 | This will create a CloudFormation stack containing the following AWS resources: 78 | * An S3 bucket to store Terraform state with default server-side-encryption enabled 79 | * A KMS Key to encrypt objects stored in the above S3 bucket 80 | 81 | These resources are exposed to CloudFormation Exports which will be used in subsequent steps. 82 | 83 | ### Step 2: Initialize Terraform 84 | 85 | This will read from CloudFormation Exports to generate two files (`terraform.auto.backend_config` and `terraform.auto.tfvars`) that are used in later steps. 86 | 87 | ```bash 88 | cd /path/to/quorum-cloud/aws/templates/_terraform_init 89 | terraform init 90 | terraform apply -var network_name=dev -var region=us-east-1 -auto-approve 91 | ``` 92 | 93 | Replace `` with the AWS region being used. 94 | 95 | If `network_name` is not provided, a random name will be generated. 96 | 97 | ### Step 3: Prepare for deployment 98 | 99 | ```bash 100 | cd /path/to/quorum-cloud/aws/templates/ 101 | touch terraform.tfvars 102 | ``` 103 | 104 | Populate `terraform.tfvars` with the below template, replacing the subnet IDs with the corresponding IDs for the VPC subnets being used. 105 | 106 | ```hcl 107 | is_igw_subnets = "false" 108 | 109 | # private subnets routable to Internet via NAT Gateway 110 | subnet_ids = [ 111 | "subnet-4c30c605", 112 | "subnet-4c30c605", 113 | "subnet-09263334", 114 | "subnet-5236300a", 115 | ] 116 | 117 | bastion_public_subnet_id = "subnet-3a8d8707" 118 | 119 | consensus_mechanism = "istanbul" 120 | 121 | # tx_privacy_engine = "constellation" 122 | 123 | access_bastion_cidr_blocks = [ 124 | "190.190.190.190/32", 125 | ] 126 | ``` 127 | 128 | * `subnet_ids`: ECS will provision containers in these subnets. The subnets must be routable to the Internet (either because they are public subnets by default or because they are private subnets routed via NAT Gateway) 129 | * `is_igw_subnets`: `true` if the above `subnet_ids` are attached with Internet Gateway, `false` otherwise 130 | * `bastion_public_subnet_id`: where Bastion node is provisioned. This must be a public subnet 131 | * `tx_privacy_engine`: the default value is `tessera` 132 | * `access_bastion_cidr_blocks`: In order to access the Bastion node from a particular IP/set of IPs the corresponding CIDR blocks must be set 133 | 134 | **Note:** [`variables.tf`](templates/variables.tf) contains full options to configure the network 135 | 136 | To create an Ethereum private network use following: 137 | 138 | ```hcl 139 | consensus_mechanism = "clique" 140 | is_ethereum_network = "true" 141 | is_ethereum_v1_9_x = "true" 142 | quorum_docker_image = "ethereum/client-go" 143 | quorum_docker_image_tag = "alltools-v1.9.5" 144 | ``` 145 | 146 | ### Step 4: Deploy the network 147 | 148 | ```bash 149 | cd /path/to/quorum-cloud/aws/templates/ 150 | terraform init -backend-config=terraform.auto.backend_config -reconfigure 151 | terraform apply 152 | ``` 153 | 154 | Terraform will prompt to accept the proposed infrastructure changes. After the changes are accepted and the deployment is complete, information about the created network will be output. 155 | 156 | An example of the output is: 157 | ```bash 158 | Quorum Docker Image = quorumengineering/quorum:latest 159 | Privacy Engine Docker Image = quorumengineering/tessera:latest 160 | Number of Quorum Nodes = 7 161 | ECS Task Revision = 1 162 | CloudWatch Log Group = /ecs/quorum/dev 163 | 164 | bastion_host_dns = ec2-5-1-112-217.us-east-1.compute.amazonaws.com 165 | bastion_host_ip = 5.1.112.217 166 | bucket_name = eu-west-2-ecs-dev-6dj72u9s6335853j 167 | chain_id = 4021 168 | ecs_cluster_name = quorum-network-dev 169 | network_name = dev 170 | private_key_file = /path/to/quorum-cloud/aws/templates/quorum-dev.pem 171 | ``` 172 | 173 | ### Step 5: Examining the network 174 | 175 | Noting the `bastion_host_ip`/`bastion_host_dns` and `private_key_file` from the output of the previous step, run the following to SSH in to the Bastion node: 176 | 177 | ```bash 178 | chmod 600 179 | ssh -i ec2-user@ 180 | ``` 181 | 182 | From the Bastion node it is possible to `geth attach` to any of the Quorum nodes with a simple alias: 183 | ```bash 184 | [bastion-node]$ Node1 185 | ``` 186 | 187 | It is also possible to `geth attach` to any of the nodes without having to first explicitly SSH into the Bastion node: 188 | 189 | ```bash 190 | ssh -t -i ec2-user@ Node1 191 | ``` 192 | 193 | `ethstats` is available at `http://:3000` 194 | 195 | ### Step 6: Cleaning up 196 | ```bash 197 | cd /path/to/quorum-cloud/aws/templates/ 198 | terraform destroy 199 | ``` 200 | 201 | Note: In case `terraform destroy` is unable to detroy all the AWS resources, run [`utils/cleanup.sh`](utils/cleanup) (which uses [aws-nuke](https://github.com/rebuy-de/aws-nuke)) to perform full clean up 202 | 203 | ## Logging 204 | 205 | * The logs for each running node and bootstrap tasks are available in CloudWatch Group `/ecs/quorum/**` 206 | * CPU and Memory utilization metrics are also available in CloudWatch 207 | -------------------------------------------------------------------------------- /aws/prepareEnvironment/quorum-prepare-environment.cfn.yml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: "2010-09-09" 2 | Description: Create resources required prior to Quorum deployment 3 | Resources: 4 | DeploymentStateBucketKey: 5 | Type: "AWS::KMS::Key" 6 | Properties: 7 | Description: This is used to encrypt/decrypt objects stored in Quorum deployment state bucket 8 | Enabled: True 9 | KeyPolicy: 10 | Version: "2012-10-17" 11 | Id: quorum-deployment-state-key-permissions 12 | Statement: 13 | - Sid: Enable IAM User Permissions 14 | Effect: Allow 15 | Principal: 16 | AWS: !Sub "arn:aws:iam::${AWS::AccountId}:root" 17 | Action: 18 | - "kms:*" 19 | Resource: "*" 20 | DeploymentStateBucketKeyAlias: 21 | Type: "AWS::KMS::Alias" 22 | Properties: 23 | AliasName: !Sub "alias/${AWS::Region}-quorum-deployment-state" 24 | TargetKeyId: !Ref DeploymentStateBucketKey 25 | DeploymentStateBucket: 26 | Type: "AWS::S3::Bucket" 27 | Properties: 28 | BucketName: !Sub "${AWS::Region}-quorum-deployment-state-${AWS::AccountId}" 29 | AccessControl: Private 30 | BucketEncryption: 31 | ServerSideEncryptionConfiguration: 32 | - ServerSideEncryptionByDefault: 33 | SSEAlgorithm: "aws:kms" 34 | KMSMasterKeyID: !Ref DeploymentStateBucketKey 35 | VersioningConfiguration: 36 | Status: Enabled 37 | DeploymentStateBucketPolicy: 38 | Type: "AWS::S3::BucketPolicy" 39 | Properties: 40 | Bucket: !Ref DeploymentStateBucket 41 | PolicyDocument: 42 | Statement: 43 | - Sid: "Allow access for IAM Users" 44 | Action: "s3:*" 45 | Effect: "Allow" 46 | Resource: 47 | - !Join ["", ["arn:aws:s3:::", !Ref DeploymentStateBucket]] 48 | - !Join ["", ["arn:aws:s3:::", !Ref DeploymentStateBucket, "/*"]] 49 | Principal: 50 | AWS: !Sub "arn:aws:iam::${AWS::AccountId}:root" 51 | - Sid: "Deny access when no encryption header" 52 | Action: "s3:PutObject" 53 | Effect: "Deny" 54 | Resource: 55 | - !Join ["", ["arn:aws:s3:::", !Ref DeploymentStateBucket]] 56 | - !Join ["", ["arn:aws:s3:::", !Ref DeploymentStateBucket, "/*"]] 57 | Principal: "*" 58 | Condition: 59 | "Null": 60 | s3:x-amz-server-side-encryption: "true" 61 | - Sid: "Deny access when no aws:kms encryption algo header" 62 | Action: "s3:PutObject" 63 | Effect: "Deny" 64 | Resource: 65 | - !Join ["", ["arn:aws:s3:::", !Ref DeploymentStateBucket]] 66 | - !Join ["", ["arn:aws:s3:::", !Ref DeploymentStateBucket, "/*"]] 67 | Principal: "*" 68 | Condition: 69 | "StringNotEquals": 70 | s3:x-amz-server-side-encryption: "aws:kms" 71 | Outputs: 72 | DeploymentStateBucketName: 73 | Description: >- 74 | Bucket that stores Terraform states 75 | Export: 76 | Name: quorum-deployment-state-bucket-name 77 | Value: !Ref DeploymentStateBucket 78 | KeyAlias: 79 | Description: -> 80 | Key Alias of KMS Key used to encrypt/decrypt objects stored in Quorum deployment state bucket 81 | Export: 82 | Name: quorum-deployment-state-bucket-kms-key-alias 83 | Value: !Ref DeploymentStateBucketKeyAlias 84 | KeyARN: 85 | Description: >- 86 | Key ARN of KMS Key used to encrypt/decrypt objects stored in Quorum deployment state bucket 87 | Export: 88 | Name: quorum-deployment-state-bucket-kms-key-arn 89 | Value: !GetAtt 90 | - DeploymentStateBucketKey 91 | - Arn -------------------------------------------------------------------------------- /aws/templates/_terraform_init/main.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "${var.region}" 3 | } 4 | 5 | locals { 6 | tfinit_filename = "terraform.auto.backend_config" 7 | tfvars_filename = "terraform.auto.tfvars" 8 | deployment_id = "${coalesce(var.network_name, join("", random_id.deployment_id.*.b64_url))}" 9 | } 10 | 11 | data "aws_cloudformation_export" "state_bucket_name" { 12 | name = "quorum-deployment-state-bucket-name" 13 | } 14 | 15 | data "aws_cloudformation_export" "kms_key_alias" { 16 | name = "quorum-deployment-state-bucket-kms-key-alias" 17 | } 18 | 19 | data "aws_kms_alias" "state_bucket" { 20 | name = "${data.aws_cloudformation_export.kms_key_alias.value}" 21 | } 22 | 23 | resource "random_id" "deployment_id" { 24 | count = "${var.network_name == "" ? 1 : 0}" 25 | prefix = "q-" 26 | byte_length = 8 27 | } 28 | 29 | resource "local_file" "tfinit" { 30 | filename = "${format("%s/../%s", path.module, local.tfinit_filename)}" 31 | 32 | content = < /dev/null 2>&1 \ 122 | | echo Wait for nodes in Quorum network being up ... $count/${var.number_of_nodes} 123 | sleep 1 124 | done 125 | 126 | if which jq >/dev/null; then 127 | echo "Found jq" 128 | else 129 | echo "jq not found. Instaling ..." 130 | sudo yum -y install jq 131 | fi 132 | 133 | for t in `aws ecs list-tasks --cluster ${local.ecs_cluster_name} | jq -r .taskArns[]` 134 | do 135 | task_metadata=$(aws ecs describe-tasks --cluster ${local.ecs_cluster_name} --tasks $t) 136 | HOST_IP=$(echo $task_metadata | jq -r '.tasks[0] | .containers[] | select(.name == "${local.quorum_run_container_name}") | .networkInterfaces[] | .privateIpv4Address') 137 | group=$(echo $task_metadata | jq -r '.tasks[0] | .group') 138 | taskArn=$(echo $task_metadata | jq -r '.tasks[0] | .taskDefinitionArn') 139 | # only care about new task 140 | if [[ "$taskArn" == *:$TASK_REVISION ]]; then 141 | echo $group | sudo tee ${local.shared_volume_container_path}/mappings/${local.normalized_host_ip} 142 | fi 143 | done 144 | 145 | cat < /dev/null 2>&1 \ 193 | | echo Wait for nodes in Ethereum network being up ... $count/${var.number_of_nodes} 194 | sleep 1 195 | done 196 | 197 | if which jq >/dev/null; then 198 | echo "Found jq" 199 | else 200 | echo "jq not found. Instaling ..." 201 | sudo yum -y install jq 202 | fi 203 | 204 | for t in `aws ecs list-tasks --cluster ${local.ecs_cluster_name} | jq -r .taskArns[]` 205 | do 206 | task_metadata=$(aws ecs describe-tasks --cluster ${local.ecs_cluster_name} --tasks $t) 207 | HOST_IP=$(echo $task_metadata | jq -r '.tasks[0] | .containers[] | select(.name == "${local.quorum_run_container_name}") | .networkInterfaces[] | .privateIpv4Address') 208 | group=$(echo $task_metadata | jq -r '.tasks[0] | .group') 209 | taskArn=$(echo $task_metadata | jq -r '.tasks[0] | .taskDefinitionArn') 210 | # only care about new task 211 | if [[ "$taskArn" == *:$TASK_REVISION ]]; then 212 | echo $group | sudo tee ${local.shared_volume_container_path}/mappings/${local.normalized_host_ip} 213 | fi 214 | done 215 | 216 | cat < ${local.quorum_password_file}", 17 | "bootnode -genkey ${local.quorum_data_dir}/geth/nodekey", 18 | "export NODE_ID=$(bootnode -nodekey ${local.quorum_data_dir}/geth/nodekey -writeaddress)", 19 | "geth version", 20 | "echo Creating an account for this node", 21 | "geth --datadir ${local.quorum_data_dir} account new --password ${local.quorum_password_file}", 22 | "export KEYSTORE_FILE=$(ls ${local.quorum_data_dir}/keystore/ | head -n1)", 23 | "export ACCOUNT_ADDRESS=$(cat ${local.quorum_data_dir}/keystore/$KEYSTORE_FILE | sed 's/^.*\"address\":\"\\([^\"]*\\)\".*$/\\1/g')", 24 | "echo Writing account address $ACCOUNT_ADDRESS to ${local.account_address_file}", 25 | "echo $ACCOUNT_ADDRESS > ${local.account_address_file}", 26 | "echo Writing Node Id [$NODE_ID] to ${local.node_id_file}", 27 | "echo $NODE_ID > ${local.node_id_file}", 28 | ] 29 | 30 | node_key_bootstrap_container_definition = { 31 | name = "${local.node_key_bootstrap_container_name}" 32 | image = "${local.quorum_docker_image}" 33 | essential = "false" 34 | 35 | logConfiguration = { 36 | logDriver = "awslogs" 37 | 38 | options = { 39 | awslogs-group = "${aws_cloudwatch_log_group.quorum.name}" 40 | awslogs-region = "${var.region}" 41 | awslogs-stream-prefix = "logs" 42 | } 43 | } 44 | 45 | mountPoints = [ 46 | { 47 | sourceVolume = "${local.shared_volume_name}" 48 | containerPath = "${local.shared_volume_container_path}" 49 | }, 50 | ] 51 | 52 | environments = [] 53 | 54 | portMappings = [] 55 | 56 | volumesFrom = [] 57 | 58 | healthCheck = { 59 | interval = 30 60 | retries = 10 61 | timeout = 60 62 | startPeriod = 300 63 | 64 | command = [ 65 | "CMD-SHELL", 66 | "[ -f ${local.node_id_file} ];", 67 | ] 68 | } 69 | 70 | entrypoint = [ 71 | "/bin/sh", 72 | "-c", 73 | "${join("\n", local.node_key_bootstrap_commands)}", 74 | ] 75 | 76 | dockerLabels = "${local.common_tags}" 77 | 78 | cpu = 0 79 | } 80 | 81 | // bootstrap the extraData, this must be used inside metadata_bootstrap_commands to inherit metadata info 82 | clique_bootstrap_commands = [ 83 | "all=\"0x0000000000000000000000000000000000000000000000000000000000000000\"; for f in `ls ${local.accounts_folder}`; do address=$(cat ${local.accounts_folder}/$f); all=\"$all$(echo $address)\"; done;all=\"$all$(echo 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000)\";", 84 | "echo clique signer Addresses: $all", 85 | "extraData=\"\\\"$(echo $all)\\\"\"", 86 | ] 87 | 88 | // bootstrap the extraData, this must be used inside metadata_bootstrap_commands to inherit metadata info 89 | istanbul_bootstrap_commands = [ 90 | "curl -L https://dl.bintray.com/quorumengineering/istanbul-tools/istanbul-tools_v1.0.2_linux_amd64.tar.gz -o tools.tar.gz", 91 | "tar xfvz tools.tar.gz", 92 | "all=\"\"; for f in `ls ${local.node_ids_folder}`; do address=$(cat ${local.node_ids_folder}/$f); all=\"$all,$(./istanbul address --nodeidhex $address)\"; done", 93 | "all=\"$${all:1}\"", 94 | "echo Validator Addresses: $all", 95 | "extraData=\"\\\"$(./istanbul extra encode --validators $all | awk -F: '{print $2}' | tr -d ' ')\\\"\"", 96 | ] 97 | 98 | quorum_metadata_bootstrap_commands = [ 99 | "set -e", 100 | "echo Wait until Node Key is ready ...", 101 | "while [ ! -f \"${local.node_id_file}\" ]; do sleep 1; done", 102 | "apk update", 103 | "apk add curl jq", 104 | "export TASK_REVISION=$(curl -s 169.254.170.2/v2/metadata | jq '.Revision' -r)", 105 | "echo \"Task Revision: $TASK_REVISION\"", 106 | "echo $TASK_REVISION > ${local.task_revision_file}", 107 | "export HOST_IP=$(curl -s 169.254.170.2/v2/metadata | jq '.Containers[] | select(.Name == \"${local.metadata_bootstrap_container_name}\") | .Networks[] | select(.NetworkMode == \"awsvpc\") | .IPv4Addresses[0]' -r )", 108 | "echo \"Host IP: $HOST_IP\"", 109 | "echo $HOST_IP > ${local.host_ip_file}", 110 | "export TASK_ARN=$(curl -s 169.254.170.2/v2/metadata | jq -r '.TaskARN')", 111 | "aws ecs describe-tasks --cluster ${local.ecs_cluster_name} --tasks $TASK_ARN | jq -r '.tasks[0] | .group' > ${local.service_file}", 112 | "mkdir -p ${local.hosts_folder}", 113 | "mkdir -p ${local.node_ids_folder}", 114 | "mkdir -p ${local.accounts_folder}", 115 | "aws s3 cp ${local.node_id_file} s3://${local.s3_revision_folder}/nodeids/${local.normalized_host_ip} --sse aws:kms --sse-kms-key-id ${aws_kms_key.bucket.arn}", 116 | "aws s3 cp ${local.host_ip_file} s3://${local.s3_revision_folder}/hosts/${local.normalized_host_ip} --sse aws:kms --sse-kms-key-id ${aws_kms_key.bucket.arn}", 117 | "aws s3 cp ${local.account_address_file} s3://${local.s3_revision_folder}/accounts/${local.normalized_host_ip} --sse aws:kms --sse-kms-key-id ${aws_kms_key.bucket.arn}", 118 | 119 | // Gather all IPs 120 | "count=0; while [ $count -lt ${var.number_of_nodes} ]; do count=$(ls ${local.hosts_folder} | grep ^ip | wc -l); aws s3 cp --recursive s3://${local.s3_revision_folder}/hosts ${local.hosts_folder} > /dev/null 2>&1 | echo \"Wait for other containers to report their IPs ... $count/${var.number_of_nodes}\"; sleep 1; done", 121 | 122 | "echo \"All containers have reported their IPs\"", 123 | 124 | // Gather all Accounts 125 | "count=0; while [ $count -lt ${var.number_of_nodes} ]; do count=$(ls ${local.accounts_folder} | grep ^ip | wc -l); aws s3 cp --recursive s3://${local.s3_revision_folder}/accounts ${local.accounts_folder} > /dev/null 2>&1 | echo \"Wait for other nodes to report their accounts ... $count/${var.number_of_nodes}\"; sleep 1; done", 126 | 127 | "echo \"All nodes have registered accounts\"", 128 | 129 | // Gather all Node IDs 130 | "count=0; while [ $count -lt ${var.number_of_nodes} ]; do count=$(ls ${local.node_ids_folder} | grep ^ip | wc -l); aws s3 cp --recursive s3://${local.s3_revision_folder}/nodeids ${local.node_ids_folder} > /dev/null 2>&1 | echo \"Wait for other nodes to report their IDs ... $count/${var.number_of_nodes}\"; sleep 1; done", 131 | 132 | "echo \"All nodes have registered their IDs\"", 133 | 134 | // Prepare Genesis file 135 | "alloc=\"\"; for f in `ls ${local.accounts_folder}`; do address=$(cat ${local.accounts_folder}/$f); alloc=\"$alloc,\\\"$address\\\": { \"balance\": \"\\\"1000000000000000000000000000\\\"\"}\"; done", 136 | 137 | "alloc=\"{$${alloc:1}}\"", 138 | "extraData=\"\\\"0x0000000000000000000000000000000000000000000000000000000000000000\\\"\"", 139 | "${var.consensus_mechanism == "istanbul" ? join("\n", local.istanbul_bootstrap_commands) : ""}", 140 | "${var.consensus_mechanism == "clique" ? join("\n", local.clique_bootstrap_commands) : ""}", 141 | "mixHash=\"\\\"${element(local.consensus_config_map["genesis_mixHash"], 0)}\\\"\"", 142 | "difficulty=\"\\\"${element(local.consensus_config_map["genesis_difficulty"], 0)}\\\"\"", 143 | "echo '${replace(jsonencode(local.quorum_genesis), "/\"(true|false|[0-9]+)\"/", "$1")}' | jq \". + { alloc : $alloc, extraData: $extraData, mixHash: $mixHash, difficulty: $difficulty}${var.consensus_mechanism == "istanbul" ? " | .config=.config + {istanbul: {epoch: 30000, policy: 0} }" : ""}${var.consensus_mechanism == "clique" ? " | .config=.config + {clique: {epoch: 30000, period: 1} }" : ""}\" > ${local.genesis_file}", 144 | "cat ${local.genesis_file}", 145 | 146 | // Write status 147 | "echo \"Done!\" > ${local.metadata_bootstrap_container_status_file}", 148 | 149 | "echo Wait until privacy engine initialized ...", 150 | "while [ ! -f \"${local.tx_privacy_engine_address_file}\" ]; do sleep 1; done", 151 | "aws s3 cp ${local.tx_privacy_engine_address_file} s3://${local.s3_revision_folder}/privacyaddresses/${local.normalized_host_ip} --sse aws:kms --sse-kms-key-id ${aws_kms_key.bucket.arn}", 152 | ] 153 | 154 | eth_metadata_bootstrap_commands = [ 155 | "set -e", 156 | "echo Wait until Node Key is ready ...", 157 | "while [ ! -f \"${local.node_id_file}\" ]; do sleep 1; done", 158 | "apk update", 159 | "apk add curl jq", 160 | "export TASK_REVISION=$(curl -s 169.254.170.2/v2/metadata | jq '.Revision' -r)", 161 | "echo \"Task Revision: $TASK_REVISION\"", 162 | "echo $TASK_REVISION > ${local.task_revision_file}", 163 | "export HOST_IP=$(curl -s 169.254.170.2/v2/metadata | jq '.Containers[] | select(.Name == \"${local.metadata_bootstrap_container_name}\") | .Networks[] | select(.NetworkMode == \"awsvpc\") | .IPv4Addresses[0]' -r )", 164 | "echo \"Host IP: $HOST_IP\"", 165 | "echo $HOST_IP > ${local.host_ip_file}", 166 | "export TASK_ARN=$(curl -s 169.254.170.2/v2/metadata | jq -r '.TaskARN')", 167 | "aws ecs describe-tasks --cluster ${local.ecs_cluster_name} --tasks $TASK_ARN | jq -r '.tasks[0] | .group' > ${local.service_file}", 168 | "mkdir -p ${local.hosts_folder}", 169 | "mkdir -p ${local.node_ids_folder}", 170 | "mkdir -p ${local.accounts_folder}", 171 | "aws s3 cp ${local.node_id_file} s3://${local.s3_revision_folder}/nodeids/${local.normalized_host_ip} --sse aws:kms --sse-kms-key-id ${aws_kms_key.bucket.arn}", 172 | "aws s3 cp ${local.host_ip_file} s3://${local.s3_revision_folder}/hosts/${local.normalized_host_ip} --sse aws:kms --sse-kms-key-id ${aws_kms_key.bucket.arn}", 173 | "aws s3 cp ${local.account_address_file} s3://${local.s3_revision_folder}/accounts/${local.normalized_host_ip} --sse aws:kms --sse-kms-key-id ${aws_kms_key.bucket.arn}", 174 | 175 | // Gather all IPs 176 | "count=0; while [ $count -lt ${var.number_of_nodes} ]; do count=$(ls ${local.hosts_folder} | grep ^ip | wc -l); aws s3 cp --recursive s3://${local.s3_revision_folder}/hosts ${local.hosts_folder} > /dev/null 2>&1 | echo \"Wait for other containers to report their IPs ... $count/${var.number_of_nodes}\"; sleep 1; done", 177 | 178 | "echo \"All containers have reported their IPs\"", 179 | 180 | // Gather all Accounts 181 | "count=0; while [ $count -lt ${var.number_of_nodes} ]; do count=$(ls ${local.accounts_folder} | grep ^ip | wc -l); aws s3 cp --recursive s3://${local.s3_revision_folder}/accounts ${local.accounts_folder} > /dev/null 2>&1 | echo \"Wait for other nodes to report their accounts ... $count/${var.number_of_nodes}\"; sleep 1; done", 182 | 183 | "echo \"All nodes have registered accounts\"", 184 | 185 | // Gather all Node IDs 186 | "count=0; while [ $count -lt ${var.number_of_nodes} ]; do count=$(ls ${local.node_ids_folder} | grep ^ip | wc -l); aws s3 cp --recursive s3://${local.s3_revision_folder}/nodeids ${local.node_ids_folder} > /dev/null 2>&1 | echo \"Wait for other nodes to report their IDs ... $count/${var.number_of_nodes}\"; sleep 1; done", 187 | 188 | "echo \"All nodes have registered their IDs\"", 189 | 190 | // Prepare Genesis file 191 | "alloc=\"\"; for f in `ls ${local.accounts_folder}`; do address=$(cat ${local.accounts_folder}/$f); alloc=\"$alloc,\\\"$address\\\": { \"balance\": \"\\\"1000000000000000000000000000\\\"\"}\"; done", 192 | 193 | "alloc=\"{$${alloc:1}}\"", 194 | "extraData=\"\\\"0x0000000000000000000000000000000000000000000000000000000000000000\\\"\"", 195 | "${join("\n", local.clique_bootstrap_commands)}", 196 | "mixHash=\"\\\"${element(local.consensus_config_map["genesis_mixHash"], 0)}\\\"\"", 197 | "difficulty=\"\\\"${element(local.consensus_config_map["genesis_difficulty"], 0)}\\\"\"", 198 | "echo '${replace(jsonencode(local.eth_genesis), "/\"(true|false|[0-9]+)\"/", "$1")}' | jq \". + { alloc : $alloc, extraData: $extraData, mixHash: $mixHash, difficulty: $difficulty}${var.consensus_mechanism == "clique" ? " | .config=.config + {clique: {epoch: 30000, period: 1} }" : ""}\" > ${local.genesis_file}", 199 | "cat ${local.genesis_file}", 200 | 201 | // Write status 202 | "echo \"Done!\" > ${local.metadata_bootstrap_container_status_file}", 203 | 204 | ] 205 | 206 | metadata_bootstrap_container_definition = { 207 | name = "${local.metadata_bootstrap_container_name}" 208 | image = "${local.aws_cli_docker_image}" 209 | essential = "false" 210 | 211 | logConfiguration = { 212 | logDriver = "awslogs" 213 | 214 | options = { 215 | awslogs-group = "${aws_cloudwatch_log_group.quorum.name}" 216 | awslogs-region = "${var.region}" 217 | awslogs-stream-prefix = "logs" 218 | } 219 | } 220 | 221 | mountPoints = [ 222 | { 223 | sourceVolume = "${local.shared_volume_name}" 224 | containerPath = "${local.shared_volume_container_path}" 225 | }, 226 | ] 227 | 228 | environments = [] 229 | 230 | portMappings = [] 231 | 232 | volumesFrom = [ 233 | { 234 | sourceContainer = "${local.node_key_bootstrap_container_name}" 235 | }, 236 | ] 237 | 238 | healthCheck = { 239 | interval = 30 240 | retries = 10 241 | timeout = 60 242 | startPeriod = 300 243 | 244 | command = [ 245 | "CMD-SHELL", 246 | "[ -f ${local.metadata_bootstrap_container_status_file} ];", 247 | ] 248 | } 249 | 250 | entryPoint = [ 251 | "/bin/sh", 252 | "-c", 253 | "${var.is_ethereum_network == "true" ? join("\n",local.eth_metadata_bootstrap_commands) : join("\n",local.quorum_metadata_bootstrap_commands)}", 254 | ] 255 | 256 | dockerLabels = "${local.common_tags}" 257 | 258 | cpu = 0 259 | } 260 | } 261 | -------------------------------------------------------------------------------- /aws/templates/container_definitions.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | shared_volume_name = "quorum_shared_volume" 3 | shared_volume_container_path = "/qdata" 4 | tx_privacy_engine_socket_file = "${local.shared_volume_container_path}/tm.ipc" 5 | tx_privacy_engine_address_file = "${element(compact(local.tx_privacy_address_files), 0)}" 6 | 7 | node_key_bootstrap_container_name = "node-key-bootstrap" 8 | metadata_bootstrap_container_name = "metadata-bootstrap" 9 | quorum_run_container_name = "quorum-run" 10 | tx_privacy_engine_run_container_name = "${var.tx_privacy_engine}-run" 11 | istanbul_extradata_bootstrap_container_name = "istanbul-extradata-bootstrap" 12 | 13 | consensus_config = { 14 | raft = { 15 | geth_args = [ 16 | "--raft", 17 | "--raftport ${local.raft_port}", 18 | ] 19 | 20 | enode_params = [ 21 | "raftport=${local.raft_port}", 22 | ] 23 | 24 | genesis_mixHash = ["0x00000000000000000000000000000000000000647572616c65787365646c6578"] 25 | genesis_difficulty = ["0x00"] 26 | } 27 | 28 | istanbul = { 29 | geth_args = [ 30 | "--istanbul.blockperiod 1", 31 | "--emitcheckpoints", 32 | "--syncmode full", 33 | "--mine", 34 | "--minerthreads 1", 35 | ] 36 | 37 | enode_params = [] 38 | 39 | genesis_mixHash = ["0x63746963616c2062797a616e74696e65206661756c7420746f6c6572616e6365"] 40 | genesis_difficulty = ["0x01"] 41 | } 42 | 43 | clique = { 44 | geth_args = [ 45 | "--syncmode full", 46 | "--mine", 47 | "--minerthreads 1", 48 | ] 49 | enode_params = [] 50 | genesis_mixHash = ["0x0000000000000000000000000000000000000000000000000000000000000000"] 51 | genesis_difficulty = ["0x01"] 52 | 53 | } 54 | } 55 | 56 | 57 | tx_privacy_address_files = [ 58 | "${var.tx_privacy_engine == "constellation" ? local.constellation_pub_key_file : ""}", 59 | "${var.tx_privacy_engine == "tessera" ? local.tessera_pub_key_file : ""}", 60 | ] 61 | 62 | quorum_common_container_definitions = [ 63 | "${local.node_key_bootstrap_container_definition}", 64 | "${local.metadata_bootstrap_container_definition}", 65 | "${local.quorum_run_container_definition}", 66 | ] 67 | 68 | eth_common_container_definitions = [ 69 | "${local.node_key_bootstrap_container_definition}", 70 | "${local.metadata_bootstrap_container_definition}", 71 | "${local.eth_run_container_definition}", 72 | ] 73 | 74 | container_definitions_for_constellation = [ 75 | "${local.quorum_common_container_definitions}", 76 | "${local.constellation_run_container_definition}", 77 | ] 78 | 79 | container_definitions_for_tessera = [ 80 | "${local.quorum_common_container_definitions}", 81 | "${local.tessera_run_container_definition}", 82 | ] 83 | 84 | quorum_container_definitions = [ 85 | "${var.tx_privacy_engine == "constellation" ? jsonencode(local.container_definitions_for_constellation) : ""}", 86 | "${var.tx_privacy_engine == "tessera" ? jsonencode(local.container_definitions_for_tessera) : ""}", 87 | ] 88 | 89 | eth_container_definitions = [ 90 | "${jsonencode(local.eth_common_container_definitions)}", 91 | ] 92 | } 93 | -------------------------------------------------------------------------------- /aws/templates/container_definitions_constellation.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | constellation_config_file = "${local.shared_volume_container_path}/constellation.cfg" 3 | constellation_port = 10000 4 | constellation_pub_key_file = "${local.shared_volume_container_path}/tm.pub" 5 | 6 | constellation_config_commands = [ 7 | "constellation-node --generatekeys=${local.shared_volume_container_path}/tm < /dev/null", 8 | "export HOST_IP=$(cat ${local.host_ip_file})", 9 | "echo \"\nHost IP: $HOST_IP\"", 10 | "echo \"Public Key: $(cat ${local.constellation_pub_key_file})\"", 11 | "all=\"\"; for f in `ls ${local.hosts_folder} | grep -v ${local.normalized_host_ip}`; do ip=$(cat ${local.hosts_folder}/$f); all=\"$all,\\\"http://$ip:${local.constellation_port}/\\\"\"; done", 12 | "echo \"Creating ${local.constellation_config_file}\"", 13 | "echo \"# This file is auto generated. Please do not edit\" > ${local.constellation_config_file}", 14 | "echo \"url = \\\"http://$HOST_IP:${local.constellation_port}/\\\"\" >> ${local.constellation_config_file}", 15 | "echo \"port = ${local.constellation_port}\" >> ${local.constellation_config_file}", 16 | "echo \"socket = \\\"${local.tx_privacy_engine_socket_file}\\\"\" >> ${local.constellation_config_file}", 17 | "echo \"othernodes = [\\\"http://$HOST_IP:${local.constellation_port}/\\\"$all]\" >> ${local.constellation_config_file}", 18 | "echo \"publickeys = [\\\"${local.shared_volume_container_path}/tm.pub\\\"]\" >> ${local.constellation_config_file}", 19 | "echo \"privatekeys = [\\\"${local.shared_volume_container_path}/tm.key\\\"]\" >> ${local.constellation_config_file}", 20 | "echo \"storage = \\\"/constellation\\\"\" >> ${local.constellation_config_file}", 21 | "echo \"verbosity = 4\" >> ${local.constellation_config_file}", 22 | "cat ${local.constellation_config_file}", 23 | ] 24 | 25 | constellation_run_commands = [ 26 | "set -e", 27 | "echo Wait until metadata bootstrap completed ...", 28 | "while [ ! -f \"${local.metadata_bootstrap_container_status_file}\" ]; do sleep 1; done", 29 | "${local.constellation_config_commands}", 30 | "constellation-node ${local.constellation_config_file}", 31 | ] 32 | 33 | constellation_run_container_definition = { 34 | name = "${local.tx_privacy_engine_run_container_name}" 35 | image = "${local.tx_privacy_engine_docker_image}" 36 | essential = "false" 37 | 38 | logConfiguration = { 39 | logDriver = "awslogs" 40 | 41 | options = { 42 | awslogs-group = "${aws_cloudwatch_log_group.quorum.name}" 43 | awslogs-region = "${var.region}" 44 | awslogs-stream-prefix = "logs" 45 | } 46 | } 47 | 48 | portMappings = [ 49 | { 50 | containerPort = "${local.constellation_port}" 51 | }, 52 | ] 53 | 54 | mountPoints = [ 55 | { 56 | sourceVolume = "${local.shared_volume_name}" 57 | containerPath = "${local.shared_volume_container_path}" 58 | }, 59 | ] 60 | 61 | volumesFrom = [ 62 | { 63 | sourceContainer = "${local.metadata_bootstrap_container_name}" 64 | }, 65 | ] 66 | 67 | healthCheck = { 68 | interval = 30 69 | retries = 10 70 | timeout = 60 71 | startPeriod = 300 72 | 73 | command = [ 74 | "CMD-SHELL", 75 | "[ -S ${local.tx_privacy_engine_socket_file} ];", 76 | ] 77 | } 78 | 79 | entrypoint = [ 80 | "/bin/sh", 81 | "-c", 82 | "${join("\n", local.constellation_run_commands)}", 83 | ] 84 | 85 | dockerLabels = "${local.common_tags}" 86 | 87 | cpu = 0 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /aws/templates/container_definitions_quorum.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | quorum_rpc_port = 22000 3 | quorum_p2p_port = 21000 4 | raft_port = 50400 5 | quorum_data_dir = "${local.shared_volume_container_path}/dd" 6 | quorum_password_file = "${local.shared_volume_container_path}/passwords.txt" 7 | quorum_static_nodes_file = "${local.quorum_data_dir}/static-nodes.json" 8 | quorum_permissioned_nodes_file = "${local.quorum_data_dir}/permissioned-nodes.json" 9 | genesis_file = "${local.shared_volume_container_path}/genesis.json" 10 | node_id_file = "${local.shared_volume_container_path}/node_id" 11 | node_ids_folder = "${local.shared_volume_container_path}/nodeids" 12 | accounts_folder = "${local.shared_volume_container_path}/accounts" 13 | privacy_addresses_folder = "${local.shared_volume_container_path}/privacyaddresses" 14 | # store Tessera pub keys 15 | 16 | consensus_config_map = "${local.consensus_config[var.consensus_mechanism]}" 17 | 18 | quorum_config_commands = [ 19 | "mkdir -p ${local.quorum_data_dir}/geth", 20 | "echo \"\" > ${local.quorum_password_file}", 21 | "echo \"Creating ${local.quorum_static_nodes_file} and ${local.quorum_permissioned_nodes_file}\"", 22 | "all=\"\"; for f in `ls ${local.node_ids_folder}`; do nodeid=$(cat ${local.node_ids_folder}/$f); ip=$(cat ${local.hosts_folder}/$f); all=\"$all,\\\"enode://$nodeid@$ip:${local.quorum_p2p_port}?discport=0&${join("&", local.consensus_config_map["enode_params"])}\\\"\"; done; all=$${all:1}", 23 | "echo \"[$all]\" > ${local.quorum_static_nodes_file}", 24 | "echo \"[$all]\" > ${local.quorum_permissioned_nodes_file}", 25 | "echo Permissioned Nodes: $(cat ${local.quorum_permissioned_nodes_file})", 26 | "geth --datadir ${local.quorum_data_dir} init ${local.genesis_file}", 27 | "export IDENTITY=$(cat ${local.service_file} | awk -F: '{print $2}')", 28 | ] 29 | 30 | additional_args = "${local.consensus_config_map["geth_args"]}" 31 | 32 | geth_args = [ 33 | "--datadir ${local.quorum_data_dir}", 34 | "--rpc", 35 | "--rpcaddr 0.0.0.0", 36 | "--rpcapi admin,db,eth,debug,miner,net,shh,txpool,personal,web3,quorum,${var.consensus_mechanism}", 37 | "--rpcport ${local.quorum_rpc_port}", 38 | "--port ${local.quorum_p2p_port}", 39 | "--unlock 0", 40 | "--password ${local.quorum_password_file}", 41 | "--nodiscover", 42 | "--networkid ${random_integer.network_id.result}", 43 | "--verbosity 5", 44 | "--debug", 45 | "--identity $IDENTITY", 46 | "${var.is_ethereum_v1_9_x == "true" ? "--allow-insecure-unlock" : ""}", 47 | "--ethstats \"$IDENTITY:${random_id.ethstat_secret.hex}@${aws_instance.bastion.private_ip}:${local.ethstats_port}\"", 48 | ] 49 | 50 | geth_args_combined = "${join(" ", concat(local.geth_args, local.additional_args))}" 51 | 52 | quorum_run_commands = [ 53 | "set -e", 54 | "echo Wait until metadata bootstrap completed ...", 55 | "while [ ! -f \"${local.metadata_bootstrap_container_status_file}\" ]; do sleep 1; done", 56 | "echo Wait until ${var.tx_privacy_engine} is ready ...", 57 | "while [ ! -S \"${local.tx_privacy_engine_socket_file}\" ]; do sleep 1; done", 58 | "${local.quorum_config_commands}", 59 | "echo 'Running geth with: ${local.geth_args_combined}'", 60 | "geth ${local.geth_args_combined}", 61 | ] 62 | 63 | eth_run_commands = [ 64 | "set -e", 65 | "echo Wait until metadata bootstrap completed ...", 66 | "while [ ! -f \"${local.metadata_bootstrap_container_status_file}\" ]; do sleep 1; done", 67 | "${local.quorum_config_commands}", 68 | "echo 'Running geth with: ${local.geth_args_combined}'", 69 | "geth ${local.geth_args_combined}", 70 | ] 71 | 72 | quorum_run_container_definition = { 73 | name = "${local.quorum_run_container_name}" 74 | image = "${local.quorum_docker_image}" 75 | essential = "true" 76 | 77 | logConfiguration = { 78 | logDriver = "awslogs" 79 | 80 | options = { 81 | awslogs-group = "${aws_cloudwatch_log_group.quorum.name}" 82 | awslogs-region = "${var.region}" 83 | awslogs-stream-prefix = "logs" 84 | } 85 | } 86 | 87 | mountPoints = [ 88 | { 89 | sourceVolume = "${local.shared_volume_name}" 90 | containerPath = "${local.shared_volume_container_path}" 91 | }, 92 | ] 93 | 94 | healthCheck = { 95 | interval = 30 96 | retries = 10 97 | timeout = 60 98 | startPeriod = 300 99 | 100 | command = [ 101 | "CMD-SHELL", 102 | "[ -S ${local.quorum_data_dir}/geth.ipc ];", 103 | ] 104 | } 105 | 106 | environments = [] 107 | 108 | portMappings = [] 109 | 110 | volumesFrom = [ 111 | { 112 | sourceContainer = "${local.metadata_bootstrap_container_name}" 113 | }, 114 | { 115 | sourceContainer = "${local.tx_privacy_engine_run_container_name}" 116 | }, 117 | ] 118 | 119 | environment = [ 120 | { 121 | name = "PRIVATE_CONFIG" 122 | value = "${local.tx_privacy_engine_socket_file}" 123 | }, 124 | ] 125 | 126 | entrypoint = [ 127 | "/bin/sh", 128 | "-c", 129 | "${join("\n", local.quorum_run_commands)}", 130 | ] 131 | 132 | dockerLabels = "${local.common_tags}" 133 | 134 | cpu = 0 135 | } 136 | 137 | eth_run_container_definition = { 138 | name = "${local.quorum_run_container_name}" 139 | image = "${local.quorum_docker_image}" 140 | essential = "true" 141 | 142 | logConfiguration = { 143 | logDriver = "awslogs" 144 | 145 | options = { 146 | awslogs-group = "${aws_cloudwatch_log_group.quorum.name}" 147 | awslogs-region = "${var.region}" 148 | awslogs-stream-prefix = "logs" 149 | } 150 | } 151 | 152 | mountPoints = [ 153 | { 154 | sourceVolume = "${local.shared_volume_name}" 155 | containerPath = "${local.shared_volume_container_path}" 156 | }, 157 | ] 158 | 159 | healthCheck = { 160 | interval = 30 161 | retries = 10 162 | timeout = 60 163 | startPeriod = 300 164 | 165 | command = [ 166 | "CMD-SHELL", 167 | "[ -S ${local.quorum_data_dir}/geth.ipc ];", 168 | ] 169 | } 170 | 171 | environments = [] 172 | 173 | portMappings = [] 174 | 175 | volumesFrom = [ 176 | { 177 | sourceContainer = "${local.metadata_bootstrap_container_name}" 178 | } 179 | ] 180 | 181 | environment = [] 182 | 183 | entrypoint = [ 184 | "/bin/sh", 185 | "-c", 186 | "${join("\n",local.eth_run_commands)}", 187 | ] 188 | 189 | dockerLabels = "${local.common_tags}" 190 | 191 | cpu = 0 192 | } 193 | 194 | quorum_genesis = { 195 | "alloc" = {} 196 | 197 | "coinbase" = "0x0000000000000000000000000000000000000000" 198 | 199 | "config" = { 200 | "homesteadBlock" = 0 201 | "byzantiumBlock" = 0 202 | "constantinopleBlock" = 0 203 | "chainId" = "${random_integer.network_id.result}" 204 | "eip150Block" = 0 205 | "eip155Block" = 0 206 | "eip150Hash" = "0x0000000000000000000000000000000000000000000000000000000000000000" 207 | "eip158Block" = 0 208 | "isQuorum" = "true" 209 | } 210 | 211 | "difficulty" = "0x0" 212 | "extraData" = "0x0000000000000000000000000000000000000000000000000000000000000000" 213 | "gasLimit" = "0xE0000000" 214 | "mixHash" = "0x00000000000000000000000000000000000000647572616c65787365646c6578" 215 | "nonce" = "0x0" 216 | "parentHash" = "0x0000000000000000000000000000000000000000000000000000000000000000" 217 | "timestamp" = "0x00" 218 | } 219 | 220 | eth_genesis = { 221 | "alloc" = {} 222 | 223 | "coinbase" = "0x0000000000000000000000000000000000000000" 224 | 225 | "config" = { 226 | "homesteadBlock" = 0 227 | "byzantiumBlock" = 0 228 | "constantinopleBlock" = 0 229 | "chainId" = "${random_integer.network_id.result}" 230 | "eip150Block" = 0 231 | "eip155Block" = 0 232 | "eip150Hash" = "0x0000000000000000000000000000000000000000000000000000000000000000" 233 | "eip158Block" = 0 234 | } 235 | 236 | "difficulty" = "0x0" 237 | "extraData" = "0x0000000000000000000000000000000000000000000000000000000000000000" 238 | "gasLimit" = "0xE0000000" 239 | "mixHash" = "0x00000000000000000000000000000000000000647572616c65787365646c6578" 240 | "nonce" = "0x0" 241 | "parentHash" = "0x0000000000000000000000000000000000000000000000000000000000000000" 242 | "timestamp" = "0x00" 243 | } 244 | } 245 | 246 | resource "random_integer" "network_id" { 247 | min = 2018 248 | max = 9999 249 | 250 | keepers = { 251 | changes_when = "${var.network_name}" 252 | } 253 | } 254 | -------------------------------------------------------------------------------- /aws/templates/container_definitions_tessera.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | tessera_config_file = "${local.shared_volume_container_path}/tessera.cfg" 3 | tessera_port = 9000 4 | tessera_thirdparty_port = 9080 5 | tessera_command = "java -jar /tessera/tessera-app.jar" 6 | tessera_pub_key_file = "${local.shared_volume_container_path}/.pub" 7 | 8 | tessera_config_commands = [ 9 | "apk update", 10 | "apk add jq", 11 | "cd ${local.shared_volume_container_path}; echo \"\n\" | ${local.tessera_command} -keygen ${local.shared_volume_container_path}/", 12 | "export HOST_IP=$(cat ${local.host_ip_file})", 13 | "export TM_PUB=$(cat ${local.tessera_pub_key_file})", 14 | "export TM_KEY=$(cat ${local.shared_volume_container_path}/.key)", 15 | "echo \"\nHost IP: $HOST_IP\"", 16 | "echo \"Public Key: $TM_PUB\"", 17 | "all=\"\"; for f in `ls ${local.hosts_folder} | grep -v ${local.normalized_host_ip}`; do ip=$(cat ${local.hosts_folder}/$f); all=\"$all,{ \\\"url\\\": \\\"http://$ip:${local.tessera_port}/\\\" }\"; done", 18 | "all=\"[{ \\\"url\\\": \\\"http://$HOST_IP:${local.tessera_port}/\\\" }$all]\"", 19 | "export TESSERA_VERSION=${var.tessera_docker_image_tag}", 20 | "export V=$(echo -e \"0.8\n$TESSERA_VERSION\" | sort -n -r -t '.' -k 1,1 -k 2,2 | head -n1)", 21 | "echo \"Creating ${local.tessera_config_file}\"", 22 | <