Skip to content

Commit ed90bd3

Browse files
Feat/enable autoresume for byoc (#2470)
adds a route from the edge proxies to call the API to resume sandboxes when autoresume is on implements the oidc auth for the API so we can use the JWTs from edge <> our control plane new scope: sandboxes:lifecycle
1 parent dd91ea8 commit ed90bd3

57 files changed

Lines changed: 1328 additions & 96 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env.gcp.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ DEFAULT_PERSISTENT_VOLUME_TYPE=
123123
# Persistent volume types (default: {})
124124
PERSISTENT_VOLUME_TYPES=
125125

126+
# Client proxy OIDC issuer for edge gRPC autoresume auth.
127+
CLIENT_PROXY_OIDC_ISSUER_URL=
128+
126129
# Sandbox firewall: comma-separated CIDRs to allow through the private-range deny list
127130
# ALLOW_SANDBOX_INTERNAL_CIDRS=
128131

.github/actions/start-services/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ runs:
104104
SHARED_CHUNK_CACHE_PATH: "./.e2b-chunk-cache"
105105
REDIS_URL: "localhost:6379"
106106
# Client-proxy config
107-
API_GRPC_ADDRESS: "localhost:5009"
107+
API_INTERNAL_GRPC_ADDRESS: "localhost:5009"
108108
DEFAULT_PERSISTENT_VOLUME_TYPE: "test-volume-type"
109109
SANDBOX_STORAGE_BACKEND: "redis"
110110
run: |

.github/workflows/integration_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: Run Integration Tests
3535
env:
3636
TESTS_API_SERVER_URL: "http://localhost:3000"
37-
TESTS_API_GRPC_ADDRESS: "localhost:5009"
37+
TESTS_API_INTERNAL_GRPC_ADDRESS: "localhost:5009"
3838
TESTS_ORCHESTRATOR_HOST: "localhost:5008"
3939
TESTS_ENVD_PROXY: "http://localhost:3002"
4040
TESTS_CLIENT_PROXY: "http://localhost:3002"

iac/modules/job-api/jobs/api.hcl

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ job "api" {
1919
static = "${port_number}"
2020
}
2121

22-
port "grpc" {
23-
static = "${api_grpc_port}"
22+
port "api_internal_grpc" {
23+
static = "${api_internal_grpc_port}"
2424
}
2525

26+
port "grpc_api" {}
27+
2628
%{ if prevent_colocation }
2729
port "scheduling-block" {
2830
// This port is used to block scheduling of jobs with the same block on the same node.
@@ -61,16 +63,39 @@ job "api" {
6163
}
6264

6365
service {
64-
name = "api-grpc"
65-
port = "grpc"
66+
name = "api-internal-grpc"
67+
port = "api_internal_grpc"
6668
task = "start"
6769

6870
check {
6971
type = "tcp"
70-
name = "grpc"
72+
name = "api-internal-grpc"
73+
interval = "3s"
74+
timeout = "3s"
75+
port = "api_internal_grpc"
76+
}
77+
}
78+
79+
service {
80+
name = "grpc-api"
81+
port = "grpc_api"
82+
task = "start"
83+
84+
tags = [
85+
"traefik.enable=true",
86+
"traefik.http.routers.grpc-api.rule=HostRegexp(`grpc-api.{domain:.+}`)",
87+
"traefik.http.routers.grpc-api.ruleSyntax=v2",
88+
"traefik.http.routers.grpc-api.priority=500",
89+
"traefik.http.routers.grpc-api.service=grpc-api",
90+
"traefik.http.services.grpc-api.loadbalancer.server.scheme=h2c"
91+
]
92+
93+
check {
94+
type = "tcp"
95+
name = "grpc-api"
7196
interval = "3s"
7297
timeout = "3s"
73-
port = "grpc"
98+
port = "grpc_api"
7499
}
75100
}
76101

@@ -114,7 +139,8 @@ job "api" {
114139
NODE_ID = "$${node.unique.id}"
115140
NOMAD_TOKEN = "${nomad_acl_token}"
116141
ORCHESTRATOR_PORT = "${orchestrator_port}"
117-
API_GRPC_PORT = "${api_grpc_port}"
142+
API_INTERNAL_GRPC_PORT = "${api_internal_grpc_port}"
143+
API_EDGE_GRPC_PORT = "$${NOMAD_PORT_grpc_api}"
118144
ADMIN_TOKEN = "${admin_token}"
119145
SANDBOX_ACCESS_TOKEN_HASH_SEED = "${sandbox_access_token_hash_seed}"
120146

@@ -164,7 +190,7 @@ job "api" {
164190
config {
165191
network_mode = "host"
166192
image = "${api_docker_image}"
167-
ports = ["${port_name}"]
193+
ports = ["${port_name}", "grpc_api"]
168194
args = [
169195
"--port", "${port_number}",
170196
]

iac/modules/job-api/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ resource "nomad_job" "api" {
2323
logs_collector_address = var.logs_collector_address
2424
port_name = var.port_name
2525
port_number = var.port_number
26-
api_grpc_port = var.api_grpc_port
26+
api_internal_grpc_port = var.api_internal_grpc_port
2727
api_docker_image = var.api_docker_image
2828
postgres_connection_string = var.postgres_connection_string
2929
postgres_read_replica_connection_string = var.postgres_read_replica_connection_string

iac/modules/job-api/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ variable "port_number" {
3131
type = number
3232
}
3333

34-
variable "api_grpc_port" {
34+
variable "api_internal_grpc_port" {
3535
type = number
3636
default = 5009
3737
}

iac/modules/job-client-proxy/jobs/client-proxy.hcl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,19 @@ job "client-proxy" {
113113
REDIS_TLS_CA_BASE64 = "${redis_tls_ca_base64}"
114114
REDIS_URL = "${redis_url}"
115115

116-
%{ if api_grpc_address != "" }
117-
# used only when client-proxy is deployed directly in the cluster next to the API
118-
API_GRPC_ADDRESS = "${api_grpc_address}"
116+
%{ if api_internal_grpc_address != "" }
117+
# used by in-cluster client-proxy to call API ResumeSandbox over gRPC
118+
API_INTERNAL_GRPC_ADDRESS = "${api_internal_grpc_address}"
119+
%{ endif }
120+
121+
%{ if api_edge_grpc_address != "" }
122+
# used by external client-proxy to call edge API ResumeSandbox over gRPC
123+
API_EDGE_GRPC_ADDRESS = "${api_edge_grpc_address}"
124+
%{ if api_edge_grpc_oauth_client_id != "" }
125+
API_EDGE_GRPC_OAUTH_CLIENT_ID = "${api_edge_grpc_oauth_client_id}"
126+
API_EDGE_GRPC_OAUTH_CLIENT_SECRET = "${api_edge_grpc_oauth_client_secret}"
127+
API_EDGE_GRPC_OAUTH_TOKEN_URL = "${api_edge_grpc_oauth_token_url}"
128+
%{ endif }
119129
%{ endif }
120130

121131
%{ if launch_darkly_api_key != "" }

iac/modules/job-client-proxy/main.tf

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
locals {
2+
api_internal_grpc_address = trimspace(var.api_internal_grpc_address)
3+
api_edge_grpc_address = trimspace(var.api_edge_grpc_address)
4+
}
5+
16
resource "nomad_job" "client_proxy" {
27
jobspec = templatefile("${path.module}/jobs/client-proxy.hcl", {
38
update_stanza = var.update_stanza
@@ -17,8 +22,13 @@ resource "nomad_job" "client_proxy" {
1722
redis_tls_ca_base64 = var.redis_tls_ca_base64
1823
redis_pool_size = var.redis_pool_size
1924

20-
image = var.image
21-
api_grpc_address = trimspace(var.api_grpc_address)
25+
image = var.image
26+
api_internal_grpc_address = local.api_internal_grpc_address
27+
api_edge_grpc_address = local.api_edge_grpc_address
28+
29+
api_edge_grpc_oauth_client_id = trimspace(var.api_edge_grpc_oauth_client_id)
30+
api_edge_grpc_oauth_client_secret = trimspace(var.api_edge_grpc_oauth_client_secret)
31+
api_edge_grpc_oauth_token_url = trimspace(var.api_edge_grpc_oauth_token_url)
2232

2333
otel_collector_grpc_endpoint = var.otel_collector_grpc_endpoint
2434
logs_collector_address = var.logs_collector_address

iac/modules/job-client-proxy/variables.tf

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,34 @@ variable "image" {
6363
type = string
6464
}
6565

66-
variable "api_grpc_address" {
66+
variable "api_internal_grpc_address" {
6767
type = string
6868
default = ""
6969
}
7070

71+
variable "api_edge_grpc_address" {
72+
type = string
73+
default = ""
74+
}
75+
76+
variable "api_edge_grpc_oauth_client_id" {
77+
type = string
78+
default = ""
79+
sensitive = true
80+
}
81+
82+
variable "api_edge_grpc_oauth_client_secret" {
83+
type = string
84+
default = ""
85+
sensitive = true
86+
}
87+
88+
variable "api_edge_grpc_oauth_token_url" {
89+
type = string
90+
default = ""
91+
sensitive = true
92+
}
93+
7194
variable "otel_collector_grpc_endpoint" {
7295
type = string
7396
}

iac/provider-aws/.terraform.lock.hcl

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)