@coffre/ui 0.6.1 → 0.7.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.
Files changed (119) hide show
  1. package/dist/chunks/{audit-sentence-CUUMshIp.js → audit-sentence-C1_gRxWW.js} +91 -26
  2. package/dist/chunks/audit-sentence-C1_gRxWW.js.map +1 -0
  3. package/dist/chunks/{connected-apps-DTpatjge.js → connected-apps-Bn5rEoV2.js} +4 -4
  4. package/dist/chunks/{connected-apps-DTpatjge.js.map → connected-apps-Bn5rEoV2.js.map} +1 -1
  5. package/dist/chunks/{delete-place-SOOYVt6A.js → delete-place-CQCDHkne.js} +4 -4
  6. package/dist/chunks/{delete-place-SOOYVt6A.js.map → delete-place-CQCDHkne.js.map} +1 -1
  7. package/dist/chunks/{directory-DrtdKny2.js → directory-BQNOdze_.js} +22 -19
  8. package/dist/chunks/directory-BQNOdze_.js.map +1 -0
  9. package/dist/chunks/{folders-hR2Lnk0k.js → folders-Dw240WMJ.js} +2 -2
  10. package/dist/chunks/{folders-hR2Lnk0k.js.map → folders-Dw240WMJ.js.map} +1 -1
  11. package/dist/chunks/{grants-DDBui9YD.js → grants-CJIBrkod.js} +5 -5
  12. package/dist/chunks/{grants-DDBui9YD.js.map → grants-CJIBrkod.js.map} +1 -1
  13. package/dist/chunks/multi-combobox-CsIXihuc.js +99 -0
  14. package/dist/chunks/multi-combobox-CsIXihuc.js.map +1 -0
  15. package/dist/chunks/{offboarding-C7ECW5o0.js → offboarding-CrgwaetA.js} +4 -4
  16. package/dist/chunks/offboarding-CrgwaetA.js.map +1 -0
  17. package/dist/chunks/personal-tokens-B8rkT-DI.js +138 -0
  18. package/dist/chunks/personal-tokens-B8rkT-DI.js.map +1 -0
  19. package/dist/chunks/{principal-page-CB6dAABC.js → principal-page-DDmmV1KQ.js} +37 -27
  20. package/dist/chunks/principal-page-DDmmV1KQ.js.map +1 -0
  21. package/dist/chunks/{project-page-BHNUvr2L.js → project-page-BI--vjt3.js} +2 -2
  22. package/dist/chunks/{project-page-BHNUvr2L.js.map → project-page-BI--vjt3.js.map} +1 -1
  23. package/dist/chunks/{queries-DgQo3mC-.js → queries-epz4MIuW.js} +103 -18
  24. package/dist/chunks/queries-epz4MIuW.js.map +1 -0
  25. package/dist/chunks/{references-BQc35Q9g.js → references-DImfw0cz.js} +4 -4
  26. package/dist/chunks/{references-BQc35Q9g.js.map → references-DImfw0cz.js.map} +1 -1
  27. package/dist/chunks/{role-field-BfWRCqzl.js → role-field-C1KhNaIR.js} +2 -2
  28. package/dist/chunks/{role-field-BfWRCqzl.js.map → role-field-C1KhNaIR.js.map} +1 -1
  29. package/dist/chunks/{row-state-Zf3kZVhd.js → row-state-BsIHspy4.js} +2 -2
  30. package/dist/chunks/{row-state-Zf3kZVhd.js.map → row-state-BsIHspy4.js.map} +1 -1
  31. package/dist/chunks/{theme-B6-V9JvY.js → theme-3b4DnCow.js} +2 -2
  32. package/dist/chunks/{theme-B6-V9JvY.js.map → theme-3b4DnCow.js.map} +1 -1
  33. package/dist/chunks/{ui-Br-dNUTc.js → ui-2kwXXfrX.js} +95 -22
  34. package/dist/chunks/ui-2kwXXfrX.js.map +1 -0
  35. package/dist/chunks/{use-action-DthL5hL8.js → use-action-BB-RcHo1.js} +2 -2
  36. package/dist/chunks/{use-action-DthL5hL8.js.map → use-action-BB-RcHo1.js.map} +1 -1
  37. package/dist/chunks/{use-change-By4cG8bT.js → use-change-CQyDpCqw.js} +323 -31
  38. package/dist/chunks/use-change-CQyDpCqw.js.map +1 -0
  39. package/dist/chunks/{use-shell-D6kjSPls.js → use-shell-C_NmvCt_.js} +2 -2
  40. package/dist/chunks/{use-shell-D6kjSPls.js.map → use-shell-C_NmvCt_.js.map} +1 -1
  41. package/dist/index.d.ts +46 -164
  42. package/dist/index.js +143 -129
  43. package/dist/index.js.map +1 -1
  44. package/dist/pages/account.d.ts +1 -1
  45. package/dist/pages/account.js +29 -12
  46. package/dist/pages/account.js.map +1 -1
  47. package/dist/pages/approval.js +1 -1
  48. package/dist/pages/audit.js +96 -90
  49. package/dist/pages/audit.js.map +1 -1
  50. package/dist/pages/device-login.js +1 -1
  51. package/dist/pages/environment.js +949 -412
  52. package/dist/pages/environment.js.map +1 -1
  53. package/dist/pages/login.js +2 -2
  54. package/dist/pages/oauth-authorize.js +1 -1
  55. package/dist/pages/project-access.js +9 -9
  56. package/dist/pages/project-access.js.map +1 -1
  57. package/dist/pages/project-environments.js +112 -64
  58. package/dist/pages/project-environments.js.map +1 -1
  59. package/dist/pages/project-settings.d.ts +1 -1
  60. package/dist/pages/project-settings.js +54 -75
  61. package/dist/pages/project-settings.js.map +1 -1
  62. package/dist/pages/project.js +3 -7
  63. package/dist/pages/project.js.map +1 -1
  64. package/dist/pages/projects.js +50 -77
  65. package/dist/pages/projects.js.map +1 -1
  66. package/dist/pages/service-account.js +284 -160
  67. package/dist/pages/service-account.js.map +1 -1
  68. package/dist/pages/service-accounts.js +4 -4
  69. package/dist/pages/settings.js +5 -5
  70. package/dist/pages/unregistered.js +1 -1
  71. package/dist/pages/user.js +5 -5
  72. package/dist/pages/users.js +4 -4
  73. package/package.json +3 -3
  74. package/src/components/actions-log.tsx +3 -2
  75. package/src/components/command-palette.tsx +4 -5
  76. package/src/components/directory.tsx +7 -14
  77. package/src/components/generate-value.tsx +15 -7
  78. package/src/components/missing.tsx +63 -67
  79. package/src/components/offboarding.tsx +1 -1
  80. package/src/components/personal-tokens.tsx +131 -0
  81. package/src/components/principal-page.tsx +30 -17
  82. package/src/components/regenerate.tsx +72 -0
  83. package/src/components/service-tokens.tsx +5 -14
  84. package/src/components/shell.tsx +79 -75
  85. package/src/components/trusted-workloads.tsx +179 -19
  86. package/src/components/ui.tsx +35 -25
  87. package/src/lib/audit-sentences.ts +100 -12
  88. package/src/lib/bindings.ts +41 -3
  89. package/src/lib/changes.ts +215 -29
  90. package/src/lib/clipboard.ts +40 -0
  91. package/src/lib/copy-attempts.ts +103 -0
  92. package/src/lib/dismissal.ts +24 -0
  93. package/src/lib/generate.ts +3 -146
  94. package/src/lib/optimistic.ts +3 -1
  95. package/src/lib/queries.ts +121 -17
  96. package/src/lib/recipes.ts +63 -0
  97. package/src/lib/reveal.ts +7 -1
  98. package/src/lib/row-reads.ts +64 -0
  99. package/src/lib/secret-edit-batch.ts +64 -5
  100. package/src/options.ts +43 -51
  101. package/src/pages/account.tsx +27 -5
  102. package/src/pages/audit.tsx +38 -31
  103. package/src/pages/environment.tsx +655 -121
  104. package/src/pages/project-access.tsx +1 -1
  105. package/src/pages/project-environments.tsx +92 -45
  106. package/src/pages/project-settings.tsx +9 -20
  107. package/src/pages/project.tsx +1 -5
  108. package/src/pages/projects.tsx +13 -28
  109. package/src/parity.ts +20 -4
  110. package/src/styles/globals.css +143 -131
  111. package/dist/chunks/audit-sentence-CUUMshIp.js.map +0 -1
  112. package/dist/chunks/directory-DrtdKny2.js.map +0 -1
  113. package/dist/chunks/offboarding-C7ECW5o0.js.map +0 -1
  114. package/dist/chunks/principal-page-CB6dAABC.js.map +0 -1
  115. package/dist/chunks/project-environments-lEzFHUt4.js +0 -11
  116. package/dist/chunks/project-environments-lEzFHUt4.js.map +0 -1
  117. package/dist/chunks/queries-DgQo3mC-.js.map +0 -1
  118. package/dist/chunks/ui-Br-dNUTc.js.map +0 -1
  119. package/dist/chunks/use-change-By4cG8bT.js.map +0 -1
@@ -0,0 +1,72 @@
1
+ import type { SecretKey } from '@coffre/client';
2
+ import { describeRecipe, parseRecipe, recipeProblem, type Generation } from '@coffre/core/recipe';
3
+
4
+ import { Generate } from './icons';
5
+ import { ConfirmDialog, Tip } from './ui';
6
+
7
+ /** What a generated key's recipe makes, in words; null for one this page does not know. */
8
+ export function recipeInWords(generated: Generation): string | null {
9
+ return recipeProblem(generated.recipe) === null ? describeRecipe(parseRecipe(generated.recipe)) : null;
10
+ }
11
+
12
+ /** Beside a key whose value was generated: how, on hover or focus. */
13
+ export function RecipeMark({ generated }: { generated: Generation }) {
14
+ const label = `Generated: ${recipeInWords(generated) ?? generated.recipe}`;
15
+ return (
16
+ <Tip label={label}>
17
+ <span className="recipe-mark" tabIndex={0} role="img" aria-label={label}>
18
+ <Generate size={12} />
19
+ </span>
20
+ </Tip>
21
+ );
22
+ }
23
+
24
+ /**
25
+ * Asks before regenerating a key by its recipe (`regenerateSecret`, which
26
+ * the row runs on confirm): a new value made in this browser, written as
27
+ * its next version, and never shown. A key pair's either half makes the
28
+ * pair again, both keys in one write, in the environment the page is on.
29
+ */
30
+ export function RegenerateSecret({
31
+ open,
32
+ onOpenChange,
33
+ place,
34
+ entry,
35
+ generated,
36
+ onConfirm,
37
+ }: {
38
+ open: boolean;
39
+ onOpenChange: (open: boolean) => void;
40
+ /** `project/environment`, where it is written. */
41
+ place: string;
42
+ entry: SecretKey;
43
+ generated: Generation;
44
+ onConfirm: () => void;
45
+ }) {
46
+ const made = recipeInWords(generated);
47
+ const body =
48
+ generated.pair === undefined
49
+ ? `A new value, ${made ?? generated.recipe}, is made in this browser and saved as v${(entry.version ?? 0) + 1}. Nobody sees it; whatever reads ${place} gets it from now on.`
50
+ : `A new key pair is made in this browser and saved as ${generated.pair.private} and ${generated.pair.public}, together. Nobody sees it; whatever reads ${place} gets both from now on.`;
51
+ return (
52
+ <ConfirmDialog
53
+ open={open}
54
+ onOpenChange={onOpenChange}
55
+ title={
56
+ <>
57
+ Regenerate <span className="mono">{entry.key}</span>
58
+ {generated.pair !== undefined && ' and its pair'}?
59
+ </>
60
+ }
61
+ body={body}
62
+ detail={
63
+ <p className="hint">
64
+ Recipe <span className="mono">{generated.recipe}</span>
65
+ {generated.pair !== undefined && made !== null && <>: {made}</>}
66
+ </p>
67
+ }
68
+ confirmLabel="Regenerate"
69
+ onConfirm={onConfirm}
70
+ />
71
+ );
72
+ }
@@ -1,4 +1,4 @@
1
- import type { ServiceTokenRow } from '@coffre/client';
1
+ import type { TokenRow } from '@coffre/client';
2
2
  import { credentialScopeInWords } from '@coffre/core/access';
3
3
  import { Fragment, useState } from 'react';
4
4
  import { revokeCredential } from '../lib/changes';
@@ -19,25 +19,16 @@ const LIFETIMES = [30, 90, 180, 365] as const;
19
19
  * OIDC. A value exists in exactly
20
20
  * one place, this dialog, for as long as it stays open: coffre keeps a hash.
21
21
  */
22
- export function ServiceTokens({ serviceId, tokens, grants }: { serviceId: string; tokens: ServiceTokenRow[]; grants: HeldGrant[] }) {
23
- const change = revokeCredential(useCoffre(), serviceId);
22
+ export function ServiceTokens({ serviceId, tokens, grants }: { serviceId: string; tokens: TokenRow[]; grants: HeldGrant[] }) {
23
+ const change = revokeCredential(useCoffre(), memberRef('service', serviceId));
24
24
  const revoke = useChange(change);
25
25
  const { status, dismiss } = useChangeStatus(change.list.queryKey);
26
26
 
27
27
  return (
28
28
  <>
29
- <Card
30
- labelledBy="service-tokens"
31
- title="Bearer tokens"
32
- description={
33
- <>
34
- A long-lived secret, for CI that can't use OIDC. For example, a cron job on your own server runs{' '}
35
- <span className="mono nowrap">coffre login &lt;url&gt; --token</span> with one. coffre shows it once.
36
- </>
37
- }
38
- >
29
+ <Card labelledBy="service-tokens" title="Bearer tokens">
39
30
  {tokens.length === 0 ? (
40
- <EmptyState title="No bearer tokens">CI that signs in with OIDC needs none.</EmptyState>
31
+ <EmptyState title="No bearer tokens" />
41
32
  ) : (
42
33
  <div className="dt-wrap">
43
34
  <table className="dt">
@@ -5,7 +5,7 @@ import {
5
5
  type ReactElement,
6
6
  type ReactNode,
7
7
  } from 'react';
8
- import { Link, useNavigate, useRouterState } from '@tanstack/react-router';
8
+ import { Link, useRouterState } from '@tanstack/react-router';
9
9
  import { Dialog } from '@base-ui/react/dialog';
10
10
  import { Menu } from '@base-ui/react/menu';
11
11
  import { INSTANCE_ROLES } from '@coffre/core/access';
@@ -410,7 +410,7 @@ function Breadcrumbs({
410
410
  </span>
411
411
  <span className="crumb">
412
412
  <span className="crumb-link" aria-current="page">
413
- <span>{projectSlug}</span>
413
+ <span className="crumb-name">{projectSlug}</span>
414
414
  </span>
415
415
  </span>
416
416
  </nav>
@@ -419,7 +419,8 @@ function Breadcrumbs({
419
419
 
420
420
  if (section !== 'projects' || projectSlug === undefined) return null;
421
421
 
422
- const active = projects.filter((project) => project.archivedAt === null);
422
+ // The active projects, and this one even archived: its page is its entry in the list.
423
+ const listed = projects.filter((project) => project.archivedAt === null || project.slug === projectSlug);
423
424
  const project = projects.find((entry) => entry.slug === projectSlug);
424
425
 
425
426
  return (
@@ -431,7 +432,7 @@ function Breadcrumbs({
431
432
  <span className="crumb-sep" aria-hidden>
432
433
  /
433
434
  </span>
434
- <ProjectCrumb slug={projectSlug} current={environmentSlug === undefined} projects={active} />
435
+ <ProjectCrumb slug={projectSlug} current={environmentSlug === undefined} projects={listed} />
435
436
 
436
437
  {environmentSlug !== undefined && (
437
438
  <>
@@ -449,6 +450,11 @@ function Breadcrumbs({
449
450
  );
450
451
  }
451
452
 
453
+ /**
454
+ * The project you are in, one button that lists every project. Its own
455
+ * page, all its environments, is the current one in that list. Each entry
456
+ * is a link, so the router fetches its page as it is pointed at or focused.
457
+ */
452
458
  function ProjectCrumb({
453
459
  slug,
454
460
  current,
@@ -458,46 +464,39 @@ function ProjectCrumb({
458
464
  current: boolean;
459
465
  projects: ProjectSummary[];
460
466
  }) {
461
- const navigate = useNavigate();
462
467
  return (
463
- <span className="crumb">
464
- <Link
465
- className="crumb-link"
466
- to="/projects/$project"
467
- params={{ project: slug }}
468
+ <Menu.Root>
469
+ <Menu.Trigger
470
+ className="crumb-link crumb-switch crumb-project"
471
+ aria-label={`${slug}, switch project`}
468
472
  aria-current={current ? 'page' : undefined}
469
473
  >
470
474
  <Tile name={slug} />
471
- <span className="crumb-project-name">{slug}</span>
472
- </Link>
473
- <Menu.Root>
474
- <Menu.Trigger className="crumb-switch" aria-label="Switch project">
475
- <ChevronsUpDown size={14} />
476
- </Menu.Trigger>
477
- <MenuPopup align="start">
478
- <Menu.Group>
479
- <Menu.GroupLabel className="menu-label">Projects</Menu.GroupLabel>
480
- {projects.map((project) => (
481
- <Menu.Item
482
- key={project.slug}
483
- className="menu-item"
484
- onClick={() =>
485
- navigate({ to: '/projects/$project', params: { project: project.slug } })
486
- }
487
- >
488
- <Tile name={project.slug} />
489
- {project.slug}
490
- <span className="menu-hint">{project.name}</span>
491
- {project.slug === slug && <Check size={14} className="menu-check" />}
492
- </Menu.Item>
493
- ))}
494
- </Menu.Group>
495
- </MenuPopup>
496
- </Menu.Root>
497
- </span>
475
+ <span className="crumb-name crumb-project-name">{slug}</span>
476
+ <ChevronsUpDown size={14} className="crumb-chevron" />
477
+ </Menu.Trigger>
478
+ <MenuPopup align="start">
479
+ <Menu.Group>
480
+ <Menu.GroupLabel className="menu-label">Projects</Menu.GroupLabel>
481
+ {projects.map((project) => (
482
+ <Menu.LinkItem
483
+ key={project.slug}
484
+ className="menu-item"
485
+ closeOnClick
486
+ render={<Link to="/projects/$project" params={{ project: project.slug }} />}
487
+ >
488
+ <Tile name={project.slug} />
489
+ {project.slug}
490
+ {project.slug === slug && <Check size={14} className="menu-check" />}
491
+ </Menu.LinkItem>
492
+ ))}
493
+ </Menu.Group>
494
+ </MenuPopup>
495
+ </Menu.Root>
498
496
  );
499
497
  }
500
498
 
499
+ /** The environment you are in, one button that lists its siblings you can open, as links like the project's. */
501
500
  function EnvironmentCrumb({
502
501
  projectSlug,
503
502
  slug,
@@ -507,45 +506,50 @@ function EnvironmentCrumb({
507
506
  slug: string;
508
507
  environments: ProjectSummary['environments'];
509
508
  }) {
510
- const navigate = useNavigate();
511
- return (
512
- <span className="crumb">
509
+ if (environments.length === 0) {
510
+ return (
513
511
  <span className="crumb-link" aria-current="page">
514
- <span>{slug}</span>
512
+ <span className="crumb-name">{slug}</span>
515
513
  </span>
516
- {environments.length > 0 && (
517
- <Menu.Root>
518
- <Menu.Trigger className="crumb-switch" aria-label="Switch environment">
519
- <ChevronsUpDown size={14} />
520
- </Menu.Trigger>
521
- <MenuPopup align="start">
522
- <Menu.Group>
523
- <Menu.GroupLabel className="menu-label">
524
- Environments in {projectSlug}
525
- </Menu.GroupLabel>
526
- {environments.map((environment) => (
527
- <Menu.Item
528
- key={environment.slug}
529
- className="menu-item"
530
- onClick={() =>
531
- navigate({
532
- to: '/projects/$project/$environment',
533
- params: { project: projectSlug, environment: environment.slug },
534
- })
535
- }
536
- >
537
- <span className="mono">{environment.slug}</span>
538
- <span className="menu-hint">
539
- {environment.details?.secretCount ?? 0} secret
540
- {environment.details?.secretCount === 1 ? '' : 's'}
541
- </span>
542
- {environment.slug === slug && <Check size={14} className="menu-check" />}
543
- </Menu.Item>
544
- ))}
545
- </Menu.Group>
546
- </MenuPopup>
547
- </Menu.Root>
548
- )}
549
- </span>
514
+ );
515
+ }
516
+ return (
517
+ <Menu.Root>
518
+ <Menu.Trigger
519
+ className="crumb-link crumb-switch"
520
+ aria-label={`${slug}, switch environment`}
521
+ aria-current="page"
522
+ >
523
+ <span className="crumb-name">{slug}</span>
524
+ <ChevronsUpDown size={14} className="crumb-chevron" />
525
+ </Menu.Trigger>
526
+ <MenuPopup align="start">
527
+ <Menu.Group>
528
+ <Menu.GroupLabel className="menu-label">
529
+ Environments in {projectSlug}
530
+ </Menu.GroupLabel>
531
+ {environments.map((environment) => (
532
+ <Menu.LinkItem
533
+ key={environment.slug}
534
+ className="menu-item"
535
+ closeOnClick
536
+ render={
537
+ <Link
538
+ to="/projects/$project/$environment"
539
+ params={{ project: projectSlug, environment: environment.slug }}
540
+ />
541
+ }
542
+ >
543
+ <span className="mono">{environment.slug}</span>
544
+ <span className="menu-hint">
545
+ {environment.details?.secretCount ?? 0} secret
546
+ {environment.details?.secretCount === 1 ? '' : 's'}
547
+ </span>
548
+ {environment.slug === slug && <Check size={14} className="menu-check" />}
549
+ </Menu.LinkItem>
550
+ ))}
551
+ </Menu.Group>
552
+ </MenuPopup>
553
+ </Menu.Root>
550
554
  );
551
555
  }
@@ -1,9 +1,25 @@
1
- import type { BindingPlan, BindingView, CoffreClient } from '@coffre/client';
1
+ import type { BindingPlan, BindingView, CoffreClient, KeysPlan } from '@coffre/client';
2
2
  import { credentialScopeInWords } from '@coffre/core/access';
3
3
  import { claimValues, EVENT_EXPOSURE, githubEventsAt, GITLAB_PIPELINE_SOURCES } from '@coffre/core/workloads';
4
4
  import { useQuery } from '@tanstack/react-query';
5
5
  import { Fragment, useEffect, useState } from 'react';
6
- import { askedScope, bindingOf, EMPTY_FORM, githubTarget, listedIds, listingGap, planned, summary, type Form, type GitHubLookup, type RefKind, type ScopeChoice } from '../lib/bindings';
6
+ import {
7
+ askedScope,
8
+ bindingOf,
9
+ EMPTY_FORM,
10
+ githubTarget,
11
+ keySetOf,
12
+ keysOf,
13
+ listedIds,
14
+ listingGap,
15
+ planned,
16
+ summary,
17
+ type Form,
18
+ type GitHubLookup,
19
+ type KeySet,
20
+ type RefKind,
21
+ type ScopeChoice,
22
+ } from '../lib/bindings';
7
23
  import { removeBinding } from '../lib/changes';
8
24
  import { memberRef, statusOf, useCoffre } from '../lib/coffre';
9
25
  import { affects, queries } from '../lib/queries';
@@ -16,7 +32,7 @@ import { RowFailure, RowPending, rowClass } from './row-state';
16
32
  import { Card } from './page';
17
33
  import { ScopePicker, wholeScope, type HeldGrant } from './scope-picker';
18
34
  import { ConfirmButton, EmptyState, ErrorLine, Modal, Notice, Spinner, Timestamp } from './ui';
19
- import { CheckCircle, GitHub, Link, Plus, X } from './icons';
35
+ import { CheckCircle, GitHub, Key, Link, Plus, X } from './icons';
20
36
 
21
37
  /**
22
38
  * The CI runs that may sign in as a service, by the ID token their platform
@@ -31,18 +47,9 @@ export function TrustedWorkloads({ serviceId, bindings, grants }: { serviceId: s
31
47
 
32
48
  return (
33
49
  <>
34
- <Card
35
- labelledBy="trusted-workloads"
36
- title="Sign in with OIDC"
37
- description={
38
- <>
39
- A CI run signs in with the ID token GitHub Actions or GitLab gives it, so there is no secret to store. For example,{' '}
40
- <span className="mono">deploy.yml</span> in <span className="mono">acme/api</span>, on pushes to <span className="mono">main</span>.
41
- </>
42
- }
43
- >
50
+ <Card labelledBy="trusted-workloads" title="Sign in with OIDC">
44
51
  {bindings.length === 0 ? (
45
- <EmptyState title="No trust bindings">Trust a workflow to let its runs sign in.</EmptyState>
52
+ <EmptyState title="No trust bindings" />
46
53
  ) : (
47
54
  <div className="dt-wrap">
48
55
  <table className="dt">
@@ -73,6 +80,7 @@ export function TrustedWorkloads({ serviceId, bindings, grants }: { serviceId: s
73
80
  <details className="claims">
74
81
  <summary>Claims</summary>
75
82
  <Claims binding={binding} />
83
+ {binding.keys !== null && <ReplaceKeys serviceId={serviceId} issuer={binding.issuer} bindings={bindings} />}
76
84
  </details>
77
85
  </span>
78
86
  </span>
@@ -136,7 +144,7 @@ export function TrustedWorkloads({ serviceId, bindings, grants }: { serviceId: s
136
144
  );
137
145
  }
138
146
 
139
- function Claims({ binding }: { binding: Pick<BindingPlan, 'issuer' | 'jwksUri' | 'claims'> }) {
147
+ function Claims({ binding }: { binding: Pick<BindingPlan, 'issuer' | 'jwksUri' | 'keys' | 'claims'> }) {
140
148
  return (
141
149
  <table className="claims-table">
142
150
  <tbody>
@@ -152,13 +160,136 @@ function Claims({ binding }: { binding: Pick<BindingPlan, 'issuer' | 'jwksUri' |
152
160
  ))}
153
161
  <tr>
154
162
  <th>keys</th>
155
- <td className="mono">{binding.jwksUri}</td>
163
+ <td className="mono">{keysOf(binding)}</td>
156
164
  </tr>
157
165
  </tbody>
158
166
  </table>
159
167
  );
160
168
  }
161
169
 
170
+ /**
171
+ * New keys, pasted, for the service's bindings on an issuer whose keys they
172
+ * carry: when the issuer rotates its keys. Each binding is replaced by one
173
+ * the same but for them, as the review says before anything is saved.
174
+ */
175
+ function ReplaceKeys({ serviceId, issuer, bindings }: { serviceId: string; issuer: string; bindings: BindingView[] }) {
176
+ const [open, setOpen] = useState(false);
177
+ const [text, setText] = useState('');
178
+ // The plan, with the keys it was made for: Save sends those, whatever the field says by then.
179
+ const [preview, setPreview] = useState<{ plan: KeysPlan; jwks: KeySet } | null>(null);
180
+ const plan = preview?.plan ?? null;
181
+ const coffre = useCoffre();
182
+ const member = memberRef('service', serviceId);
183
+ const { pending, error, setError, run } = useAction();
184
+ const on = bindings.filter((binding) => binding.issuer === issuer).length;
185
+
186
+ function close() {
187
+ setOpen(false);
188
+ setText('');
189
+ setPreview(null);
190
+ setError(null);
191
+ }
192
+
193
+ function review() {
194
+ let jwks: KeySet;
195
+ try {
196
+ const pasted = keySetOf(text);
197
+ if (pasted === undefined) throw new Error("Paste the issuer's key set");
198
+ jwks = pasted;
199
+ } catch (problem) {
200
+ setError((problem as Error).message);
201
+ return;
202
+ }
203
+ void run(() => coffre.bindings.previewKeys(member, { issuer, jwks }), { affects: [], onSuccess: (next) => setPreview({ plan: next, jwks }) });
204
+ }
205
+
206
+ return (
207
+ <>
208
+ <button className="act" type="button" onClick={() => setOpen(true)}>
209
+ <Key size={13} />
210
+ Replace keys
211
+ </button>
212
+ <Modal open={open} onOpenChange={(next) => (next ? setOpen(true) : close())} title={preview === null ? 'Replace keys' : 'Review the keys'}>
213
+ {preview === null || plan === null ? (
214
+ <form
215
+ className="form"
216
+ onSubmit={(event) => {
217
+ event.preventDefault();
218
+ review();
219
+ }}
220
+ >
221
+ <p>
222
+ The {on === 1 ? 'binding' : `${on} bindings`} of <span className="mono">service:{serviceId}</span> on{' '}
223
+ <span className="mono">{issuer}</span> will verify tokens with these keys alone. While the issuer rotates, paste a set that
224
+ holds the old key and the new, and tokens signed with either sign in.
225
+ </p>
226
+ <label className="field">
227
+ <span className="label">Keys</span>
228
+ <textarea
229
+ className="input mono"
230
+ rows={6}
231
+ value={text}
232
+ spellCheck={false}
233
+ placeholder='{ "keys": [ … ] }'
234
+ onChange={(event) => {
235
+ setText(event.target.value);
236
+ setError(null);
237
+ }}
238
+ />
239
+ <span className="hint">
240
+ From a Kubernetes cluster: <span className="mono">kubectl get --raw /openid/v1/jwks</span>
241
+ </span>
242
+ </label>
243
+ <ErrorLine error={error} />
244
+ <div className="dialog-actions">
245
+ <button className="btn" type="button" onClick={close}>
246
+ Cancel
247
+ </button>
248
+ <button className="btn btn-primary" type="submit" disabled={pending}>
249
+ {pending && <Spinner />}
250
+ Review
251
+ </button>
252
+ </div>
253
+ </form>
254
+ ) : (
255
+ <div className="form">
256
+ <p>
257
+ {plan.replaces.length === 1 ? 'Its binding' : `Its ${plan.replaces.length} bindings`} on <span className="mono">{issuer}</span>{' '}
258
+ {plan.replaces.length === 1 ? 'is' : 'are'} replaced by {plan.replaces.length === 1 ? 'one' : 'ones'} the same but for these keys.
259
+ Credentials {plan.replaces.length === 1 ? 'it' : 'they'} issued, five minutes each at most, end at once.
260
+ </p>
261
+ <table className="claims-table">
262
+ <tbody>
263
+ {plan.keys.map((key) => (
264
+ <tr key={key.thumbprint}>
265
+ <th className="mono">{key.alg}</th>
266
+ <td className="mono">{key.kid ?? key.thumbprint}</td>
267
+ </tr>
268
+ ))}
269
+ </tbody>
270
+ </table>
271
+ <ErrorLine error={error} />
272
+ <div className="dialog-actions">
273
+ <button className="btn" type="button" onClick={() => setPreview(null)}>
274
+ Back
275
+ </button>
276
+ <button
277
+ className="btn btn-primary"
278
+ type="button"
279
+ disabled={pending}
280
+ onClick={() => void run(() => coffre.bindings.replaceKeys(member, { issuer, jwks: preview.jwks }), { affects: affects.bindings(member), onSuccess: close })}
281
+ >
282
+ {pending && <Spinner />}
283
+ Save keys
284
+ </button>
285
+ </div>
286
+ </div>
287
+ )}
288
+ </Modal>
289
+ </>
290
+ );
291
+ }
292
+
162
293
  /** Beside `pull_request` and `workflow_run` in the events' list: they run code nobody reviewed, said in full once chosen. */
163
294
  function exposureNote(event: string) {
164
295
  return EVENT_EXPOSURE[event] === undefined ? null : <span className="tag tag-amber">unreviewed code</span>;
@@ -259,6 +390,8 @@ function TrustWorkload({ serviceId, grants, bindings }: { serviceId: string; gra
259
390
  const whole = (): ScopeChoice => ({ scope: wholeScope(grants), chosen: false });
260
391
  const [choice, setChoice] = useState(whole);
261
392
  const [plan, setPlan] = useState<BindingPlan | null>(null);
393
+ // What the plan was made from: Save sends it, whatever the form says by then.
394
+ const [reviewed, setReviewed] = useState<ReturnType<typeof input> | null>(null);
262
395
  const coffre = useCoffre();
263
396
  const member = memberRef('service', serviceId);
264
397
  const { pending, error, setError, run } = useAction();
@@ -302,6 +435,7 @@ function TrustWorkload({ serviceId, grants, bindings }: { serviceId: string; gra
302
435
  // One that replaces bindings reaches what they did unless told: the picker says so, should the person go back.
303
436
  onSuccess: (next) => {
304
437
  setPlan(next);
438
+ setReviewed(request);
305
439
  setChoice((current) => planned(current, next));
306
440
  },
307
441
  });
@@ -503,11 +637,37 @@ function TrustWorkload({ serviceId, grants, bindings }: { serviceId: string; gra
503
637
 
504
638
  {form.platform === 'other' && (
505
639
  <>
506
- {field('Issuer', 'issuer', { placeholder: 'https://accounts.google.com' })}
640
+ {field('Issuer', 'issuer', {
641
+ placeholder: 'https://accounts.google.com',
642
+ hint: form.jwks.trim() === '' ? undefined : 'Exactly as its tokens name it in iss: with its keys pasted below, coffre asks it nothing.',
643
+ })}
507
644
  {field('Subject (sub)', 'sub', { mono: true, hint: "You vouch for what this issuer's subject means: a Google service account's unique ID, say." })}
508
645
  <label className="field">
509
646
  <span className="label">Other claims, one <span className="mono">name=value</span> a line</span>
510
- <textarea className="input mono" rows={3} value={form.extra} onChange={(event) => set({ extra: event.target.value })} />
647
+ <textarea
648
+ className="input mono"
649
+ rows={3}
650
+ value={form.extra}
651
+ spellCheck={false}
652
+ placeholder="kubernetes.io.serviceaccount.uid=…"
653
+ onChange={(event) => set({ extra: event.target.value })}
654
+ />
655
+ <span className="hint">A nested claim goes by its path, its names joined by dots.</span>
656
+ </label>
657
+ <label className="field">
658
+ <span className="label">Keys (optional)</span>
659
+ <textarea
660
+ className="input mono"
661
+ rows={3}
662
+ value={form.jwks}
663
+ spellCheck={false}
664
+ placeholder='{ "keys": [ … ] }'
665
+ onChange={(event) => set({ jwks: event.target.value })}
666
+ />
667
+ <span className="hint">
668
+ Left empty, coffre fetches the issuer's keys. Paste them for one it cannot reach, such as a private Kubernetes cluster:{' '}
669
+ <span className="mono">kubectl get --raw /openid/v1/jwks</span>
670
+ </span>
511
671
  </label>
512
672
  </>
513
673
  )}
@@ -557,7 +717,7 @@ function TrustWorkload({ serviceId, grants, bindings }: { serviceId: string; gra
557
717
  type="button"
558
718
  disabled={pending}
559
719
  // What the review said it reaches, whatever the account holds by now.
560
- onClick={() => void run(() => coffre.bindings.create(member, { ...input(), scope: plan.scope }), { affects: affects.bindings(member), onSuccess: close })}
720
+ onClick={() => void run(() => coffre.bindings.create(member, { ...reviewed!, scope: plan.scope }), { affects: affects.bindings(member), onSuccess: close })}
561
721
  >
562
722
  {pending && <Spinner />}
563
723
  Save binding