Merge pull request #967 from tdurieux/fix/deployment-and-repository-errors

fix: guard GitHub App deployments and distinguish removed repositories
This commit is contained in:
Thomas Durieux authored and GitHub committed 2026-11-15 00:18:37 +01:00
commit fbb9c5fac0
9 files changed
+118 -14

No files matched your search

+4 -6
View File
@@ -561,12 +561,10 @@ export default class Repository {
await this.markExpired();
}
}
if (
this.status == RepositoryStatus.EXPIRED ||
this.status == RepositoryStatus.EXPIRING ||
this.status == RepositoryStatus.REMOVING ||
this.status == RepositoryStatus.REMOVED
) {
if (this.status == RepositoryStatus.REMOVING || this.status == RepositoryStatus.REMOVED) {
throw new AnonymousError("is_removed", { object: this, httpStatus: 410 });
}
if (this.status == RepositoryStatus.EXPIRED || this.status == RepositoryStatus.EXPIRING) {
throw new AnonymousError("repository_expired", {
object: this,
httpStatus: 410,
+31
View File
@@ -0,0 +1,31 @@
import { createPrivateKey, createSign } from "crypto";
import { readFileSync } from "fs";
type AppKeyConfig = {
GITHUB_APP_ENABLED: boolean;
GITHUB_APP_PRIVATE_KEY: string;
GITHUB_APP_PRIVATE_KEY_FILE: string;
};
// Run in each replacement service, with its actual user, environment and mounts.
// Never include the key, its path, or crypto error details in deployment output.
export function checkGitHubAppKey(config: AppKeyConfig): void {
if (!config.GITHUB_APP_ENABLED) return;
try {
const key = createPrivateKey(config.GITHUB_APP_PRIVATE_KEY || readFileSync(config.GITHUB_APP_PRIVATE_KEY_FILE, "utf8"));
if (key.asymmetricKeyType !== "rsa") throw new Error("Not an RSA key");
createSign("RSA-SHA256").update("anonymous-github-deployment-preflight").sign(key);
} catch {
throw new Error("GitHub App signing key is missing, unreadable or invalid. Preserve the GitHub App Compose override and verify the replacement service's key configuration.");
}
}
if (require.main === module) {
try {
checkGitHubAppKey(require("../config").default);
} catch {
// Configuration validation can also fail. Do not echo environment values.
process.stderr.write("GitHub App preflight failed. Check required configuration and the read-only signing-key mount before deploying.\n");
process.exitCode = 1;
}
}