Merge pull request #3977 from bluewave-labs/fix/docker-socket-egress-exemption
fix: exempt local docker sockets
This commit is contained in:
2 files changed
+17
-15
No files matched your search
@@ -6,6 +6,7 @@ import http from "node:http";
|
|||||||
import { HardwareStats } from "@/domain/checks/check.type.js";
|
import { HardwareStats } from "@/domain/checks/check.type.js";
|
||||||
import { MonitorStats } from "@/domain/monitor-stats/monitor-stats.type.js";
|
import { MonitorStats } from "@/domain/monitor-stats/monitor-stats.type.js";
|
||||||
import { DockerLogPage } from "@/domain/docker/docker-log.type.js";
|
import { DockerLogPage } from "@/domain/docker/docker-log.type.js";
|
||||||
|
import { isDockerSocketUrl } from "@/utils/dockerHost.js";
|
||||||
|
|
||||||
export const HttpStatusCodes = [
|
export const HttpStatusCodes = [
|
||||||
...Object.keys(http.STATUS_CODES).map(Number),
|
...Object.keys(http.STATUS_CODES).map(Number),
|
||||||
@@ -67,10 +68,9 @@ export const EgressAttributableTypes = [
|
|||||||
] as const satisfies readonly MonitorType[];
|
] as const satisfies readonly MonitorType[];
|
||||||
export type EgressAttributableType = (typeof EgressAttributableTypes)[number];
|
export type EgressAttributableType = (typeof EgressAttributableTypes)[number];
|
||||||
|
|
||||||
// A Docker daemon reached over a unix socket is local IPC and cannot fail through egress; one reached over
|
// A Docker daemon reached over a unix socket (`unix:///path` or a bare absolute path) is local IPC and cannot
|
||||||
// TCP or TLS is as remote as any other target. The URL, not the type, settles it.
|
// fail through egress; one reached over TCP or TLS is as remote as any other target. The URL, not the type, settles it.
|
||||||
const isLocalDockerSocket = (monitor: Pick<Monitor, "type" | "url">): boolean =>
|
const isLocalDockerSocket = (monitor: Pick<Monitor, "type" | "url">): boolean => monitor.type === "docker" && isDockerSocketUrl(monitor.url);
|
||||||
monitor.type === "docker" && (monitor.url?.trim().startsWith("unix://") ?? false);
|
|
||||||
|
|
||||||
export const isEgressAttributable = (monitor: Pick<Monitor, "type" | "url">): boolean =>
|
export const isEgressAttributable = (monitor: Pick<Monitor, "type" | "url">): boolean =>
|
||||||
EgressAttributableTypes.some((t) => t === monitor.type) && !isLocalDockerSocket(monitor);
|
EgressAttributableTypes.some((t) => t === monitor.type) && !isLocalDockerSocket(monitor);
|
||||||
|
|||||||
@@ -291,19 +291,21 @@ describe("CheckProducer", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("never consults egress for a docker daemon on a local socket", async () => {
|
it("never consults egress for a docker daemon on a local socket", async () => {
|
||||||
const check: Record<string, unknown> = { id: "check-1" };
|
for (const url of ["unix:///var/run/docker.sock", "/var/run/docker.sock"]) {
|
||||||
const { producer, defaults } = createProducer({
|
const check: Record<string, unknown> = { id: "check-1" };
|
||||||
networkService: { requestStatus: jest.fn().mockResolvedValue({ ...failingStatus, type: "docker" }) },
|
const { producer, defaults } = createProducer({
|
||||||
checkService: { toCheck: jest.fn().mockReturnValue(check) },
|
networkService: { requestStatus: jest.fn().mockResolvedValue({ ...failingStatus, type: "docker" }) },
|
||||||
egressService: { assessAfterFailure: jest.fn().mockResolvedValue("degraded") },
|
checkService: { toCheck: jest.fn().mockReturnValue(check) },
|
||||||
});
|
egressService: { assessAfterFailure: jest.fn().mockResolvedValue("degraded") },
|
||||||
|
});
|
||||||
|
|
||||||
await producer.produce(makeMonitor({ type: "docker", url: "unix:///var/run/docker.sock" }));
|
await producer.produce(makeMonitor({ type: "docker", url }));
|
||||||
|
|
||||||
// Local IPC never leaves the instance, so it cannot fail through egress.
|
// Local IPC never leaves the instance, so it cannot fail through egress.
|
||||||
expect(defaults.egressService.assessAfterFailure).not.toHaveBeenCalled();
|
expect(defaults.egressService.assessAfterFailure).not.toHaveBeenCalled();
|
||||||
expect(check).not.toHaveProperty("egressStatus");
|
expect(check).not.toHaveProperty("egressStatus");
|
||||||
expect(defaults.buffer.addToBuffer).toHaveBeenCalledWith(check);
|
expect(defaults.buffer.addToBuffer).toHaveBeenCalledWith(check);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it("consults egress for a hardware check and for a docker daemon reached over TCP", async () => {
|
it("consults egress for a hardware check and for a docker daemon reached over TCP", async () => {
|
||||||
|
|||||||
Reference in new issue
Block a user