@cubocicloide/stack-react-fastapi 13.2.0 → 13.3.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/dist/index.js +82 -20
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/templates/aws-eks/backend/Dockerfile.prod.hbs +11 -4
- package/templates/aws-eks/docs/docs/deploy.md.hbs +29 -0
- package/templates/aws-eks/frontend/Dockerfile.prod +7 -3
- package/templates/aws-eks/frontend/nginx.conf +2 -1
- package/templates/aws-eks/iac/helm/app/values.yaml.hbs +3 -2
- package/templates/aws-eks/iac/terraform/bootstrap/main.tf.hbs +23 -3
- package/templates/aws-eks/iac/terraform/main.tf.hbs +10 -1
- package/templates/base/docs/docs/dude.md.hbs +19 -0
- package/templates/base/frontend/src/pages/index.tsx +2 -2
- package/templates/base/security/_trivyignore.yaml +49 -0
package/package.json
CHANGED
|
@@ -9,13 +9,20 @@ WORKDIR /app
|
|
|
9
9
|
|
|
10
10
|
RUN pip install --no-cache-dir uv
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
# Run as an unprivileged user (trivy DS002). The user is created *before* the
|
|
13
|
+
# virtualenv is built so every layer is written with the right ownership — a
|
|
14
|
+
# trailing `chown -R /app` would instead duplicate the whole .venv into an
|
|
15
|
+
# extra layer.
|
|
16
|
+
RUN useradd -m -u 1000 appuser && chown appuser:appuser /app
|
|
17
|
+
USER appuser
|
|
18
|
+
|
|
19
|
+
COPY --chown=appuser:appuser pyproject.toml .
|
|
13
20
|
RUN uv sync --no-cache --no-dev
|
|
14
21
|
|
|
15
|
-
COPY app ./app
|
|
22
|
+
COPY --chown=appuser:appuser app ./app
|
|
16
23
|
{{#if withPostgres}}
|
|
17
|
-
COPY alembic ./alembic
|
|
18
|
-
COPY alembic.ini ./alembic.ini
|
|
24
|
+
COPY --chown=appuser:appuser alembic ./alembic
|
|
25
|
+
COPY --chown=appuser:appuser alembic.ini ./alembic.ini
|
|
19
26
|
{{/if}}
|
|
20
27
|
|
|
21
28
|
EXPOSE 8000
|
|
@@ -94,6 +94,35 @@ dude iac ship --env staging
|
|
|
94
94
|
> `dude iac deploy --env staging --tag <sha>` (use the tag from
|
|
95
95
|
> `dude iac status --env dev`).
|
|
96
96
|
|
|
97
|
+
## Image tags
|
|
98
|
+
|
|
99
|
+
The ECR repositories are **immutable**: a tag is written once and can never be
|
|
100
|
+
overwritten. That is what makes "promote the image from dev to staging" mean
|
|
101
|
+
something — a tag names one exact set of bytes, for as long as it exists.
|
|
102
|
+
|
|
103
|
+
So `dude iac build/push/ship` derive the tag from your git state rather than
|
|
104
|
+
letting you overwrite one:
|
|
105
|
+
|
|
106
|
+
| Working tree | Tag |
|
|
107
|
+
|--------------|-----|
|
|
108
|
+
| clean | `<git-short-sha>` |
|
|
109
|
+
| uncommitted changes | `<git-short-sha>-dirty-<hash-of-the-diff>` |
|
|
110
|
+
|
|
111
|
+
The `-dirty-<hash>` part is why iterating on a branch works: every edit changes
|
|
112
|
+
the digest, so every `dude iac ship` gets a fresh tag. Re-shipping a state you
|
|
113
|
+
have already pushed — same commit, same edits — is the one case that stops, and
|
|
114
|
+
it stops *before* building, with the three options spelled out:
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
✗ <repo>:<tag> already exists, and the repository is immutable.
|
|
118
|
+
• commit your work and re-run — a new SHA gives a new tag;
|
|
119
|
+
• push under a different tag: dude iac push --env dev --tag <tag>.1
|
|
120
|
+
• or deploy what is already there: dude iac deploy --env dev --tag <tag>
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
That last one is usually what you want: the image is already in ECR, so there is
|
|
124
|
+
nothing to rebuild.
|
|
125
|
+
|
|
97
126
|
## HTTPS on a custom domain *(optional)*
|
|
98
127
|
|
|
99
128
|
Set these in `iac/terraform/environments/dev/terraform.tfvars` (the Route53
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# Production image for the frontend: build the Vite app, serve the static
|
|
2
|
-
# bundle with nginx. Used by the Helm deployment (port
|
|
2
|
+
# bundle with nginx. Used by the Helm deployment (port 8080). The dev Dockerfile
|
|
3
3
|
# (Vite dev server) is kept for `dude up`.
|
|
4
4
|
#
|
|
5
5
|
# VITE_* values are baked in at build time — pass them as build args:
|
|
@@ -21,8 +21,12 @@ ENV VITE_REACT_QUERY_DEVTOOLS=$VITE_REACT_QUERY_DEVTOOLS
|
|
|
21
21
|
COPY . .
|
|
22
22
|
RUN pnpm build
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
# nginx-unprivileged is the stock nginx image rebuilt to run as UID 101 with no
|
|
25
|
+
# root master process (trivy DS002). Because it cannot bind a privileged port,
|
|
26
|
+
# it listens on 8080 — see nginx.conf and `frontend.port` in the Helm values.
|
|
27
|
+
FROM nginxinc/nginx-unprivileged:1.27-alpine
|
|
25
28
|
COPY --from=build /app/dist /usr/share/nginx/html
|
|
26
29
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
|
27
|
-
|
|
30
|
+
USER nginx
|
|
31
|
+
EXPOSE 8080
|
|
28
32
|
CMD ["nginx", "-g", "daemon off;"]
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
# (path-based), so nginx only needs to serve the static bundle and fall back to
|
|
3
3
|
# index.html for client-side routes.
|
|
4
4
|
server {
|
|
5
|
-
|
|
5
|
+
# 8080, not 80: the image runs unprivileged and cannot bind a port < 1024.
|
|
6
|
+
listen 8080;
|
|
6
7
|
server_name _;
|
|
7
8
|
root /usr/share/nginx/html;
|
|
8
9
|
index index.html;
|
|
@@ -34,8 +34,9 @@ backend:
|
|
|
34
34
|
|
|
35
35
|
frontend:
|
|
36
36
|
replicas: 2
|
|
37
|
-
## nginx serving the production build (see frontend/Dockerfile.prod)
|
|
38
|
-
port
|
|
37
|
+
## nginx serving the production build (see frontend/Dockerfile.prod). 8080
|
|
38
|
+
## because that image runs unprivileged and cannot bind a port below 1024.
|
|
39
|
+
port: 8080
|
|
39
40
|
resources:
|
|
40
41
|
requests:
|
|
41
42
|
cpu: 50m
|
|
@@ -49,12 +49,32 @@ resource "aws_s3_bucket_versioning" "state" {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
# Terraform state records every attribute of every resource — including the
|
|
53
|
+
# generated RDS password — so it gets a customer managed key rather than the
|
|
54
|
+
# AWS-owned S3 key (AVD-AWS-0132). The practical difference is control: rotation
|
|
55
|
+
# you can schedule, a key policy you can audit, and the ability to revoke access
|
|
56
|
+
# to the state without touching the bucket.
|
|
57
|
+
resource "aws_kms_key" "state" {
|
|
58
|
+
description = "${var.project_name} — Terraform state encryption"
|
|
59
|
+
enable_key_rotation = true
|
|
60
|
+
deletion_window_in_days = 7
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
resource "aws_kms_alias" "state" {
|
|
64
|
+
name = "alias/${var.project_name}-tfstate"
|
|
65
|
+
target_key_id = aws_kms_key.state.key_id
|
|
66
|
+
}
|
|
67
|
+
|
|
52
68
|
resource "aws_s3_bucket_server_side_encryption_configuration" "state" {
|
|
53
69
|
bucket = aws_s3_bucket.state.id
|
|
54
70
|
rule {
|
|
55
71
|
apply_server_side_encryption_by_default {
|
|
56
|
-
sse_algorithm
|
|
72
|
+
sse_algorithm = "aws:kms"
|
|
73
|
+
kms_master_key_id = aws_kms_key.state.arn
|
|
57
74
|
}
|
|
75
|
+
# One data key per bucket rather than one per object: same protection, and
|
|
76
|
+
# it keeps the (billed) KMS request count flat as the state grows.
|
|
77
|
+
bucket_key_enabled = true
|
|
58
78
|
}
|
|
59
79
|
}
|
|
60
80
|
|
|
@@ -82,7 +102,7 @@ resource "aws_dynamodb_table" "lock" {
|
|
|
82
102
|
# only here, with the rest of the shared backend.
|
|
83
103
|
resource "aws_ecr_repository" "backend" {
|
|
84
104
|
name = "${var.project_name}-backend"
|
|
85
|
-
image_tag_mutability = "
|
|
105
|
+
image_tag_mutability = "IMMUTABLE"
|
|
86
106
|
force_delete = true
|
|
87
107
|
|
|
88
108
|
image_scanning_configuration {
|
|
@@ -92,7 +112,7 @@ resource "aws_ecr_repository" "backend" {
|
|
|
92
112
|
|
|
93
113
|
resource "aws_ecr_repository" "frontend" {
|
|
94
114
|
name = "${var.project_name}-frontend"
|
|
95
|
-
image_tag_mutability = "
|
|
115
|
+
image_tag_mutability = "IMMUTABLE"
|
|
96
116
|
force_delete = true
|
|
97
117
|
|
|
98
118
|
image_scanning_configuration {
|
|
@@ -56,6 +56,13 @@ module "eks" {
|
|
|
56
56
|
min_size = var.node_min_size
|
|
57
57
|
max_size = var.node_max_size
|
|
58
58
|
desired_size = var.node_desired_size
|
|
59
|
+
|
|
60
|
+
# IMDSv2 is not configured here on purpose: the module already defaults
|
|
61
|
+
# `metadata_options` to { http_endpoint = "enabled", http_tokens =
|
|
62
|
+
# "required", http_put_response_hop_limit = 2 }. That variable is
|
|
63
|
+
# replaced wholesale rather than merged, so overriding it with just
|
|
64
|
+
# `http_tokens` would silently drop the hop limit to the AWS default of
|
|
65
|
+
# 1 and cut pods off from the instance metadata endpoint.
|
|
59
66
|
}
|
|
60
67
|
}
|
|
61
68
|
}
|
|
@@ -255,11 +262,13 @@ resource "aws_security_group" "rds" {
|
|
|
255
262
|
cidr_blocks = [var.vpc_cidr]
|
|
256
263
|
}
|
|
257
264
|
|
|
265
|
+
# Restrict egress to VPC only (security best practice)
|
|
258
266
|
egress {
|
|
267
|
+
description = "Allow outbound to VPC for responses"
|
|
259
268
|
from_port = 0
|
|
260
269
|
to_port = 0
|
|
261
270
|
protocol = "-1"
|
|
262
|
-
cidr_blocks = [
|
|
271
|
+
cidr_blocks = [var.vpc_cidr]
|
|
263
272
|
}
|
|
264
273
|
|
|
265
274
|
lifecycle {
|
|
@@ -237,6 +237,25 @@ git add security/baseline.json && git commit -m "chore(security): update baselin
|
|
|
237
237
|
`security/baseline.json` must be committed — it is the source of truth for
|
|
238
238
|
accepted findings. Subsequent scans only flag findings that are **not** in the
|
|
239
239
|
baseline.
|
|
240
|
+
|
|
241
|
+
**Baseline or ignore file?** Two mechanisms, deliberately different:
|
|
242
|
+
|
|
243
|
+
| | Use for | Behaviour |
|
|
244
|
+
|-|---------|-----------|
|
|
245
|
+
| `security/baseline.json` | findings you have triaged and mean to address | fingerprinted; a finding reappears as *new* if its location changes, and `dude security verify` prunes it once fixed |
|
|
246
|
+
| `security/.trivyignore.yaml` | findings that are correct **by design** and will never be fixed | matched by rule id + path; permanently silent, with a `statement:` recording why |
|
|
247
|
+
|
|
248
|
+
The scaffold ships one ignore entry: **DS002** (container runs as root) on
|
|
249
|
+
`backend/Dockerfile` and `frontend/Dockerfile`. Those are the development images
|
|
250
|
+
that `dude up` builds — they never leave your machine, they bind-mount your
|
|
251
|
+
source tree, and pinning them to a non-root UID breaks writes back into it (the
|
|
252
|
+
alembic revision `dude db makemigration` generates, for instance) on any host
|
|
253
|
+
whose UID is not 1000. The images that actually ship — `Dockerfile.prod` for
|
|
254
|
+
both backend and frontend — do run unprivileged.
|
|
255
|
+
|
|
256
|
+
Trivy is also pointed away from `.terraform/`: once `dude iac init` has run,
|
|
257
|
+
that directory holds the vendored source of every third-party Terraform module,
|
|
258
|
+
and its misconfigurations are not yours to fix.
|
|
240
259
|
{{#if withIac}}
|
|
241
260
|
|
|
242
261
|
---
|
|
@@ -90,10 +90,10 @@ export default function HomePage() {
|
|
|
90
90
|
<Col xs={24} md={8}>
|
|
91
91
|
<Card title={<><CodeOutlined /> Quick links</>} style={{ height: '100%' }}>
|
|
92
92
|
<Space wrap size="middle">
|
|
93
|
-
<Link href="/api/docs" target="_blank">
|
|
93
|
+
<Link href="http://localhost:8000/api/docs" target="_blank">
|
|
94
94
|
API docs (Swagger)
|
|
95
95
|
</Link>
|
|
96
|
-
<Link href="/api/redoc" target="_blank">
|
|
96
|
+
<Link href="http://localhost:8000/api/redoc" target="_blank">
|
|
97
97
|
ReDoc
|
|
98
98
|
</Link>
|
|
99
99
|
<Link href="http://localhost:8001" target="_blank">
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Trivy ignore file — accepted findings, with the reason recorded next to each.
|
|
2
|
+
#
|
|
3
|
+
# This is for findings that are *by design* and will never be "fixed", so they
|
|
4
|
+
# would otherwise reappear on every scan. Findings you have merely triaged and
|
|
5
|
+
# intend to address belong in the baseline instead:
|
|
6
|
+
#
|
|
7
|
+
# dude security accept # absorb current findings
|
|
8
|
+
# dude security verify --rule-id <id> # confirm a fix, prune from the baseline
|
|
9
|
+
#
|
|
10
|
+
# Wired in by `dude security scan` via --ignorefile; delete this file and every
|
|
11
|
+
# entry below becomes a live finding again.
|
|
12
|
+
|
|
13
|
+
vulnerabilities:
|
|
14
|
+
- id: GHSA-qwww-vcr4-c8h2
|
|
15
|
+
paths:
|
|
16
|
+
- frontend/package-lock.json
|
|
17
|
+
- frontend/pnpm-lock.yaml
|
|
18
|
+
# Revisit rather than forget: after this date trivy reports it again.
|
|
19
|
+
expired_at: 2027-02-01
|
|
20
|
+
statement: >
|
|
21
|
+
Not reachable in this application. The advisory is a CSRF bypass in React
|
|
22
|
+
Router's RSC (React Server Components) mode; this frontend is a Vite SPA
|
|
23
|
+
doing client-side routing with react-router-dom, and never runs RSC. The
|
|
24
|
+
only published fix is react-router 8.3.0 — a major version with breaking
|
|
25
|
+
routing changes — so upgrading is a deliberate migration, not a patch.
|
|
26
|
+
Re-check when moving to react-router 8 for any other reason.
|
|
27
|
+
|
|
28
|
+
misconfigurations:
|
|
29
|
+
- id: DS002
|
|
30
|
+
paths:
|
|
31
|
+
- backend/Dockerfile
|
|
32
|
+
- frontend/Dockerfile
|
|
33
|
+
statement: >
|
|
34
|
+
Development images only. They are built by `dude up` and never leave the
|
|
35
|
+
developer's machine — Kubernetes runs backend/Dockerfile.prod and
|
|
36
|
+
frontend/Dockerfile.prod, both of which do run as an unprivileged user.
|
|
37
|
+
Forcing a non-root UID here breaks writes to the bind-mounted source tree
|
|
38
|
+
(`dude db makemigration` writing alembic/versions/, for one) on any host
|
|
39
|
+
whose UID is not 1000.
|
|
40
|
+
|
|
41
|
+
- id: DS002
|
|
42
|
+
paths:
|
|
43
|
+
- iac/runner/Dockerfile
|
|
44
|
+
statement: >
|
|
45
|
+
Local tooling container, not a workload. `dude iac *` runs terraform,
|
|
46
|
+
kubectl, helm and k9s inside it with your own ~/.aws and ~/.kube mounted
|
|
47
|
+
in; it is started on demand, never deployed, and never exposed. Running
|
|
48
|
+
as root is what lets those tools write to the mounted credential caches
|
|
49
|
+
whatever your host UID happens to be.
|