secureagentbase 1.4.9 → 1.5.1
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 +17 -4
- package/dist/lib/startup-script.sh +75 -11
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -23,23 +23,36 @@ program
|
|
|
23
23
|
.option('--auto-sa', 'Create service account automatically (skips SA prompt)')
|
|
24
24
|
.option('--no-firebase', 'Skip Firebase setup')
|
|
25
25
|
.option('--billing-account <id>', 'Billing account ID (skips billing prompt)')
|
|
26
|
-
.option('--github-pat <token>', 'GitHub PAT (skips PAT prompt)')
|
|
26
|
+
.option('--github-pat <token>', 'GitHub PAT (skips PAT prompt) — prefer env SECUREAGENTBASE_GITHUB_PAT')
|
|
27
27
|
.option('--repo-name <name>', 'GitHub repo name (requires --github-pat)')
|
|
28
|
-
.option('--discord-token <token>', 'Discord bot token')
|
|
28
|
+
.option('--discord-token <token>', 'Discord bot token — prefer env SECUREAGENTBASE_DISCORD_TOKEN')
|
|
29
29
|
.option('--discord-guild <id>', 'Discord guild ID')
|
|
30
30
|
.option('--vm-zone <zone>', 'VM zone (default: us-central1-a, falls back across regions)')
|
|
31
31
|
.option('--no-vm', 'Skip VM creation')
|
|
32
32
|
.option('-y, --yes', 'Skip all confirmations (non-interactive mode)')
|
|
33
33
|
.action(async (opts) => {
|
|
34
34
|
try {
|
|
35
|
+
// Secrets may be supplied through the environment instead of argv.
|
|
36
|
+
// argv is exposed to `ps`, shell history, and any CI log that echoes
|
|
37
|
+
// the command; environment variables are not, and GitHub Actions masks
|
|
38
|
+
// values it injects as secrets. Explicit flags still win so existing
|
|
39
|
+
// automation is unaffected.
|
|
40
|
+
const githubPat = opts.githubPat || process.env.SECUREAGENTBASE_GITHUB_PAT;
|
|
41
|
+
const discordToken = opts.discordToken || process.env.SECUREAGENTBASE_DISCORD_TOKEN;
|
|
42
|
+
if (opts.githubPat) {
|
|
43
|
+
process.stderr.write('warning: --github-pat is visible in `ps` and shell history; prefer the SECUREAGENTBASE_GITHUB_PAT environment variable.\n');
|
|
44
|
+
}
|
|
45
|
+
if (opts.discordToken) {
|
|
46
|
+
process.stderr.write('warning: --discord-token is visible in `ps` and shell history; prefer the SECUREAGENTBASE_DISCORD_TOKEN environment variable.\n');
|
|
47
|
+
}
|
|
35
48
|
await runInit({
|
|
36
49
|
projectId: opts.projectId,
|
|
37
50
|
autoSa: opts.autoSa,
|
|
38
51
|
firebase: opts.firebase !== false,
|
|
39
52
|
billingAccount: opts.billingAccount,
|
|
40
|
-
githubPat
|
|
53
|
+
githubPat,
|
|
41
54
|
repoName: opts.repoName,
|
|
42
|
-
discordToken
|
|
55
|
+
discordToken,
|
|
43
56
|
discordGuild: opts.discordGuild,
|
|
44
57
|
vmZone: opts.vmZone,
|
|
45
58
|
yes: opts.yes,
|
|
@@ -114,14 +114,59 @@ grep -q '^/swapfile' /proc/swaps 2>/dev/null && echo "Swap enabled: $(grep '^/sw
|
|
|
114
114
|
# repos ship git <= 2.30, which lacks `git add --sparse` — the opencode/kimaki
|
|
115
115
|
# agent snapshot flow fails every session with exit 129: "unknown option 'sparse'".
|
|
116
116
|
# Hardened keyring + sources.list.d pattern, same as the GitHub CLI install below.
|
|
117
|
-
# If the PPA
|
|
117
|
+
# If the PPA key fails verification the repo is never added and default git stays.
|
|
118
|
+
#
|
|
119
|
+
# Pinned key fingerprints. A keyring fetched over HTTPS is unauthenticated at
|
|
120
|
+
# fetch time: whoever controls the endpoint (or the TLS chain to it) could serve
|
|
121
|
+
# a different signing key, and apt would then trust packages signed by it. So
|
|
122
|
+
# every key installed here must match this list, and the whole repository is
|
|
123
|
+
# skipped when it does not — a missing PPA is a harmless downgrade to the
|
|
124
|
+
# distro git, a substituted signing key is root code execution on the VM.
|
|
125
|
+
GITCORE_PPA_FPRS="E1DD270288B4E6030699E45FA1715D88E1DF1F24"
|
|
126
|
+
GITHUB_CLI_FPRS="2C6106201985B60E6C7AC87323F3D4EA75716059 7F38BBB59D064DBCB3D84D725612B36462313325"
|
|
127
|
+
|
|
128
|
+
# Print the fingerprints of the primary keys inside a key or keyring file.
|
|
129
|
+
key_primary_fprs() {
|
|
130
|
+
gpg --show-keys --with-colons "$1" 2>/dev/null | awk -F: '
|
|
131
|
+
/^pub:/ { want = 1; next }
|
|
132
|
+
/^fpr:/ && want { print $10; want = 0 }
|
|
133
|
+
'
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
# Succeed only if the file holds at least one primary key and *every* primary
|
|
137
|
+
# key fingerprint is in the allowlist. Extra keys are rejected rather than
|
|
138
|
+
# ignored: appending a valid-looking key to a genuine keyring would otherwise
|
|
139
|
+
# pass, and apt trusts every key in the signed-by keyring.
|
|
140
|
+
key_fprs_allowlisted() {
|
|
141
|
+
local file="$1"; shift
|
|
142
|
+
local allowed=" $* " f count=0
|
|
143
|
+
while IFS= read -r f; do
|
|
144
|
+
[ -n "$f" ] || continue
|
|
145
|
+
count=$((count + 1))
|
|
146
|
+
case "$allowed" in
|
|
147
|
+
*" $f "*) ;;
|
|
148
|
+
*) return 1 ;;
|
|
149
|
+
esac
|
|
150
|
+
done <<< "$(key_primary_fprs "$file")"
|
|
151
|
+
[ "$count" -gt 0 ]
|
|
152
|
+
}
|
|
153
|
+
|
|
118
154
|
sudo mkdir -p /usr/share/keyrings
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
sudo
|
|
123
|
-
|
|
124
|
-
|
|
155
|
+
GIT_PPA_KEY_TMP=$(mktemp)
|
|
156
|
+
if curl -fsSL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x${GITCORE_PPA_FPRS}" -o "$GIT_PPA_KEY_TMP" 2>/dev/null \
|
|
157
|
+
&& key_fprs_allowlisted "$GIT_PPA_KEY_TMP" $GITCORE_PPA_FPRS; then
|
|
158
|
+
sudo gpg --dearmor -o /usr/share/keyrings/git-core-ppa.gpg < "$GIT_PPA_KEY_TMP" > /dev/null 2>&1 && GIT_PPA_KEY_OK=true
|
|
159
|
+
else
|
|
160
|
+
echo "WARNING: git-core PPA key failed fingerprint verification; skipping PPA"
|
|
161
|
+
fi
|
|
162
|
+
rm -f "$GIT_PPA_KEY_TMP"
|
|
163
|
+
if [ "$GIT_PPA_KEY_OK" = "true" ]; then
|
|
164
|
+
UBUNTU_CODENAME=$(. /etc/os-release && echo "${VERSION_CODENAME:-focal}")
|
|
165
|
+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/git-core-ppa.gpg] https://ppa.launchpadcontent.net/git-core/ppa/ubuntu ${UBUNTU_CODENAME} main" | sudo tee /etc/apt/sources.list.d/git-core-ppa.list > /dev/null 2>&1 || true
|
|
166
|
+
sudo apt-get update -y > /dev/null 2>&1 || true
|
|
167
|
+
# Re-install so apt picks the higher PPA version (upgrades the git from above).
|
|
168
|
+
sudo apt-get install -y git > /dev/null 2>&1 || true
|
|
169
|
+
fi
|
|
125
170
|
|
|
126
171
|
# Fetch secrets from Secret Manager via the metadata-server identity (map #36).
|
|
127
172
|
# No secret values ride in VM metadata; the VM's attached service account holds
|
|
@@ -176,14 +221,29 @@ else
|
|
|
176
221
|
apt-get install -y nodejs > /dev/null 2>&1 || true
|
|
177
222
|
fi
|
|
178
223
|
|
|
179
|
-
# Install GitHub CLI
|
|
180
|
-
type gh >/dev/null 2>&1 ||
|
|
224
|
+
# Install GitHub CLI — keyring fingerprint-checked against GITHUB_CLI_FPRS above
|
|
225
|
+
type gh >/dev/null 2>&1 || {
|
|
226
|
+
GH_KEY_TMP=$(mktemp)
|
|
227
|
+
if curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg -o "$GH_KEY_TMP" 2>/dev/null \
|
|
228
|
+
&& key_fprs_allowlisted "$GH_KEY_TMP" $GITHUB_CLI_FPRS; then
|
|
229
|
+
sudo install -m 0644 "$GH_KEY_TMP" /usr/share/keyrings/githubcli-archive-keyring.gpg
|
|
230
|
+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null 2>&1 || true
|
|
231
|
+
sudo apt-get update -y > /dev/null 2>&1 || true
|
|
232
|
+
sudo apt-get install -y gh > /dev/null 2>&1 || true
|
|
233
|
+
else
|
|
234
|
+
echo "WARNING: GitHub CLI keyring failed fingerprint verification; skipping apt repo"
|
|
235
|
+
fi
|
|
236
|
+
rm -f "$GH_KEY_TMP"
|
|
237
|
+
}
|
|
181
238
|
|
|
182
239
|
# Install Kimaki (skip if already installed — re-running npm -g installs crashes with ENOTEMPTY)
|
|
240
|
+
# Pinned, not @latest: a floating tag meant two VMs provisioned days apart could run
|
|
241
|
+
# different code with no record of which version each got. Bump this deliberately.
|
|
242
|
+
KIMAKI_VERSION="1.4.0"
|
|
183
243
|
if command -v kimaki >/dev/null 2>&1; then
|
|
184
244
|
echo "kimaki already installed, skipping global install"
|
|
185
245
|
else
|
|
186
|
-
npm install -g kimaki
|
|
246
|
+
npm install -g "kimaki@${KIMAKI_VERSION}" > /dev/null 2>&1 || true
|
|
187
247
|
fi
|
|
188
248
|
|
|
189
249
|
# Clone the SecureAgentBase template repository into Kimaki's projects dir
|
|
@@ -550,7 +610,7 @@ done
|
|
|
550
610
|
if command -v kimaki &> /dev/null; then
|
|
551
611
|
KIMAKI_CMD="kimaki"
|
|
552
612
|
else
|
|
553
|
-
KIMAKI_CMD="npx -y kimaki@
|
|
613
|
+
KIMAKI_CMD="npx -y kimaki@__KIMAKI_VERSION__"
|
|
554
614
|
fi
|
|
555
615
|
|
|
556
616
|
echo "$(date): Using KIMAKI_CMD: $KIMAKI_CMD" >> /var/log/kimaki-register.log
|
|
@@ -579,6 +639,10 @@ echo "$(date): Registration failed after 30 attempts" >> /var/log/kimaki-registe
|
|
|
579
639
|
exit 1
|
|
580
640
|
REGISTER_SCRIPT
|
|
581
641
|
|
|
642
|
+
# Resolve the pinned kimaki version into the register script (the heredoc above is
|
|
643
|
+
# single-quoted so it does not expand variables; same pattern as __OPENCODE_MODEL__).
|
|
644
|
+
sed -i "s|__KIMAKI_VERSION__|$KIMAKI_VERSION|" /usr/local/bin/kimaki-register.sh
|
|
645
|
+
|
|
582
646
|
chmod +x /usr/local/bin/kimaki-register.sh
|
|
583
647
|
|
|
584
648
|
# Create project registration service
|