-
Notifications
You must be signed in to change notification settings - Fork 176
Create sandbox event endpoint and handlers #784
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
base: main
Are you sure you want to change the base?
Conversation
…er validation and register some event handlers
…nternal-sandbox-event-endpoint-e2b-2486
…nternal-sandbox-event-endpoint-e2b-2486
…nternal-sandbox-event-endpoint-e2b-2486
packages/orchestrator/internal/sandbox/network/network_linux.go
Outdated
Show resolved
Hide resolved
} | ||
|
||
// Redirect http://event.e2b.dev traffic destined to event server | ||
err = tables.Append("nat", "PREROUTING", "-i", s.VethName(), "-p", "tcp", "-d", "8.8.8.7", "--dport", "80", "-j", "REDIRECT", "--to-port", "5010") |
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.
use different IP than 8.8.8.7, I guess any IP from these should be more appropriate:
var blockedRanges = []string{
"10.0.0.0/8",
"169.254.0.0/16",
"192.168.0.0/16",
"172.16.0.0/12",
}
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.
ideally yes, i first tried private IPs, they don't leave the sandbox through the network bridge with current setup, i'd have to figure out a way to route one of the private ones this way.
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.
just note, these ranges are blocked by default, you need to enable the target IP address (maybe that might be why you haven't seen them routed)
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.
Can we maybe not use public IP, but something like metadata IP used by envd for accessing Firecracker VM metadata?
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.
More details on why Firecracker and cloud providers are using 169.254/16
https://datatracker.ietf.org/doc/html/rfc3927
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.
Perhaps provide the domain as an environment variable via envd so we are not locked into it for the future? Then does not matter what domain we will use now
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.
It does matter in a sense where it will be encoded in all envds
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.
It does matter in a sense where it will be encoded in all envds
That was my point with Perhaps provide the domain as an environment variable via envd so we are not locked into it for the future
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.
Oh, you mean through MMDS, not environment variable, correct?
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.
Yes, sorry for confusion
Also, how will we handle events like sandbox creation, deletion, etc? Basically events emitted from outside of the sandbox |
This is not meant to replace events emitted from outside the sandbox. |
I've meant that we don't have events emitted from the outside, so the question is if it maybe makes sense to have it united |
any event that can be listened to from the outside should continue to be—especially if it's uncertain the VM is running—any event we would have to poll for inside the sandbox ideally shouldn't. |
…nternal-sandbox-event-endpoint-e2b-2486
…nternal-sandbox-event-endpoint-e2b-2486
…nternal-sandbox-event-endpoint-e2b-2486
…ng to network slots and use it to map back to sandbox ID in event handler
…route according to RFC
server := &http.Server{ | ||
Addr: fmt.Sprintf(":%d", port), | ||
Handler: mux, | ||
} |
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.
What about running Gin here so we can use a strict Golang client in envd and track all version changes?
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.
sure, we can use gin, but i'm not sure it's more strict than the std lib and also what do u mean by tracking version changes in this case?
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.
but i'm not sure it's more strict than the std lib and also what do u mean by tracking version changes in this case?
I was thinking that the "metrics server" can be Gin-backed by the OpenAPI scheme, as we are using for the API, so all breaking changes will be clear (because of the re-generated schema). You will also be able to use the generated Go client from EnvD to call metrics service endpoints.
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.
The point was just make it strong types on both caller and receiver
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.
Agree with @sitole
sandboxIP := ips.slot.HostIPString() | ||
eventStore.SetSandboxIP(config.SandboxId, sandboxIP) | ||
cleanup.AddPriority(func(ctx context.Context) error { | ||
return eventStore.DelSandboxIP(sandboxIP) | ||
}) | ||
|
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.
Why can we not directly get the sandbox from the orchestrator cache and get the slot IP on it?
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.
Correct me if i'm wrong but that map uses sandbox ID as key? in my use case I need sandbox IP as key to get the ID.
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.
Yes, you are right. But still, using Redis may not be needed here? You don't need to share state to a 3rd party service, because you will always receive requests just from sandboxes that are managed by the orchestrator itself, right? This way on Orchestrator, you should always know about all sandboxes without fetching them from Redis.
Probably there will be <300 sandboxes, which means the sandboxes map is not that big to iterate it every time you need to find an IP in it. The number of sandboxes will probably not grow, because of networking, memory, and CPU limitations. If you feel that it can be issue, then we can do some pattern that will create in-memory map "sbx ip -> sbx id" and make it synced with sandboxes map.
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.
Agree with @sitole here
hostname := "e2b.local" | ||
eventProxyHostname := "events.e2b.dev" | ||
|
||
eventIP := env.GetEnv("SANDBOX_EVENT_IP", "203.0.113.0") |
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.
Lets make IP constant in some shared package
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.
Yeah, i was gonna introduce a consts.go
like in other packages.
…nternal-sandbox-event-endpoint-e2b-2486
…nternal-sandbox-event-endpoint-e2b-2486
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.
Will we use redis or clickhouse here?
hostname := "e2b.local" | ||
eventProxyHostname := "events.e2b.dev" | ||
|
||
eventIP := internal.GetSandboxEventIP() |
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.
do we want to bake in into the template? Can't we use a mmds server here?
) | ||
|
||
const ( | ||
defaultSandboxEventIP = "203.0.113.0" |
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.
why do you use TEST-NET-3 here?
server := &http.Server{ | ||
Addr: fmt.Sprintf(":%d", port), | ||
Handler: mux, | ||
} |
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.
Agree with @sitole
@0div is there some update? I would like to use the sandbox -> orchestrator HTTP server you introduced here. |
@sitole , i put this back as draft bc i would start using it once i can consume it with the webhooks system i'm implenting. |
Description
We currently do not have a way to send events from inside a sandbox and programmatically handle them from the host, this is an attempt to solve that.
Setup networking in sandbox that routes http://events.e2b.dev requests to a server listening in orchestrator with customizable handlers.
/etc/hosts
) in sandboxTest