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
workflow-secrets.tsx14.0 KB · 411 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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
/**
 * Per-repo workflow secrets — settings UI for listing, creating, and deleting
 * encrypted secrets that are substituted into workflow steps at runtime.
 *
 * Shape mirrors `src/routes/tokens.tsx` + `src/routes/webhooks.tsx`:
 *   - JSX page rendered through Layout + RepoHeader + RepoNav (active=settings).
 *   - Flash state via `?added=NAME | ?deleted=1 | ?error=...` query params.
 *   - Every mutating route is gated on `requireAuth` + `requireRepoAccess("admin")`.
 *
 * The UI never sees plaintext values after upsert — the `listRepoSecrets`
 * helper in `../lib/workflow-secrets` returns metadata only (id, name,
 * createdAt, createdBy). This file's sole job is to render and mutate.
 */

import { Hono } from "hono";
import { eq, inArray } from "drizzle-orm";
import { db } from "../db";
import { users } 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 {
  Container,
  Alert,
  EmptyState,
  Button,
  Text,
  formatRelative,
} from "../views/ui";
import {
  listRepoSecrets,
  upsertRepoSecret,
  deleteRepoSecret,
} from "../lib/workflow-secrets";
import { audit } from "../lib/notify";

const workflowSecretsRoutes = new Hono<AuthEnv>();

workflowSecretsRoutes.use("*", softAuth);

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

/** Sub-nav shown under the main RepoNav for repo settings pages. */
function SettingsSubNav({
  owner,
  repo,
  active,
}: {
  owner: string;
  repo: string;
  active: "general" | "collaborators" | "webhooks" | "secrets";
}) {
  const link = (
    href: string,
    label: string,
    key: "general" | "collaborators" | "webhooks" | "secrets"
  ) => (
    <a
      href={href}
      style={
        "padding: 6px 12px; border-radius: 6px; text-decoration: none; " +
        (active === key
          ? "background: var(--bg-secondary); color: var(--text); font-weight: 600"
          : "color: var(--text-muted)")
      }
    >
      {label}
    </a>
  );
  return (
    <div
      style="display: flex; gap: 4px; margin: 12px 0 20px; padding-bottom: 12px; border-bottom: 1px solid var(--border)"
    >
      {link(`/${owner}/${repo}/settings`, "General", "general")}
      {link(
        `/${owner}/${repo}/settings/collaborators`,
        "Collaborators",
        "collaborators"
      )}
      {link(
        `/${owner}/${repo}/settings/webhooks`,
        "Webhooks",
        "webhooks"
      )}
      {link(
        `/${owner}/${repo}/settings/secrets`,
        "Secrets",
        "secrets"
      )}
    </div>
  );
}

// ─── GET: List + add form ───────────────────────────────────────────────────

workflowSecretsRoutes.get(
  "/:owner/:repo/settings/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;

    const added = c.req.query("added");
    const deleted = c.req.query("deleted");
    const error = c.req.query("error");

    if (!repo) {
      return c.notFound();
    }

    const result = await listRepoSecrets(repo.id);
    const secrets = result.ok ? result.secrets : [];
    const loadError = result.ok ? null : result.error;

    // Resolve createdBy user ids -> usernames for display/linking.
    const creatorIds = Array.from(
      new Set(secrets.map((s) => s.createdBy).filter(Boolean) as string[])
    );
    const creatorRows = creatorIds.length
      ? await db
          .select({ id: users.id, username: users.username })
          .from(users)
          .where(inArray(users.id, creatorIds))
      : [];
    const creatorMap = new Map(creatorRows.map((r) => [r.id, r.username]));

    return c.html(
      <Layout title={`Secrets — ${ownerName}/${repoName}`} user={user}>
        <RepoHeader owner={ownerName} repo={repoName} currentUser={user.username} />
        <RepoNav owner={ownerName} repo={repoName} active="settings" />
        <Container maxWidth={760}>
          <SettingsSubNav
            owner={ownerName}
            repo={repoName}
            active="secrets"
          />

          <h2 style="margin-bottom: 8px">Workflow secrets</h2>
          <Text size={14} muted style="display:block;margin-bottom:20px">
            Secrets are encrypted at rest and only decrypted at workflow
            runtime. They are never printed to logs. Reference them in YAML
            as{" "}
            <code style="font-family: var(--font-mono); background: var(--bg-secondary); padding: 1px 6px; border-radius: 4px">
              {"${{ secrets.NAME }}"}
            </code>
            . Values are write-only — after saving, only the name is
            visible.
          </Text>

          {added && (
            <Alert variant="success">
              Secret <code>{decodeURIComponent(added)}</code> saved.
            </Alert>
          )}
          {deleted && <Alert variant="success">Secret deleted.</Alert>}
          {error && (
            <Alert variant="error">{decodeURIComponent(error)}</Alert>
          )}
          {loadError && (
            <Alert variant="error">
              Could not load secrets: {loadError}
            </Alert>
          )}

          <div class="panel" style="margin-top: 16px; padding: 0; overflow: hidden">
            {secrets.length === 0 ? (
              <div style="padding: 24px">
                <EmptyState>
                  <Text muted>No secrets yet.</Text>
                </EmptyState>
              </div>
            ) : (
              <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)">
                      Name
                    </th>
                    <th style="padding: 10px 14px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted)">
                      Added by
                    </th>
                    <th style="padding: 10px 14px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted)">
                      Added
                    </th>
                    <th style="padding: 10px 14px" />
                  </tr>
                </thead>
                <tbody>
                  {secrets.map((s) => {
                    const creator = s.createdBy
                      ? creatorMap.get(s.createdBy)
                      : null;
                    return (
                      <tr style="border-top: 1px solid var(--border)">
                        <td style="padding: 10px 14px">
                          <code
                            style="font-family: var(--font-mono); font-size: 13px"
                          >
                            {s.name}
                          </code>
                        </td>
                        <td style="padding: 10px 14px; font-size: 13px">
                          {creator ? (
                            <a href={`/${creator}`}>{creator}</a>
                          ) : (
                            <span style="color: var(--text-muted)">
                              unknown
                            </span>
                          )}
                        </td>
                        <td
                          style="padding: 10px 14px; font-size: 13px; color: var(--text-muted)"
                          title={
                            s.createdAt
                              ? new Date(s.createdAt).toISOString()
                              : ""
                          }
                        >
                          {s.createdAt
                            ? formatRelative(s.createdAt)
                            : "—"}
                        </td>
                        <td style="padding: 10px 14px; text-align: right">
                          <form
                            method="post"
                            action={`/${ownerName}/${repoName}/settings/secrets/${s.id}/delete`}
                            style="display: inline"
                            onsubmit={`return confirm('Delete secret ${s.name}?')`}
                          >
                            <Button
                              type="submit"
                              variant="danger"
                              size="sm"
                            >
                              Delete
                            </Button>
                          </form>
                        </td>
                      </tr>
                    );
                  })}
                </tbody>
              </table>
            )}
          </div>

          <h3 style="margin-top: 32px; margin-bottom: 4px">
            Add a new secret
          </h3>
          <Text size={13} muted style="display:block;margin-bottom:12px">
            Names must be uppercase letters, digits, and underscores, and
            cannot start with a digit. Adding a secret with an existing
            name replaces the stored value.
          </Text>
          <form
            method="post"
            action={`/${ownerName}/${repoName}/settings/secrets`}
          >
            <div class="form-group">
              <label for="secret-name">Name</label>
              <input
                type="text"
                id="secret-name"
                name="name"
                required
                pattern="[A-Z_][A-Z0-9_]*"
                maxlength={MAX_NAME_LEN}
                placeholder="DEPLOY_TOKEN"
                autocomplete="off"
                style="font-family: var(--font-mono)"
                title="Uppercase letters, digits, and underscores; cannot start with a digit"
              />
            </div>
            <div class="form-group">
              <label for="secret-value">Value</label>
              <textarea
                id="secret-value"
                name="value"
                required
                rows={4}
                maxlength={MAX_VALUE_LEN}
                placeholder="Paste secret value"
                autocomplete="off"
                spellcheck={false}
                style="width: 100%; font-family: var(--font-mono); font-size: 13px"
              />
            </div>
            <button type="submit" class="btn btn-primary">
              Add secret
            </button>
          </form>
        </Container>
      </Layout>
    );
  }
);

// ─── POST: Create / update ──────────────────────────────────────────────────

workflowSecretsRoutes.post(
  "/:owner/:repo/settings/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 body = await c.req.parseBody();
    const name = String(body.name || "").trim();
    const value = typeof body.value === "string" ? body.value : "";

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

    if (!name) return fail("Name is required");
    if (name.length > MAX_NAME_LEN)
      return fail(`Name must be ≤ ${MAX_NAME_LEN} characters`);
    if (!SECRET_NAME_RE.test(name))
      return fail(
        "Name must be uppercase letters, digits, and underscores, and cannot start with a digit"
      );
    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);

    // Best-effort audit — swallow any error so it never breaks the redirect.
    try {
      await audit({
        userId: user.id,
        repositoryId: repo.id,
        action: "workflow.secret.create",
        targetType: "workflow_secret",
        targetId: result.id,
        metadata: { name },
      });
    } catch {
      // audit() already swallows errors, but guard anyway.
    }

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

// ─── POST: Delete ───────────────────────────────────────────────────────────

workflowSecretsRoutes.post(
  "/:owner/:repo/settings/secrets/:secretId/delete",
  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 secretId = c.req.param("secretId");
    const base = `/${ownerName}/${repoName}/settings/secrets`;

    if (!secretId) {
      return c.redirect(`${base}?error=${encodeURIComponent("Missing secret id")}`);
    }

    const result = await deleteRepoSecret({
      repoId: repo.id,
      secretId,
    });

    if (!result.ok) {
      return c.redirect(
        `${base}?error=${encodeURIComponent(result.error)}`
      );
    }

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

    return c.redirect(`${base}?deleted=1`);
  }
);

export default workflowSecretsRoutes;