|
| 1 | +# NRLF AWS Bastion Infrastructure |
| 2 | + |
| 3 | +This directory contains the infrastructure for the NRLF AWS Bastion. This is a host that is deployed into the NRLF AWS accounts and can be used to run operations tasks against the resources in that account. For example, to run a report that reads from the DynamoDB pointers table. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +Before deploying a bastion, you will need: |
| 8 | + |
| 9 | +- An AWS account that has already been bootstrapped, as described in [bootstrap/README.md](../bootstrap/README.md) and has the account-wide infrastructure deployed as described in [account-wide-infrastructure/README.md](../account-wide-infrastructure/README.md). This is a one-time account setup step. |
| 10 | +- Your CLI configured to allow authentication to your AWS account |
| 11 | + |
| 12 | +## Deploying a bastion |
| 13 | + |
| 14 | +The bastions are emphemeral resources that should be deploy when you need them. |
| 15 | + |
| 16 | +To deploy a bastion, you will first need to login to the AWS mgmt account on the CLI. |
| 17 | + |
| 18 | +Then, initialise the Terraform workspace with: |
| 19 | + |
| 20 | +``` |
| 21 | +terraform init |
| 22 | +``` |
| 23 | + |
| 24 | +If you want a read-only bastion (can only READ from the pointers table), plan the deployment like this: |
| 25 | + |
| 26 | +``` |
| 27 | +make plan-ro |
| 28 | +``` |
| 29 | + |
| 30 | +If you want a read-write bastion (can READ and WRITE from the pointers table), plan the deployment like this: |
| 31 | + |
| 32 | +``` |
| 33 | +make plan-rw |
| 34 | +``` |
| 35 | + |
| 36 | +Once you're happy with your planned changes, you can apply them with: |
| 37 | + |
| 38 | +``` |
| 39 | +terraform apply ./bastion.tfplan |
| 40 | +``` |
| 41 | + |
| 42 | +## Using the bastion |
| 43 | + |
| 44 | +Once the bastion is deployed, you can connect to it via SSH with: |
| 45 | + |
| 46 | +``` |
| 47 | +make ssh-connection |
| 48 | +``` |
| 49 | + |
| 50 | +Once connected successfully, you will be at the SSM `$` prompt. To switch to the `nrlf_ops` user, run this command: |
| 51 | + |
| 52 | +``` |
| 53 | +sudo su - nrlf_ops |
| 54 | +``` |
| 55 | + |
| 56 | +Once switched to the `nrlf_ops` user, you can use the bastion and the installed tooling: |
| 57 | + |
| 58 | +- `cd ./NRLF` - the NRLF repo (cloned from Github `develop`) |
| 59 | +- `aws` |
| 60 | +- `git` |
| 61 | +- `python` and `poetry` |
| 62 | + |
| 63 | +see [user-data.sh](./scripts/user-data.sh) for exactly what's installed on there. |
| 64 | + |
| 65 | +### Troubleshooting the bastion |
| 66 | + |
| 67 | +#### I cannot connect to the bastion |
| 68 | + |
| 69 | +If you're running the `make ssh-connection` and are seeing this error: |
| 70 | + |
| 71 | +``` |
| 72 | +$ make ssh-connection |
| 73 | +.... |
| 74 | +An error occurred (TargetNotConnected) when calling the StartSession operation: i-06ff25164f004bee4 is not connected. |
| 75 | +make: *** [Makefile:54: ssh-connection] Error 254 |
| 76 | +$ |
| 77 | +``` |
| 78 | + |
| 79 | +If you've just created a new bastion, it may be that it hasn't started yet. Log in to the AWS console to see the state of the EC2 instance. Press the "Connect" button in the console and choose the SSM tab to see if things are working ok. |
| 80 | + |
| 81 | +If the EC2 instance is running and the console looks ok, check you have defined the correct ENV param for the installed bastion. |
| 82 | + |
| 83 | +#### The `nrlf_ops` using is missing |
| 84 | + |
| 85 | +If you're getting this error: |
| 86 | + |
| 87 | +``` |
| 88 | +$ sudo su - nrlf_ops |
| 89 | +su: user some_other does not exist or the user entry does not contain all the required fields |
| 90 | +$ |
| 91 | +``` |
| 92 | + |
| 93 | +If you've just created a new bastion, you may need to wait a little until the cloud-init script has finished. You can check the status of this process with: |
| 94 | + |
| 95 | +``` |
| 96 | +sudo tail -f /var/log/cloud-init-output.log |
| 97 | +``` |
| 98 | + |
| 99 | +#### The bastion cannot access an AWS resource that I want to use |
| 100 | + |
| 101 | +If you're trying to access an AWS resource from the bastion and are getting an access denied error, it may be that the bastion's IAM role does not have the required permissions. |
| 102 | + |
| 103 | +You can check the role in the AWS console to work out if things are missing and can edit it there too for immediate access to the resources you need. |
| 104 | + |
| 105 | +If you want to permenantly grant new access to the bastion, you can add a policy and attach it to the EC2 instance in [iam.tf](iam.tf) |
| 106 | + |
| 107 | +#### A tool I need is missing |
| 108 | + |
| 109 | +If there's a tool missing from the instance, you can add it using `apt` or via `asdf` as/when you need it. |
| 110 | + |
| 111 | +If you want a new tool to be deployed onto all bastions in the future too, add it to the [user-data.sh](./scripts/user-data.sh) script. |
0 commit comments