Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.8k
fix(workflows): redact run and export secrets#6591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0146274
fix(workflows): redact run and export secrets
TheodoreSpeaks e92b6ab
fix(workflows): preserve redacted run outputs
TheodoreSpeaks 2936dfc
fix(workflows): retain safe trace output fallback
TheodoreSpeaks 08c27c3
fix(workflows): stop deriving outputs from traces
TheodoreSpeaks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3,6 +3,7 @@ import { toError } from '@sim/utils/errors' | ||
| import { omit } from '@sim/utils/object' | ||
| import { isLargeValueRef } from '@/lib/execution/payloads/large-value-ref' | ||
| import { materializeLargeValueRef, storeLargeValue } from '@/lib/execution/payloads/store' | ||
| import { FunctionalOutputsUnavailableError } from '@/lib/logs/execution/functional-outputs' | ||
| import { projectTraceSpansForSecrets } from '@/lib/logs/execution/trace-secret-projection' | ||
| import type { TraceSpan } from '@/lib/logs/types' | ||
| import { | ||
| @@ -72,6 +73,11 @@ export interface TraceStoreReadContext { | ||
| userId?: string | ||
| } | ||
| export interface DisplayExecutionDataWithBlockOutputs { | ||
| executionData: Record<string, unknown> | ||
| blockOutputs: Map<string, unknown> | ||
| } | ||
| /** | ||
| * Write-path context. Requires the execution owner's `userId`: the externalized | ||
| * object is tracked in `workspace_files`, whose `user_id` column is NOT NULL | ||
| @@ -269,6 +275,100 @@ export async function materializeExecutionDataForDisplay( | ||
| return projectExecutionDataForDisplay(materialized, context) | ||
| } | ||
| /** | ||
| * Materializes one trusted row into its display envelope plus secret-safe functional outputs. | ||
| * Only requested execution-state outputs are projected and returned; trace spans remain display | ||
| * data and the raw execution state never crosses the display boundary. | ||
| */ | ||
| export async function materializeExecutionDataForDisplayWithBlockOutputs( | ||
| executionData: Record<string, unknown> | null | undefined, | ||
| context: TraceStoreReadContext, | ||
| blockIds: readonly string[] | ||
| ): Promise<DisplayExecutionDataWithBlockOutputs> { | ||
| const materialized = await materializeExecutionData(executionData, context) | ||
| const displayData = await projectExecutionDataForDisplay(materialized, context) | ||
| if (blockIds.length === 0) { | ||
| return { executionData: displayData, blockOutputs: new Map() } | ||
| } | ||
| const executionState = readRecord(materialized.executionState) | ||
| const blockStates = readRecord(executionState?.blockStates) | ||
| if (!blockStates) { | ||
| if (materialized.executionDataTruncated === true) { | ||
| throw new FunctionalOutputsUnavailableError() | ||
| } | ||
| return { executionData: displayData, blockOutputs: new Map() } | ||
| } | ||
| const runRegistry = await importResolvedSecretTraceRegistry( | ||
| materialized[RESOLVED_SECRET_PROVENANCE_KEY] ?? | ||
| executionState?.[RESOLVED_SECRET_PROVENANCE_KEY], | ||
| 'traceStore.blockOutputRunProvenance' | ||
| ) | ||
| const blockOutputs = new Map<string, unknown>() | ||
| const projectionStore = createReadOnlyProjectionStore(context) | ||
| for (const blockId of new Set(blockIds)) { | ||
| const blockState = readRecord(blockStates[blockId]) | ||
| if (!blockState || blockState.output === undefined) continue | ||
| const hasExactProvenance = Object.hasOwn(blockState, RESOLVED_SECRET_PROVENANCE_KEY) | ||
| const registry = hasExactProvenance | ||
| ? await importResolvedSecretTraceRegistry( | ||
| blockState[RESOLVED_SECRET_PROVENANCE_KEY], | ||
| 'traceStore.blockOutputExactProvenance' | ||
| ) | ||
| : runRegistry | ||
| const now = new Date().toISOString() | ||
| const [projected] = await projectTraceSpansForSecrets( | ||
| [ | ||
| { | ||
| id: `${LOG_DISPLAY_PROJECTION_SPAN_ID}-block-output`, | ||
| name: 'Block Output Display Projection', | ||
| type: 'display', | ||
| duration: 0, | ||
| startTime: now, | ||
| endTime: now, | ||
| output: { value: blockState.output }, | ||
| }, | ||
| ], | ||
| { registry, allowLargeValueWrites: false, store: projectionStore } | ||
| ) | ||
| if (projected?.output && Object.hasOwn(projected.output, 'value')) { | ||
| blockOutputs.set(blockId, projected.output.value) | ||
| } | ||
| } | ||
| return { executionData: displayData, blockOutputs } | ||
| } | ||
| function readRecord(value: unknown): Record<string, unknown> | undefined { | ||
| return value && typeof value === 'object' && !Array.isArray(value) | ||
| ? (value as Record<string, unknown>) | ||
| : undefined | ||
| } | ||
| async function importResolvedSecretTraceRegistry( | ||
| provenance: unknown, | ||
| origin: string | ||
| ): Promise<ResolvedSecretTraceRegistry | undefined> { | ||
| if (!isResolvedSecretTraceProvenanceV1(provenance)) return undefined | ||
| const registry = new ResolvedSecretTraceRegistry([], provenance.scope) | ||
| await registry.importProvenance(provenance, { trusted: true, origin }) | ||
| return registry | ||
| } | ||
| function createReadOnlyProjectionStore(context: TraceStoreReadContext) { | ||
| return { | ||
| workspaceId: context.workspaceId ?? undefined, | ||
| workflowId: context.workflowId ?? undefined, | ||
| executionId: context.executionId, | ||
| userId: context.userId, | ||
| trackReference: false, | ||
| } | ||
| } | ||
| /** | ||
| * Projects execution-log content with the encrypted provenance saved by the | ||
| * trusted executor. Current workflow input and final output values use their | ||
| @@ -284,12 +384,7 @@ export async function projectExecutionDataForDisplay( | ||
| executionData: Record<string, unknown>, | ||
| context: TraceStoreReadContext | ||
| ): Promise<Record<string, unknown>> { | ||
| const executionState = | ||
| executionData.executionState && | ||
| typeof executionData.executionState === 'object' && | ||
| !Array.isArray(executionData.executionState) | ||
| ? (executionData.executionState as Record<string, unknown>) | ||
| : undefined | ||
| const executionState = readRecord(executionData.executionState) | ||
| const hasTopLevelProvenance = Object.hasOwn(executionData, RESOLVED_SECRET_PROVENANCE_KEY) | ||
| const stateProvenance = executionState?.[RESOLVED_SECRET_PROVENANCE_KEY] | ||
| const provenance = executionData[RESOLVED_SECRET_PROVENANCE_KEY] ?? stateProvenance | ||
| @@ -302,15 +397,7 @@ export async function projectExecutionDataForDisplay( | ||
| return projectLegacyExecutionDataForDisplay(executionData) | ||
| } | ||
| let registry: ResolvedSecretTraceRegistry | undefined | ||
| if (isResolvedSecretTraceProvenanceV1(provenance)) { | ||
| registry = new ResolvedSecretTraceRegistry([], provenance.scope) | ||
| await registry.importProvenance(provenance, { | ||
| trusted: true, | ||
| origin: 'traceStore.spanProvenance', | ||
| }) | ||
| } | ||
cursor[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| const registry = await importResolvedSecretTraceRegistry(provenance, 'traceStore.spanProvenance') | ||
| /** | ||
| * Compaction drops `executionState`, and with it the only copy of the | ||
| @@ -339,13 +426,7 @@ export async function projectExecutionDataForDisplay( | ||
| }) | ||
| } | ||
| const projectionStore = { | ||
| workspaceId: context.workspaceId ?? undefined, | ||
| workflowId: context.workflowId ?? undefined, | ||
| executionId: context.executionId, | ||
| userId: context.userId, | ||
| trackReference: false, | ||
| } | ||
| const projectionStore = createReadOnlyProjectionStore(context) | ||
| const exactValueProjections = new Map<string, unknown>() | ||
| for (const [valueKey, provenanceKey] of Object.entries(EXACT_LOG_VALUE_PROVENANCE_KEYS)) { | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.