-
Notifications
You must be signed in to change notification settings - Fork 2k
[CRE] [4/5] ConfidentialModule, config, DB migration, syncer routing #21641
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
Open
nadahalli
wants to merge
12
commits into
develop
Choose a base branch
from
tejaswi/cw-4-confidential-module
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ee36fae
resolve go.mod conflicts
nadahalli bfe65ca
Revert file fetcher HTTP URL handling
nadahalli da4c9fd
Remove ConfidentialRelay config (belongs in cw-2 relay handler PR)
nadahalli 15579b6
Restore comments in startAndRegisterEngine, extract newV2EngineConfig
nadahalli 03fc9df
Unify engine creation flow for confidential and normal paths
nadahalli 3649839
Restore initDone comment in tryEngineCreate
nadahalli 8690d71
Inline startAndRegisterEngine back into tryEngineCreate
nadahalli 563e8a3
Restore inline comments in wireInitDoneHook
nadahalli 9e2aef8
Restore original BeholderEmitter closure pattern in newV2EngineConfig
nadahalli 973f35c
Clean up factory signatures and newV2EngineConfig param ordering
nadahalli eaaaaf8
Fix lint: errors.New, assert.Empty
nadahalli 764834e
Add BinaryURLResolver to ConfidentialModule for presigned URL support
nadahalli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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 |
|---|---|---|
|
|
@@ -537,6 +537,7 @@ func (h *eventHandler) createWorkflowSpec(ctx context.Context, payload WorkflowR | |
| SpecType: job.WASMFile, | ||
| BinaryURL: payload.BinaryURL, | ||
| ConfigURL: payload.ConfigURL, | ||
| Attributes: payload.Attributes, | ||
| } | ||
|
|
||
| if _, err = h.workflowArtifactsStore.UpsertWorkflowSpec(ctx, entry); err != nil { | ||
|
|
@@ -628,55 +629,9 @@ func (h *eventHandler) engineFactoryFn(ctx context.Context, workflowID string, o | |
| } | ||
|
|
||
| // V2 aka "NoDAG" | ||
| cfg := &v2.EngineConfig{ | ||
| Lggr: h.lggr, | ||
| Module: module, | ||
| WorkflowConfig: config, | ||
| CapRegistry: h.capRegistry, | ||
| DonSubscriber: h.workflowDonSubscriber, | ||
| UseLocalTimeProvider: h.useLocalTimeProvider, | ||
| DonTimeStore: h.donTimeStore, | ||
| ExecutionsStore: h.workflowStore, | ||
| WorkflowID: workflowID, | ||
| WorkflowOwner: owner, | ||
| WorkflowName: name, | ||
| WorkflowTag: tag, | ||
| WorkflowEncryptionKey: h.workflowEncryptionKey, | ||
| cfg := h.newV2EngineConfig(module, workflowID, owner, tag, sdkName, name, config) | ||
|
|
||
| LocalLimits: v2.EngineLimits{}, // all defaults | ||
| LocalLimiters: h.engineLimiters, | ||
| FeatureFlags: h.featureFlags, | ||
| GlobalExecutionConcurrencyLimiter: h.workflowLimits, | ||
|
|
||
| BeholderEmitter: func() custmsg.MessageEmitter { | ||
| h.emitterMu.RLock() | ||
| defer h.emitterMu.RUnlock() | ||
| return h.emitter | ||
| }(), | ||
| BillingClient: h.billingClient, | ||
|
|
||
| WorkflowRegistryAddress: h.workflowRegistryAddress, | ||
| WorkflowRegistryChainSelector: h.workflowRegistryChainSelector, | ||
| OrgResolver: h.orgResolver, | ||
| DebugMode: h.debugMode, | ||
| SecretsFetcher: h.secretsFetcher, | ||
| SdkName: sdkName, | ||
| } | ||
|
|
||
| // Wire the initDone channel to the OnInitialized lifecycle hook. | ||
| // This will be called when the engine completes initialization (including trigger subscriptions). | ||
| // We compose with any existing hook to avoid overwriting test hooks or other user-provided hooks. | ||
| if initDone != nil { | ||
| existingHook := cfg.Hooks.OnInitialized | ||
| cfg.Hooks.OnInitialized = func(err error) { | ||
| // Signal completion to the handler first | ||
| initDone <- err | ||
| // Then call any existing hook (e.g., from tests) | ||
| if existingHook != nil { | ||
| existingHook(err) | ||
| } | ||
| } | ||
| } | ||
| h.wireInitDoneHook(cfg, initDone) | ||
|
|
||
| return v2.NewEngine(cfg) | ||
| } | ||
|
|
@@ -789,24 +744,23 @@ func (h *eventHandler) tryEngineCreate(ctx context.Context, spec *job.WorkflowSp | |
| return fmt.Errorf("invalid workflow name: %w", err) | ||
| } | ||
|
|
||
| confidential, err := v2.IsConfidential(spec.Attributes) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to parse workflow attributes: %w", err) | ||
| } | ||
|
|
||
| // Create a channel to receive the initialization result. | ||
| // This allows us to wait for the engine to complete initialization (including trigger subscriptions) | ||
| // before emitting the workflowActivated event, ensuring the event accurately reflects deployment status. | ||
| initDone := make(chan error, 1) | ||
| var engine services.Service | ||
|
|
||
| // Scope the engineFactory call so that decodedBinary goes out of scope immediately after the factory returns | ||
| engine, err := func() (services.Service, error) { | ||
| return h.engineFactory( | ||
| ctx, | ||
| spec.WorkflowID, | ||
| spec.WorkflowOwner, | ||
| workflowName, | ||
| spec.WorkflowTag, | ||
| configBytes, | ||
| decodedBinary, | ||
| initDone, | ||
| ) | ||
| }() | ||
| if confidential { | ||
| h.lggr.Infow("routing workflow to confidential execution", "workflowID", spec.WorkflowID) | ||
| engine, err = h.confidentialEngineFactory(spec, workflowName, decodedBinary, initDone) | ||
| } else { | ||
| engine, err = h.engineFactory(ctx, spec.WorkflowID, spec.WorkflowOwner, workflowName, spec.WorkflowTag, configBytes, decodedBinary, initDone) | ||
| } | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create workflow engine: %w", err) | ||
| } | ||
|
|
@@ -863,6 +817,106 @@ func (h *eventHandler) tryEngineCreate(ctx context.Context, spec *job.WorkflowSp | |
| return nil | ||
| } | ||
|
|
||
| // newV2EngineConfig builds the common EngineConfig shared by both the normal | ||
| // WASM engine and the confidential engine paths. Caller supplies the module. | ||
| func (h *eventHandler) newV2EngineConfig( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice ty for doing this |
||
| module host.ModuleV2, | ||
| workflowID, owner, tag, sdkName string, | ||
| name types.WorkflowName, | ||
| config []byte, | ||
| ) *v2.EngineConfig { | ||
| return &v2.EngineConfig{ | ||
| Lggr: h.lggr, | ||
| Module: module, | ||
| WorkflowConfig: config, | ||
| CapRegistry: h.capRegistry, | ||
| DonSubscriber: h.workflowDonSubscriber, | ||
| UseLocalTimeProvider: h.useLocalTimeProvider, | ||
| DonTimeStore: h.donTimeStore, | ||
| ExecutionsStore: h.workflowStore, | ||
| WorkflowID: workflowID, | ||
| WorkflowOwner: owner, | ||
| WorkflowName: name, | ||
| WorkflowTag: tag, | ||
| WorkflowEncryptionKey: h.workflowEncryptionKey, | ||
|
|
||
| LocalLimits: v2.EngineLimits{}, // all defaults | ||
| LocalLimiters: h.engineLimiters, | ||
| FeatureFlags: h.featureFlags, | ||
| GlobalExecutionConcurrencyLimiter: h.workflowLimits, | ||
|
|
||
| BeholderEmitter: func() custmsg.MessageEmitter { | ||
| h.emitterMu.RLock() | ||
| defer h.emitterMu.RUnlock() | ||
| return h.emitter | ||
| }(), | ||
| BillingClient: h.billingClient, | ||
|
|
||
| WorkflowRegistryAddress: h.workflowRegistryAddress, | ||
| WorkflowRegistryChainSelector: h.workflowRegistryChainSelector, | ||
| OrgResolver: h.orgResolver, | ||
| SecretsFetcher: h.secretsFetcher, | ||
| DebugMode: h.debugMode, | ||
| SdkName: sdkName, | ||
| } | ||
| } | ||
|
|
||
| // wireInitDoneHook wires the initDone channel to the OnInitialized lifecycle hook. | ||
| // This will be called when the engine completes initialization (including trigger subscriptions). | ||
| // We compose with any existing hook to avoid overwriting test hooks or other user-provided hooks. | ||
| func (h *eventHandler) wireInitDoneHook(cfg *v2.EngineConfig, initDone chan<- error) { | ||
| if initDone == nil { | ||
| return | ||
| } | ||
| existingHook := cfg.Hooks.OnInitialized | ||
| cfg.Hooks.OnInitialized = func(err error) { | ||
| // Signal completion to the handler first | ||
| initDone <- err | ||
| // Then call any existing hook (e.g., from tests) | ||
| if existingHook != nil { | ||
| existingHook(err) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // confidentialEngineFactory creates a V2 engine backed by a ConfidentialModule | ||
| // instead of a local WASM module. The ConfidentialModule delegates execution to | ||
| // the confidential-workflows capability which runs the WASM inside a TEE. | ||
| func (h *eventHandler) confidentialEngineFactory( | ||
| spec *job.WorkflowSpec, | ||
| workflowName types.WorkflowName, | ||
| decodedBinary []byte, | ||
| initDone chan<- error, | ||
| ) (services.Service, error) { | ||
| attrs, err := v2.ParseWorkflowAttributes(spec.Attributes) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to parse workflow attributes: %w", err) | ||
| } | ||
|
|
||
| binaryHash := v2.ComputeBinaryHash(decodedBinary) | ||
|
|
||
| lggr := logger.Named(h.lggr, "WorkflowEngine.ConfidentialModule") | ||
| lggr = logger.With(lggr, "workflowID", spec.WorkflowID, "workflowName", spec.WorkflowName, "workflowOwner", spec.WorkflowOwner) | ||
|
|
||
| // nil resolver: raw binaryURL is passed to the enclave as-is. | ||
| // PR 5/5 (#21642) wires this to the storage service retriever | ||
| // so the enclave receives a presigned URL. | ||
| module := v2.NewConfidentialModule( | ||
| h.capRegistry, | ||
| spec.BinaryURL, | ||
| binaryHash, | ||
| spec.WorkflowID, spec.WorkflowOwner, workflowName.String(), spec.WorkflowTag, | ||
| attrs.VaultDonSecrets, | ||
| nil, | ||
| lggr, | ||
| ) | ||
|
|
||
| cfg := h.newV2EngineConfig(module, spec.WorkflowID, spec.WorkflowOwner, spec.WorkflowTag, "", workflowName, []byte(spec.Config)) | ||
| h.wireInitDoneHook(cfg, initDone) | ||
|
|
||
| return v2.NewEngine(cfg) | ||
| } | ||
|
|
||
| // logCustMsg emits a custom message to the external sink and logs an error if that fails. | ||
| func logCustMsg(ctx context.Context, cma custmsg.MessageEmitter, msg string, log logger.Logger) { | ||
| err := cma.Emit(ctx, msg) | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's figure out if we need a new
Attributesfield here or can overload a different existing field.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably open a thread with dev services today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update: this is optimal.