Skip to content

Commit 6cedb4c

Browse files
authored
Merge pull request #24 from commjoen/awsrun
First iteration to run on AWS
2 parents 2bba34f + 5f5a532 commit 6cedb4c

File tree

180 files changed

+2049
-297
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

180 files changed

+2049
-297
lines changed

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Terraform
2+
kubeconfig_wrongsecrets-exercise-cluster
3+
.terraform
4+
.terraform.lock.hcl
5+
.terraform*
6+
terraform.tfstate*
7+
aws/terraform.tfstate.*
8+
aws/terraform.tfstate.backup
9+
aws/.terraform.tfstate.lock.info
10+
11+
.idea
12+
.DS_Store

.idea/aws.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/azure/azureSettings.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/codeStyles/codeStyleConfig.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/wrongsecrets-ctf-party.iml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.pre-commit-config.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# WARNING: File managed by eadf-bot, changes committed to individual repo will be overwritten
2+
repos:
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: v4.3.0
5+
hooks:
6+
- id: check-yaml
7+
- id: end-of-file-fixer
8+
exclude: ^(src/test/resources/yourkey.txt|src/test/resources/secondkey.txt)
9+
- id: trailing-whitespace
10+
- repo: https://github.com/antonbabenko/pre-commit-terraform
11+
rev: v1.71.0
12+
hooks:
13+
- id: terraform_fmt
14+
- id: terraform_tflint
15+
args:
16+
- "--args=--only=terraform_deprecated_interpolation"
17+
- "--args=--only=terraform_deprecated_index"
18+
- "--args=--only=terraform_unused_declarations"
19+
- "--args=--only=terraform_comment_syntax"
20+
- "--args=--only=terraform_documented_outputs"
21+
- "--args=--only=terraform_documented_variables"
22+
- "--args=--only=terraform_typed_variables"
23+
- "--args=--only=terraform_module_pinned_source"
24+
- "--args=--only=terraform_naming_convention"
25+
- "--args=--only=terraform_required_version"
26+
- "--args=--only=terraform_required_providers"
27+
- "--args=--only=terraform_standard_module_structure"
28+
- "--args=--only=terraform_workspace_remote"
29+
- id: terraform_docs

ATTRIBUTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ Original Attirbution file of Multijuicer from which we Forked:
22

33
MultiJuicer uses multiple Icons / Emojis from OpenMoji: https://openmoji.org/
44

5-
The Logo was originally created by [Straight outta Mane](https://en.99designs.de/profiles/2794862) via [99Desgins](https://en.99designs.de/logo-brand-guide/contests/create-juicy-logo-open-source-project-multijuicer-1075365/entries).
5+
The Logo was originally created by [Straight outta Mane](https://en.99designs.de/profiles/2794862) via [99Desgins](https://en.99designs.de/logo-brand-guide/contests/create-juicy-logo-open-source-project-multijuicer-1075365/entries).

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,4 @@
198198
distributed under the License is distributed on an "AS IS" BASIS,
199199
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200200
See the License for the specific language governing permissions and
201-
limitations under the License.
201+
limitations under the License.

aws/README.md

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# Setup your secrets in AWS
2+
3+
In this setup we integrate the secrets-exercise online with AWS EKS and let Pods consume secrets from the AWS Parameter Store and AWS Secrets Manager.
4+
We use managed node groups so as we don't want the hassle of managing the EC2 instances ourselves, and Fargate doesn't suit our needs since we use a StatefulSet. If you want to know more about integrating secrets with EKS, check [EKS and SSM Parameter Store](https://docs.aws.amazon.com/systems-manager/latest/userguide/integrating_csi_driver.html) and [EKS and Secrets Manager](https://docs.aws.amazon.com/secretsmanager/latest/userguide/integrating_csi_driver.html).
5+
Please make sure that the account in which you run this exercise has either CloudTrail enabled, or is not linked to your current organization and/or DTAP environment.
6+
7+
## Pre-requisites
8+
9+
Have the following tools installed:
10+
11+
- AWS CLI - [Installation](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html)
12+
- EKS CTL - [Installation](https://docs.aws.amazon.com/eks/latest/userguide/eksctl.html)
13+
- Tfenv (Optional) - [Installation](https://github.com/tfutils/tfenv)
14+
- Terraform CLI - [Installation](https://learn.hashicorp.com/tutorials/terraform/install-cli)
15+
- Wget - [Installation](https://www.jcchouinard.com/wget/)
16+
- Helm [Installation](https://helm.sh/docs/intro/install/)
17+
- Kubectl [Installation](https://kubernetes.io/docs/tasks/tools/)
18+
- jq [Installation](https://stedolan.github.io/jq/download/)
19+
20+
Make sure you have an active account at AWS for which you have configured the credentials on the system where you will execute the steps below. In this example we stored the credentials under an aws profile as `awsuser`.
21+
22+
### Multi-user setup: shared state
23+
24+
If you want to host a multi-user setup, you will probably want to share the state file so that everyone can try related challenges. We have provided a starter to easily do so using a Terraform S3 backend.
25+
26+
First, create an s3 bucket (optionally add `-var="region=YOUR_DESIRED_REGION"` to the apply to use a region other than the default eu-west-1):
27+
28+
```bash
29+
cd shared-state
30+
terraform init
31+
terraform apply
32+
```
33+
34+
The bucket name should be in the output. Please use that to configure the Terraform backend in `main.tf`.
35+
36+
## Installation
37+
38+
The terraform code is loosely based on [this EKS managed Node Group TF example](https://github.com/terraform-aws-modules/terraform-aws-eks/tree/master/examples/eks_managed_node_group).
39+
40+
**Note**: Applying the Terraform means you are creating cloud infrastructure which actually costs you money. The authors are not responsible for any cost coming from following the instructions below.
41+
42+
**Note-II**: The cluster you create has its access bound to the public IP of the creator. In other words: the cluster you create with this code has its access bound to your public IP-address if you apply it locally.
43+
44+
1. export your AWS credentials (`export AWS_PROFILE=awsuser`)
45+
2. check whether you have the right profile by doing `aws sts get-caller-identity` and make sure you have enough rights with the caller its identity and that the actual accountnumber displayed is the account designated for you to apply this TF to.
46+
3. Do `terraform init` (if required, use tfenv to select TF 0.13.1 or higher )
47+
4. Do `terraform plan`
48+
5. Do `terraform apply`. Note: the apply will take 10 to 20 minutes depending on the speed of the AWS backplane.
49+
6. When creation is done, do `aws eks update-kubeconfig --region eu-west-1 --name wrongsecrets-exercise-cluster --kubeconfig ~/.kube/wrongsecrets`
50+
7. Do `export KUBECONFIG=~/.kube/wrongsecrets`
51+
8. Run `cd .. && ./build-and-deploy-aws.sh` to install the helm chart for the wrongsecrets-ctf-party.
52+
53+
Your EKS cluster should be visible in [EU-West-1](https://eu-west-1.console.aws.amazon.com/eks/home?region=eu-west-1#/clusters) by default. Want a different region? You can modify `terraform.tfvars` or input it directly using the `region` variable in plan/apply.
54+
55+
Are you done playing? Please run `terraform destroy` twice to clean up.
56+
57+
### Test it
58+
When you have completed the installation steps, you can do `kubectl port-forward service/wrongsecrets-balancer 3000:3000` and then go to [http://localhost:3000](http://localhost:3000).
59+
60+
### Clean it up
61+
62+
When you're done:
63+
64+
1. Kill the port forward.
65+
2. Run `terraform destroy` to clean up the infrastructure.
66+
1. If you've deployed the `shared-state` s3 bucket, also `cd shared-state` and `terraform destroy` there.
67+
3. Run `unset KUBECONFIG` to unset the KUBECONFIG env var.
68+
4. Run `rm ~/.kube/wrongsecrets` to remove the kubeconfig file.
69+
5. Run `rm terraform.tfstate*` to remove local state files.
70+
71+
### A few things to consider
72+
73+
1. Does your worker node now have access as well?
74+
2. Can you easily obtain the instance profile of the Node?
75+
3. Can you get the secrets in the SSM Parameter Store and Secrets Manager easily? Which paths do you see?
76+
4. Which of the 2 (SSM Parameter Store and Secrets Manager) works cross-account?
77+
5. If you have applied the secrets to the cluster, you should see at the configuration details of the cluster that Secrets encryption is "Disabled", what does that mean?
78+
79+
### When you want to share your environment with others (experimental)
80+
81+
We added additional scripts for adding an ALB and ingress so that you can use your cloudsetup with multiple people.
82+
Do the following:
83+
84+
1. Follow the installation section first.
85+
2. Run `k8s-aws-alb-script.sh` and the script will return the url at which you can reach the application.
86+
3. When you are done, before you do cleanup, first run `k8s-aws-alb-script-cleanup.sh`.
87+
88+
Note that you might have to do some manual cleanups after that.
89+
90+
## Terraform documentation
91+
The documentation below is auto-generated to give insight on what's created via Terraform.
92+
93+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
94+
## Requirements
95+
96+
| Name | Version |
97+
|------|---------|
98+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | ~> 1.1 |
99+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 4.1 |
100+
| <a name="requirement_http"></a> [http](#requirement\_http) | ~> 3.1 |
101+
| <a name="requirement_random"></a> [random](#requirement\_random) | ~> 3.0 |
102+
103+
## Providers
104+
105+
| Name | Version |
106+
|------|---------|
107+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.31.0 |
108+
| <a name="provider_http"></a> [http](#provider\_http) | 3.1.0 |
109+
| <a name="provider_random"></a> [random](#provider\_random) | 3.4.3 |
110+
111+
## Modules
112+
113+
| Name | Source | Version |
114+
|------|--------|---------|
115+
| <a name="module_eks"></a> [eks](#module\_eks) | terraform-aws-modules/eks/aws | 18.29.0 |
116+
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.14.4 |
117+
118+
## Resources
119+
120+
| Name | Type |
121+
|------|------|
122+
| [aws_iam_policy.secret_deny](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
123+
| [aws_iam_policy.secret_manager](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
124+
| [aws_iam_role.irsa_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
125+
| [aws_iam_role.user_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
126+
| [aws_iam_role_policy_attachment.irsa_role_attachment](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
127+
| [aws_iam_role_policy_attachment.user_role_attachment](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
128+
| [aws_secretsmanager_secret.secret](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/secretsmanager_secret) | resource |
129+
| [aws_secretsmanager_secret.secret_2](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/secretsmanager_secret) | resource |
130+
| [aws_secretsmanager_secret_policy.policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/secretsmanager_secret_policy) | resource |
131+
| [aws_secretsmanager_secret_policy.policy_2](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/secretsmanager_secret_policy) | resource |
132+
| [aws_secretsmanager_secret_version.secret](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/secretsmanager_secret_version) | resource |
133+
| [aws_ssm_parameter.secret](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ssm_parameter) | resource |
134+
| [random_password.password](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource |
135+
| [random_password.password2](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource |
136+
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
137+
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
138+
| [aws_iam_policy_document.assume_role_with_oidc](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
139+
| [aws_iam_policy_document.secret_manager](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
140+
| [aws_iam_policy_document.user_assume_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
141+
| [aws_iam_policy_document.user_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
142+
| [http_http.ip](https://registry.terraform.io/providers/hashicorp/http/latest/docs/data-sources/http) | data source |
143+
144+
## Inputs
145+
146+
| Name | Description | Type | Default | Required |
147+
|------|-------------|------|---------|:--------:|
148+
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | The EKS cluster name | `string` | `"wrongsecrets-exercise-cluster"` | no |
149+
| <a name="input_cluster_version"></a> [cluster\_version](#input\_cluster\_version) | The EKS cluster version to use | `string` | `"1.22"` | no |
150+
| <a name="input_region"></a> [region](#input\_region) | The AWS region to use | `string` | `"eu-west-1"` | no |
151+
152+
## Outputs
153+
154+
| Name | Description |
155+
|------|-------------|
156+
| <a name="output_cluster_endpoint"></a> [cluster\_endpoint](#output\_cluster\_endpoint) | Endpoint for EKS control plane. |
157+
| <a name="output_cluster_security_group_id"></a> [cluster\_security\_group\_id](#output\_cluster\_security\_group\_id) | Security group ids attached to the cluster control plane. |
158+
| <a name="output_irsa_role"></a> [irsa\_role](#output\_irsa\_role) | The role ARN used in the IRSA setup |
159+
| <a name="output_secrets_manager_secret_name"></a> [secrets\_manager\_secret\_name](#output\_secrets\_manager\_secret\_name) | The name of the secrets manager secret |
160+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

aws/cluster-keys.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"unseal_keys_b64": [
3+
"OCPHUjxNTQPb+NSIp9T/7ZWe0LB5UdQg8Yns9w1hL7g="
4+
],
5+
"unseal_keys_hex": [
6+
"3823c7523c4d4d03dbf8d488a7d4ffed959ed0b07951d420f189ecf70d612fb8"
7+
],
8+
"unseal_shares": 1,
9+
"unseal_threshold": 1,
10+
"recovery_keys_b64": [],
11+
"recovery_keys_hex": [],
12+
"recovery_keys_shares": 5,
13+
"recovery_keys_threshold": 3,
14+
"root_token": "s.376aF6IRjo3ZMGfvERl3vCj2"
15+
}

0 commit comments

Comments
 (0)