Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indy private #69

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
9d0b66e
Website. Bug fixes and addition of gtag manager
vlasonfa Jan 19, 2024
73241d1
Ethereum single node deployemnt option for issue #19
vlasonfa Jan 23, 2024
f435bfa
Single node Ethereum setup - add diagram to the Readme file
vlasonfa Jan 23, 2024
7f8ae91
add Indy Node sample
KatsuyaMatsuoka Jan 18, 2024
bc3c392
Merge branch 'aws-samples:main' into main
KatsuyaMatsuoka Jan 25, 2024
888cb84
Merge remote-tracking branch 'remotes/upstream/main'
fsatsuki Mar 17, 2024
88621a9
Change indy's build procedure to ansible
fsatsuki Mar 18, 2024
2537bdd
Merge branch 'aws-samples:main' into main
fsatsuki Mar 18, 2024
034da99
Merge branch 'main' of https://github.com/KatsuyaMatsuoka/aws-blockch…
fsatsuki Mar 18, 2024
6d9f963
change security group rule fo indy
fsatsuki Mar 18, 2024
4ffb925
Merge pull request #40 from KatsuyaMatsuoka/main
frbrkoala Apr 5, 2024
a0c5a66
Merge branch 'main' into indy-private
vlasonfa Apr 15, 2024
16acd04
Merge branch 'main' into indy-private
vlasonfa Apr 17, 2024
5d48882
Indy. Refactoring
vlasonfa Apr 17, 2024
25436c5
Indy. Added gitignore for python venv
vlasonfa Apr 17, 2024
495062f
Indy. Refactored CDK outputs from constructs for simpler properties e…
vlasonfa Apr 17, 2024
9668f9f
Indy. Refactoring ansible configuration for simplicity and automation
vlasonfa Apr 17, 2024
085528e
Indy. Fixing bugs in ansible inventory template file
vlasonfa Apr 18, 2024
31da2e0
cdk-nag check
fsatsuki Apr 26, 2024
75a2c7b
Merge branch 'aws-samples:main' into cdk-nag
fsatsuki Apr 26, 2024
266b128
Merge pull request #73 from fsatsuki/cdk-nag
frbrkoala May 6, 2024
42e4a85
Indy. Refactoring code and README
vlasonfa May 7, 2024
bec7729
Indy. Debugging initial deployment.
vlasonfa May 7, 2024
8e755b7
Indy. Fixed commands in README
vlasonfa May 8, 2024
9e54a46
fix ansible build failed
fsatsuki May 10, 2024
abd529b
Merge branch 'indy-private' into fix_ansible_build_failed_20240509
fsatsuki May 10, 2024
cdbd9f9
run pre-commit
fsatsuki May 10, 2024
eee2a7c
Merge pull request #77 from fsatsuki/fix_ansible_build_failed_20240509
frbrkoala May 13, 2024
7f87bdf
Indy. Ansible configuration is fixed and working.
vlasonfa May 14, 2024
0088f54
Merge branch 'aws-samples:main' into main
KatsuyaMatsuoka May 16, 2024
3af46e3
Merge branch 'indy-private' into cdk-tests
KatsuyaMatsuoka May 16, 2024
719185c
fix architecture diagram
KatsuyaMatsuoka May 16, 2024
439e031
Merge branch 'aws-samples:main' into cdk-tests
KatsuyaMatsuoka Jul 25, 2024
7ef129d
add cdk unit test
KatsuyaMatsuoka Aug 22, 2024
e2b8690
Merge remote-tracking branch 'origin/cdk-tests' into cdk-tests
KatsuyaMatsuoka Aug 22, 2024
7c8eb39
Revert "Merge branch 'aws-samples:main' into cdk-tests"
KatsuyaMatsuoka Aug 22, 2024
6ad1a67
Merge pull request #117 from KatsuyaMatsuoka/cdk-tests
frbrkoala Aug 23, 2024
b67470e
update doc for indy
KatsuyaMatsuoka Sep 5, 2024
a9faed3
Merge pull request #123 from KatsuyaMatsuoka/indy-private
frbrkoala Sep 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ ha-nodes-deploy*.json
*.OLD
.env
.idea

lib/indy/ansible/.venv
3 changes: 3 additions & 0 deletions lib/indy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
venv
*-deploy-output.json
inventory.yml
158 changes: 158 additions & 0 deletions lib/indy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
# Sample AWS Blockchain Node Runner app for Hyperledger Indy

| Contributed by |
|:--------------------:|
| [@fsatsuki](https://github.com/fsatsuki) |

[View this page in Japanese (日本語)](./README_ja.md)

## Architecture Overview

![Architecture](./doc/assets/Architecture.png)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add client to the architeture to illustrate how customers can connect and use the nodes deployed by the blueprint

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are also 3 trustee nodes, but only one is shown on the diagram. Is it correct?


This is a sample of building a Hyperledger Indy network on AWS.
The overall architecture is shown below, processing itself is performed by 4 Stewards (Validator Nodes), and network management is performed with Trustee. It consists of 4 EC2 instances for Steward and 3 EC2 instances for Trustee.

## Solution Walkthrough
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a section and responses to the Well Architected checklist. See for example:

### Well-Architected Checklist


### Setup Cloud9

We will use AWS Cloud9 to execute the subsequent commands. Follow the instructions in [Cloud9 Setup](../../docs/setup-cloud9.md)

### Clone this repository and install dependencies

```bash
git clone https://github.com/aws-samples/aws-blockchain-node-runners.git
cd aws-blockchain-node-runners
npm install
```

**NOTE:** In this tutorial we will set all major configuration through environment variables, but you also can modify parameters in `config/config.ts`.

### Deploy Indy Nodes

#### Building resources

1. Setting up initial AWS Cloud Development Kit (CDK)

The following command is executed only when using AWS CDK for the first time in the region where the deployment will be carried out.

```bash
npx cdk bootstrap
```

3. Deploying resources with CDK

```bash
npx cdk deploy --json --outputs-file indy-test-deploy-output.json

Outputs:
IndyNetworkStack.AnsibleFileTransferBucketName = 111122223333-ansible-file-transfer-bucket
IndyNetworkStack.steward1steward1InstanceId2F9F8910 = i-1234567890abcdef1
IndyNetworkStack.steward2steward2InstanceId995438F2 = i-1234567890abcdef2
IndyNetworkStack.steward3steward3InstanceIdB5D10BBE = i-1234567890abcdef3
IndyNetworkStack.steward4steward4InstanceIdB3DD7753 = i-1234567890abcdef4
IndyNetworkStack.trustee1trustee1InstanceId8FDDE052 = i-1234567890abcdef5
IndyNetworkStack.trustee2trustee2InstanceIdE12079EA = i-1234567890abcdef6
IndyNetworkStack.trustee3trustee3InstanceId508C4E4C = i-1234567890abcdef7
```

**NOTE:** User data for the Steward instance is created by referring to [the Community Docs](https://github.com/hyperledger/indy-node/blob/main/docs/source/install-docs/AWS-NodeInstall-20.04.md).

#### Building an environment using Ansible

When running on a Mac, set the following environment variables.

> export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES


##### Preparing for Ansible

- Create a Python virtual environment and install ansible
```
$ cd ansible
$ python3 -m venv venv
$ source ./venv/bin/activate
```

```
$ pip install -r requirements.txt
```

##### Describe instance information to be built in inventory.yml

- Create an indentory file containing information on the EC2 instance that will build the environment. Enter the instance ID described in the CDK output results in the settings column for each node. The value of `indyNetworkStack.ansibleFileTransferBucketName` described in CDK output results is inputted to `ansible_aws_ssm_bucket_name`. When Ansible transfers files to the target host, the Amazon Simple Storage Service (Amazon S3) bucket specified here is used.

```
cd ..
./configure-ansible-inventory.sh
```


##### Ansible parameter settings
Open `inventory/group_vars/all.yml` file and define the parameters referred to by Ansible in the configuration file. Set Indy's network name

```
INDY_NETWORK_NAME: sample-network
```

##### Execute environment construction with Ansible

- Use ansible's `ping` module to confirm that ansible can connect to the instance set in inventory/inventory.yml

```
$ ansible -m ping all -i inventory/inventory.yml
steward2 | SUCCESS => {
"changed": false,
"ping": "pong"
}
steward3 | SUCCESS => {
"changed": false,
"ping": "pong"
}
trustee1 | SUCCESS => {
"changed": false,
"ping": "pong"
}
steward4 | SUCCESS => {
"changed": false,
"ping": "pong"
}
trustee2 | SUCCESS => {
"changed": false,
"ping": "pong"
}
trustee3 | SUCCESS => {
"changed": false,
"ping": "pong"
}
steward1 | SUCCESS => {
"changed": false,
"ping": "pong"
}
```

- Execute Hyperledger Indy environment construction for target EC2 instances defined in `inventory/inventory.yml` in ansible
```
$ ansible-playbook playbook/site.yml
```

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add instructions how customers can use those nodes. The simplest might be to show how to access nodes API from the Cloud9 instance the blueprint was deployed from.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add instruction on #123


#### reference information

- [Buidling Indy Network](https://github.com/pSchlarb/indy-node/blob/documentationUpdate/docs/source/NewNetwork/NewNetwork.md)
- [Setting up EC2 instances for Indy Node](https://github.com/hyperledger/indy-node/blob/main/docs/source/install-docs/AWS-NodeInstall-20.04.md)
- [Setting up Indy Node](https://github.com/pSchlarb/indy-node/blob/documentationUpdate/docs/source/installation-and-configuration.md)

### Considerations

Matters to be examined in additional development etc. when using this sample are described.

- Change the instance type to M
- Currently, it is a T instance, but in production environments, it is recommended to change to M
- Fix the security group for Node NICs attached to Steward (Validator Node)
- Limit source IPs to node IPs of other nodes (currently open within VPC and can also be accessed by clients)
- Fix Node's private IP
- If necessary, change the subnet to which the node belongs to a public subnet
- Make Steward and Node separate instances
194 changes: 194 additions & 0 deletions lib/indy/README_ja.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
# Sample AWS Blockchain Node Runner app for Hyperledger Indy

[English](./README.md)

## Architecture Overview

![Architecture](./doc/assets/Architecture.png)

Hyperledger Indy のネットワークを AWS 上に構築するサンプルである。
全体像は下図の通り、処理自体は 4 つの Steward (Validator Node) で行われ、ネットワークの管理は Trustee で行われる。実体は Steward 用の 4 つの EC2 インスタンスと、Trustee 用の 3 つの EC2 インスタンスである。

## Solution Walkthrough

### Setup Cloud9

We will use AWS Cloud9 to execute the subsequent commands. Follow the instructions in [Cloud9 Setup](../../docs/setup-cloud9.md)

### Clone this repository and install dependencies

```bash
git clone https://github.com/aws-samples/aws-blockchain-node-runners.git
cd aws-blockchain-node-runners
npm install
```

**NOTE:** In this tutorial we will set all major configuration through environment variables, but you also can modify parameters in `config/config.ts`.

### Deploy Indy Nodes

#### リソースの構築

1. npm の依存パッケージをインストール

```bash
cd lib/indy
pwd
# Make sure you are in aws-blockchain-node-runners/lib/indy
npm install
```

2. AWS Cloud Development Kit (CDK) の初期設定

下記のコマンドはデプロイを実施するリージョンで AWS CDK を使用していない場合のみ実施する

```bash
npx cdk bootstrap
```

3. CDK でリソースの構築

```bash
npx cdk deploy

Outputs:
IndyNetworkStack.AnsibleFileTransferBucketName = 111122223333-ansible-file-transfer-bucket
IndyNetworkStack.steward1steward1InstanceId2F9F8910 = i-1234567890abcdef1
IndyNetworkStack.steward2steward2InstanceId995438F2 = i-1234567890abcdef2
IndyNetworkStack.steward3steward3InstanceIdB5D10BBE = i-1234567890abcdef3
IndyNetworkStack.steward4steward4InstanceIdB3DD7753 = i-1234567890abcdef4
IndyNetworkStack.trustee1trustee1InstanceId8FDDE052 = i-1234567890abcdef5
IndyNetworkStack.trustee2trustee2InstanceIdE12079EA = i-1234567890abcdef6
IndyNetworkStack.trustee3trustee3InstanceId508C4E4C = i-1234567890abcdef7
```

**NOTE:** Steward インスタンスのユーザーデータは [Community の Doc](https://github.com/hyperledger/indy-node/blob/main/docs/source/install-docs/AWS-NodeInstall-20.04.md) を参考に作成している。

# Ansibleを使用した環境構築

Macで実行する場合は次の環境変数を設定する。

> export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES

## Ansibleの事前準備

- pythonの仮想環境を作成しansibleを導入する
```
$ cd ansible
$ python3 -m venv .venv
$ source .venv/bin/activate
```

```
$ pip install -r requirements.txt
```

## AnsibleとSession Manager

- EC2 Instanceに対してSession Managerを使用したSSHアクセスを実現するために、 [Install the Session Manager plugin for the AWS CLI](https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html) を参照して、Session Manager Pluginをインストールする。Session Managerを使用することでセキュリティグループの設定をすることなく、インターネットからアクセスできないPrivate SubnetのEC2 Instanceに対してAnsibleによるデプロイが可能となる。

- AnsibleがAWS Systems Manager Session Managerを使用してEC2にSSHログインするためのプラグインをインストールする。
```
$ ansible-galaxy collection install community.aws
```

## 構築対象のインスタンス情報をInventory.ymlに記載する
- 環境構築を行うEC2インスタンスの情報を記載したIndentoryファイルを作成する。CDKの出力結果に記載されているインスタンスのIDをそれぞれのノードの設定欄に記入する。 `ansible_aws_ssm_bucket_name` には CDKの出力結果に記載されている `IndyNetworkStack.AnsibleFileTransferBucketName` の値を入力する。Ansibleが対象のホストに対してファイルを転送する時に、ここで指定したAmazon Simple Storage Service(Amazon S3) Bucketを使用する。
```
$ vi inventory/inventory.yml
all:
hosts:
steward1:
ansible_aws_ssm_instance_id: i-1234567890abcdef1
steward2:
ansible_aws_ssm_instance_id: i-1234567890abcdef2
steward3:
ansible_aws_ssm_instance_id: i-1234567890abcdef3
steward4:
ansible_aws_ssm_instance_id: i-1234567890abcdef4
trustee1:
ansible_aws_ssm_instance_id: i-1234567890abcdef5
trustee2:
ansible_aws_ssm_instance_id: i-1234567890abcdef6
trustee3:
ansible_aws_ssm_instance_id: i-1234567890abcdef7
children:
steward:
hosts:
steward[1:4]:
trustee:
hosts:
trustee1

vars:
ansible_connection: aws_ssm
ansible_aws_ssm_region: aa-example-1
ansible_aws_ssm_s3_addressing_style: virtual
ansible_aws_ssm_bucket_name: 111122223333-ansible-file-transfer-bucket
```

## Ansibleの設定
Ansibleが参照するパラメータを設定ファイルで定義する。

```
$ vi inventory/group_vars/all.yml
INDY_NETEORK_NAME: sample-network
```
## Ansibleによる環境構築の実行

- inventory/inventory.ymlで設定したインスタンスにansibleが接続できることをansibleの `ping` モジュールを使用して確認する
```
$ ansible -m ping all -i inventory/inventory.yml
steward2 | SUCCESS => {
"changed": false,
"ping": "pong"
}
steward3 | SUCCESS => {
"changed": false,
"ping": "pong"
}
trustee1 | SUCCESS => {
"changed": false,
"ping": "pong"
}
steward4 | SUCCESS => {
"changed": false,
"ping": "pong"
}
trustee2 | SUCCESS => {
"changed": false,
"ping": "pong"
}
trustee3 | SUCCESS => {
"changed": false,
"ping": "pong"
}
steward1 | SUCCESS => {
"changed": false,
"ping": "pong"
}
```

- ansibleで `inventory/inventory.yml` で定義した対象のEC2インスタンスに対してHyperledger Indyの環境構築を実行する
```
$ ansible-playbook playbook/site.yml
```


## 参考情報
- [Indy Network の構築](https://github.com/pSchlarb/indy-node/blob/documentationUpdate/docs/source/NewNetwork/NewNetwork.md)
- [Indy Node のための EC2 セットアップ](https://github.com/hyperledger/indy-node/blob/main/docs/source/install-docs/AWS-NodeInstall-20.04.md)
- [Indy Node のセットアップ](https://github.com/pSchlarb/indy-node/blob/documentationUpdate/docs/source/installation-and-configuration.md)

### 考慮事項

本サンプルを利用するにあたり追加開発などで検討する事項を記載する。

- インスタンスタイプを M 系に変更
- 現状は T 系インスタンスであるが本番環境では M 系などへの変更を推奨
- Steward (Validator Node) にアタッチされている Node NIC の Security Group を修正
- Source IP を他ノードの Node IP に制限する (現在は VPC 内にオープンになっており、Client からもアクセスできる)
- Node の Private IP を固定
- 必要に応じて Node の属するサブネットを Public Subnet にする
- Steward と Node を別インスタンスにする
9 changes: 9 additions & 0 deletions lib/indy/ansible/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# config file for ansible -- https://ansible.com/
# ===============================================

[defaults]
inventory = ./inventory/inventory.yml
host_key_checking = False
deprecation_warnings=False
roles_path: ./roles
interpreter_python: /usr/bin/python3
1 change: 1 addition & 0 deletions lib/indy/ansible/inventory/group_vars/all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INDY_NETWORK_NAME: sample-network
Loading
Loading