-
Notifications
You must be signed in to change notification settings - Fork 219
feat: add sandbox network out configuration #1447
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 9 commits
09d9394
05c3c98
e0a5b01
4ba7bc7
33c5a57
e3e805c
1c4264b
d9e12b3
01a4356
ef7e29b
61047a4
738177c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,25 +13,50 @@ import ( | |
| "google.golang.org/protobuf/types/known/timestamppb" | ||
|
|
||
| "github.com/e2b-dev/infra/packages/api/internal/api" | ||
| "github.com/e2b-dev/infra/packages/api/internal/db/types" | ||
| teamtypes "github.com/e2b-dev/infra/packages/api/internal/db/types" | ||
| "github.com/e2b-dev/infra/packages/api/internal/orchestrator/nodemanager" | ||
| "github.com/e2b-dev/infra/packages/api/internal/orchestrator/placement" | ||
| "github.com/e2b-dev/infra/packages/api/internal/sandbox" | ||
| "github.com/e2b-dev/infra/packages/api/internal/utils" | ||
| "github.com/e2b-dev/infra/packages/db/queries" | ||
| "github.com/e2b-dev/infra/packages/db/types" | ||
| "github.com/e2b-dev/infra/packages/shared/pkg/consts" | ||
| "github.com/e2b-dev/infra/packages/shared/pkg/grpc/orchestrator" | ||
| "github.com/e2b-dev/infra/packages/shared/pkg/logger" | ||
| "github.com/e2b-dev/infra/packages/shared/pkg/telemetry" | ||
| ut "github.com/e2b-dev/infra/packages/shared/pkg/utils" | ||
| ) | ||
|
|
||
| const internetBlockAddress = "0.0.0.0/0" | ||
|
|
||
| // buildNetworkConfig constructs the orchestrator network configuration from the input parameters | ||
| func buildNetworkConfig(network *types.SandboxNetworkConfig, allowInternetAccess *bool) *orchestrator.SandboxNetworkConfig { | ||
| orchNetwork := &orchestrator.SandboxNetworkConfig{ | ||
| Egress: &orchestrator.SandboxNetworkEgressConfig{}, | ||
| } | ||
|
|
||
| // Copy network configuration if provided | ||
| if network != nil && network.Egress != nil { | ||
| orchNetwork.Egress.AllowedAddresses = network.Egress.AllowedAddresses | ||
| orchNetwork.Egress.BlockedAddresses = network.Egress.BlockedAddresses | ||
| } | ||
|
|
||
| // Handle the case where internet access is explicitly disabled | ||
| // This should be applied after copying the network config to preserve allowed addresses | ||
| if allowInternetAccess != nil && !*allowInternetAccess { | ||
|
Member
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. I think we should return error when both network egress allow/block lists and allow internet are provided. It can bring unexpected behavior for users.
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. The allowOut takes precedence over blockOut also, internet is defined by default, allowInternetAccess false does the same as blockOut=[0.0.0.0/0] |
||
| // Block all internet access - this overrides any other blocked addresses | ||
| orchNetwork.Egress.BlockedAddresses = []string{internetBlockAddress} | ||
| } | ||
|
|
||
| return orchNetwork | ||
| } | ||
|
|
||
| func (o *Orchestrator) CreateSandbox( | ||
| ctx context.Context, | ||
| sandboxID, | ||
| executionID, | ||
| alias string, | ||
| team *types.Team, | ||
| team *teamtypes.Team, | ||
| build queries.EnvBuild, | ||
| metadata map[string]string, | ||
| envVars map[string]string, | ||
|
|
@@ -44,6 +69,7 @@ func (o *Orchestrator) CreateSandbox( | |
| autoPause bool, | ||
| envdAuthToken *string, | ||
| allowInternetAccess *bool, | ||
| network *types.SandboxNetworkConfig, | ||
| ) (sbx sandbox.Sandbox, apiErr *api.APIError) { | ||
| ctx, childSpan := tracer.Start(ctx, "create-sandbox") | ||
| defer childSpan.End() | ||
|
|
@@ -138,6 +164,8 @@ func (o *Orchestrator) CreateSandbox( | |
| sbxDomain = cluster.SandboxDomain | ||
| } | ||
|
|
||
| orchNetwork := buildNetworkConfig(network, allowInternetAccess) | ||
dobrac marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| sbxRequest := &orchestrator.SandboxCreateRequest{ | ||
| Sandbox: &orchestrator.SandboxConfig{ | ||
| BaseTemplateId: baseTemplateID, | ||
|
|
@@ -160,6 +188,7 @@ func (o *Orchestrator) CreateSandbox( | |
| Snapshot: isResume, | ||
| AutoPause: autoPause, | ||
| AllowInternetAccess: allowInternetAccess, | ||
| Network: orchNetwork, | ||
| TotalDiskSizeMb: ut.FromPtr(build.TotalDiskSizeMb), | ||
| }, | ||
| StartTime: timestamppb.New(startTime), | ||
|
|
@@ -237,6 +266,7 @@ func (o *Orchestrator) CreateSandbox( | |
| allowInternetAccess, | ||
| baseTemplateID, | ||
| sbxDomain, | ||
| network, | ||
| ) | ||
|
|
||
| o.sandboxStore.Add(ctx, sbx, true) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ import ( | |
|
|
||
| "github.com/e2b-dev/infra/packages/api/internal/sandbox" | ||
| "github.com/e2b-dev/infra/packages/api/internal/utils" | ||
| "github.com/e2b-dev/infra/packages/db/types" | ||
| "github.com/e2b-dev/infra/packages/shared/pkg/consts" | ||
| ) | ||
|
|
||
|
|
@@ -46,6 +47,13 @@ func (n *Node) GetSandboxes(ctx context.Context) ([]sandbox.Sandbox, error) { | |
| return nil, fmt.Errorf("failed to parse build ID '%s' for job: %w", config.GetBuildId(), parseErr) | ||
| } | ||
|
|
||
| network := &types.SandboxNetworkConfig{ | ||
| Egress: &types.SandboxNetworkEgressConfig{ | ||
| AllowedAddresses: config.GetNetwork().GetEgress().GetAllowedAddresses(), | ||
|
||
| BlockedAddresses: config.GetNetwork().GetEgress().GetBlockedAddresses(), | ||
| }, | ||
| } | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| sandboxesInfo = append( | ||
| sandboxesInfo, | ||
| sandbox.NewSandbox( | ||
|
|
@@ -73,6 +81,7 @@ func (n *Node) GetSandboxes(ctx context.Context) ([]sandbox.Sandbox, error) { | |
| config.AllowInternetAccess, //nolint:protogetter // we need the nil check too | ||
| config.GetBaseTemplateId(), | ||
| n.SandboxDomain, | ||
| network, | ||
| ), | ||
| ) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| -- +goose Up | ||
| -- +goose StatementBegin | ||
|
|
||
| ALTER TABLE snapshots | ||
| ADD COLUMN config jsonb NULL; | ||
| -- +goose StatementEnd | ||
|
|
||
| -- +goose Down | ||
| -- +goose StatementBegin | ||
| ALTER TABLE snapshots | ||
| DROP COLUMN IF EXISTS config; | ||
| -- +goose StatementEnd |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.