feat(relay): limit managed tunnels per user (#4530)
Co-authored-by: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
23ea08daf2
commit
a78f245dff
11 files changed
+404
-2
No files matched your search
@@ -143,6 +143,8 @@ function relayProtectedErrorMessage(error: RelayProtectedErrorType): string {
|
||||
return `Relay could not link the environment (${error.reason}).`;
|
||||
case "RelayEnvironmentLinkUnavailableError":
|
||||
return `Relay cannot provision the managed endpoint (${error.reason}).`;
|
||||
case "RelayEnvironmentLinkLimitExceededError":
|
||||
return `Relay refused the link: this account already has its maximum of ${error.maxTunnels} managed tunnels. Unlink an environment to free one up.`;
|
||||
case "RelayAgentActivityPublishProofExpiredError":
|
||||
return "Relay rejected an expired agent activity publish proof.";
|
||||
case "RelayAgentActivityPublishProofInvalidError":
|
||||
|
||||
@@ -154,6 +154,8 @@ function relayProtectedErrorMessage(error: RelayProtectedErrorType): string {
|
||||
return `Relay could not link the environment (${error.reason}).`;
|
||||
case "RelayEnvironmentLinkUnavailableError":
|
||||
return `Relay cannot provision the managed endpoint (${error.reason}).`;
|
||||
case "RelayEnvironmentLinkLimitExceededError":
|
||||
return `Relay refused the link: this account already has its maximum of ${error.maxTunnels} managed tunnels. Unlink an environment to free one up.`;
|
||||
case "RelayAgentActivityPublishProofExpiredError":
|
||||
return "Relay rejected an expired agent activity publish proof.";
|
||||
case "RelayAgentActivityPublishProofInvalidError":
|
||||
|
||||
@@ -9,6 +9,7 @@ import * as Redacted from "effect/Redacted";
|
||||
import * as RelayConfiguration from "../Config.ts";
|
||||
import * as ManagedEndpointAllocations from "./ManagedEndpointAllocations.ts";
|
||||
import * as ManagedEndpointProvider from "./ManagedEndpointProvider.ts";
|
||||
import * as ManagedTunnelLimits from "./ManagedTunnelLimits.ts";
|
||||
|
||||
const config = RelayConfiguration.RelayConfiguration.of({
|
||||
relayIssuer: "https://relay.example.test",
|
||||
@@ -200,10 +201,24 @@ function makeAllocations(calls: AllocationCall[] = []) {
|
||||
});
|
||||
}
|
||||
|
||||
function makeTunnelLimits(
|
||||
calls: Array<{ readonly userId: string; readonly environmentId: string }> = [],
|
||||
result: ManagedTunnelLimits.ManagedTunnelLimitExceeded | null = null,
|
||||
) {
|
||||
return ManagedTunnelLimits.ManagedTunnelLimits.of({
|
||||
ensureCapacity: (input) =>
|
||||
Effect.suspend(() => {
|
||||
calls.push(input);
|
||||
return result === null ? Effect.void : Effect.fail(result);
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
function providerLayer(
|
||||
tunnelClient = makeTunnelClient(),
|
||||
dnsClient = makeDnsClient(),
|
||||
allocations = makeAllocations(),
|
||||
tunnelLimits = makeTunnelLimits(),
|
||||
) {
|
||||
return ManagedEndpointProvider.layer.pipe(
|
||||
Layer.provideMerge(NodeServices.layer),
|
||||
@@ -213,6 +228,7 @@ function providerLayer(
|
||||
Layer.provide(
|
||||
Layer.succeed(ManagedEndpointAllocations.ManagedEndpointAllocations, allocations),
|
||||
),
|
||||
Layer.provide(Layer.succeed(ManagedTunnelLimits.ManagedTunnelLimits, tunnelLimits)),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -311,6 +327,67 @@ describe("ManagedEndpointProvider", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it.effect("checks the managed tunnel limit before reserving an allocation", () => {
|
||||
const limitCalls: Array<{ readonly userId: string; readonly environmentId: string }> = [];
|
||||
|
||||
return Effect.gen(function* () {
|
||||
const provider = yield* ManagedEndpointProvider.ManagedEndpointProvider;
|
||||
yield* provider.provision({
|
||||
userId: "user_ABC",
|
||||
environmentId: "env_ABC",
|
||||
origin: { localHttpHost: "127.0.0.1", localHttpPort: 3773 },
|
||||
});
|
||||
|
||||
expect(limitCalls).toEqual([{ userId: "user_ABC", environmentId: "env_ABC" }]);
|
||||
}).pipe(
|
||||
Effect.provide(
|
||||
providerLayer(
|
||||
makeTunnelClient(),
|
||||
makeDnsClient(),
|
||||
makeAllocations(),
|
||||
makeTunnelLimits(limitCalls),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
it.effect("refuses to provision past the managed tunnel limit without side effects", () => {
|
||||
const tunnelCalls: TunnelCall[] = [];
|
||||
const dnsCalls: DnsCall[] = [];
|
||||
const allocationCalls: AllocationCall[] = [];
|
||||
const exceeded = new ManagedTunnelLimits.ManagedTunnelLimitExceeded({
|
||||
userId: "user_ABC",
|
||||
environmentId: "env_ABC",
|
||||
maxTunnels: 10,
|
||||
activeTunnels: 10,
|
||||
});
|
||||
|
||||
return Effect.gen(function* () {
|
||||
const provider = yield* ManagedEndpointProvider.ManagedEndpointProvider;
|
||||
const error = yield* Effect.flip(
|
||||
provider.provision({
|
||||
userId: "user_ABC",
|
||||
environmentId: "env_ABC",
|
||||
origin: { localHttpHost: "127.0.0.1", localHttpPort: 3773 },
|
||||
}),
|
||||
);
|
||||
|
||||
expect(error).toBe(exceeded);
|
||||
expect(tunnelCalls).toEqual([]);
|
||||
expect(dnsCalls).toEqual([]);
|
||||
expect(allocationCalls).toEqual([]);
|
||||
}).pipe(
|
||||
Effect.provide(
|
||||
providerLayer(
|
||||
makeTunnelClient(tunnelCalls),
|
||||
makeDnsClient(dnsCalls),
|
||||
makeAllocations(allocationCalls),
|
||||
makeTunnelLimits([], exceeded),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
it.effect("uses stage-scoped stable names without leaking unusual environment ids", () => {
|
||||
const tunnelCalls: TunnelCall[] = [];
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
managedEndpointTunnelName,
|
||||
} from "../deploymentConfig.ts";
|
||||
import * as ManagedEndpointAllocations from "./ManagedEndpointAllocations.ts";
|
||||
import * as ManagedTunnelLimits from "./ManagedTunnelLimits.ts";
|
||||
|
||||
export class ManagedEndpointProvisioningNotConfigured extends Schema.TaggedErrorClass<ManagedEndpointProvisioningNotConfigured>()(
|
||||
"ManagedEndpointProvisioningNotConfigured",
|
||||
@@ -41,6 +42,7 @@ export class ManagedEndpointProvisioningNotConfigured extends Schema.TaggedError
|
||||
|
||||
const ManagedEndpointProvisioningStage = Schema.Literals([
|
||||
"derive-environment-hash",
|
||||
"check-tunnel-limit",
|
||||
"reserve-allocation",
|
||||
"ensure-tunnel",
|
||||
"validate-tunnel-response",
|
||||
@@ -112,7 +114,8 @@ export class ManagedEndpointOriginNotAllowed extends Schema.TaggedErrorClass<Man
|
||||
export type ManagedEndpointProviderError =
|
||||
| ManagedEndpointProvisioningNotConfigured
|
||||
| ManagedEndpointProvisioningFailed
|
||||
| ManagedEndpointOriginNotAllowed;
|
||||
| ManagedEndpointOriginNotAllowed
|
||||
| ManagedTunnelLimits.ManagedTunnelLimitExceeded;
|
||||
|
||||
export interface ManagedEndpointProvisioningResult {
|
||||
readonly endpoint: RelayManagedEndpoint;
|
||||
@@ -331,6 +334,7 @@ export const make = Effect.gen(function* () {
|
||||
const tunnels = yield* ManagedEndpointTunnelClient;
|
||||
const dns = yield* ManagedEndpointDnsClient;
|
||||
const allocations = yield* ManagedEndpointAllocations.ManagedEndpointAllocations;
|
||||
const tunnelLimits = yield* ManagedTunnelLimits.ManagedTunnelLimits;
|
||||
|
||||
const updateExistingDnsRecords = Effect.fnUntraced(function* (
|
||||
records: ReadonlyArray<{ readonly id: string }>,
|
||||
@@ -504,6 +508,26 @@ export const make = Effect.gen(function* () {
|
||||
environmentHash,
|
||||
);
|
||||
const requestedTunnelName = managedEndpointTunnelName(cf.namespace, environmentHash);
|
||||
yield* tunnelLimits
|
||||
.ensureCapacity({
|
||||
userId: input.userId,
|
||||
environmentId: input.environmentId,
|
||||
})
|
||||
.pipe(
|
||||
Effect.catchTags({
|
||||
ManagedTunnelLimitPersistenceError: (cause) =>
|
||||
Effect.fail(
|
||||
new ManagedEndpointProvisioningFailed({
|
||||
userId: input.userId,
|
||||
environmentId: input.environmentId,
|
||||
stage: "check-tunnel-limit",
|
||||
hostname: requestedHostname,
|
||||
tunnelName: requestedTunnelName,
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
}),
|
||||
);
|
||||
const allocation = yield* allocations
|
||||
.reserve({
|
||||
userId: input.userId,
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
import { describe, expect, it } from "@effect/vitest";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
|
||||
import * as RelayDb from "../db.ts";
|
||||
import {
|
||||
relayManagedEndpointAllocations,
|
||||
relayManagedTunnelLimits,
|
||||
} from "../persistence/schema.ts";
|
||||
import * as ManagedTunnelLimits from "./ManagedTunnelLimits.ts";
|
||||
|
||||
const layerWithDb = (db: RelayDb.RelayDb["Service"]) =>
|
||||
ManagedTunnelLimits.layer.pipe(Layer.provide(Layer.succeed(RelayDb.RelayDb, db)));
|
||||
|
||||
function makeFakeDb(input: {
|
||||
readonly overrideRows?: Effect.Effect<ReadonlyArray<{ readonly maxTunnels: number }>, Error>;
|
||||
readonly countRows?: Effect.Effect<ReadonlyArray<{ readonly activeTunnels: number }>, Error>;
|
||||
}) {
|
||||
return {
|
||||
select: () => ({
|
||||
from: (table: unknown) => {
|
||||
if (table === relayManagedTunnelLimits) {
|
||||
return {
|
||||
where: () => ({
|
||||
limit: () => input.overrideRows ?? Effect.succeed([]),
|
||||
}),
|
||||
};
|
||||
}
|
||||
expect(table).toBe(relayManagedEndpointAllocations);
|
||||
return {
|
||||
where: () => input.countRows ?? Effect.succeed([{ activeTunnels: 0 }]),
|
||||
};
|
||||
},
|
||||
}),
|
||||
} as unknown as RelayDb.RelayDb["Service"];
|
||||
}
|
||||
|
||||
describe("ManagedTunnelLimits", () => {
|
||||
it.effect("allows provisioning below the default limit", () => {
|
||||
const fakeDb = makeFakeDb({
|
||||
countRows: Effect.succeed([
|
||||
{ activeTunnels: ManagedTunnelLimits.DEFAULT_MANAGED_TUNNEL_LIMIT - 1 },
|
||||
]),
|
||||
});
|
||||
|
||||
return Effect.gen(function* () {
|
||||
const limits = yield* ManagedTunnelLimits.ManagedTunnelLimits;
|
||||
yield* limits.ensureCapacity({ userId: "user-1", environmentId: "environment-1" });
|
||||
}).pipe(Effect.provide(layerWithDb(fakeDb)));
|
||||
});
|
||||
|
||||
it.effect("rejects provisioning at the default limit of 3", () => {
|
||||
const fakeDb = makeFakeDb({
|
||||
countRows: Effect.succeed([{ activeTunnels: 3 }]),
|
||||
});
|
||||
|
||||
return Effect.gen(function* () {
|
||||
const limits = yield* ManagedTunnelLimits.ManagedTunnelLimits;
|
||||
const error = yield* Effect.flip(
|
||||
limits.ensureCapacity({ userId: "user-1", environmentId: "environment-1" }),
|
||||
);
|
||||
|
||||
expect(error).toMatchObject({
|
||||
_tag: "ManagedTunnelLimitExceeded",
|
||||
userId: "user-1",
|
||||
environmentId: "environment-1",
|
||||
maxTunnels: 3,
|
||||
activeTunnels: 3,
|
||||
});
|
||||
}).pipe(Effect.provide(layerWithDb(fakeDb)));
|
||||
});
|
||||
|
||||
it.effect("honors a per-user override above the default", () => {
|
||||
const fakeDb = makeFakeDb({
|
||||
overrideRows: Effect.succeed([{ maxTunnels: 25 }]),
|
||||
countRows: Effect.succeed([{ activeTunnels: 10 }]),
|
||||
});
|
||||
|
||||
return Effect.gen(function* () {
|
||||
const limits = yield* ManagedTunnelLimits.ManagedTunnelLimits;
|
||||
yield* limits.ensureCapacity({ userId: "user-1", environmentId: "environment-1" });
|
||||
}).pipe(Effect.provide(layerWithDb(fakeDb)));
|
||||
});
|
||||
|
||||
it.effect("honors a per-user override below the default", () => {
|
||||
const fakeDb = makeFakeDb({
|
||||
overrideRows: Effect.succeed([{ maxTunnels: 1 }]),
|
||||
countRows: Effect.succeed([{ activeTunnels: 1 }]),
|
||||
});
|
||||
|
||||
return Effect.gen(function* () {
|
||||
const limits = yield* ManagedTunnelLimits.ManagedTunnelLimits;
|
||||
const error = yield* Effect.flip(
|
||||
limits.ensureCapacity({ userId: "user-1", environmentId: "environment-1" }),
|
||||
);
|
||||
|
||||
expect(error).toMatchObject({
|
||||
_tag: "ManagedTunnelLimitExceeded",
|
||||
maxTunnels: 1,
|
||||
activeTunnels: 1,
|
||||
});
|
||||
}).pipe(Effect.provide(layerWithDb(fakeDb)));
|
||||
});
|
||||
|
||||
it.effect("retains database failures with operation and user identity", () => {
|
||||
const cause = new Error("database unavailable");
|
||||
const fakeDb = makeFakeDb({
|
||||
overrideRows: Effect.fail(cause),
|
||||
});
|
||||
|
||||
return Effect.gen(function* () {
|
||||
const limits = yield* ManagedTunnelLimits.ManagedTunnelLimits;
|
||||
const error = yield* Effect.flip(
|
||||
limits.ensureCapacity({ userId: "user-1", environmentId: "environment-1" }),
|
||||
);
|
||||
|
||||
expect(error).toMatchObject({
|
||||
_tag: "ManagedTunnelLimitPersistenceError",
|
||||
operation: "load-limit",
|
||||
userId: "user-1",
|
||||
});
|
||||
expect(error).toHaveProperty("cause", cause);
|
||||
}).pipe(Effect.provide(layerWithDb(fakeDb)));
|
||||
});
|
||||
|
||||
it.effect("retains count failures with operation and user identity", () => {
|
||||
const cause = new Error("database unavailable");
|
||||
const fakeDb = makeFakeDb({
|
||||
countRows: Effect.fail(cause),
|
||||
});
|
||||
|
||||
return Effect.gen(function* () {
|
||||
const limits = yield* ManagedTunnelLimits.ManagedTunnelLimits;
|
||||
const error = yield* Effect.flip(
|
||||
limits.ensureCapacity({ userId: "user-1", environmentId: "environment-1" }),
|
||||
);
|
||||
|
||||
expect(error).toMatchObject({
|
||||
_tag: "ManagedTunnelLimitPersistenceError",
|
||||
operation: "count-tunnels",
|
||||
userId: "user-1",
|
||||
});
|
||||
}).pipe(Effect.provide(layerWithDb(fakeDb)));
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,114 @@
|
||||
import { and, count, eq, ne } from "drizzle-orm";
|
||||
import * as Context from "effect/Context";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Schema from "effect/Schema";
|
||||
|
||||
import * as RelayDb from "../db.ts";
|
||||
import {
|
||||
relayManagedEndpointAllocations,
|
||||
relayManagedTunnelLimits,
|
||||
} from "../persistence/schema.ts";
|
||||
|
||||
/**
|
||||
* Managed tunnels a user may hold at once unless a row in
|
||||
* `relay_managed_tunnel_limits` overrides it for that user.
|
||||
*/
|
||||
export const DEFAULT_MANAGED_TUNNEL_LIMIT = 3;
|
||||
|
||||
export class ManagedTunnelLimitPersistenceError extends Schema.TaggedErrorClass<ManagedTunnelLimitPersistenceError>()(
|
||||
"ManagedTunnelLimitPersistenceError",
|
||||
{
|
||||
operation: Schema.Literals(["load-limit", "count-tunnels"]),
|
||||
userId: Schema.String,
|
||||
cause: Schema.Defect(),
|
||||
},
|
||||
) {
|
||||
override get message(): string {
|
||||
return `Managed tunnel limit '${this.operation}' failed for user '${this.userId}'`;
|
||||
}
|
||||
}
|
||||
|
||||
export class ManagedTunnelLimitExceeded extends Schema.TaggedErrorClass<ManagedTunnelLimitExceeded>()(
|
||||
"ManagedTunnelLimitExceeded",
|
||||
{
|
||||
userId: Schema.String,
|
||||
environmentId: Schema.String,
|
||||
maxTunnels: Schema.Number,
|
||||
activeTunnels: Schema.Number,
|
||||
},
|
||||
) {
|
||||
override get message(): string {
|
||||
return `Managed tunnel limit reached for user '${this.userId}': ${this.activeTunnels} of ${this.maxTunnels} tunnels in use`;
|
||||
}
|
||||
}
|
||||
|
||||
export class ManagedTunnelLimits extends Context.Service<
|
||||
ManagedTunnelLimits,
|
||||
{
|
||||
readonly ensureCapacity: (input: {
|
||||
readonly userId: string;
|
||||
readonly environmentId: string;
|
||||
}) => Effect.Effect<void, ManagedTunnelLimitExceeded | ManagedTunnelLimitPersistenceError>;
|
||||
}
|
||||
>()("t3code-relay/environments/ManagedTunnelLimits") {}
|
||||
|
||||
export const make = Effect.gen(function* () {
|
||||
const db = yield* RelayDb.RelayDb;
|
||||
|
||||
return ManagedTunnelLimits.of({
|
||||
ensureCapacity: Effect.fn("relay.managed_tunnel_limits.ensure_capacity")(function* (input) {
|
||||
const overrides = yield* db
|
||||
.select({ maxTunnels: relayManagedTunnelLimits.maxTunnels })
|
||||
.from(relayManagedTunnelLimits)
|
||||
.where(eq(relayManagedTunnelLimits.userId, input.userId))
|
||||
.limit(1)
|
||||
.pipe(
|
||||
Effect.mapError(
|
||||
(cause) =>
|
||||
new ManagedTunnelLimitPersistenceError({
|
||||
operation: "load-limit",
|
||||
userId: input.userId,
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
);
|
||||
const maxTunnels = overrides[0]?.maxTunnels ?? DEFAULT_MANAGED_TUNNEL_LIMIT;
|
||||
|
||||
// Allocations already held for this environment are excluded so that
|
||||
// re-linking an environment the user already has a tunnel for stays
|
||||
// idempotent even when the account is at its limit.
|
||||
const counted = yield* db
|
||||
.select({ activeTunnels: count() })
|
||||
.from(relayManagedEndpointAllocations)
|
||||
.where(
|
||||
and(
|
||||
eq(relayManagedEndpointAllocations.userId, input.userId),
|
||||
ne(relayManagedEndpointAllocations.environmentId, input.environmentId),
|
||||
),
|
||||
)
|
||||
.pipe(
|
||||
Effect.mapError(
|
||||
(cause) =>
|
||||
new ManagedTunnelLimitPersistenceError({
|
||||
operation: "count-tunnels",
|
||||
userId: input.userId,
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
);
|
||||
const activeTunnels = counted[0]?.activeTunnels ?? 0;
|
||||
|
||||
if (activeTunnels >= maxTunnels) {
|
||||
return yield* new ManagedTunnelLimitExceeded({
|
||||
userId: input.userId,
|
||||
environmentId: input.environmentId,
|
||||
maxTunnels,
|
||||
activeTunnels,
|
||||
});
|
||||
}
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
export const layer = Layer.effect(ManagedTunnelLimits, make);
|
||||
@@ -43,6 +43,7 @@ import {
|
||||
RelayEnvironmentLinkProofExpiredError,
|
||||
RelayEnvironmentLinkProofInvalidError,
|
||||
RelayEnvironmentLinkUnavailableError,
|
||||
RelayEnvironmentLinkLimitExceededError,
|
||||
RelayEnvironmentPrincipal,
|
||||
type RelayEnvironmentConnectRequest,
|
||||
type RelayDpopAccessTokenScope,
|
||||
@@ -536,6 +537,12 @@ export const clientApi = HttpApiBuilder.group(
|
||||
reason: "origin_not_allowed",
|
||||
traceId,
|
||||
}),
|
||||
ManagedTunnelLimitExceeded: (limitError, traceId) =>
|
||||
new RelayEnvironmentLinkLimitExceededError({
|
||||
code: "environment_link_limit_exceeded",
|
||||
maxTunnels: limitError.maxTunnels,
|
||||
traceId,
|
||||
}),
|
||||
EnvironmentLinkUpsertPersistenceError: (_error, traceId) =>
|
||||
new RelayEnvironmentLinkFailedError({
|
||||
code: "environment_link_failed",
|
||||
|
||||
@@ -105,6 +105,13 @@ export const relayManagedEndpointAllocations = pgTable(
|
||||
],
|
||||
);
|
||||
|
||||
export const relayManagedTunnelLimits = pgTable("relay_managed_tunnel_limits", {
|
||||
userId: varchar("user_id", { length: 191 }).primaryKey(),
|
||||
maxTunnels: integer("max_tunnels").notNull(),
|
||||
createdAt: varchar("created_at", { length: 64 }).notNull(),
|
||||
updatedAt: varchar("updated_at", { length: 64 }).notNull(),
|
||||
});
|
||||
|
||||
export const relayEnvironmentCredentials = pgTable(
|
||||
"relay_environment_credentials",
|
||||
{
|
||||
|
||||
@@ -55,6 +55,7 @@ import * as EnvironmentConnector from "./environments/EnvironmentConnector.ts";
|
||||
import * as EnvironmentLinker from "./environments/EnvironmentLinker.ts";
|
||||
import * as EnvironmentPublishSignatures from "./environments/EnvironmentPublishSignatures.ts";
|
||||
import * as ManagedEndpointProvider from "./environments/ManagedEndpointProvider.ts";
|
||||
import * as ManagedTunnelLimits from "./environments/ManagedTunnelLimits.ts";
|
||||
import * as MobileRegistrations from "./agentActivity/MobileRegistrations.ts";
|
||||
|
||||
const webcryptoLayer = Layer.succeed(
|
||||
@@ -205,7 +206,13 @@ export default class Api extends Cloudflare.Worker<Api>()(
|
||||
Layer.provideMerge(AgentActivityRows.layer),
|
||||
Layer.provideMerge(Devices.layer),
|
||||
Layer.provideMerge(EnvironmentCredentials.layer),
|
||||
Layer.provideMerge(Layer.mergeAll(EnvironmentLinks.layer, ManagedEndpointAllocations.layer)),
|
||||
Layer.provideMerge(
|
||||
Layer.mergeAll(
|
||||
EnvironmentLinks.layer,
|
||||
ManagedEndpointAllocations.layer,
|
||||
ManagedTunnelLimits.layer,
|
||||
),
|
||||
),
|
||||
Layer.provideMerge(LiveActivities.layer),
|
||||
Layer.provideMerge(DeliveryAttempts.layer),
|
||||
Layer.provideMerge(RelayTokens.layer),
|
||||
|
||||
@@ -45,6 +45,7 @@ function relayProtectedError(error: RelayProtectedError): ConnectionAttemptError
|
||||
});
|
||||
case "RelayEnvironmentConnectNotAuthorizedError":
|
||||
case "RelayEnvironmentLinkProofInvalidError":
|
||||
case "RelayEnvironmentLinkLimitExceededError":
|
||||
return new ConnectionBlockedError({
|
||||
reason: "permission",
|
||||
detail: error.message,
|
||||
|
||||
@@ -439,6 +439,20 @@ export class RelayEnvironmentLinkUnavailableError extends Schema.TaggedErrorClas
|
||||
}
|
||||
}
|
||||
|
||||
export class RelayEnvironmentLinkLimitExceededError extends Schema.TaggedErrorClass<RelayEnvironmentLinkLimitExceededError>()(
|
||||
"RelayEnvironmentLinkLimitExceededError",
|
||||
{
|
||||
code: Schema.Literal("environment_link_limit_exceeded"),
|
||||
maxTunnels: Schema.Number,
|
||||
traceId: TrimmedNonEmptyString,
|
||||
},
|
||||
{ httpApiStatus: 403 },
|
||||
) {
|
||||
override get message(): string {
|
||||
return `Relay managed tunnel limit reached: this account allows at most ${this.maxTunnels} tunnels`;
|
||||
}
|
||||
}
|
||||
|
||||
export class RelayAgentActivityPublishProofExpiredError extends Schema.TaggedErrorClass<RelayAgentActivityPublishProofExpiredError>()(
|
||||
"RelayAgentActivityPublishProofExpiredError",
|
||||
{
|
||||
@@ -489,6 +503,7 @@ export const RelayProtectedError = Schema.Union([
|
||||
RelayEnvironmentEndpointTimedOutError,
|
||||
RelayEnvironmentLinkFailedError,
|
||||
RelayEnvironmentLinkUnavailableError,
|
||||
RelayEnvironmentLinkLimitExceededError,
|
||||
RelayAgentActivityPublishProofExpiredError,
|
||||
RelayAgentActivityPublishProofInvalidError,
|
||||
RelayInternalError,
|
||||
@@ -502,6 +517,7 @@ const RelayEnvironmentLinkErrors = [
|
||||
RelayEnvironmentLinkProofExpiredError,
|
||||
RelayEnvironmentLinkProofInvalidError,
|
||||
RelayEnvironmentLinkUnavailableError,
|
||||
RelayEnvironmentLinkLimitExceededError,
|
||||
RelayEnvironmentLinkFailedError,
|
||||
RelayInternalError,
|
||||
] as const;
|
||||
|
||||
Reference in new issue
Block a user