Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions apps/controller/src/composition/repository-credentials/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ export async function loadConfiguration(
}
return gateway;
}
type TlsPair = Readonly<{ cert: Buffer; key: Buffer }>;
const loadTlsAndFactoryOptions = async (gateway: Record<string, unknown>) => {
cert = await readProtected(string(gateway.tlsCertFile), 131072, false);
tlsKey = await readProtected(string(gateway.tlsKeyFile), 65536);
const tls: TlsPair = { cert, key: tlsKey };
createSecureContext({ ...tls, minVersion: "TLSv1.2" });
return {
tls,
gatewayOrigin: config.gateway.publicOrigin,
limits: config.limits,
clock,
};
};
let tls: TlsPair;
let factory: LoadedConfiguration["factory"] &
Pick<GitHubDriverFactory, "trustedUpstreamOrigins">;
if (backendInput.kind === "github-prepared-git-registry") {
Expand Down Expand Up @@ -122,14 +136,8 @@ export async function loadConfiguration(
const apiOrigin =
backendInput.apiOrigin === undefined ? {} : { apiOrigin: string(backendInput.apiOrigin) };
const gateway = validateGateway();
cert = await readProtected(string(gateway.tlsCertFile), 131072, false);
tlsKey = await readProtected(string(gateway.tlsKeyFile), 65536);
createSecureContext({ cert, key: tlsKey, minVersion: "TLSv1.2" });
const factoryOptions = {
gatewayOrigin: config.gateway.publicOrigin,
limits: config.limits,
clock,
};
const { tls: loadedTls, ...factoryOptions } = await loadTlsAndFactoryOptions(gateway);
tls = loadedTls;
const { createPreparedGitHubRegistryFactory } =
await import("../../drivers/repo/github/access/warm-registry-factory.ts");
factory = createPreparedGitHubRegistryFactory({
Expand Down Expand Up @@ -162,14 +170,8 @@ export async function loadConfiguration(
const { createGitHubStaticTokenOwner } =
await import("../../drivers/repo/github/access/static-token.ts");
owner = createGitHubStaticTokenOwner({ token: token.subarray(0, length) });
cert = await readProtected(string(gateway.tlsCertFile), 131072, false);
tlsKey = await readProtected(string(gateway.tlsKeyFile), 65536);
createSecureContext({ cert, key: tlsKey, minVersion: "TLSv1.2" });
const factoryOptions = {
gatewayOrigin: config.gateway.publicOrigin,
limits: config.limits,
clock,
};
const { tls: loadedTls, ...factoryOptions } = await loadTlsAndFactoryOptions(gateway);
tls = loadedTls;
const { createGitHubDriverFactory } =
await import("../../drivers/repo/github/access/factory.ts");
factory = createGitHubDriverFactory({
Expand All @@ -178,12 +180,11 @@ export async function loadConfiguration(
configuration,
});
}
const ownedCert = cert;
const ownedTlsKey = tlsKey;
const ownedTls = tls;
const ownedAuthority = owner;
return Object.freeze({
config,
tls: Object.freeze({ cert: ownedCert, key: ownedTlsKey }),
tls: Object.freeze(ownedTls),
factory,
trustedUpstreamOrigins: factory.trustedUpstreamOrigins,
...(upstreamCa === undefined ? {} : { upstreamCa }),
Expand All @@ -192,8 +193,8 @@ export async function loadConfiguration(
: { authority: "github-prepared-git-registry" as const }),
close() {
ownedAuthority?.close();
ownedCert.fill(0);
ownedTlsKey.fill(0);
ownedTls.cert.fill(0);
ownedTls.key.fill(0);
},
});
} catch (error) {
Expand Down
Loading