grada-run 0.41.5 → 0.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +18 -8
- package/package.json +1 -1
- package/src/commands/add.js +93 -11
- package/src/commands/alerts.js +69 -31
- package/src/commands/apply.js +62 -10
- package/src/commands/db/backup.js +1 -2
- package/src/commands/db/connect.js +27 -14
- package/src/commands/db/enable-vector.js +19 -6
- package/src/commands/db/import.js +114 -22
- package/src/commands/db/migrate.js +77 -73
- package/src/commands/db/restore.js +38 -6
- package/src/commands/destroy.js +68 -6
- package/src/commands/diagnose.js +57 -32
- package/src/commands/doctor.js +5 -3
- package/src/commands/domain.js +55 -7
- package/src/commands/drift.js +2 -1
- package/src/commands/eject.js +13 -2
- package/src/commands/exec.js +9 -4
- package/src/commands/gc.js +135 -6
- package/src/commands/init.js +75 -9
- package/src/commands/logs.js +127 -38
- package/src/commands/mcp.js +3 -2
- package/src/commands/rollback.js +230 -74
- package/src/commands/secrets.js +251 -61
- package/src/commands/status.js +17 -8
- package/src/commands/sync-ai.js +4 -3
- package/src/commands/wake.js +45 -1
- package/src/data/action-pins.js +26 -0
- package/src/utils/addons.js +9 -6
- package/src/utils/ai-rules.js +3 -2
- package/src/utils/backup.js +16 -2
- package/src/utils/command.js +20 -0
- package/src/utils/db-tunnel.js +15 -5
- package/src/utils/detector.js +8 -0
- package/src/utils/ecs-runner.js +16 -3
- package/src/utils/frameworks.js +14 -2
- package/src/utils/generator.js +33 -16
- package/src/utils/prompts.js +20 -4
- package/src/utils/resolvers.js +74 -11
- package/src/utils/revision-discovery.js +19 -7
- package/templates/docker/nestjs.Dockerfile +2 -2
- package/templates/docker/nextjs.Dockerfile +3 -3
- package/templates/docker/node.Dockerfile +2 -2
- package/templates/docker/nuxt.Dockerfile +2 -2
- package/templates/docker/static.Dockerfile +1 -1
- package/templates/docker/svelte.Dockerfile +2 -2
- package/templates/github/deploy-lambda.yml +73 -11
- package/templates/github/deploy-static.yml +4 -3
- package/templates/github/deploy.yml +114 -12
- package/templates/github/drift.yml +74 -5
- package/templates/github/preview-lambda.yml +143 -13
- package/templates/github/preview.yml +141 -13
- package/templates/github/teardown.yml +77 -12
- package/templates/terraform/addons/bedrock.tf +6 -2
- package/templates/terraform/addons/s3.tf +33 -0
- package/templates/terraform/backend.tf +7 -0
- package/templates/terraform/cloudfront-lambda.tf +125 -6
- package/templates/terraform/cloudfront.tf +137 -10
- package/templates/terraform/database-mysql.tf +5 -1
- package/templates/terraform/database.tf +5 -1
- package/templates/terraform/main.tf +36 -1
- package/templates/terraform/network.tf +5 -2
- package/templates/terraform/oidc.tf +3 -2
- package/templates/terraform/secrets.tf +6 -4
- package/templates/terraform/worker.tf +7 -0
|
@@ -1,6 +1,60 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# App CDN cache policies: a single path-only key (Managed-CachingOptimized)
|
|
2
|
+
# is wrong for an app server — one slot per path gets shared by HTML docs,
|
|
3
|
+
# API/RSC variants, redirects, and errors, so a cacheable variant poisons
|
|
4
|
+
# every other viewer of that path. Each traffic class below gets its own
|
|
5
|
+
# key instead (BUG-82).
|
|
6
|
+
data "aws_cloudfront_cache_policy" "disabled" {
|
|
7
|
+
name = "Managed-CachingDisabled"
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
# Default behavior key: query strings + cookies + router headers, so each
|
|
11
|
+
# page variant (search params, session, RSC/prefetch) caches independently
|
|
12
|
+
# and authenticated bytes never cross viewers. The header keys are harmless
|
|
13
|
+
# when absent — frameworks that never send them simply never vary on them.
|
|
14
|
+
resource "aws_cloudfront_cache_policy" "app_default" {
|
|
15
|
+
name = "${local.app_name}-app-default"
|
|
16
|
+
comment = "Per-variant app key: all query strings, cookies, and router headers"
|
|
17
|
+
default_ttl = 60
|
|
18
|
+
max_ttl = 86400
|
|
19
|
+
min_ttl = 0
|
|
20
|
+
parameters_in_cache_key_and_forwarded_to_origin {
|
|
21
|
+
cookies_config {
|
|
22
|
+
cookie_behavior = "all"
|
|
23
|
+
}
|
|
24
|
+
headers_config {
|
|
25
|
+
header_behavior = "whitelist"
|
|
26
|
+
headers {
|
|
27
|
+
items = ["RSC", "Next-Router-State-Tree", "Next-Router-Prefetch", "Next-Url"]
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
query_strings_config {
|
|
31
|
+
query_string_behavior = "all"
|
|
32
|
+
}
|
|
33
|
+
enable_accept_encoding_brotli = true
|
|
34
|
+
enable_accept_encoding_gzip = true
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
# Framework build assets are content-hashed: path-only key, immutable TTL.
|
|
39
|
+
resource "aws_cloudfront_cache_policy" "app_static" {
|
|
40
|
+
name = "${local.app_name}-app-static"
|
|
41
|
+
comment = "Content-hashed framework assets: immutable, long TTL"
|
|
42
|
+
default_ttl = 31536000
|
|
43
|
+
max_ttl = 31536000
|
|
44
|
+
min_ttl = 0
|
|
45
|
+
parameters_in_cache_key_and_forwarded_to_origin {
|
|
46
|
+
cookies_config {
|
|
47
|
+
cookie_behavior = "none"
|
|
48
|
+
}
|
|
49
|
+
headers_config {
|
|
50
|
+
header_behavior = "none"
|
|
51
|
+
}
|
|
52
|
+
query_strings_config {
|
|
53
|
+
query_string_behavior = "none"
|
|
54
|
+
}
|
|
55
|
+
enable_accept_encoding_brotli = true
|
|
56
|
+
enable_accept_encoding_gzip = true
|
|
57
|
+
}
|
|
4
58
|
}
|
|
5
59
|
|
|
6
60
|
# Fetch the AWS Managed Origin Request Policy (Passes query strings/cookies to your app)
|
|
@@ -8,10 +62,18 @@ data "aws_cloudfront_origin_request_policy" "all_viewer" {
|
|
|
8
62
|
name = "Managed-AllViewerExceptHostHeader"
|
|
9
63
|
}
|
|
10
64
|
|
|
65
|
+
# Managed security headers (HSTS, frame/clickjacking guards, content-type
|
|
66
|
+
# sniffing) on every behavior (BUG-92).
|
|
67
|
+
data "aws_cloudfront_response_headers_policy" "security" {
|
|
68
|
+
name = "Managed-SecurityHeadersPolicy"
|
|
69
|
+
}
|
|
70
|
+
|
|
11
71
|
# trivy:ignore:AVD-AWS-0011 - WAF is omitted by default to prevent unexpected monthly costs for users
|
|
12
72
|
resource "aws_cloudfront_distribution" "cdn" {
|
|
13
73
|
enabled = true
|
|
14
74
|
is_ipv6_enabled = true
|
|
75
|
+
comment = "${local.app_name}-cdn"
|
|
76
|
+
price_class = "PriceClass_100"
|
|
15
77
|
wait_for_deployment = false # Prevents Terraform from hanging for 10+ minutes
|
|
16
78
|
|
|
17
79
|
origin {
|
|
@@ -28,6 +90,31 @@ resource "aws_cloudfront_distribution" "cdn" {
|
|
|
28
90
|
}
|
|
29
91
|
}
|
|
30
92
|
|
|
93
|
+
ordered_cache_behavior {
|
|
94
|
+
path_pattern = "/api/*"
|
|
95
|
+
allowed_methods = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"]
|
|
96
|
+
cached_methods = ["GET", "HEAD"]
|
|
97
|
+
target_origin_id = "ApiGatewayOrigin"
|
|
98
|
+
|
|
99
|
+
viewer_protocol_policy = "redirect-to-https"
|
|
100
|
+
|
|
101
|
+
cache_policy_id = data.aws_cloudfront_cache_policy.disabled.id
|
|
102
|
+
origin_request_policy_id = data.aws_cloudfront_origin_request_policy.all_viewer.id
|
|
103
|
+
response_headers_policy_id = data.aws_cloudfront_response_headers_policy.security.id
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
ordered_cache_behavior {
|
|
107
|
+
path_pattern = "/_next/static/*"
|
|
108
|
+
allowed_methods = ["GET", "HEAD", "OPTIONS"]
|
|
109
|
+
cached_methods = ["GET", "HEAD"]
|
|
110
|
+
target_origin_id = "ApiGatewayOrigin"
|
|
111
|
+
|
|
112
|
+
viewer_protocol_policy = "redirect-to-https"
|
|
113
|
+
|
|
114
|
+
cache_policy_id = aws_cloudfront_cache_policy.app_static.id
|
|
115
|
+
response_headers_policy_id = data.aws_cloudfront_response_headers_policy.security.id
|
|
116
|
+
}
|
|
117
|
+
|
|
31
118
|
default_cache_behavior {
|
|
32
119
|
# Allow all HTTP methods so API POST/PUT requests still work
|
|
33
120
|
allowed_methods = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"]
|
|
@@ -36,9 +123,41 @@ resource "aws_cloudfront_distribution" "cdn" {
|
|
|
36
123
|
|
|
37
124
|
viewer_protocol_policy = "redirect-to-https"
|
|
38
125
|
|
|
39
|
-
#
|
|
40
|
-
cache_policy_id
|
|
41
|
-
origin_request_policy_id
|
|
126
|
+
# Per-variant app key + full-variance origin forwarding
|
|
127
|
+
cache_policy_id = aws_cloudfront_cache_policy.app_default.id
|
|
128
|
+
origin_request_policy_id = data.aws_cloudfront_origin_request_policy.all_viewer.id
|
|
129
|
+
response_headers_policy_id = data.aws_cloudfront_response_headers_policy.security.id
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
# Error TTL caps: origin error bodies pass through untouched, but cache
|
|
133
|
+
# briefly so a transient 404/5xx never sticks for hours.
|
|
134
|
+
custom_error_response {
|
|
135
|
+
error_code = 400
|
|
136
|
+
error_caching_min_ttl = 60
|
|
137
|
+
}
|
|
138
|
+
custom_error_response {
|
|
139
|
+
error_code = 403
|
|
140
|
+
error_caching_min_ttl = 60
|
|
141
|
+
}
|
|
142
|
+
custom_error_response {
|
|
143
|
+
error_code = 404
|
|
144
|
+
error_caching_min_ttl = 60
|
|
145
|
+
}
|
|
146
|
+
custom_error_response {
|
|
147
|
+
error_code = 500
|
|
148
|
+
error_caching_min_ttl = 10
|
|
149
|
+
}
|
|
150
|
+
custom_error_response {
|
|
151
|
+
error_code = 502
|
|
152
|
+
error_caching_min_ttl = 10
|
|
153
|
+
}
|
|
154
|
+
custom_error_response {
|
|
155
|
+
error_code = 503
|
|
156
|
+
error_caching_min_ttl = 10
|
|
157
|
+
}
|
|
158
|
+
custom_error_response {
|
|
159
|
+
error_code = 504
|
|
160
|
+
error_caching_min_ttl = 10
|
|
42
161
|
}
|
|
43
162
|
|
|
44
163
|
restrictions {
|
|
@@ -1,6 +1,60 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# App CDN cache policies: a single path-only key (Managed-CachingOptimized)
|
|
2
|
+
# is wrong for an app server — one slot per path gets shared by HTML docs,
|
|
3
|
+
# API/RSC variants, redirects, and errors, so a cacheable variant poisons
|
|
4
|
+
# every other viewer of that path. Each traffic class below gets its own
|
|
5
|
+
# key instead (BUG-82).
|
|
6
|
+
data "aws_cloudfront_cache_policy" "disabled" {
|
|
7
|
+
name = "Managed-CachingDisabled"
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
# Default behavior key: query strings + cookies + router headers, so each
|
|
11
|
+
# page variant (search params, session, RSC/prefetch) caches independently
|
|
12
|
+
# and authenticated bytes never cross viewers. The header keys are harmless
|
|
13
|
+
# when absent — frameworks that never send them simply never vary on them.
|
|
14
|
+
resource "aws_cloudfront_cache_policy" "app_default" {
|
|
15
|
+
name = "${local.app_name}-app-default"
|
|
16
|
+
comment = "Per-variant app key: all query strings, cookies, and router headers"
|
|
17
|
+
default_ttl = 60
|
|
18
|
+
max_ttl = 86400
|
|
19
|
+
min_ttl = 0
|
|
20
|
+
parameters_in_cache_key_and_forwarded_to_origin {
|
|
21
|
+
cookies_config {
|
|
22
|
+
cookie_behavior = "all"
|
|
23
|
+
}
|
|
24
|
+
headers_config {
|
|
25
|
+
header_behavior = "whitelist"
|
|
26
|
+
headers {
|
|
27
|
+
items = ["RSC", "Next-Router-State-Tree", "Next-Router-Prefetch", "Next-Url"]
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
query_strings_config {
|
|
31
|
+
query_string_behavior = "all"
|
|
32
|
+
}
|
|
33
|
+
enable_accept_encoding_brotli = true
|
|
34
|
+
enable_accept_encoding_gzip = true
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
# Framework build assets are content-hashed: path-only key, immutable TTL.
|
|
39
|
+
resource "aws_cloudfront_cache_policy" "app_static" {
|
|
40
|
+
name = "${local.app_name}-app-static"
|
|
41
|
+
comment = "Content-hashed framework assets: immutable, long TTL"
|
|
42
|
+
default_ttl = 31536000
|
|
43
|
+
max_ttl = 31536000
|
|
44
|
+
min_ttl = 0
|
|
45
|
+
parameters_in_cache_key_and_forwarded_to_origin {
|
|
46
|
+
cookies_config {
|
|
47
|
+
cookie_behavior = "none"
|
|
48
|
+
}
|
|
49
|
+
headers_config {
|
|
50
|
+
header_behavior = "none"
|
|
51
|
+
}
|
|
52
|
+
query_strings_config {
|
|
53
|
+
query_string_behavior = "none"
|
|
54
|
+
}
|
|
55
|
+
enable_accept_encoding_brotli = true
|
|
56
|
+
enable_accept_encoding_gzip = true
|
|
57
|
+
}
|
|
4
58
|
}
|
|
5
59
|
|
|
6
60
|
# Fetch the AWS Managed Origin Request Policy (Passes query strings/cookies to your app)
|
|
@@ -8,17 +62,33 @@ data "aws_cloudfront_origin_request_policy" "all_viewer" {
|
|
|
8
62
|
name = "Managed-AllViewerExceptHostHeader"
|
|
9
63
|
}
|
|
10
64
|
|
|
65
|
+
# Managed security headers (HSTS, frame/clickjacking guards, content-type
|
|
66
|
+
# sniffing) on every behavior (BUG-92).
|
|
67
|
+
data "aws_cloudfront_response_headers_policy" "security" {
|
|
68
|
+
name = "Managed-SecurityHeadersPolicy"
|
|
69
|
+
}
|
|
70
|
+
|
|
11
71
|
# trivy:ignore:AVD-AWS-0011 - WAF is omitted by default to prevent unexpected monthly costs for users
|
|
12
72
|
resource "aws_cloudfront_distribution" "cdn" {
|
|
13
73
|
enabled = true
|
|
14
74
|
is_ipv6_enabled = true
|
|
75
|
+
comment = "${local.app_name}-cdn"
|
|
76
|
+
price_class = "PriceClass_100"
|
|
15
77
|
wait_for_deployment = false # Prevents Terraform from hanging for 10+ minutes
|
|
16
|
-
|
|
78
|
+
|
|
17
79
|
origin {
|
|
18
80
|
# Point the CDN at the Load Balancer we provision in main.tf
|
|
19
81
|
domain_name = aws_lb.main.dns_name
|
|
20
82
|
origin_id = "ALBOrigin"
|
|
21
83
|
|
|
84
|
+
# Origin secret (BUG-91): proves to the ALB that the request came
|
|
85
|
+
# through THIS distribution — any other tenant's distro, or a direct
|
|
86
|
+
# ALB hit, lacks the header and gets a 403 from the listener rule.
|
|
87
|
+
custom_header {
|
|
88
|
+
name = "X-Grada-Origin-Secret"
|
|
89
|
+
value = random_password.origin_secret.result
|
|
90
|
+
}
|
|
91
|
+
|
|
22
92
|
custom_origin_config {
|
|
23
93
|
http_port = 80
|
|
24
94
|
https_port = 443
|
|
@@ -28,6 +98,31 @@ resource "aws_cloudfront_distribution" "cdn" {
|
|
|
28
98
|
}
|
|
29
99
|
}
|
|
30
100
|
|
|
101
|
+
ordered_cache_behavior {
|
|
102
|
+
path_pattern = "/api/*"
|
|
103
|
+
allowed_methods = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"]
|
|
104
|
+
cached_methods = ["GET", "HEAD"]
|
|
105
|
+
target_origin_id = "ALBOrigin"
|
|
106
|
+
|
|
107
|
+
viewer_protocol_policy = "redirect-to-https"
|
|
108
|
+
|
|
109
|
+
cache_policy_id = data.aws_cloudfront_cache_policy.disabled.id
|
|
110
|
+
origin_request_policy_id = data.aws_cloudfront_origin_request_policy.all_viewer.id
|
|
111
|
+
response_headers_policy_id = data.aws_cloudfront_response_headers_policy.security.id
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
ordered_cache_behavior {
|
|
115
|
+
path_pattern = "/_next/static/*"
|
|
116
|
+
allowed_methods = ["GET", "HEAD", "OPTIONS"]
|
|
117
|
+
cached_methods = ["GET", "HEAD"]
|
|
118
|
+
target_origin_id = "ALBOrigin"
|
|
119
|
+
|
|
120
|
+
viewer_protocol_policy = "redirect-to-https"
|
|
121
|
+
|
|
122
|
+
cache_policy_id = aws_cloudfront_cache_policy.app_static.id
|
|
123
|
+
response_headers_policy_id = data.aws_cloudfront_response_headers_policy.security.id
|
|
124
|
+
}
|
|
125
|
+
|
|
31
126
|
default_cache_behavior {
|
|
32
127
|
# Allow all HTTP methods so API POST/PUT requests still work
|
|
33
128
|
allowed_methods = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"]
|
|
@@ -36,9 +131,41 @@ resource "aws_cloudfront_distribution" "cdn" {
|
|
|
36
131
|
|
|
37
132
|
viewer_protocol_policy = "redirect-to-https"
|
|
38
133
|
|
|
39
|
-
#
|
|
40
|
-
cache_policy_id
|
|
41
|
-
origin_request_policy_id
|
|
134
|
+
# Per-variant app key + full-variance origin forwarding
|
|
135
|
+
cache_policy_id = aws_cloudfront_cache_policy.app_default.id
|
|
136
|
+
origin_request_policy_id = data.aws_cloudfront_origin_request_policy.all_viewer.id
|
|
137
|
+
response_headers_policy_id = data.aws_cloudfront_response_headers_policy.security.id
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
# Error TTL caps: origin error bodies pass through untouched, but cache
|
|
141
|
+
# briefly so a transient 404/5xx never sticks for hours.
|
|
142
|
+
custom_error_response {
|
|
143
|
+
error_code = 400
|
|
144
|
+
error_caching_min_ttl = 60
|
|
145
|
+
}
|
|
146
|
+
custom_error_response {
|
|
147
|
+
error_code = 403
|
|
148
|
+
error_caching_min_ttl = 60
|
|
149
|
+
}
|
|
150
|
+
custom_error_response {
|
|
151
|
+
error_code = 404
|
|
152
|
+
error_caching_min_ttl = 60
|
|
153
|
+
}
|
|
154
|
+
custom_error_response {
|
|
155
|
+
error_code = 500
|
|
156
|
+
error_caching_min_ttl = 10
|
|
157
|
+
}
|
|
158
|
+
custom_error_response {
|
|
159
|
+
error_code = 502
|
|
160
|
+
error_caching_min_ttl = 10
|
|
161
|
+
}
|
|
162
|
+
custom_error_response {
|
|
163
|
+
error_code = 503
|
|
164
|
+
error_caching_min_ttl = 10
|
|
165
|
+
}
|
|
166
|
+
custom_error_response {
|
|
167
|
+
error_code = 504
|
|
168
|
+
error_caching_min_ttl = 10
|
|
42
169
|
}
|
|
43
170
|
|
|
44
171
|
restrictions {
|
|
@@ -65,7 +192,7 @@ output "z_NEXT_STEP_REQUIRED" {
|
|
|
65
192
|
🚀 INFRASTRUCTURE PROVISIONED SUCCESSFULLY!
|
|
66
193
|
====================================================================
|
|
67
194
|
|
|
68
|
-
Your AWS environment is ready. However, your URLs listed above will
|
|
195
|
+
Your AWS environment is ready. However, your URLs listed above will
|
|
69
196
|
return an error until your application code is actually deployed.
|
|
70
197
|
|
|
71
198
|
TO DEPLOY YOUR APP:
|
|
@@ -73,8 +200,8 @@ TO DEPLOY YOUR APP:
|
|
|
73
200
|
2. git commit -m "ci: configure grada"
|
|
74
201
|
3. git push origin main
|
|
75
202
|
|
|
76
|
-
Once the GitHub Action completes, your site will be live at the
|
|
203
|
+
Once the GitHub Action completes, your site will be live at the
|
|
77
204
|
CloudFront URL!
|
|
78
205
|
====================================================================
|
|
79
206
|
EOT
|
|
80
|
-
}
|
|
207
|
+
}
|
|
@@ -26,7 +26,11 @@ resource "aws_db_instance" "postgres" {
|
|
|
26
26
|
engine_version = "8.0"
|
|
27
27
|
instance_class = "db.t4g.micro"
|
|
28
28
|
allocated_storage = 20
|
|
29
|
-
|
|
29
|
+
# Cap storage autoscaling: without a ceiling a runaway workload can
|
|
30
|
+
# grow the volume (and the bill) without bound.
|
|
31
|
+
max_allocated_storage = 200
|
|
32
|
+
backup_retention_period = 7
|
|
33
|
+
storage_encrypted = true
|
|
30
34
|
|
|
31
35
|
# Strip dashes for the database name: RDS MySQL db_name must begin with a
|
|
32
36
|
# letter and contain only alphanumeric characters (e.g. my-project -> myproject)
|
|
@@ -26,7 +26,11 @@ resource "aws_db_instance" "postgres" {
|
|
|
26
26
|
engine_version = "16"
|
|
27
27
|
instance_class = "db.t4g.micro"
|
|
28
28
|
allocated_storage = 20
|
|
29
|
-
|
|
29
|
+
# Cap storage autoscaling: without a ceiling a runaway workload can
|
|
30
|
+
# grow the volume (and the bill) without bound.
|
|
31
|
+
max_allocated_storage = 200
|
|
32
|
+
backup_retention_period = 7
|
|
33
|
+
storage_encrypted = true
|
|
30
34
|
|
|
31
35
|
# Clean up dashes for the database name (e.g. my-project -> my_project)
|
|
32
36
|
db_name = replace(local.app_name, "-", "_")
|
|
@@ -150,7 +150,7 @@ resource "aws_ecs_task_definition" "app" {
|
|
|
150
150
|
lifecycle {
|
|
151
151
|
precondition {
|
|
152
152
|
condition = length(setintersection(toset(local.secret_keys), toset(local.managed_env_names))) == 0
|
|
153
|
-
error_message = "secret_keys.json collides with container environment: ${join(", ", setintersection(toset(local.secret_keys), toset(local.managed_env_names)))}. Remove the key(s) from .env and re-push (push skips them automatically)."
|
|
153
|
+
error_message = "secret_keys.json collides with container environment: ${join(", ", setintersection(toset(local.secret_keys), toset(local.managed_env_names)))}. Remove the key(s) from .env and re-push (push skips them automatically). If push does not skip the key, this guard list is stale — remove the entry from managed_env_names in terraform/main.tf."
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
|
|
@@ -228,6 +228,16 @@ resource "aws_lb_target_group" "app" {
|
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
230
|
|
|
231
|
+
# Origin secret (BUG-91): only requests bearing the header CloudFront
|
|
232
|
+
# injects may reach the app. The CloudFront edge-IP security group alone
|
|
233
|
+
# cannot prove WHICH distribution sent a request — any tenant's distro
|
|
234
|
+
# could point at this ALB — so the listener forwards solely on a header
|
|
235
|
+
# match and 403s everything else (including direct ALB hits).
|
|
236
|
+
resource "random_password" "origin_secret" {
|
|
237
|
+
length = 32
|
|
238
|
+
special = false
|
|
239
|
+
}
|
|
240
|
+
|
|
231
241
|
# trivy:ignore:AVD-AWS-0054 - CloudFront handles HTTPS edge termination; ALB uses HTTP to avoid complex ACM DNS validation for users
|
|
232
242
|
resource "aws_lb_listener" "http" {
|
|
233
243
|
load_balancer_arn = aws_lb.main.arn
|
|
@@ -235,9 +245,30 @@ resource "aws_lb_listener" "http" {
|
|
|
235
245
|
protocol = "HTTP"
|
|
236
246
|
|
|
237
247
|
default_action {
|
|
248
|
+
type = "fixed-response"
|
|
249
|
+
fixed_response {
|
|
250
|
+
content_type = "text/plain"
|
|
251
|
+
message_body = "Forbidden"
|
|
252
|
+
status_code = "403"
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
resource "aws_lb_listener_rule" "origin_secret" {
|
|
258
|
+
listener_arn = aws_lb_listener.http.arn
|
|
259
|
+
priority = 1
|
|
260
|
+
|
|
261
|
+
action {
|
|
238
262
|
type = "forward"
|
|
239
263
|
target_group_arn = aws_lb_target_group.app.arn
|
|
240
264
|
}
|
|
265
|
+
|
|
266
|
+
condition {
|
|
267
|
+
http_header {
|
|
268
|
+
http_header_name = "X-Grada-Origin-Secret"
|
|
269
|
+
values = [random_password.origin_secret.result]
|
|
270
|
+
}
|
|
271
|
+
}
|
|
241
272
|
}
|
|
242
273
|
|
|
243
274
|
# --- ECS Service ---
|
|
@@ -307,6 +338,10 @@ output "ecr_repository_url" {
|
|
|
307
338
|
}
|
|
308
339
|
|
|
309
340
|
# --- CloudWatch Alarms ---
|
|
341
|
+
# State-only alarm: visible in the console, notifies nobody. There is no
|
|
342
|
+
# notification destination at scaffold time; `grada alerts` provisions
|
|
343
|
+
# separate alarms wired to SNS, and this one stays as a console signal so
|
|
344
|
+
# quiet trees still show red (BUG-101).
|
|
310
345
|
resource "aws_cloudwatch_metric_alarm" "alb_5xx_errors" {
|
|
311
346
|
alarm_name = "${local.app_name}-high-5xx-errors"
|
|
312
347
|
comparison_operator = "GreaterThanThreshold"
|
|
@@ -80,8 +80,11 @@ resource "aws_security_group" "alb" {
|
|
|
80
80
|
to_port = 80
|
|
81
81
|
protocol = "tcp"
|
|
82
82
|
# CloudFront-only: the origin speaks plaintext HTTP, so direct browser
|
|
83
|
-
# access would bypass the CDN (and TLS on domained trees).
|
|
84
|
-
#
|
|
83
|
+
# access would bypass the CDN (and TLS on domained trees). The origin
|
|
84
|
+
# secret (random_password.origin_secret) proves WHICH distribution sent
|
|
85
|
+
# a request — the listener 403s anything without it. Debugging via the
|
|
86
|
+
# direct URL needs both a temporary personal-IP rule and the
|
|
87
|
+
# X-Grada-Origin-Secret header value from the Terraform state.
|
|
85
88
|
prefix_list_ids = [data.aws_ec2_managed_prefix_list.cloudfront.id]
|
|
86
89
|
}
|
|
87
90
|
|
|
@@ -48,8 +48,9 @@ resource "aws_iam_role" "github_actions" {
|
|
|
48
48
|
# remote, or the setup prompt. "repo:*" means any GitHub repo's
|
|
49
49
|
# Actions can assume this role — re-scope before going live.
|
|
50
50
|
# Scoped trusts render both subject-claim formats: the classic
|
|
51
|
-
# `repo:<owner>/<name
|
|
52
|
-
# `repo:<owner>@*/<name
|
|
51
|
+
# `repo:<owner>/<name>:<suffix>` plus the immutable-claim
|
|
52
|
+
# companion `repo:<owner>@*/<name>@*:<same suffix>`
|
|
53
|
+
# (repos created after 2026-07-15).
|
|
53
54
|
"token.actions.githubusercontent.com:sub" : {{GITHUB_REPO_SUB}}
|
|
54
55
|
}
|
|
55
56
|
StringEquals = {
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
# 1. Only create the Secret Vault in the default (production) workspace
|
|
4
4
|
resource "aws_secretsmanager_secret" "app_secrets" {
|
|
5
|
-
count
|
|
6
|
-
name
|
|
7
|
-
description
|
|
8
|
-
|
|
5
|
+
count = terraform.workspace == "default" ? 1 : 0
|
|
6
|
+
name = "{{PROJECT_NAME}}{{RESOURCE_SUFFIX}}-secrets"
|
|
7
|
+
description = "Environment variables for {{PROJECT_NAME}}"
|
|
8
|
+
# 30-day recovery (BUG-163): an instant-delete vault turns any destroy
|
|
9
|
+
# bug into unrecoverable secret loss. Lower per-tree if you must.
|
|
10
|
+
recovery_window_in_days = 30
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
# 2. Fetch the existing Secret Vault when running in a PR workspace
|
|
@@ -55,6 +55,13 @@ resource "aws_ecs_service" "worker" {
|
|
|
55
55
|
desired_count = 1
|
|
56
56
|
enable_execute_command = true
|
|
57
57
|
|
|
58
|
+
# Same safety net as the app service: a bad worker revision rolls
|
|
59
|
+
# back automatically instead of flapping forever.
|
|
60
|
+
deployment_circuit_breaker {
|
|
61
|
+
enable = true
|
|
62
|
+
rollback = true
|
|
63
|
+
}
|
|
64
|
+
|
|
58
65
|
network_configuration {
|
|
59
66
|
subnets = aws_subnet.public[*].id
|
|
60
67
|
security_groups = [aws_security_group.ecs_tasks.id]
|