Skip to content

Commit bccdbe9

Browse files
carderneTrigger.dev RepoOps
authored andcommitted
feat(webapp): agent vault ux
Mono-RevId: 6016a29ff277d47ef7a9b828b5babb0c4a979ee7
1 parent 90d66c0 commit bccdbe9

20 files changed

Lines changed: 1959 additions & 352 deletions

File tree

‎apps/webapp/app/presenters/v3/EnvironmentVariableKeyPresenter.server.ts‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { effectiveVaultHosts } from "~/services/secretProxy/variables.server";
2+
import { proxyConfigHosts } from "~/services/secretProxy/placeholder.server";
13
import { boundedIn } from "@trigger.dev/database";
24
import type { PrismaClient, PrismaReplicaClient } from "~/db.server";
35
import { $replica, prisma } from "~/db.server";
@@ -25,6 +27,8 @@ const valueSelect = {
2527
lastUpdatedBy: true,
2628
updatedAt: true,
2729
isSecret: true,
30+
isProxyOnly: true,
31+
proxyConfig: true,
2832
} as const;
2933

3034
type ValueRecord = {
@@ -34,6 +38,8 @@ type ValueRecord = {
3438
lastUpdatedBy: unknown;
3539
updatedAt: Date;
3640
isSecret: boolean;
41+
isProxyOnly: boolean;
42+
proxyConfig: unknown;
3743
};
3844

3945
type EnvironmentVariableKeyEnvironment = Pick<
@@ -196,7 +202,18 @@ export class EnvironmentVariableKeyPresenter {
196202
take: branchPageSize,
197203
});
198204

199-
const values: ValueRecord[] = [...environmentValues, ...branchValues];
205+
const vaultHosts = await effectiveVaultHosts(
206+
this.#replicaClient,
207+
[...environmentValues, ...branchValues].map((value) => ({
208+
...value,
209+
variableId: variable.id,
210+
})),
211+
environments
212+
);
213+
// A value in Vault through its parent is as unreadable as one in Vault itself.
214+
const values: ValueRecord[] = [...environmentValues, ...branchValues].map((value) =>
215+
vaultHosts.has(`${variable.id}:${value.environmentId}`) ? { ...value, isSecret: true } : value
216+
);
200217

201218
const repository = new EnvironmentVariablesRepository(this.#prismaClient, this.#replicaClient);
202219
const [{ values: plainValues, unavailableEnvironments }, usersById] = await Promise.all([
@@ -239,6 +256,13 @@ export class EnvironmentVariableKeyPresenter {
239256
value: plainValue,
240257
...(valueUnavailable ? { valueUnavailable: true } : {}),
241258
isSecret: value.isSecret,
259+
...(vaultHosts.has(`${variable.id}:${value.environmentId}`)
260+
? {
261+
vaultHosts: vaultHosts.get(`${variable.id}:${value.environmentId}`)!.hosts,
262+
vaultInherited: vaultHosts.get(`${variable.id}:${value.environmentId}`)!.inherited,
263+
}
264+
: {}),
265+
...(value.isProxyOnly ? { vaultConfiguredHosts: proxyConfigHosts(value.proxyConfig) } : {}),
242266
version: value.version,
243267
lastUpdatedBy,
244268
updatedByUser: user

‎apps/webapp/app/presenters/v3/EnvironmentVariablesPresenter.server.ts‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ import type { RuntimeEnvironmentType } from "@trigger.dev/database";
2626

2727
import { boundedIn, Prisma } from "@trigger.dev/database";
2828
type Result = Awaited<ReturnType<EnvironmentVariablesPresenter["call"]>>;
29+
import { hasAgentVault } from "~/v3/featureFlags";
30+
import { effectiveVaultHosts } from "~/services/secretProxy/variables.server";
31+
import { proxyConfigHosts } from "~/services/secretProxy/placeholder.server";
32+
2933
export type EnvironmentVariableWithSetValues = Result["environmentVariables"][number];
3034

3135
export const DEFAULT_ENV_VARS_PAGE_SIZE = 50;
@@ -79,6 +83,7 @@ export class EnvironmentVariablesPresenter {
7983
const project = await this.#replicaClient.project.findFirst({
8084
select: {
8185
id: true,
86+
secretProxyEnabled: true,
8287
organization: { select: { featureFlags: true } },
8388
},
8489
where: {
@@ -215,6 +220,8 @@ export class EnvironmentVariablesPresenter {
215220
lastUpdatedBy: true,
216221
updatedAt: true,
217222
isSecret: true,
223+
isProxyOnly: true,
224+
proxyConfig: true,
218225
},
219226
where: {
220227
environmentId: {
@@ -275,11 +282,21 @@ export class EnvironmentVariablesPresenter {
275282

276283
const repository = new EnvironmentVariablesRepository(this.#prismaClient, this.#replicaClient);
277284

285+
const vaultHosts = await effectiveVaultHosts(
286+
this.#replicaClient,
287+
environmentVariables.flatMap((variable) =>
288+
variable.values.map((value) => ({ ...value, variableId: variable.id }))
289+
),
290+
listedEnvironments
291+
);
292+
const vaultOf = (variableId: string, environmentId: string) =>
293+
vaultHosts.get(`${variableId}:${environmentId}`);
294+
278295
const nonSecretItems: Array<{ environmentId: string; key: string }> = [];
279296
for (const environmentVariable of environmentVariables) {
280297
for (const env of listedEnvironments) {
281298
const valueRecord = environmentVariable.values.find((v) => v.environmentId === env.id);
282-
if (valueRecord && !valueRecord.isSecret) {
299+
if (valueRecord && !valueRecord.isSecret && !vaultOf(environmentVariable.id, env.id)) {
283300
nonSecretItems.push({ environmentId: env.id, key: environmentVariable.key });
284301
}
285302
}
@@ -302,14 +319,17 @@ export class EnvironmentVariablesPresenter {
302319
}
303320

304321
return {
322+
vaultEnabled: project.secretProxyEnabled,
323+
vaultAvailable: hasAgentVault(project.organization.featureFlags),
305324
allowEmptyEnvironmentVariableValues: await emptyEnvironmentVariableValuesEnabled(
306325
project.organization.featureFlags,
307326
this.#prismaClient
308327
),
309328
environmentVariables: environmentVariables.flatMap((environmentVariable) => {
310329
const rows = listedEnvironments.flatMap((env) => {
311330
const valueRecord = environmentVariable.values.find((v) => v.environmentId === env.id);
312-
const isSecret = valueRecord?.isSecret ?? false;
331+
const vault = vaultOf(environmentVariable.id, env.id);
332+
const isSecret = (valueRecord?.isSecret ?? false) || vault !== undefined;
313333

314334
if (!valueRecord) {
315335
return [];
@@ -348,6 +368,10 @@ export class EnvironmentVariablesPresenter {
348368
value: isSecret || valueUnavailable ? "" : val!,
349369
...(valueUnavailable ? { valueUnavailable: true } : {}),
350370
isSecret,
371+
...(vault ? { vaultHosts: vault.hosts, vaultInherited: vault.inherited } : {}),
372+
...(valueRecord.isProxyOnly
373+
? { vaultConfiguredHosts: proxyConfigHosts(valueRecord.proxyConfig) }
374+
: {}),
351375
version: valueRecord.version,
352376
lastUpdatedBy,
353377
updatedByUser,

‎apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.environment-variables.key.$keyParam/route.tsx‎

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ import {
4747
useEnvironmentVariablesPageData,
4848
type MaskedEnvironmentVariable,
4949
} from "~/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.environment-variables/EnvironmentVariableControls";
50+
import {
51+
EditVaultValueButton,
52+
VaultDomain,
53+
} from "~/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.environment-variables/Vault";
5054
import type { EnvironmentVariablesOutletContext } from "~/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.environment-variables/route";
5155
import { recordDashboardEnvironmentVariableKeyRead } from "~/services/auditLogs/envVarReadAudit.server";
5256
import { resolveProjectAuthScope } from "~/services/projectAuthScope.server";
@@ -349,6 +353,10 @@ export default function Page() {
349353
const oidcEnvironment =
350354
project.environments.find((e) => e.id === oidcEnvironmentId) ?? environment;
351355
const { pagination } = detail.branches;
356+
const vaultRows = [
357+
...detail.environments.flatMap((row) => (row.variable ? [row.variable] : [])),
358+
...detail.branches.variables,
359+
].filter((variable) => variable.vaultHosts);
352360
const branchPagePath = (page: number) => {
353361
const params = new URLSearchParams(location.search);
354362
if (page > 1) {
@@ -566,6 +574,29 @@ export default function Page() {
566574
)}
567575
</Section>
568576
)}
577+
578+
{vaultRows.length > 0 && (
579+
<Section title="Agent Vault">
580+
<Property.Table className="px-3">
581+
{vaultRows.map((variable) => (
582+
<Property.Item key={variable.environment.id}>
583+
<Property.Label className="flex min-w-0 items-center gap-1">
584+
<EnvironmentCombo environment={variable.environment} className="text-sm" />
585+
</Property.Label>
586+
<Property.Value>
587+
<ul className="flex flex-wrap gap-1 py-1">
588+
{variable.vaultHosts?.map((host) => (
589+
<li key={host}>
590+
<VaultDomain host={host} />
591+
</li>
592+
))}
593+
</ul>
594+
</Property.Value>
595+
</Property.Item>
596+
))}
597+
</Property.Table>
598+
</Section>
599+
)}
569600
</>
570601
)}
571602
</div>
@@ -828,14 +859,18 @@ function PanelValue({
828859
<div className={"flex shrink-0 items-center"}>
829860
{!variable.permissionDenied && !isReadOnly && (
830861
<>
831-
<Button
832-
ref={editButtonRef}
833-
type="button"
834-
variant="small-menu-item"
835-
LeadingIcon={PencilSquareIcon}
836-
aria-label={`Edit ${variable.key} in ${environmentFullTitle(variable.environment)}`}
837-
onClick={() => editing.setEditingEnvironmentId(variable.environment.id)}
838-
/>
862+
{variable.vaultHosts ? (
863+
<EditVaultValueButton variable={variable} />
864+
) : (
865+
<Button
866+
ref={editButtonRef}
867+
type="button"
868+
variant="small-menu-item"
869+
LeadingIcon={PencilSquareIcon}
870+
aria-label={`Edit ${variable.key} in ${environmentFullTitle(variable.environment)}`}
871+
onClick={() => editing.setEditingEnvironmentId(variable.environment.id)}
872+
/>
873+
)}
839874
<DeleteEnvironmentVariableButton
840875
variable={variable}
841876
previewBase={counts.previewBase === "set" ? "set" : "unset"}

0 commit comments

Comments
 (0)