Skip to content

Commit f54c30b

Browse files
committed
Add: GET_SECRETS_CRITICAL and GET_SECRETS_CRITICAL envvars to fine-grained disabling of cloud secrets manager for critical secrets and plain envvars [GS-41].
Add: Secret and KMS access policies to the "template-sam.yml" file [GS-41]. Add: generate_cf_dynamodb and deploy_dynamodb to Makefile [GS-84]. Add: "scripts/aws_dynamodb/generate_dynamodb_cf/generate_dynamodb_cf.py" and its ".sh" to generate the "cf-template-dynamodb.yml" file in the project's scripts directory [GS-84]. Add: "scripts/aws_dynamodb/run-dynamodb-deploy.sh" to deploy generated "cf-template-dynamodb.yml" [GS-84]. Add: "scripts/aws_cf_processor/run-cf-deployment.sh" enhanced to simulate the EC2 + ALB in AWS LocalStack [GS-97]. Add: "scripts/aws_cf_processor/test_localstack.sh" to test localstack EC2 functionality with the LOCALSTACK_AUTH_TOKEN envvar [GS-97]. Change: set APP_DB_URI when GET_SECRETS_ENABLED=0 or GET_SECRETS_CRITICAL=0 in "run_aws.sh" [GS-41]. Change: "aws_secrets_manager.sh" enhanced to use "run-cf-deployment.sh" [GS-41]. Change: "cf_template_kms_key.yml" and "cf_template_secrets.yml" renamed to "cf-template-kms-key.yml" and "cf-template-secrets.yml" [GS-41]. Change: "scripts/aws_ec2_elb/ec2_elb_manager.sh" removed [GS-96]. Fix: issue reporting the "_placeholder" missing parameter in the SAM template in verify_base_names() of big_lambdas_manager.sh. Fix: "scripts/aws_ec2_elb/run-ec2-cloud-deploy.sh" and "cf-template-ec2-elb.yml" issues to finish the EC2 + ELB deployments (EBS volume encryption postponed) [GS-96].
1 parent e7863a6 commit f54c30b

20 files changed

+1772
-2186
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,7 @@ scripts/dns/Dockerfile
7272

7373
response.json
7474

75-
tmp
75+
tmp
76+
77+
localstack_requirements.txt
78+
venv

CHANGELOG.md

+9-6
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,18 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a Ch
2222
---
2323

2424
### New
25-
Add password and API Keys to AWS Secrets [GS-41].
26-
Add: AWS Secrets manager to Makefile [GS-41].
27-
Add: EC2+ALB App deployment [GS-96].
28-
Add: delpoy_ec2 and deploy_ecr_creation to Makefile [GS-96].
25+
Add password and API Keys to AWS Secrets using AWS CloudFormation [GS-41].
26+
Add AWS Secrets manager to Makefile [GS-41].
27+
Add EC2+ALB App deployment using AWS CloudFormation [GS-96].
28+
Add depLoy_ec2 and deploy_ecr_creation to Makefile [GS-96].
29+
Add DynamoDB tables creation from the JSON configs using AWS CloudFormation [GS-84].
30+
Add "run-cf-deployment.sh" to standarize all Cloudformation calls [GS-96].
2931

3032
### Changes
3133
Change APP_STAGE dynamic assignment in run_aws.sh, set_chalice_cnf.sh, and big_lambdas_manager.sh, and secure_local_server/docker_entrypoint.sh [GS-41].
32-
Change __pycache__ removal simplified in big_lambdas_manager.sh [GS-96].
33-
Change APP_DB_URI and ther secrets assignment removed in big_lambdas_manager.sh, docker-compose-big-lambda-AL2.yml, docker-compose-big-lambda-Alpine.yml [GS-41].
34+
__pycache__ removal simplified in big_lambdas_manager.sh [GS-96].
35+
APP_DB_URI and the secrets assignment removed in big_lambdas_manager.sh, docker-compose-big-lambda-AL2.yml, docker-compose-big-lambda-Alpine.yml [GS-41].
36+
Remove all envvars from "template-sam.yml" [GS-96].
3437

3538
### Fixes
3639
Fix 'USER_AGENT environment variable not set...' LangSmith warning message removed in run_aws.sh, big_lambdas_manager.sh, aws_big_lambda/template-sam.yml, and secure_local_server/docker_entrypoint.sh.

Makefile

+15
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ create_aws_config:
160160
generate_sam_dynamodb:
161161
sh node_modules/genericsuite-be-scripts/scripts/aws_big_lambda/generate_sam_dynamodb/run_generate_sam_dynamodb.sh
162162

163+
generate_cf_dynamodb:
164+
sh node_modules/genericsuite-be-scripts/scripts/aws_dynamodb/generate_dynamodb_cf/generate_dynamodb_cf.sh
165+
163166
## Deployment
164167

165168
deploy_qa: create_s3_bucket_qa
@@ -187,8 +190,16 @@ deploy_ecr_creation:
187190
sh node_modules/genericsuite-be-scripts/scripts/aws_ec2_elb/run-fastapi-ecr-creation.sh
188191

189192
deploy_ec2:
193+
# E.g.
194+
# CICD_MODE=0 ACTION=run STAGE=qa TARGET=ec2 ECR_DOCKER_IMAGE_TAG=0.0.16 make deploy_ec2
195+
# CICD_MODE=0 ACTION=destroy STAGE=qa TARGET=ec2 ECR_DOCKER_IMAGE_TAG=0.0.16 make deploy_ec2
190196
sh node_modules/genericsuite-be-scripts/scripts/aws_ec2_elb/run-ec2-cloud-deploy.sh
191197

198+
deploy_dynamodb:
199+
# CICD_MODE=0 ACTION=run STAGE=qa TARGET=dynamodb ENGINE=localstack make deploy_dynamodb
200+
# CICD_MODE=0 ACTION=run STAGE=qa TARGET=dynamodb make deploy_dynamodb
201+
sh node_modules/genericsuite-be-scripts/scripts/aws_dynamodb/run-dynamodb-deploy.sh
202+
192203
deploy: deploy_qa
193204

194205
## Secrets
@@ -198,6 +209,10 @@ generate_seed:
198209
sh node_modules/genericsuite-be-scripts/scripts/cryptography/run_generate_seed.sh
199210

200211
aws_secrets:
212+
# E.g.
213+
# CICD_MODE=0 ACTION=run STAGE=qa TARGET=kms make aws_secrets
214+
# CICD_MODE=0 ACTION=run STAGE=qa TARGET=kms ENGINE=localstack make aws_secrets
215+
# CICD_MODE=0 ACTION=run STAGE=qa TARGET=secrets make aws_secrets
201216
sh node_modules/genericsuite-be-scripts/scripts/aws_secrets/aws_secrets_manager.sh
202217

203218
# aws_secrets_create:

scripts/aws/run_aws.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ if [[ "$1" = "run_local" || "$1" = "" ]]; then
159159

160160
export APP_DB_ENGINE=$(eval echo \$APP_DB_ENGINE_${STAGE_UPPERCASE})
161161
export APP_DB_NAME=$(eval echo \$APP_DB_NAME_${STAGE_UPPERCASE})
162-
# export APP_DB_URI=$(eval echo \$APP_DB_URI_${STAGE_UPPERCASE})
162+
if [[ "${GET_SECRETS_ENABLED}" = 0 || "${GET_SECRETS_CRITICAL}" = "0" ]]; then
163+
export APP_DB_URI=$(eval echo \$APP_DB_URI_${STAGE_UPPERCASE})
164+
fi
163165
export APP_CORS_ORIGIN="$(eval echo \"\$APP_CORS_ORIGIN_${STAGE_UPPERCASE}\")"
164166
export AWS_S3_CHATBOT_ATTACHMENTS_BUCKET=$(eval echo \$AWS_S3_CHATBOT_ATTACHMENTS_BUCKET_${STAGE_UPPERCASE})
165167

scripts/aws_big_lambda/big_lambdas_manager.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,8 @@ get_ssl_cert_arn() {
555555
}
556556

557557
verify_base_names() {
558-
base_names=("CLOUD_PROVIDER AWS_REGION APP_DB_URI APP_DB_NAME APP_DB_ENGINE APP_NAME APP_SECRET_KEY APP_SUPERADMIN_EMAIL APP_HOST_NAME STORAGE_URL_SEED GIT_SUBMODULE_LOCAL_PATH")
558+
local names="CLOUD_PROVIDER AWS_REGION APP_DB_URI APP_DB_NAME APP_DB_ENGINE APP_NAME APP_SECRET_KEY APP_SUPERADMIN_EMAIL APP_HOST_NAME STORAGE_URL_SEED GIT_SUBMODULE_LOCAL_PATH"
559+
local base_names=(${names})
559560
ERROR_FLAG=0
560561

561562
for base_name in "${base_names[@]}"; do

scripts/aws_big_lambda/generate_sam_dynamodb/generate_sam_dynamodb.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ def get_dynamodb_definition(config: dict, table_prefix: str) -> dict:
108108

109109
def generate_dynamodb_definitions(basedir: str, table_prefix: str):
110110
"""
111-
Generates DynamoDB table definitions from frontend and backend config files.
111+
Generates DynamoDB table definitions from frontend and backend
112+
config files.
112113
"""
113114
dynamodb_definitions = {}
114115

@@ -120,16 +121,19 @@ def generate_dynamodb_definitions(basedir: str, table_prefix: str):
120121
for file in files:
121122
_ = DEBUG and print(f'File: {file}')
122123
if file.endswith('.json'):
123-
with open(os.path.join(root, file), 'r', encoding="utf-8") as f:
124+
with open(os.path.join(root, file), 'r',
125+
encoding="utf-8") as f:
124126
config = json.load(f)
125127
# if file exists in backend config, merge them
126128
file_path = os.path.join(basedir, 'backend', file)
127129
if os.path.exists(file_path):
128130
with open(file_path, 'r', encoding="utf-8") as f:
129131
config.update(json.load(f))
130-
table_definition = get_dynamodb_definition(config, table_prefix)
132+
table_definition = get_dynamodb_definition(config,
133+
table_prefix)
131134
if table_definition:
132-
# table_name = table_definition['Properties']['TableName']
135+
# table_name = \
136+
# table_definition['Properties']['TableName']
133137
# dynamodb_definitions[table_name] = table_definition
134138
dynamodb_definitions.update(table_definition)
135139

@@ -145,7 +149,8 @@ def generate_sam_dynamodb():
145149
print('')
146150

147151
if len(sys.argv) < 4:
148-
print('Usage: python generate_sam_dynamodb.py <base_config_path> <target_template_path> <table_prefix>')
152+
print('Usage: python generate_sam_dynamodb.py <base_config_path>' +
153+
'<target_template_path> <table_prefix>')
149154
sys.exit(1)
150155

151156
base_config_path = sys.argv[1]
@@ -156,7 +161,8 @@ def generate_sam_dynamodb():
156161
print(f'target_template_path: {target_template_path}')
157162
print('')
158163

159-
dynamodb_def = generate_dynamodb_definitions(basedir=base_config_path,
164+
dynamodb_def = generate_dynamodb_definitions(
165+
basedir=base_config_path,
160166
table_prefix=table_prefix)
161167
# Open the target template file to write the DynamoDB table definition
162168
with open(target_template_path, 'w', encoding="utf-8") as f:

scripts/aws_big_lambda/template-sam.yml

+34-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,34 @@ Resources:
5454
- logs:CreateLogStream
5555
- logs:PutLogEvents
5656
Resource: arn:*:logs:*:*:*
57+
- PolicyName: Ec2SecretsAccessPolicy
58+
PolicyDocument:
59+
Version: '2012-10-17'
60+
Statement:
61+
- Effect: Allow
62+
Action:
63+
- secretsmanager:GetSecretValue
64+
Resource: '*'
65+
# Resource:
66+
# # - arn:aws:secretsmanager:*:*:secret:AWS_SECRETS_MANAGER_SECRETS_NAME_placeholder
67+
# - !Sub arn:aws:secretsmanager:*:*:secret:${AsmSecretsName}
68+
# # - arn:aws:secretsmanager:*:*:secret:AWS_SECRETS_MANAGER_ENVS_NAME_placeholder
69+
# - !Sub arn:aws:secretsmanager:*:*:secret:${AsmEnvsName}
70+
- PolicyName: Ec2KmsAccessPolicy
71+
PolicyDocument:
72+
Version: '2012-10-17'
73+
Statement:
74+
- Effect: Allow
75+
Action:
76+
- kms:Decrypt
77+
- kms:GenerateDataKey*
78+
- kms:CreateGrant
79+
Resource: !Sub 'arn:aws:kms:${AWS::Region}:${AWS::AccountId}:key/*'
80+
# Resource: !Sub 'arn:aws:kms:${AWS::Region}:${AWS::AccountId}:alias/${KmsKeyAlias}'
81+
# Resource: '*'
82+
# Resource:
83+
# # - arn:aws:kms:AWS_REGION_placeholder:AWS_ACCOUNT_ID_placeholder:alias/AWS_KMS_KEY_ALIAS_placeholder
84+
# - !Sub arn:aws:kms:${AwsRegion}:${AwsAccountId}:alias/${KmsKeyAlias}
5785

5886
APIHandler:
5987
Type: AWS::Serverless::Function
@@ -72,7 +100,12 @@ Resources:
72100
APP_NAME: APP_NAME_placeholder
73101
APP_STAGE: APP_STAGE_placeholder
74102
CLOUD_PROVIDER: CLOUD_PROVIDER_placeholder
75-
AWS_REGION: AWS_REGION_placeholder
103+
# AWS_REGION: AWS_REGION_placeholder
104+
# Lambda was unable to configure your environment variables because the environment variables you have provided contains reserved keys that are currently not supported for modification. Reserved keys used in this request: AWS_REGION
105+
106+
# GET_SECRETS_ENABLED: 0
107+
# GET_SECRETS_ENVVARS: 0
108+
# GET_SECRETS_CRITICAL: 0
76109

77110
# AI_ASSISTANT_NAME: AI_ASSISTANT_NAME_placeholder
78111
# APP_VERSION: APP_VERSION_placeholder

0 commit comments

Comments
 (0)