Skip to content

Commit 1b54dde

Browse files
committed
Merge remote-tracking branch 'origin/main' into t3/windows-service-trim
2 parents a65dbed + 10128e5 commit 1b54dde

129 files changed

Lines changed: 4026 additions & 505 deletions

File tree

Some content is hidden

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

‎apps/marketing/src/layouts/Layout.astro‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const {
4646
const currentLocale = localeInfo(locale);
4747
const homeHref = localizedHref(locale, "/");
4848
const downloadHref = localizedHref(locale, "/download");
49-
// English-only pages still declare themselves, so every page carries hreflang and x-default.
49+
// English-only pages still declare themselves, so every indexable page carries hreflang and x-default.
5050
const alternates = localizedPath
5151
? LOCALES.map((entry) => ({
5252
hreflang: entry.code,
@@ -95,8 +95,12 @@ const canonicalUrl = new URL(Astro.url.pathname, Astro.site);
9595
<link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16" />
9696
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
9797
<link rel="sitemap" type="application/xml" href="/sitemap.xml" />
98-
{alternates.map((entry) => <link rel="alternate" hreflang={entry.hreflang} href={entry.href} />)}
99-
<link rel="alternate" hreflang="x-default" href={defaultAlternate.href} />
98+
{!noindex && (
99+
<>
100+
{alternates.map((entry) => <link rel="alternate" hreflang={entry.hreflang} href={entry.href} />)}
101+
<link rel="alternate" hreflang="x-default" href={defaultAlternate.href} />
102+
</>
103+
)}
100104
<title>{title}</title>
101105
<script is:inline type="application/ld+json" set:html={structuredData} />
102106
</head>

‎apps/marketing/src/lib/seo.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ export const websiteJsonLd = (): JsonLd => ({
3838
publisher: { "@id": ORGANIZATION_ID },
3939
});
4040

41-
export const softwareJsonLd = (): JsonLd => ({
41+
export const softwareJsonLd = (description: string): JsonLd => ({
4242
"@type": "SoftwareApplication",
4343
"@id": SOFTWARE_ID,
4444
name: SITE_NAME,
45-
description: `${SITE_NAME}. ${SITE_TAGLINE}.`,
45+
description,
4646
url: SITE_ORIGIN,
4747
downloadUrl: absoluteUrl("/download"),
4848
applicationCategory: "DeveloperApplication",

‎apps/marketing/src/pages/[...locale]/download.astro‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const imageProps = {
2828
title={t.title}
2929
description={t.description}
3030
jsonLd={[
31-
softwareJsonLd(),
31+
softwareJsonLd(messagesFor(locale).layout.defaultDescription),
3232
breadcrumbJsonLd([
3333
{ name: "T3 Code", path: localizedHref(locale, "/") },
3434
{ name: t.breadcrumb, path: localizedHref(locale, "/download") },

‎apps/marketing/src/pages/[...locale]/index.astro‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const mobileEndorsementRows = [
4141
<Layout
4242
title={t.title}
4343
description={t.description}
44-
jsonLd={[softwareJsonLd()]}
44+
jsonLd={[softwareJsonLd(messagesFor(locale).layout.defaultDescription)]}
4545
locale={locale}
4646
localizedPath="/"
4747
>

‎apps/server/src/cloud/CloudLink.lifecycle.test.ts‎

Lines changed: 104 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,23 @@ import * as Path from "effect/Path";
99
import * as PlatformError from "effect/PlatformError";
1010
import * as Schema from "effect/Schema";
1111
import * as Stream from "effect/Stream";
12-
import { HttpClient, HttpClientResponse, HttpServer, type HttpClientRequest } from "effect/http";
12+
import * as TestClock from "effect/testing/TestClock";
13+
import {
14+
HttpClient,
15+
HttpClientResponse,
16+
HttpServer,
17+
HttpServerRequest,
18+
type HttpClientRequest,
19+
} from "effect/http";
20+
import { RELAY_LINK_PROOF_TYP, signRelayJwt, verifyRelayJwt } from "@t3tools/shared/relayJwt";
1321
import * as NetAddress from "effect/net/NetAddress";
1422

15-
import { EnvironmentId } from "@t3tools/contracts";
23+
import {
24+
AuthSessionId,
25+
type AuthEnvironmentScope,
26+
EnvironmentAuthenticatedPrincipal,
27+
EnvironmentId,
28+
} from "@t3tools/contracts";
1629
import * as EnvironmentKeys from "./environmentKeys.ts";
1730
import * as EnvironmentAuth from "../auth/EnvironmentAuth.ts";
1831
import * as ServerSecretStore from "../auth/ServerSecretStore.ts";
@@ -28,7 +41,10 @@ import * as ServerEnvironment from "../environment/ServerEnvironment.ts";
2841
import * as AgentAwarenessRelay from "../relay/AgentAwarenessRelay.ts";
2942
import { CLOUD_CLI_DESIRED_LINK_SECRET } from "./CliState.ts";
3043
import * as CliTokenManager from "./CliTokenManager.ts";
31-
import { RelayManagedEndpointRecoveryRegistrationRequest } from "@t3tools/contracts/relay";
44+
import {
45+
RelayEnvironmentLinkProofPayload,
46+
RelayManagedEndpointRecoveryRegistrationRequest,
47+
} from "@t3tools/contracts/relay";
3248
import {
3349
CLOUD_ENDPOINT_CONFIRMED_ORIGIN,
3450
CLOUD_ENDPOINT_RUNTIME_CONFIG,
@@ -186,7 +202,13 @@ describe("releaseManagedTunnelOnShutdown", () => {
186202
ServerEnvironment.ServerEnvironment,
187203
ServerEnvironment.ServerEnvironment.of({
188204
getEnvironmentId: Effect.succeed(EnvironmentId.make("env_123")),
189-
getDescriptor: Effect.die("unused"),
205+
getDescriptor: Effect.succeed({
206+
environmentId: EnvironmentId.make("env_123"),
207+
label: "Test environment",
208+
platform: { os: "linux", arch: "x64" },
209+
serverVersion: "0.0.0-test",
210+
capabilities: { repositoryIdentity: true },
211+
}),
190212
}),
191213
),
192214
Effect.provideService(
@@ -252,6 +274,84 @@ describe("releaseManagedTunnelOnShutdown", () => {
252274
Effect.scoped,
253275
);
254276

277+
it.effect.each([
278+
{ direction: "ahead", skewSeconds: 600 },
279+
{ direction: "behind", skewSeconds: -600 },
280+
])(
281+
"signs a link proof accepted at relay time when the host clock is $direction",
282+
({ skewSeconds }) => {
283+
const { store } = makeMemorySecretStore();
284+
285+
return Effect.gen(function* () {
286+
const relayNow = 1_800_000_000;
287+
const relayIssuer = "https://relay.example.test";
288+
const relayKeys = yield* EnvironmentKeys.getOrCreateEnvironmentKeyPairFromSecretStore(
289+
makeMemorySecretStore().store,
290+
);
291+
const challenge = yield* signRelayJwt({
292+
privateKey: relayKeys.privateKey,
293+
typ: "t3-link-challenge+jwt",
294+
payload: {
295+
kind: "environment_link_challenge",
296+
iss: relayIssuer,
297+
aud: relayIssuer,
298+
sub: "user-123",
299+
jti: "challenge-jti",
300+
iat: relayNow,
301+
exp: relayNow + 300,
302+
notificationsEnabled: true,
303+
liveActivitiesEnabled: false,
304+
managedTunnelsEnabled: false,
305+
},
306+
});
307+
yield* TestClock.setTime((relayNow + skewSeconds) * 1_000);
308+
const link = yield* CloudLink.CloudLink;
309+
const proof = yield* link
310+
.linkProof(
311+
{
312+
challenge,
313+
relayIssuer,
314+
endpoint: {
315+
httpBaseUrl: "http://127.0.0.1:3773",
316+
wsBaseUrl: "ws://127.0.0.1:3773",
317+
providerKind: "manual",
318+
},
319+
origin: { localHttpHost: "127.0.0.1", localHttpPort: 3773 },
320+
},
321+
HttpServerRequest.fromWeb(
322+
new Request("http://127.0.0.1:3773/api/t3-connect/link-proof"),
323+
),
324+
)
325+
.pipe(
326+
Effect.provideService(EnvironmentAuthenticatedPrincipal, {
327+
sessionId: AuthSessionId.make("test-session"),
328+
subject: "test",
329+
method: "bearer-access-token",
330+
scopes: new Set<AuthEnvironmentScope>(),
331+
}),
332+
);
333+
const environmentKeys =
334+
yield* EnvironmentKeys.getOrCreateEnvironmentKeyPairFromSecretStore(store);
335+
yield* TestClock.setTime(relayNow * 1_000);
336+
const verified = yield* verifyRelayJwt(RelayEnvironmentLinkProofPayload, {
337+
publicKey: environmentKeys.publicKey,
338+
token: proof,
339+
typ: RELAY_LINK_PROOF_TYP,
340+
issuer: "t3-env:env_123",
341+
audience: relayIssuer,
342+
});
343+
344+
expect(verified).toMatchObject({
345+
iat: relayNow,
346+
exp: relayNow + 300,
347+
challenge,
348+
environmentId: "env_123",
349+
scopes: ["agent_activity_notifications"],
350+
});
351+
}).pipe(provideReleaseHarness({ store, applyConfigCalls: [], requests: [] }));
352+
},
353+
);
354+
255355
const managedLinkSecrets = [
256356
[CLOUD_ENDPOINT_RUNTIME_CONFIG, "runtime-config"],
257357
[CLOUD_ENDPOINT_CONFIRMED_ORIGIN, "confirmed-origin"],

‎apps/server/src/cloud/CloudLink.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
} from "@t3tools/contracts/relay";
3030
import { withRelayClientTracing } from "@t3tools/shared/relayTracing";
3131
import {
32+
decodeRelayJwt,
3233
normalizeRelayIssuer,
3334
RELAY_HEALTH_REQUEST_TYP,
3435
RELAY_HEALTH_RESPONSE_TYP,
@@ -592,16 +593,22 @@ const make = Effect.gen(function* () {
592593
return yield* new CloudLinkOriginInvalidError({ origin: "endpoint" });
593594
}
594595
const now = yield* DateTime.now;
595-
const expiresAt = DateTime.add(now, { minutes: 5 });
596596
const nowSeconds = Math.floor(now.epochMilliseconds / 1_000);
597+
// Borrow only the relay clock; the relay still verifies and consumes the challenge.
598+
const issuedAt = yield* decodeRelayJwt(request.challenge).pipe(
599+
Effect.map(({ iat }) =>
600+
typeof iat === "number" && Number.isSafeInteger(iat) && iat > 0 ? iat : nowSeconds,
601+
),
602+
Effect.orElseSucceed(() => nowSeconds),
603+
);
597604
const descriptor = yield* environment.getDescriptor;
598605
const payload = {
599606
iss: `t3-env:${descriptor.environmentId}`,
600607
aud: normalizeRelayIssuer(request.relayIssuer),
601608
sub: descriptor.environmentId,
602609
jti: yield* random.uuidV4(),
603-
iat: nowSeconds,
604-
exp: Math.floor(expiresAt.epochMilliseconds / 1_000),
610+
iat: issuedAt,
611+
exp: issuedAt + 5 * 60,
605612
challenge: request.challenge,
606613
descriptor,
607614
environmentId: descriptor.environmentId,

‎apps/server/src/cloud/ManagedEndpointRuntime.test.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,57 @@ describe("CloudManagedEndpointRuntime", () => {
516516
}),
517517
);
518518

519+
it.effect("remembers an HTTP/2 fallback the relay client made on its own", () =>
520+
Effect.gen(function* () {
521+
const context = yield* Layer.build(
522+
ServerSecretStore.layer.pipe(
523+
Layer.provide(ServerConfig.layerTest(process.cwd(), { prefix: "t3-transport-test-" })),
524+
Layer.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
525+
),
526+
);
527+
const secretStoreLayer = Layer.succeed(
528+
ServerSecretStore.ServerSecretStore,
529+
context.pipe(Context.get(ServerSecretStore.ServerSecretStore)),
530+
);
531+
const start = (spawner: ReturnType<typeof ChildProcessSpawner.make>) =>
532+
buildCloudManagedEndpointRuntime(
533+
spawner,
534+
layerRelayClientAvailable,
535+
unusedHttpClient,
536+
secretStoreLayer,
537+
);
538+
const registered = (protocol: string) =>
539+
`2026-11-10T01:43:17Z INF Registered tunnel connection connIndex=0 connection=c1 event=0 ip=198.41.192.7 location=fra08 protocol=${protocol}\n`;
540+
541+
yield* Effect.gen(function* () {
542+
const fixture = yield* makeTransportSpawner();
543+
const runtime = yield* start(fixture.spawner);
544+
yield* runtime.applyConfig(tunnelConfig);
545+
yield* fixture.emit(0, registered("quic"));
546+
yield* Stream.runHead(runtime.tunnelConnected);
547+
}).pipe(Effect.scoped);
548+
yield* Effect.gen(function* () {
549+
const fixture = yield* makeTransportSpawner();
550+
const runtime = yield* start(fixture.spawner);
551+
yield* runtime.applyConfig(tunnelConfig);
552+
expect(fixture.spawned[0]!.args).not.toContain("--protocol");
553+
// cloudflared, started with `auto`, gave up on QUIC itself.
554+
yield* fixture.emit(0, registered("http2"));
555+
yield* Stream.runHead(runtime.tunnelConnected);
556+
// The connector already runs on HTTP/2, so it is not restarted.
557+
expect(fixture.spawned).toHaveLength(1);
558+
expect(fixture.killed).toEqual([]);
559+
}).pipe(Effect.scoped);
560+
561+
yield* Effect.gen(function* () {
562+
const fixture = yield* makeTransportSpawner();
563+
const runtime = yield* start(fixture.spawner);
564+
yield* runtime.applyConfig(tunnelConfig);
565+
expect(fixture.spawned[0]!.args.slice(-3)).toEqual(["--protocol", "http2", "run"]);
566+
}).pipe(Effect.scoped);
567+
}),
568+
);
569+
519570
it.effect(
520571
"ignores invalid or unreadable fallback state and still falls back if persistence fails",
521572
() =>

‎apps/server/src/cloud/ManagedEndpointRuntime.ts‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -571,10 +571,7 @@ export const make = Effect.gen(function* () {
571571
}
572572
});
573573

574-
const switchToHttp2 = Effect.fnUntraced(function* (connector: ActiveConnector) {
575-
const active = yield* Ref.get(activeRef);
576-
const desiredConfig = yield* Ref.get(desiredConfigRef);
577-
if ((yield* Ref.get(http2Ref)) || active !== connector || !desiredConfig) return;
574+
const rememberHttp2Fallback = Effect.fnUntraced(function* () {
578575
yield* Ref.set(http2Ref, true);
579576
yield* secrets
580577
.set(
@@ -586,6 +583,13 @@ export const make = Effect.gen(function* () {
586583
.pipe(
587584
Effect.catch(() => Effect.logWarning("Could not persist the relay client HTTP/2 fallback")),
588585
);
586+
});
587+
588+
const switchToHttp2 = Effect.fnUntraced(function* (connector: ActiveConnector) {
589+
const active = yield* Ref.get(activeRef);
590+
const desiredConfig = yield* Ref.get(desiredConfigRef);
591+
if ((yield* Ref.get(http2Ref)) || active !== connector || !desiredConfig) return;
592+
yield* rememberHttp2Fallback();
589593
yield* Effect.logWarning("Relay client keeps losing QUIC connections; switching to HTTP/2", {
590594
pid: Number(connector.child.pid),
591595
tunnelId: connector.config.tunnelId,
@@ -630,11 +634,18 @@ export const make = Effect.gen(function* () {
630634
output,
631635
};
632636
switch (classifyRelayClientOutput(line)) {
633-
case "connected":
637+
case "connected": {
634638
rejectedRegistrations = 0;
639+
const protocol = RELAY_CLIENT_PROTOCOL.exec(line)?.[1] ?? null;
635640
return Deferred.succeed(connector.registered, undefined).pipe(
641+
Effect.andThen(Ref.set(connector.protocol, protocol)),
642+
// cloudflared started with `auto` fell back on its own; later starts skip QUIC too.
636643
Effect.andThen(
637-
Ref.set(connector.protocol, RELAY_CLIENT_PROTOCOL.exec(line)?.[1] ?? null),
644+
protocol === "http2" && !transportChosenByUser
645+
? Ref.get(http2Ref).pipe(
646+
Effect.flatMap((http2) => (http2 ? Effect.void : rememberHttp2Fallback())),
647+
)
648+
: Effect.void,
638649
),
639650
Effect.andThen(
640651
Effect.logInfo("Relay client tunnel connection registered", attributes),
@@ -652,6 +663,7 @@ export const make = Effect.gen(function* () {
652663
),
653664
Effect.asVoid,
654665
);
666+
}
655667
case "unregistered":
656668
return Effect.logInfo("Relay client tunnel connection unregistered", attributes);
657669
case "warning":

0 commit comments

Comments
 (0)