Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
82 changes: 81 additions & 1 deletion .github/workflows/run-ci-cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,10 @@ jobs:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-region: ${{ vars.AWS_REGION }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
role-duration-seconds: 1200
role-external-id: nest-staging-terraform
role-session-name: GitHubActions-BuildStagingImages
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/nest-staging-terraform

- name: Login to Amazon ECR
uses: aws-actions/amazon-ecr-login@062b18b96a7aff071d4dc91bc00c4c1a7945b076
Expand Down Expand Up @@ -618,6 +622,73 @@ jobs:
frontend-sbom-${{ env.RELEASE_VERSION }}.cdx.json
timeout-minutes: 5

bootstrap-staging-nest:
name: Bootstrap Nest Staging
env:
TF_INPUT: false
TF_IN_AUTOMATION: true
environment: staging
if: |
github.repository == 'OWASP/Nest' &&
github.ref == 'refs/heads/main'
needs:
- scan-staging-images
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@61815dcd50bd041e203e49132bacad1fd04d2708
with:
aws-access-key-id: ${{ secrets.BOOTSTRAP_AWS_ACCESS_KEY_ID }}
aws-region: ${{ vars.AWS_REGION }}
aws-secret-access-key: ${{ secrets.BOOTSTRAP_AWS_SECRET_ACCESS_KEY }}

- name: Install Terraform
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd
with:
terraform_version: 1.14.0

- name: Prepare terraform backend
env:
AWS_REGION: ${{ vars.AWS_REGION }}
TF_STATE_BUCKET_NAME: ${{ secrets.BOOTSTRAP_TF_STATE_BUCKET_NAME }}
TF_STATE_DYNAMODB_TABLE_NAME: ${{ secrets.BOOTSTRAP_TF_STATE_DYNAMODB_TABLE_NAME }}
run: |
umask 377
cat > infrastructure/bootstrap/terraform.tfbackend <<-EOF
bucket="$TF_STATE_BUCKET_NAME"
dynamodb_table="$TF_STATE_DYNAMODB_TABLE_NAME"
region="$AWS_REGION"
EOF

- name: Prepare terraform variables
env:
AWS_REGION: ${{ vars.AWS_REGION }}
PROJECT_NAME: 'nest'
run: |
umask 377
cat > infrastructure/bootstrap/terraform.tfvars <<-EOF
aws_region="$AWS_REGION"
project_name="$PROJECT_NAME"
EOF

- name: Terraform Init
working-directory: infrastructure/bootstrap
run: terraform init -backend-config=terraform.tfbackend

- name: Terraform Validate
working-directory: infrastructure/bootstrap
run: terraform validate

- name: Terraform Apply
working-directory: infrastructure/bootstrap
run: terraform apply -auto-approve
timeout-minutes: 10

plan-staging-nest:
name: Plan Nest Staging
env:
Expand All @@ -628,6 +699,7 @@ jobs:
github.repository == 'OWASP/Nest' &&
github.ref == 'refs/heads/main'
needs:
- bootstrap-staging-nest
- scan-staging-images
- set-release-version
permissions:
Expand All @@ -643,6 +715,10 @@ jobs:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-region: ${{ vars.AWS_REGION }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
role-duration-seconds: 1200
role-external-id: nest-staging-terraform
role-session-name: GitHubActions-StagingPlan
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/nest-staging-terraform

- name: Install Terraform
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd
Expand Down Expand Up @@ -740,6 +816,10 @@ jobs:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-region: ${{ vars.AWS_REGION }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
role-duration-seconds: 1200
role-external-id: nest-staging-terraform
role-session-name: GitHubActions-StagingDeploy
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/nest-staging-terraform

- name: Install Terraform
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd
Expand Down Expand Up @@ -800,7 +880,7 @@ jobs:

- name: Install backend dependencies
working-directory: backend
run: poetry sync --no-root --without dev --without test --without video
run: poetry sync --no-root --without test --without video

- name: Prepare Zappa settings
env:
Expand Down
2 changes: 2 additions & 0 deletions cspell/custom-dict.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ pyyaml
quasis
rediss
relativedelta
replicationgroup
repositorycontributor
requirepass
rqworker
Expand All @@ -184,6 +185,7 @@ skillstruck
slackbot
slideshare
speakerdeck
subgrp
superfences
tfbackend
tgz
Expand Down
61 changes: 56 additions & 5 deletions infrastructure/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ Ensure you have the following setup/installed:
- Setup Project: [CONTRIBUTING.md](https://github.com/OWASP/Nest/blob/main/CONTRIBUTING.md)
- Terraform: [Terraform Documentation](https://developer.hashicorp.com/terraform/docs)
- AWS CLI: [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)
- An AWS account with credentials configured locally.
- An AWS account.
Note: Refer to the respective `README.md` files for more information.

## Setting up the infrastructure

Follow these steps to set up the infrastructure:

1. **Setup Backend (one-time setup)**:
- Prerequisite: Create a `nest-backend` IAM user with the policies defined in `infrastructure/backend/README.md`.

- Navigate to the backend directory:

Expand Down Expand Up @@ -44,7 +46,56 @@ Follow these steps to set up the infrastructure:
> [!NOTE]
> It is recommended to not destroy the backend resources unless absolutely necessary.

2. **Setup Main Infrastructure (staging)**:
2. **Bootstrap IAM Role**:
- Prerequisite: Create a `nest-bootstrap` IAM user with the policies defined in `infrastructure/bootstrap/README.md`.

- Navigate to the bootstrap directory:

```bash
cd infrastructure/bootstrap/
```

- Create a local terraform variables file:

```bash
touch terraform.tfvars
```

- Copy the contents from the example file:

```bash
cat terraform.tfvars.example > terraform.tfvars
```

- Create a local backend configuration file:

```bash
touch terraform.tfbackend
```

- Copy the contents from the example file:

```bash
cat terraform.tfbackend.example > terraform.tfbackend
```

> [!NOTE]
> Update the state bucket name in `terraform.tfbackend` with the name of the state bucket (bootstrap) created in the previous step.

- Initialize Terraform if needed:

```bash
terraform init -backend-config=terraform.tfbackend
```

- Apply the changes to create the bootstrap resources:

```bash
terraform apply
```

3. **Setup Main Infrastructure (staging)**:
- Prerequisite: Create a `nest-staging` IAM user with the policies defined in `infrastructure/staging/README.md`

- Navigate to the main infrastructure directory. If you are in `infrastructure/backend`, you can use:

Expand Down Expand Up @@ -94,7 +145,7 @@ Follow these steps to set up the infrastructure:
terraform apply
```

3. **Populate Secrets**
4. **Populate Secrets**

- Visit the AWS Console > Systems Manager > Parameter Store.
- Populate all `DJANGO_*` secrets that have `to-be-set-in-aws-console` value.
Expand Down Expand Up @@ -299,8 +350,8 @@ Migrate and load data into the new database.

```bash
aws ecs update-service \
--cluster owasp-nest-staging-frontend-cluster \
--service owasp-nest-staging-frontend-service \
--cluster nest-staging-frontend-cluster \
--service nest-staging-frontend-service \
--force-new-deployment \
--region us-east-2
```
Expand Down
89 changes: 89 additions & 0 deletions infrastructure/backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
## Inline Permissions
Use the following inline permissions for the `nest-backend` IAM User
*Note*: replace ${AWS_ACCOUNT_ID} and ${AWS_BACKEND_KMS_KEY_ARN} with appropriate values.

```json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "S3Management",
"Effect": "Allow",
"Action": [
"s3:CreateBucket",
"s3:DeleteBucket",
"s3:GetAccelerateConfiguration",
"s3:GetBucketAcl",
"s3:GetBucketCors",
"s3:GetBucketLogging",
"s3:GetBucketObjectLockConfiguration",
"s3:GetBucketPolicy",
"s3:GetBucketPublicAccessBlock",
"s3:GetBucketRequestPayment",
"s3:GetBucketTagging",
"s3:GetBucketVersioning",
"s3:GetBucketWebsite",
"s3:GetEncryptionConfiguration",
"s3:GetLifecycleConfiguration",
"s3:GetObject",
"s3:GetReplicationConfiguration",
"s3:ListBucket",
"s3:PutBucketLogging",
"s3:PutBucketObjectLockConfiguration",
"s3:PutBucketPolicy",
"s3:PutBucketPublicAccessBlock",
"s3:PutBucketTagging",
"s3:PutBucketVersioning",
"s3:PutEncryptionConfiguration",
"s3:PutLifecycleConfiguration",
"s3:PutObject"
],
"Resource": [
"arn:aws:s3:::nest-terraform-state-*",
"arn:aws:s3:::nest-terraform-state-*/*"
]
},
{
"Sid": "DynamoDBManagement",
"Effect": "Allow",
"Action": [
"dynamodb:CreateTable",
"dynamodb:DeleteTable",
"dynamodb:DescribeContinuousBackups",
"dynamodb:DescribeTable",
"dynamodb:DescribeTimeToLive",
"dynamodb:ListTagsOfResource",
"dynamodb:TagResource",
"dynamodb:UntagResource",
"dynamodb:UpdateContinuousBackups",
"dynamodb:UpdateTable"
],
"Resource": "arn:aws:dynamodb:*:${AWS_ACCOUNT_ID}:table/nest-terraform-state-lock-*"
},
{
"Sid": "KMSManagement",
"Effect": "Allow",
"Action": [
"kms:CreateAlias",
"kms:CreateGrant",
"kms:CreateKey",
"kms:DeleteAlias",
"kms:DescribeKey",
"kms:DisableKeyRotation",
"kms:EnableKeyRotation",
"kms:GetKeyPolicy",
"kms:GetKeyRotationStatus",
"kms:ListAliases",
"kms:ListResourceTags",
"kms:PutKeyPolicy",
"kms:ScheduleKeyDeletion",
"kms:TagResource",
"kms:UntagResource",
"kms:UpdateAlias",
"kms:UpdateKeyDescription"
],
"Resource": "${AWS_BACKEND_KMS_KEY_ARN}"
}
]
}
```
Loading
Loading