-
Notifications
You must be signed in to change notification settings - Fork 2k
Support HTTP URLs in file fetcher and system-test instrumentation #22044
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
Changes from all commits
88cbefe
396a390
2b5bf52
1072792
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "chainlink": patch | ||
| --- | ||
|
|
||
| Support HTTP URLs in file fetcher for local confidential workflow testing, add system-test instrumentation #changed |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -211,14 +211,22 @@ func newFileFetcher(basePath string, lggr logger.Logger) types.FetcherFunc { | |
| if err != nil { | ||
| return nil, fmt.Errorf("invalid URL: %w", err) | ||
| } | ||
| // Confidential workflows register with HTTP URLs (for the enclave). | ||
| // Extract the filename so the file fetcher can find the local copy. | ||
| if u.Scheme == "http" || u.Scheme == "https" { | ||
|
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. if it's "confidential" shall it only allow https ?
Contributor
Author
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. Confidential means that the workflow runs in TEE's. If the user wants to do http requests from TEE's, why stop them? They know what they are doing.
Contributor
Author
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. Ah, this is the fetcher URL. It can be http because we check the returned binary's hash against the hash that was sent in the request - so, the server that hosts the wasm binary cannot send back bad things. |
||
| u.Path = filepath.Base(u.Path) | ||
| if u.Path == "." || u.Path == "/" { | ||
| return nil, errors.New("HTTP URL has no filename in path") | ||
| } | ||
| } | ||
|
nadahalli marked this conversation as resolved.
nadahalli marked this conversation as resolved.
|
||
| fullPath := filepath.Clean(u.Path) | ||
|
|
||
| // ensure that the incoming request URL is either relative or absolute but within the basePath | ||
| if !filepath.IsAbs(fullPath) { | ||
| // If it's not absolute, we assume it's relative to the basePath | ||
| fullPath = filepath.Join(basePath, fullPath) | ||
| } | ||
| if !strings.HasPrefix(fullPath, basePath) { | ||
| if !strings.HasPrefix(fullPath, basePath+string(filepath.Separator)) && fullPath != basePath { | ||
| return nil, fmt.Errorf("request URL %s is not within the basePath %s", fullPath, basePath) | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| package confidentialrelay | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| tomlser "github.com/pelletier/go-toml/v2" | ||
| "github.com/pkg/errors" | ||
| "github.com/rs/zerolog" | ||
|
|
||
| chainselectors "github.com/smartcontractkit/chain-selectors" | ||
|
|
||
| "github.com/smartcontractkit/chainlink/deployment/cre/jobs/pkg" | ||
| "github.com/smartcontractkit/chainlink/system-tests/lib/cre" | ||
| coretoml "github.com/smartcontractkit/chainlink/v2/core/config/toml" | ||
| corechainlink "github.com/smartcontractkit/chainlink/v2/core/services/chainlink" | ||
| ) | ||
|
|
||
| const flag = cre.ConfidentialRelayCapability | ||
|
|
||
| type ConfidentialRelay struct{} | ||
|
|
||
| func (o *ConfidentialRelay) Flag() cre.CapabilityFlag { | ||
| return flag | ||
| } | ||
|
|
||
| func (o *ConfidentialRelay) PreEnvStartup( | ||
| ctx context.Context, | ||
| testLogger zerolog.Logger, | ||
| don *cre.DonMetadata, | ||
| topology *cre.Topology, | ||
| creEnv *cre.Environment, | ||
| ) (*cre.PreEnvStartupOutput, error) { | ||
| registryChainID, chErr := chainselectors.ChainIdFromSelector(creEnv.RegistryChainSelector) | ||
| if chErr != nil { | ||
| return nil, errors.Wrapf(chErr, "failed to get chain ID from selector %d", creEnv.RegistryChainSelector) | ||
| } | ||
|
|
||
| hErr := topology.AddGatewayHandlers(*don, []string{pkg.GatewayHandlerTypeConfidentialRelay}) | ||
| if hErr != nil { | ||
| return nil, errors.Wrapf(hErr, "failed to add gateway handlers to gateway config for don %s", don.Name) | ||
| } | ||
|
|
||
| cErr := don.ConfigureForGatewayAccess(registryChainID, *topology.GatewayConnectors) | ||
| if cErr != nil { | ||
| return nil, errors.Wrapf(cErr, "failed to add gateway connectors to node's TOML config for don %s", don.Name) | ||
| } | ||
|
|
||
| // Set TOML config to activate the confidential relay handler on DON nodes. | ||
| capConfig, ok := don.CapabilityConfigs[flag] | ||
| if ok && capConfig.Values != nil { | ||
| ns := don.MustNodeSet() | ||
| for i := range ns.NodeSpecs { | ||
| currentConfig := ns.NodeSpecs[i].Node.TestConfigOverrides | ||
| var typedConfig corechainlink.Config | ||
| if currentConfig != "" { | ||
| if err := tomlser.Unmarshal([]byte(currentConfig), &typedConfig); err != nil { | ||
| return nil, errors.Wrapf(err, "failed to unmarshal node TOML config for node %d", i) | ||
| } | ||
| } | ||
|
|
||
| enabled := true | ||
| typedConfig.CRE.ConfidentialRelay = &coretoml.ConfidentialRelayConfig{Enabled: &enabled} | ||
|
|
||
| out, err := tomlser.Marshal(typedConfig) | ||
| if err != nil { | ||
| return nil, errors.Wrapf(err, "failed to marshal node TOML config for node %d", i) | ||
| } | ||
| ns.NodeSpecs[i].Node.TestConfigOverrides = string(out) | ||
| } | ||
| } | ||
|
|
||
| // No on-chain capability registration needed. The relay handler is a CRE subservice, | ||
| // not a registered capability. The mock capability that runs on the relay DON is | ||
| // registered separately via the mock flag. | ||
| return &cre.PreEnvStartupOutput{}, nil | ||
| } | ||
|
|
||
| func (o *ConfidentialRelay) PostEnvStartup( | ||
| ctx context.Context, | ||
| testLogger zerolog.Logger, | ||
| don *cre.Don, | ||
| dons *cre.Dons, | ||
| creEnv *cre.Environment, | ||
| ) error { | ||
| return nil | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.