mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-07 05:22:56 +00:00
Implement a second HTTP server within compute_ctl (#10574)
The compute_ctl HTTP server has the following purposes: - Allow management via the control plane - Provide an endpoint for scaping metrics - Provide APIs for compute internal clients - Neon Postgres extension for installing remote extensions - local_proxy for installing extensions and adding grants The first two purposes require the HTTP server to be available outside the compute. The Neon threat model is a bad actor within our internal network. We need to reduce the surface area of attack. By exposing unnecessary unauthenticated HTTP endpoints to the internal network, we increase the surface area of attack. For endpoints described in the third bullet point, we can just run an extra HTTP server, which is only bound to the loopback interface since all consumers of those endpoints are within the compute.
This commit is contained in:
@@ -9,21 +9,23 @@ from requests.adapters import HTTPAdapter
|
||||
class EndpointHttpClient(requests.Session):
|
||||
def __init__(
|
||||
self,
|
||||
port: int,
|
||||
external_port: int,
|
||||
internal_port: int,
|
||||
):
|
||||
super().__init__()
|
||||
self.port = port
|
||||
self.external_port: int = external_port
|
||||
self.internal_port: int = internal_port
|
||||
|
||||
self.mount("http://", HTTPAdapter())
|
||||
|
||||
def dbs_and_roles(self):
|
||||
res = self.get(f"http://localhost:{self.port}/dbs_and_roles")
|
||||
res = self.get(f"http://localhost:{self.external_port}/dbs_and_roles")
|
||||
res.raise_for_status()
|
||||
return res.json()
|
||||
|
||||
def database_schema(self, database: str):
|
||||
res = self.get(
|
||||
f"http://localhost:{self.port}/database_schema?database={urllib.parse.quote(database, safe='')}"
|
||||
f"http://localhost:{self.external_port}/database_schema?database={urllib.parse.quote(database, safe='')}"
|
||||
)
|
||||
res.raise_for_status()
|
||||
return res.text
|
||||
@@ -34,20 +36,20 @@ class EndpointHttpClient(requests.Session):
|
||||
"version": version,
|
||||
"database": database,
|
||||
}
|
||||
res = self.post(f"http://localhost:{self.port}/extensions", json=body)
|
||||
res = self.post(f"http://localhost:{self.internal_port}/extensions", json=body)
|
||||
res.raise_for_status()
|
||||
return res.json()
|
||||
|
||||
def set_role_grants(self, database: str, role: str, schema: str, privileges: list[str]):
|
||||
res = self.post(
|
||||
f"http://localhost:{self.port}/grants",
|
||||
f"http://localhost:{self.internal_port}/grants",
|
||||
json={"database": database, "schema": schema, "role": role, "privileges": privileges},
|
||||
)
|
||||
res.raise_for_status()
|
||||
return res.json()
|
||||
|
||||
def metrics(self) -> str:
|
||||
res = self.get(f"http://localhost:{self.port}/metrics")
|
||||
res = self.get(f"http://localhost:{self.external_port}/metrics")
|
||||
res.raise_for_status()
|
||||
return res.text
|
||||
|
||||
@@ -62,5 +64,5 @@ class EndpointHttpClient(requests.Session):
|
||||
}
|
||||
)
|
||||
|
||||
res = self.post(f"http://localhost:{self.port}/failpoints", json=body)
|
||||
res = self.post(f"http://localhost:{self.internal_port}/failpoints", json=body)
|
||||
res.raise_for_status()
|
||||
|
||||
Reference in New Issue
Block a user