Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
claude/adoring-hopper-5x74bqclaude/affectionate-feynman-ykrf1hclaude/architecture-audit-design-wxprenclaude/build-status-update-3MXsfclaude/charming-meitner-mllb5rclaude/compare-gate-gluecron-s4mFQclaude/confident-faraday-tikcwbclaude/continue-work-XMTlIclaude/crontech-gluecron-deploy-7MIECclaude/crontech-platform-setup-SeKfwclaude/design-2026claude/ecstatic-ptolemy-jMdigclaude/enhance-github-integration-QNHdGclaude/fix-aa-loop-issue-PonMQclaude/fix-actions-and-processclaude/fix-desktop-errors-XqoW8claude/fix-red-workflowsclaude/fix-website-access-6FKJNclaude/gatetest-integration-hardeningclaude/github-audit-improvements-bDFr9claude/gluecron-launch-status-FoMRlclaude/hopeful-lamport-olfCTclaude/issue-to-pr-and-protectionsclaude/jolly-heisenberg-2sg1Qclaude/launch-preparation-QmTb6claude/new-session-xk1l7claude/plan-platform-architecture-kkN4yclaude/platform-analysis-roadmap-1nUGLclaude/platform-launch-assessment-8dWV8claude/polish-platform-release-AeDrUclaude/resume-previous-work-KzyLwclaude/review-crontech-handoff-qYEVqclaude/review-project-completeness-lHhS2claude/review-readme-docs-ulqPKclaude/serene-edison-rj87weclaude/setup-multi-repo-dev-BCwNQclaude/ship-fixes-and-tests-Jvz1cclaude/site-audit-competitive-pctlwgclaude/site-migration-vercel-XstpKclaude/standalone-product-repos-XHFTDcopilot/feat-smart-empty-states-keyboard-first-enhancementcopilot/feat-smart-morning-digest-review-context-restorecopilot/fix-and-process-workflowscopilot/update-ai-powered-code-reviewfeat/debt-mapfeat/push-policy-codeowners-hardeningfeat/smart-digest-contextfeat/stage-impactfeat/t1-secret-migrationfeat/u-polishfeat/w-self-hostfeat/w2-claude-configfix/agent-journey-orphan-sweepgatetest/auto-fix-1776586424172gatetest/auto-fix-1776586534814gatetest/auto-fix-1776590685143gatetest/auto-fix-1776590808199mainops/redeploy-retriggerstyle/dxt-cta-themeworktree-agent-a3377aad30d55da26worktree-agent-a7ef607b7ee1d6c74
import-secrets.tsx14.7 KB · 384 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
/**
 * Block T1 — GitHub Actions secret-migration checklist UI.
 *
 * After a user imports a GitHub repo (see `src/routes/import.tsx`), if their
 * GitHub repo had any Actions secrets we pre-create matching placeholder
 * rows in `workflow_secrets` (via `src/lib/github-secrets-import.ts`) and
 * redirect to `GET /:owner/:repo/import/secrets`. This route renders the
 * one-shot checklist — name + status pill + a password input per row + a
 * "Save" button per row. The Done button always works, even with empty
 * placeholders remaining, because users can come back later via the
 * regular `/settings/secrets` page.
 *
 * Why a separate route from `workflow-secrets.tsx`?
 *   - Different UX shape (vertical checklist vs add-form-on-top table)
 *   - Different copy ("we found N secrets from your GitHub repo")
 *   - Different one-shot lifecycle (cleanup empty placeholders on Done)
 *
 * Empty-vs-filled detection: we decrypt each row and check if plaintext
 * is the empty string. Cheap, accurate, and avoids leaking the "is this
 * a placeholder?" boolean as a database column (which would also force
 * a migration for a feature we shipped behaviourally).
 *
 * CSRF: every POST is guarded by the global `csrfProtect` middleware
 * (see `src/middleware/csrf.ts`); same-origin Origin/Referer check is the
 * primary defence. Each value submission still goes through the existing
 * `upsertRepoSecret` encryption layer — no plaintext storage.
 */

import { Hono } from "hono";
import { and, eq } from "drizzle-orm";
import { db } from "../db";
import { workflowSecrets } from "../db/schema";
import { Layout } from "../views/layout";
import { RepoHeader, RepoNav } from "../views/components";
import { softAuth, requireAuth } from "../middleware/auth";
import type { AuthEnv } from "../middleware/auth";
import { requireRepoAccess } from "../middleware/repo-access";
import { Alert, Container, Text } from "../views/ui";
import { upsertRepoSecret, listRepoSecrets } from "../lib/workflow-secrets";
import { decryptSecret } from "../lib/workflow-secrets-crypto";
import { audit } from "../lib/notify";

const importSecretsRoutes = new Hono<AuthEnv>();

importSecretsRoutes.use("*", softAuth);

const SECRET_NAME_RE = /^[A-Z_][A-Z0-9_]*$/;
const MAX_VALUE_LEN = 32768;

type ChecklistRow = {
  id: string;
  name: string;
  status: "pasted" | "empty";
};

/**
 * Load each secret row for the repo and decrypt it to determine empty
 * (placeholder) vs filled. Returns an empty array on any DB or decrypt
 * failure — the route handler degrades to "no rows" rather than erroring,
 * because this UI is an optional post-import polish step.
 */
async function loadChecklist(repoId: string): Promise<ChecklistRow[]> {
  let rows: { id: string; name: string; encryptedValue: string }[];
  try {
    rows = await db
      .select({
        id: workflowSecrets.id,
        name: workflowSecrets.name,
        encryptedValue: workflowSecrets.encryptedValue,
      })
      .from(workflowSecrets)
      .where(eq(workflowSecrets.repositoryId, repoId));
  } catch {
    return [];
  }

  // Sort: empty placeholders first (so the user works through them), then
  // filled rows alphabetically. Stable within each group.
  const out: ChecklistRow[] = rows.map((r) => {
    const dec = decryptSecret(r.encryptedValue);
    const status: "pasted" | "empty" =
      dec.ok && dec.plaintext === "" ? "empty" : "pasted";
    return { id: r.id, name: r.name, status };
  });
  out.sort((a, b) => {
    if (a.status !== b.status) return a.status === "empty" ? -1 : 1;
    return a.name.localeCompare(b.name);
  });
  return out;
}

// ─── GET: Checklist ─────────────────────────────────────────────────────────

importSecretsRoutes.get(
  "/:owner/:repo/import/secrets",
  requireAuth,
  requireRepoAccess("admin"),
  async (c) => {
    const { owner: ownerName, repo: repoName } = c.req.param();
    const user = c.get("user")!;
    const repo = c.get("repository") as { id: string } | undefined;
    if (!repo) return c.notFound();

    const saved = c.req.query("saved");
    const error = c.req.query("error");

    const rows = await loadChecklist(repo.id);
    const emptyCount = rows.filter((r) => r.status === "empty").length;
    const pastedCount = rows.length - emptyCount;

    // If the repo has zero placeholders at all (e.g. the user came back to
    // this URL after finishing earlier), short-circuit to the regular
    // settings page so they're not stuck on a screen showing no rows.
    if (rows.length === 0) {
      return c.redirect(`/${ownerName}/${repoName}`);
    }

    return c.html(
      <Layout
        title={`Import secrets — ${ownerName}/${repoName}`}
        user={user}
      >
        <RepoHeader owner={ownerName} repo={repoName} currentUser={user.username} />
        <RepoNav owner={ownerName} repo={repoName} active="settings" />
        <Container maxWidth={780}>
          <div
            style="position: sticky; top: 0; background: var(--bg); padding: 20px 0 16px; border-bottom: 1px solid var(--border); margin-bottom: 20px; z-index: 5"
          >
            <h2 style="margin-bottom: 6px">
              Migrate {rows.length} secret{rows.length === 1 ? "" : "s"} from GitHub
            </h2>
            <Text size={14} muted style="display:block;margin-bottom:8px">
              We found {rows.length} Actions secret{rows.length === 1 ? "" : "s"} on
              your GitHub repo. Paste each value below to migrate them.{" "}
              <strong>
                {pastedCount} pasted · {emptyCount} still empty
              </strong>
              .
            </Text>
            <Text size={13} muted style="display:block">
              Need the value? Find it in{" "}
              <code style="font-family: var(--font-mono); background: var(--bg-secondary); padding: 1px 6px; border-radius: 4px">
                github.com/{ownerName}/{repoName}/settings/secrets/actions
              </code>
              {" "}— each value is opaque so you can't read it from GitHub, you'll
              need to copy from wherever you originally created it
              (1Password, .env file, etc.).
            </Text>
          </div>

          {saved && (
            <Alert variant="success">
              Saved <code>{decodeURIComponent(saved)}</code>.
            </Alert>
          )}
          {error && <Alert variant="error">{decodeURIComponent(error)}</Alert>}

          <div
            class="panel"
            style="padding: 0; overflow: hidden; margin-top: 8px"
          >
            <table
              class="file-table"
              style="width: 100%; border-collapse: collapse"
            >
              <thead>
                <tr style="background: var(--bg-secondary); text-align: left">
                  <th style="padding: 10px 14px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); width: 40%">
                    Secret name
                  </th>
                  <th style="padding: 10px 14px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); width: 15%">
                    Status
                  </th>
                  <th style="padding: 10px 14px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted)">
                    Value
                  </th>
                </tr>
              </thead>
              <tbody>
                {rows.map((row) => {
                  const action = `/${ownerName}/${repoName}/import/secrets/${encodeURIComponent(row.name)}`;
                  const pillStyle =
                    row.status === "pasted"
                      ? "background: var(--green-dim, #1f3d2a); color: var(--green, #3fb950); border: 1px solid var(--green, #3fb950)"
                      : "background: var(--yellow-dim, #3d3520); color: var(--yellow, #d29922); border: 1px solid var(--yellow, #d29922)";
                  return (
                    <tr
                      data-secret-row={row.name}
                      style="border-top: 1px solid var(--border); vertical-align: middle"
                    >
                      <td style="padding: 10px 14px">
                        <code style="font-family: var(--font-mono); font-size: 13px">
                          {row.name}
                        </code>
                      </td>
                      <td style="padding: 10px 14px">
                        <span
                          data-status-pill
                          style={
                            "display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 12px; font-weight: 500; " +
                            pillStyle
                          }
                        >
                          {row.status === "pasted" ? "Pasted" : "Empty"}
                        </span>
                      </td>
                      <td style="padding: 10px 14px">
                        <form method="post" action={action} style="display: flex; gap: 8px">
                          <input
                            type="password"
                            name="value"
                            required
                            maxlength={MAX_VALUE_LEN}
                            placeholder={
                              row.status === "pasted"
                                ? "Already savedpaste new value to overwrite"
                                : "Paste value"
                            }
                            autocomplete="off"
                            spellcheck={false}
                            style="flex: 1; font-family: var(--font-mono); font-size: 13px; padding: 6px 10px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text)"
                          />
                          <button
                            type="submit"
                            class="btn btn-primary"
                            style="padding: 6px 14px"
                          >
                            Save
                          </button>
                        </form>
                      </td>
                    </tr>
                  );
                })}
              </tbody>
            </table>
          </div>

          <form
            method="post"
            action={`/${ownerName}/${repoName}/import/secrets/done`}
            style="margin-top: 24px; display: flex; gap: 12px; align-items: center"
          >
            <button type="submit" class="btn btn-primary">
              Done — take me to my repo
            </button>
            <label style="font-size: 13px; color: var(--text-muted); display: flex; align-items: center; gap: 6px">
              <input
                type="checkbox"
                name="cleanup_empty"
                value="1"
              />
              Also delete the {emptyCount} empty placeholder{emptyCount === 1 ? "" : "s"} on my way out
            </label>
          </form>
        </Container>
      </Layout>
    );
  }
);

// ─── POST: Save one value ───────────────────────────────────────────────────

importSecretsRoutes.post(
  "/:owner/:repo/import/secrets/done",
  requireAuth,
  requireRepoAccess("admin"),
  async (c) => {
    const { owner: ownerName, repo: repoName } = c.req.param();
    const user = c.get("user")!;
    const repo = c.get("repository") as { id: string } | undefined;
    if (!repo) return c.notFound();

    const body = await c.req.parseBody();
    const cleanup = String(body.cleanup_empty || "") === "1";

    if (cleanup) {
      try {
        const meta = await listRepoSecrets(repo.id);
        if (meta.ok) {
          // Decrypt each row to find empty placeholders, then delete them
          // by id+repo (defensive scope, same shape as deleteRepoSecret).
          const rows = await db
            .select({
              id: workflowSecrets.id,
              name: workflowSecrets.name,
              encryptedValue: workflowSecrets.encryptedValue,
            })
            .from(workflowSecrets)
            .where(eq(workflowSecrets.repositoryId, repo.id));
          let deleted = 0;
          for (const r of rows) {
            const dec = decryptSecret(r.encryptedValue);
            if (dec.ok && dec.plaintext === "") {
              await db
                .delete(workflowSecrets)
                .where(
                  and(
                    eq(workflowSecrets.id, r.id),
                    eq(workflowSecrets.repositoryId, repo.id)
                  )
                );
              deleted++;
            }
          }
          if (deleted > 0) {
            try {
              await audit({
                userId: user.id,
                repositoryId: repo.id,
                action: "workflow.secret.import_cleanup",
                targetType: "repository",
                targetId: repo.id,
                metadata: { deleted },
              });
            } catch {
              // best-effort
            }
          }
        }
      } catch {
        // Cleanup errors never block the redirect — user can re-run via
        // the regular /settings/secrets UI.
      }
    }

    return c.redirect(`/${ownerName}/${repoName}`);
  }
);

importSecretsRoutes.post(
  "/:owner/:repo/import/secrets/:name",
  requireAuth,
  requireRepoAccess("admin"),
  async (c) => {
    const { owner: ownerName, repo: repoName } = c.req.param();
    const rawName = c.req.param("name");
    const user = c.get("user")!;
    const repo = c.get("repository") as { id: string } | undefined;
    if (!repo) return c.notFound();

    const base = `/${ownerName}/${repoName}/import/secrets`;
    const fail = (msg: string) =>
      c.redirect(`${base}?error=${encodeURIComponent(msg)}`);

    const name = (rawName || "").trim();
    if (!name || !SECRET_NAME_RE.test(name)) {
      return fail("Invalid secret name");
    }

    const body = await c.req.parseBody();
    const value = typeof body.value === "string" ? body.value : "";

    if (!value) return fail("Value is required");
    if (value.length > MAX_VALUE_LEN)
      return fail(`Value must be <= ${MAX_VALUE_LEN} characters`);

    const result = await upsertRepoSecret({
      repoId: repo.id,
      name,
      value,
      createdBy: user.id,
    });

    if (!result.ok) return fail(result.error);

    try {
      await audit({
        userId: user.id,
        repositoryId: repo.id,
        action: "workflow.secret.import_pasted",
        targetType: "workflow_secret",
        targetId: result.id,
        metadata: { name },
      });
    } catch {
      // best-effort
    }

    return c.redirect(`${base}?saved=${encodeURIComponent(name)}`);
  }
);

export default importSecretsRoutes;