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.
@@ -0,0 +1 @@
1
+ 2
@@ -0,0 +1 @@
1
+ fbba7d902caff4a42500d3e4072acb67a7e4e070cb83115e94f6993d6b90f0b6 index.js
@@ -0,0 +1,365 @@
1
+ set -eu
2
+ cat > canopy-worker.service << 'CANOPYFILEEOF'
3
+ [Unit]
4
+ Description=CanopyCMS Worker Daemon
5
+ After=network.target
6
+ # Stopped before the gateway, so its drain runs while the gateway is up.
7
+ After=canopy-github.socket canopy-github.service
8
+ Requires=canopy-github.socket
9
+ Wants=canopy-github.service
10
+ # Never run against an unmounted /mnt/efs (user-data adds the fstab entry).
11
+ RequiresMountsFor=/mnt/efs
12
+
13
+ [Service]
14
+ Type=simple
15
+ User=ec2-user
16
+ WorkingDirectory=/opt/canopy-worker
17
+ # Namespaced binary, not bare `node`: AL2023 points /usr/bin/node at
18
+ # an installed version through `alternatives`, and AWS documents that
19
+ # selection as able to change at any time. node-22 always means 22.
20
+ ExecStart=/usr/bin/node-22 index.js
21
+ Restart=always
22
+ RestartSec=5
23
+ TimeoutStartSec=300
24
+ # Stopping drains: SIGTERM reaches node ONLY (mixed), so the git
25
+ # children it waits for keep running. Whatever is left when node
26
+ # exits, or at TimeoutStopSec, is SIGKILLed; 120s outlasts the 90s
27
+ # drain and its abort grace.
28
+ KillMode=mixed
29
+ TimeoutStopSec=120
30
+ # A worker that drained for an instance termination exits with this;
31
+ # restarting it would start work on an instance about to disappear.
32
+ RestartPreventExitStatus=75
33
+ SuccessExitStatus=75
34
+ # File output, not journal: the CloudWatch agent cannot read journald,
35
+ # so it tails this file instead.
36
+ # systemd opens append: targets as root, following symlinks, before it
37
+ # applies the sandbox or drops to User=. So the service must own neither
38
+ # the file nor its directory: one that could swap the file for a symlink
39
+ # would have its output appended to any file on the host as root.
40
+ # Hence no LogsDirectory=, which chowns the directory to User=. Both are
41
+ # created root-owned before the first start (user-data does), since
42
+ # without the directory the start fails with 209/STDOUT. The service
43
+ # writes through the descriptor systemd hands it.
44
+ StandardOutput=append:/var/log/canopy-worker/worker.log
45
+ StandardError=append:/var/log/canopy-worker/worker.log
46
+ # The worker requires it; it holds nothing secret.
47
+ StateDirectory=canopy-worker
48
+ EnvironmentFile=/opt/canopy-worker/.env
49
+ # What this unit provides; a bundle needing more refuses to start.
50
+ Environment=CANOPYCMS_WORKER_CONTRACT=2
51
+ # The GitHub gateway, its only way to GitHub, the Clerk API and the
52
+ # instance role.
53
+ Environment=CANOPYCMS_GITHUB_GATEWAY_SOCKET=/run/canopy-github/gateway.sock
54
+ # Sandbox. Writable: the workspace, the state dir (StateDirectory=) and a
55
+ # private /tmp.
56
+ # ProtectHome=tmpfs, not yes: every git call reads per-user files under
57
+ # $HOME (~/.config/git/attributes, ignore), and an inaccessible /home
58
+ # makes each read warn "Permission denied"; an empty one is a silent
59
+ # ENOENT. It also hides /run/user, so the worker cannot reach a user
60
+ # manager of an operator logged in as its user.
61
+ # Then the cut: no network but lo, no route to the instance metadata
62
+ # service, only unix sockets, the journal and /dev/shm hidden, and no
63
+ # core dumps. The worker checks at boot that the network cut took
64
+ # effect (only lo, no route to the metadata service), and ProtectProc
65
+ # and ProtectHome.
66
+ NoNewPrivileges=yes
67
+ ProtectSystem=strict
68
+ ProtectHome=tmpfs
69
+ PrivateTmp=yes
70
+ PrivateDevices=yes
71
+ ProtectProc=invisible
72
+ ProtectKernelTunables=yes
73
+ ProtectKernelModules=yes
74
+ ProtectKernelLogs=yes
75
+ ProtectControlGroups=yes
76
+ ProtectClock=yes
77
+ ProtectHostname=yes
78
+ RestrictNamespaces=yes
79
+ RestrictSUIDSGID=yes
80
+ RestrictRealtime=yes
81
+ LockPersonality=yes
82
+ SystemCallArchitectures=native
83
+ CapabilityBoundingSet=
84
+ ReadWritePaths=/mnt/efs
85
+ PrivateNetwork=yes
86
+ IPAddressDeny=any
87
+ RestrictAddressFamilies=AF_UNIX
88
+ PrivateIPC=yes
89
+ InaccessiblePaths=-/run/dbus
90
+ InaccessiblePaths=-/dev/shm
91
+ InaccessiblePaths=-/var/log/journal
92
+ InaccessiblePaths=-/run/log/journal
93
+ SystemCallFilter=@system-service
94
+ LimitCORE=0
95
+
96
+ [Install]
97
+ WantedBy=multi-user.target
98
+ CANOPYFILEEOF
99
+ cat > canopy-worker-single-process.service << 'CANOPYFILEEOF'
100
+ [Unit]
101
+ Description=CanopyCMS Worker Daemon
102
+ After=network.target
103
+ # Never run against an unmounted /mnt/efs (user-data adds the fstab entry).
104
+ RequiresMountsFor=/mnt/efs
105
+
106
+ [Service]
107
+ Type=simple
108
+ User=ec2-user
109
+ WorkingDirectory=/opt/canopy-worker
110
+ # Namespaced binary, not bare `node`: AL2023 points /usr/bin/node at
111
+ # an installed version through `alternatives`, and AWS documents that
112
+ # selection as able to change at any time. node-22 always means 22.
113
+ ExecStart=/usr/bin/node-22 index.js
114
+ Restart=always
115
+ RestartSec=5
116
+ TimeoutStartSec=300
117
+ # Stopping drains: SIGTERM reaches node ONLY (mixed), so the git
118
+ # children it waits for keep running. Whatever is left when node
119
+ # exits, or at TimeoutStopSec, is SIGKILLed; 120s outlasts the 90s
120
+ # drain and its abort grace.
121
+ KillMode=mixed
122
+ TimeoutStopSec=120
123
+ # A worker that drained for an instance termination exits with this;
124
+ # restarting it would start work on an instance about to disappear.
125
+ RestartPreventExitStatus=75
126
+ SuccessExitStatus=75
127
+ # File output, not journal: the CloudWatch agent cannot read journald,
128
+ # so it tails this file instead.
129
+ # systemd opens append: targets as root, following symlinks, before it
130
+ # applies the sandbox or drops to User=. So the service must own neither
131
+ # the file nor its directory: one that could swap the file for a symlink
132
+ # would have its output appended to any file on the host as root.
133
+ # Hence no LogsDirectory=, which chowns the directory to User=. Both are
134
+ # created root-owned before the first start (user-data does), since
135
+ # without the directory the start fails with 209/STDOUT. The service
136
+ # writes through the descriptor systemd hands it.
137
+ StandardOutput=append:/var/log/canopy-worker/worker.log
138
+ StandardError=append:/var/log/canopy-worker/worker.log
139
+ # The private GitHub mirror, /var/lib/canopy-worker on the root volume:
140
+ # the only git repository the GitHub credential is used in. The worker
141
+ # does not start without it.
142
+ StateDirectory=canopy-worker
143
+ EnvironmentFile=/opt/canopy-worker/.env
144
+ EnvironmentFile=/opt/canopy-worker/gateway.env
145
+ # What this unit provides; a bundle needing more refuses to start.
146
+ Environment=CANOPYCMS_WORKER_CONTRACT=1
147
+ # Sandbox. Writable: the workspace, the state dir (StateDirectory=) and a
148
+ # private /tmp.
149
+ # ProtectHome=tmpfs, not yes: every git call reads per-user files under
150
+ # $HOME (~/.config/git/attributes, ignore), and an inaccessible /home
151
+ # makes each read warn "Permission denied"; an empty one is a silent
152
+ # ENOENT. It also hides /run/user, so the worker cannot reach a user
153
+ # manager of an operator logged in as its user.
154
+ NoNewPrivileges=yes
155
+ ProtectSystem=strict
156
+ ProtectHome=tmpfs
157
+ PrivateTmp=yes
158
+ PrivateDevices=yes
159
+ ProtectProc=invisible
160
+ ProtectKernelTunables=yes
161
+ ProtectKernelModules=yes
162
+ ProtectKernelLogs=yes
163
+ ProtectControlGroups=yes
164
+ ProtectClock=yes
165
+ ProtectHostname=yes
166
+ RestrictNamespaces=yes
167
+ RestrictSUIDSGID=yes
168
+ RestrictRealtime=yes
169
+ LockPersonality=yes
170
+ SystemCallArchitectures=native
171
+ CapabilityBoundingSet=
172
+ ReadWritePaths=/mnt/efs
173
+
174
+ [Install]
175
+ WantedBy=multi-user.target
176
+ CANOPYFILEEOF
177
+ cat > canopy-github.service << 'CANOPYFILEEOF'
178
+ [Unit]
179
+ Description=CanopyCMS GitHub gateway
180
+ After=network.target canopy-github.socket
181
+ Requires=canopy-github.socket
182
+ # Mounted before this unit sets up its namespace, so the mount is what
183
+ # InaccessiblePaths= hides.
184
+ RequiresMountsFor=/mnt/efs
185
+ # A boot or prepare() that fails holds its cause for the worker for 60s,
186
+ # then exits 1. Restarting it is how a transient cause recovers, so
187
+ # systemd never gives up on it. systemd 252 has no growing RestartSec
188
+ # (no RestartSteps=); the hold paces it to one attempt every 72s or so.
189
+ StartLimitIntervalSec=0
190
+
191
+ [Service]
192
+ Type=simple
193
+ User=canopy-github
194
+ Group=canopy-github
195
+ WorkingDirectory=/opt/canopy-worker
196
+ ExecStart=/usr/bin/node-22 index.js gateway
197
+ # Descriptor 3, owned by the worker user, so only it and root connect.
198
+ Sockets=canopy-github.socket
199
+ Restart=always
200
+ RestartSec=5
201
+ # Stopping drains: answers new requests "stopping", lets those under way
202
+ # finish for up to 60s, then exits. SIGTERM reaches node only (mixed);
203
+ # a running fetch job is SIGKILLed with the cgroup when node exits.
204
+ KillMode=mixed
205
+ TimeoutStopSec=150
206
+ # File output, not journal: the CloudWatch agent cannot read journald,
207
+ # so it tails this file instead.
208
+ # systemd opens append: targets as root, following symlinks, before it
209
+ # applies the sandbox or drops to User=. So the service must own neither
210
+ # the file nor its directory: one that could swap the file for a symlink
211
+ # would have its output appended to any file on the host as root.
212
+ # Hence no LogsDirectory=, which chowns the directory to User=. Both are
213
+ # created root-owned before the first start (user-data does), since
214
+ # without the directory the start fails with 209/STDOUT. The service
215
+ # writes through the descriptor systemd hands it.
216
+ StandardOutput=append:/var/log/canopy-github/gateway.log
217
+ StandardError=append:/var/log/canopy-github/gateway.log
218
+ # The private GitHub mirror and the per-command credential files. 0700:
219
+ # the default 0755 would let the worker's user read both.
220
+ StateDirectory=canopy-github
221
+ StateDirectoryMode=0700
222
+ # 0640 root:canopy-github: the secrets, unreadable to the worker.
223
+ EnvironmentFile=/opt/canopy-worker/gateway.env
224
+ # What this unit provides; a bundle needing more refuses to start.
225
+ Environment=CANOPYCMS_WORKER_CONTRACT=2
226
+ # Sandbox. Writable: the state dir and a private /tmp. No view of EFS,
227
+ # which the gateway checks at boot, as it checks that cores are not
228
+ # piped to a helper and that its core limit is zero.
229
+ NoNewPrivileges=yes
230
+ ProtectSystem=strict
231
+ ProtectHome=tmpfs
232
+ PrivateTmp=yes
233
+ PrivateDevices=yes
234
+ ProtectProc=invisible
235
+ ProtectKernelTunables=yes
236
+ ProtectKernelModules=yes
237
+ ProtectKernelLogs=yes
238
+ ProtectControlGroups=yes
239
+ ProtectClock=yes
240
+ ProtectHostname=yes
241
+ RestrictNamespaces=yes
242
+ RestrictSUIDSGID=yes
243
+ RestrictRealtime=yes
244
+ LockPersonality=yes
245
+ SystemCallArchitectures=native
246
+ CapabilityBoundingSet=
247
+ InaccessiblePaths=/mnt/efs
248
+ RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 AF_NETLINK
249
+ PrivateIPC=yes
250
+ InaccessiblePaths=-/run/dbus
251
+ InaccessiblePaths=-/dev/shm
252
+ InaccessiblePaths=-/var/log/journal
253
+ InaccessiblePaths=-/run/log/journal
254
+ SystemCallFilter=@system-service
255
+ LimitCORE=0
256
+
257
+ [Install]
258
+ WantedBy=multi-user.target
259
+ CANOPYFILEEOF
260
+ cat > canopy-github.socket << 'CANOPYFILEEOF'
261
+ [Unit]
262
+ Description=CanopyCMS GitHub gateway socket
263
+
264
+ [Socket]
265
+ ListenStream=/run/canopy-github/gateway.sock
266
+ # Only the worker user (and root) can connect. The gateway refuses to
267
+ # run as this socket's owner, or with group or other access to it.
268
+ SocketUser=ec2-user
269
+ SocketGroup=ec2-user
270
+ SocketMode=0600
271
+ # Root-owned: systemd chowns the socket by name, following symlinks,
272
+ # which is safe only in a directory nobody else can write.
273
+ DirectoryMode=0755
274
+
275
+ [Install]
276
+ WantedBy=sockets.target
277
+ CANOPYFILEEOF
278
+ cat > canopy-inspect << 'CANOPYFILEEOF'
279
+ #!/bin/bash
280
+ # canopy-inspect: run a command on EFS as the worker does, never as root.
281
+ # canopy-inspect <command> [args...]
282
+ # canopy-inspect --interactive
283
+ # Run as root. Each command runs as uid 1000 inside the worker unit's
284
+ # sandbox (no network, no secret), after inspect-checks has proved it.
285
+ set -euo pipefail
286
+ props=(
287
+ -p 'NoNewPrivileges=yes'
288
+ -p 'ProtectSystem=strict'
289
+ -p 'ProtectHome=tmpfs'
290
+ -p 'PrivateTmp=yes'
291
+ -p 'PrivateDevices=yes'
292
+ -p 'ProtectProc=invisible'
293
+ -p 'ProtectKernelTunables=yes'
294
+ -p 'ProtectKernelModules=yes'
295
+ -p 'ProtectKernelLogs=yes'
296
+ -p 'ProtectControlGroups=yes'
297
+ -p 'ProtectClock=yes'
298
+ -p 'ProtectHostname=yes'
299
+ -p 'RestrictNamespaces=yes'
300
+ -p 'RestrictSUIDSGID=yes'
301
+ -p 'RestrictRealtime=yes'
302
+ -p 'LockPersonality=yes'
303
+ -p 'SystemCallArchitectures=native'
304
+ -p 'CapabilityBoundingSet='
305
+ -p 'ReadWritePaths=/mnt/efs'
306
+ -p 'PrivateNetwork=yes'
307
+ -p 'IPAddressDeny=any'
308
+ -p 'RestrictAddressFamilies=AF_UNIX'
309
+ -p 'PrivateIPC=yes'
310
+ -p 'InaccessiblePaths=-/run/dbus'
311
+ -p 'InaccessiblePaths=-/dev/shm'
312
+ -p 'InaccessiblePaths=-/var/log/journal'
313
+ -p 'InaccessiblePaths=-/run/log/journal'
314
+ -p 'SystemCallFilter=@system-service'
315
+ -p 'LimitCORE=0'
316
+ )
317
+ run=(/usr/bin/systemd-run --quiet --wait --collect
318
+ --uid=ec2-user --gid=ec2-user "${props[@]}")
319
+ usage() {
320
+ echo "usage: canopy-inspect <command> [args...] | canopy-inspect --interactive" >&2
321
+ exit 2
322
+ }
323
+ [ "$#" -ge 1 ] || usage
324
+ if [ "$1" = --interactive ]; then
325
+ [ "$#" -eq 1 ] || usage
326
+ echo 'canopy-inspect: this terminal relays escape sequences both ways;' >&2
327
+ echo 'paste nothing from it into a root shell.' >&2
328
+ exec "${run[@]}" --pty -- /opt/canopy-worker/inspect-checks /bin/bash --noprofile --rcfile /opt/canopy-worker/inspect.rc -i
329
+ fi
330
+ # stdin from /dev/null, stderr into stdout, and both through cat -v: the
331
+ # sandbox's output never reaches the terminal raw, and it reads nothing
332
+ # from the operator's.
333
+ "${run[@]}" --pipe -- /opt/canopy-worker/inspect-checks "$@" </dev/null 2>&1 | cat -v
334
+ CANOPYFILEEOF
335
+ cat > inspect-checks << 'CANOPYFILEEOF'
336
+ #!/bin/bash
337
+ # inspect-checks: canopy-inspect's sandbox proves itself, then runs the
338
+ # command. Any failure refuses, and the command never runs.
339
+ set -euo pipefail
340
+ refuse() {
341
+ echo "canopy-inspect: refusing to run: $*" >&2
342
+ exit 1
343
+ }
344
+ /usr/bin/node-22 /opt/canopy-worker/index.js self-check ||
345
+ refuse "the worker's self-checks failed"
346
+ [ "$(id -u)" = 1000 ] || refuse "not running as uid 1000"
347
+ grep -Eq '^NoNewPrivs:[[:space:]]+1$' /proc/self/status ||
348
+ refuse "NoNewPrivileges is not in effect"
349
+ grep -Eq '^Seccomp:[[:space:]]+2$' /proc/self/status || refuse "no seccomp filter"
350
+ # ProtectHome=tmpfs: /run/user is a tmpfs of the sandbox's own, empty, so no
351
+ # operator's user manager is reachable. (systemd 252 mounts it writable.)
352
+ awk '$5 == "/run/user" { for (i = 7; i < NF; i++) if ($i == "-") t = $(i + 1) }
353
+ END { exit t != "tmpfs" }' /proc/self/mountinfo && [ -z "$(ls -A /run/user)" ] ||
354
+ refuse "/run/user is not an empty tmpfs of its own"
355
+ for hidden in /dev/shm /var/log/journal /run/log/journal; do
356
+ if ls "$hidden" >/dev/null 2>&1; then refuse "$hidden is accessible"; fi
357
+ done
358
+ if sudo -n true >/dev/null 2>&1; then refuse "sudo works"; fi
359
+ exec -- "$@"
360
+ CANOPYFILEEOF
361
+ cat > inspect.rc << 'CANOPYFILEEOF'
362
+ # canopy-inspect --interactive's shell. Root-owned, like everything here.
363
+ PS1='canopy-inspect:\w\$ '
364
+ cd /mnt/efs
365
+ CANOPYFILEEOF
@@ -0,0 +1,25 @@
1
+ # /opt/canopy-worker/gateway.env: canopy-github.service's environment, for a hand install.
2
+ # Create it unreadable to the worker's user, before writing to it:
3
+ # install -m 0640 -o root -g canopy-github /dev/null /opt/canopy-worker/gateway.env
4
+ # The worker's own .env carries CANOPYCMS_WORKSPACE_ROOT, CANOPYCMS_GITHUB_OWNER,
5
+ # CANOPYCMS_GITHUB_REPO, CANOPYCMS_DEPLOYMENT_NAME and, when set, CANOPYCMS_BASE_BRANCH and
6
+ # CANOPYCMS_SETTINGS_BRANCH, and nothing secret: the worker refuses to start beside a secret.
7
+ CANOPYCMS_GITHUB_OWNER=your-org
8
+ CANOPYCMS_GITHUB_REPO=your-site
9
+ AWS_REGION=us-east-1
10
+ # The branch the worker syncs; the gateway never pushes it. Set it here and in the worker's .env.
11
+ CANOPYCMS_BASE_BRANCH=main
12
+ # A token, by its Secrets Manager ARN (and the field, for a JSON secret)...
13
+ CANOPYCMS_GITHUB_TOKEN_SECRET_ARN=arn:aws:secretsmanager:us-east-1:123456789012:secret:github-token
14
+ #CANOPYCMS_GITHUB_TOKEN_SECRET_JSON_FIELD=token
15
+ # ...or a GitHub App: all three, and no token.
16
+ #CANOPYCMS_GITHUB_APP_ID=123456
17
+ #CANOPYCMS_GITHUB_APP_INSTALLATION_ID=7890123
18
+ #CANOPYCMS_GITHUB_APP_PRIVATE_KEY_SECRET_ARN=arn:aws:secretsmanager:us-east-1:123456789012:secret:github-app-key
19
+ #CANOPYCMS_GITHUB_APP_PRIVATE_KEY_SECRET_JSON_FIELD=privateKey
20
+ CLERK_SECRET_KEY_SECRET_ARN=arn:aws:secretsmanager:us-east-1:123456789012:secret:clerk-secret-key
21
+ #CLERK_SECRET_KEY_SECRET_JSON_FIELD=secretKey
22
+ # Branches the gateway never pushes, deletes or opens a pull request from: names and `*` globs.
23
+ #CANOPYCMS_PROTECTED_BRANCHES=release/*,production
24
+ # On spot capacity, so the gateway watches for an interruption notice too.
25
+ #CANOPYCMS_WORKER_CAPACITY=spot