canopycms-cdk 0.0.68-int.98 → 0.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canopycms-cdk",
3
- "version": "0.0.68-int.98",
3
+ "version": "0.1.0",
4
4
  "description": "AWS CDK constructs and EC2 worker for CanopyCMS deployment",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -23,6 +23,9 @@
23
23
  "dist",
24
24
  "worker/dist",
25
25
  "worker/canopy-worker.service",
26
+ "worker/canopy-github.service",
27
+ "worker/canopy-github.socket",
28
+ "worker/gateway.env.example",
26
29
  "lambda/asset-transform/dist"
27
30
  ],
28
31
  "engines": {
@@ -31,7 +34,7 @@
31
34
  "peerDependencies": {
32
35
  "aws-cdk-lib": "^2.260.0",
33
36
  "constructs": "^10.0.0",
34
- "canopycms": "0.0.68-int.98"
37
+ "canopycms": "0.1.0"
35
38
  },
36
39
  "peerDependenciesMeta": {
37
40
  "aws-cdk-lib": {
@@ -46,6 +49,7 @@
46
49
  "@types/react": "^18.3.12",
47
50
  "@types/aws-lambda": "^8.10.145",
48
51
  "aws-cdk-lib": "^2.260.0",
52
+ "@aws-sdk/client-auto-scaling": "^3.600.0",
49
53
  "@aws-sdk/client-s3": "^3.600.0",
50
54
  "@aws-sdk/client-secrets-manager": "^3.600.0",
51
55
  "@octokit/auth-app": "^6.1.4",
@@ -56,14 +60,15 @@
56
60
  "tsx": "^4.19.0",
57
61
  "typescript": "^5.6.3",
58
62
  "vitest": "^4.1.0",
59
- "canopycms": "0.0.68-int.98",
60
- "canopycms-auth-clerk": "0.0.68-int.98"
63
+ "canopycms": "0.1.0",
64
+ "canopycms-auth-clerk": "0.1.0"
61
65
  },
62
66
  "scripts": {
63
67
  "build": "rm -rf dist && tsc && node ../../scripts/add-js-extensions.mjs dist",
64
- "build:worker": "esbuild worker/index.ts --bundle --platform=node --target=node22 --format=esm --outfile=worker/dist/index.js --banner:js=\"import { createRequire } from 'module'; const require = createRequire(import.meta.url);\"",
68
+ "build:worker": "node --import tsx worker/build.ts",
69
+ "build:worker-metadata": "node --import tsx worker/write-bundle-metadata.ts",
65
70
  "build:lambda": "node lambda/asset-transform/build.mjs",
66
- "build:test-fixtures": "pnpm run build:worker && node lambda/asset-transform/build.mjs --skip-native",
71
+ "build:test-fixtures": "pnpm run build:worker && pnpm run build:worker-metadata && node lambda/asset-transform/build.mjs --skip-native",
67
72
  "lint": "eslint src/ 'lambda/**/*.ts' 'canary/**/*.ts' 'worker/**/*.ts' 'test-support/**/*.ts'",
68
73
  "test": "pnpm run build:test-fixtures && vitest run",
69
74
  "typecheck": "tsc --noEmit && tsc --noEmit -p lambda/tsconfig.json && tsc --noEmit -p canary/tsconfig.json && tsc --noEmit -p worker/tsconfig.json && tsc --noEmit -p test-support/tsconfig.json"
@@ -0,0 +1,81 @@
1
+ [Unit]
2
+ Description=CanopyCMS GitHub gateway
3
+ After=network.target canopy-github.socket
4
+ Requires=canopy-github.socket
5
+ # Mounted before this unit sets up its namespace, so the mount is what
6
+ # InaccessiblePaths= hides.
7
+ RequiresMountsFor=/mnt/efs
8
+ # A boot or prepare() that fails holds its cause for the worker for 60s,
9
+ # then exits 1. Restarting it is how a transient cause recovers, so
10
+ # systemd never gives up on it. systemd 252 has no growing RestartSec
11
+ # (no RestartSteps=); the hold paces it to one attempt every 72s or so.
12
+ StartLimitIntervalSec=0
13
+
14
+ [Service]
15
+ Type=simple
16
+ User=canopy-github
17
+ Group=canopy-github
18
+ WorkingDirectory=/opt/canopy-worker
19
+ ExecStart=/usr/bin/node-22 index.js gateway
20
+ # Descriptor 3, owned by the worker user, so only it and root connect.
21
+ Sockets=canopy-github.socket
22
+ Restart=always
23
+ RestartSec=5
24
+ # Stopping drains: answers new requests "stopping", lets those under way
25
+ # finish for up to 60s, then exits. SIGTERM reaches node only (mixed);
26
+ # a running fetch job is SIGKILLed with the cgroup when node exits.
27
+ KillMode=mixed
28
+ TimeoutStopSec=150
29
+ # File output, not journal: the CloudWatch agent cannot read journald,
30
+ # so it tails this file instead.
31
+ # systemd opens append: targets as root, following symlinks, before it
32
+ # applies the sandbox or drops to User=. So the service must own neither
33
+ # the file nor its directory: one that could swap the file for a symlink
34
+ # would have its output appended to any file on the host as root.
35
+ # Hence no LogsDirectory=, which chowns the directory to User=. Both are
36
+ # created root-owned before the first start (user-data does), since
37
+ # without the directory the start fails with 209/STDOUT. The service
38
+ # writes through the descriptor systemd hands it.
39
+ StandardOutput=append:/var/log/canopy-github/gateway.log
40
+ StandardError=append:/var/log/canopy-github/gateway.log
41
+ # The private GitHub mirror and the per-command credential files. 0700:
42
+ # the default 0755 would let the worker's user read both.
43
+ StateDirectory=canopy-github
44
+ StateDirectoryMode=0700
45
+ # 0640 root:canopy-github: the secrets, unreadable to the worker.
46
+ EnvironmentFile=/opt/canopy-worker/gateway.env
47
+ # What this unit provides; a bundle needing more refuses to start.
48
+ Environment=CANOPYCMS_WORKER_CONTRACT=2
49
+ # Sandbox. Writable: the state dir and a private /tmp. No view of EFS,
50
+ # which the gateway checks at boot, as it checks that cores are not
51
+ # piped to a helper and that its core limit is zero.
52
+ NoNewPrivileges=yes
53
+ ProtectSystem=strict
54
+ ProtectHome=tmpfs
55
+ PrivateTmp=yes
56
+ PrivateDevices=yes
57
+ ProtectProc=invisible
58
+ ProtectKernelTunables=yes
59
+ ProtectKernelModules=yes
60
+ ProtectKernelLogs=yes
61
+ ProtectControlGroups=yes
62
+ ProtectClock=yes
63
+ ProtectHostname=yes
64
+ RestrictNamespaces=yes
65
+ RestrictSUIDSGID=yes
66
+ RestrictRealtime=yes
67
+ LockPersonality=yes
68
+ SystemCallArchitectures=native
69
+ CapabilityBoundingSet=
70
+ InaccessiblePaths=/mnt/efs
71
+ RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 AF_NETLINK
72
+ PrivateIPC=yes
73
+ InaccessiblePaths=-/run/dbus
74
+ InaccessiblePaths=-/dev/shm
75
+ InaccessiblePaths=-/var/log/journal
76
+ InaccessiblePaths=-/run/log/journal
77
+ SystemCallFilter=@system-service
78
+ LimitCORE=0
79
+
80
+ [Install]
81
+ WantedBy=multi-user.target
@@ -0,0 +1,16 @@
1
+ [Unit]
2
+ Description=CanopyCMS GitHub gateway socket
3
+
4
+ [Socket]
5
+ ListenStream=/run/canopy-github/gateway.sock
6
+ # Only the worker user (and root) can connect. The gateway refuses to
7
+ # run as this socket's owner, or with group or other access to it.
8
+ SocketUser=ec2-user
9
+ SocketGroup=ec2-user
10
+ SocketMode=0600
11
+ # Root-owned: systemd chowns the socket by name, following symlinks,
12
+ # which is safe only in a directory nobody else can write.
13
+ DirectoryMode=0755
14
+
15
+ [Install]
16
+ WantedBy=sockets.target
@@ -1,34 +1,95 @@
1
1
  [Unit]
2
2
  Description=CanopyCMS Worker Daemon
3
3
  After=network.target
4
- # Never run against an unmounted workspace filesystem (matches the deployed
5
- # copy of this unit, which cms-service.ts user-data writes with an fstab
6
- # entry for /mnt/efs).
4
+ # Stopped before the gateway, so its drain runs while the gateway is up.
5
+ After=canopy-github.socket canopy-github.service
6
+ Requires=canopy-github.socket
7
+ Wants=canopy-github.service
8
+ # Never run against an unmounted /mnt/efs (user-data adds the fstab entry).
7
9
  RequiresMountsFor=/mnt/efs
8
10
 
9
11
  [Service]
10
12
  Type=simple
11
13
  User=ec2-user
12
14
  WorkingDirectory=/opt/canopy-worker
13
- ExecStart=/usr/bin/node index.js
15
+ # Namespaced binary, not bare `node`: AL2023 points /usr/bin/node at
16
+ # an installed version through `alternatives`, and AWS documents that
17
+ # selection as able to change at any time. node-22 always means 22.
18
+ ExecStart=/usr/bin/node-22 index.js
14
19
  Restart=always
15
20
  RestartSec=5
16
21
  TimeoutStartSec=300
22
+ # Stopping drains: SIGTERM reaches node ONLY (mixed), so the git
23
+ # children it waits for keep running. Whatever is left when node
24
+ # exits, or at TimeoutStopSec, is SIGKILLed; 120s outlasts the 90s
25
+ # drain and its abort grace.
26
+ KillMode=mixed
27
+ TimeoutStopSec=120
28
+ # A worker that drained for an instance termination exits with this;
29
+ # restarting it would start work on an instance about to disappear.
30
+ RestartPreventExitStatus=75
31
+ SuccessExitStatus=75
17
32
  # File output, not journal: the CloudWatch agent cannot read journald,
18
- # so it tails this file instead (agent config lives in the cms-service.ts
19
- # user-data, which writes the deployed copy of this unit).
20
- # CAUTION: /var/log/canopy-worker must exist BEFORE first start. systemd
21
- # opens append: targets before it creates LogsDirectory= dirs
22
- # (systemd#27591), so without the pre-created dir the exec fails with
23
- # 209/STDOUT and Restart=always crash-loops forever. The deployed user-data
24
- # runs mkdir first; do the same if you install this unit by hand.
25
- # LogsDirectory= is kept for ownership management on subsequent starts.
26
- LogsDirectory=canopy-worker
33
+ # so it tails this file instead.
34
+ # systemd opens append: targets as root, following symlinks, before it
35
+ # applies the sandbox or drops to User=. So the service must own neither
36
+ # the file nor its directory: one that could swap the file for a symlink
37
+ # would have its output appended to any file on the host as root.
38
+ # Hence no LogsDirectory=, which chowns the directory to User=. Both are
39
+ # created root-owned before the first start (user-data does), since
40
+ # without the directory the start fails with 209/STDOUT. The service
41
+ # writes through the descriptor systemd hands it.
27
42
  StandardOutput=append:/var/log/canopy-worker/worker.log
28
43
  StandardError=append:/var/log/canopy-worker/worker.log
29
-
30
- # Environment
44
+ # The worker requires it; it holds nothing secret.
45
+ StateDirectory=canopy-worker
31
46
  EnvironmentFile=/opt/canopy-worker/.env
47
+ # What this unit provides; a bundle needing more refuses to start.
48
+ Environment=CANOPYCMS_WORKER_CONTRACT=2
49
+ # The GitHub gateway, its only way to GitHub, the Clerk API and the
50
+ # instance role.
51
+ Environment=CANOPYCMS_GITHUB_GATEWAY_SOCKET=/run/canopy-github/gateway.sock
52
+ # Sandbox. Writable: the workspace, the state dir (StateDirectory=) and a
53
+ # private /tmp.
54
+ # ProtectHome=tmpfs, not yes: every git call reads per-user files under
55
+ # $HOME (~/.config/git/attributes, ignore), and an inaccessible /home
56
+ # makes each read warn "Permission denied"; an empty one is a silent
57
+ # ENOENT. It also hides /run/user, so the worker cannot reach a user
58
+ # manager of an operator logged in as its user.
59
+ # Then the cut: no network but lo, no route to the instance metadata
60
+ # service, only unix sockets, the journal and /dev/shm hidden, and no
61
+ # core dumps. The worker checks at boot that the network cut took
62
+ # effect (only lo, no route to the metadata service), and ProtectProc
63
+ # and ProtectHome.
64
+ NoNewPrivileges=yes
65
+ ProtectSystem=strict
66
+ ProtectHome=tmpfs
67
+ PrivateTmp=yes
68
+ PrivateDevices=yes
69
+ ProtectProc=invisible
70
+ ProtectKernelTunables=yes
71
+ ProtectKernelModules=yes
72
+ ProtectKernelLogs=yes
73
+ ProtectControlGroups=yes
74
+ ProtectClock=yes
75
+ ProtectHostname=yes
76
+ RestrictNamespaces=yes
77
+ RestrictSUIDSGID=yes
78
+ RestrictRealtime=yes
79
+ LockPersonality=yes
80
+ SystemCallArchitectures=native
81
+ CapabilityBoundingSet=
82
+ ReadWritePaths=/mnt/efs
83
+ PrivateNetwork=yes
84
+ IPAddressDeny=any
85
+ RestrictAddressFamilies=AF_UNIX
86
+ PrivateIPC=yes
87
+ InaccessiblePaths=-/run/dbus
88
+ InaccessiblePaths=-/dev/shm
89
+ InaccessiblePaths=-/var/log/journal
90
+ InaccessiblePaths=-/run/log/journal
91
+ SystemCallFilter=@system-service
92
+ LimitCORE=0
32
93
 
33
94
  [Install]
34
95
  WantedBy=multi-user.target