overleaf-cep/server-ce/hotfix/5.5.2/pr_26783.patch
Brian Gough 0c462d45d1 Merge pull request #26815 from overleaf/bg-sp-hotfix-5-5-2
[CE/SP] Hotfix 5.5.2

GitOrigin-RevId: bcd409968ef0321dd1d8050553e7c9a02d3efdc4
2025-07-07 08:05:45 +00:00

58 lines
1.9 KiB
Diff

diff --git a/services/web/modules/server-ce-scripts/scripts/check-mongodb.mjs b/services/web/modules/server-ce-scripts/scripts/check-mongodb.mjs
index 29f5e7ffd26..46be91a1d9c 100644
--- a/services/web/modules/server-ce-scripts/scripts/check-mongodb.mjs
+++ b/services/web/modules/server-ce-scripts/scripts/check-mongodb.mjs
@@ -9,6 +9,34 @@ const { ObjectId } = mongodb
const MIN_MONGO_VERSION = [6, 0]
const MIN_MONGO_FEATURE_COMPATIBILITY_VERSION = [6, 0]
+// Allow ignoring admin check failures via an environment variable
+const OVERRIDE_ENV_VAR_NAME = 'ALLOW_MONGO_ADMIN_CHECK_FAILURES'
+
+function shouldSkipAdminChecks() {
+ return process.env[OVERRIDE_ENV_VAR_NAME] === 'true'
+}
+
+function handleUnauthorizedError(err, feature) {
+ if (
+ err instanceof mongodb.MongoServerError &&
+ err.codeName === 'Unauthorized'
+ ) {
+ console.warn(`Warning: failed to check ${feature} (not authorised)`)
+ if (!shouldSkipAdminChecks()) {
+ console.error(
+ `Please ensure the MongoDB user has the required admin permissions, or\n` +
+ `set the environment variable ${OVERRIDE_ENV_VAR_NAME}=true to ignore this check.`
+ )
+ process.exit(1)
+ }
+ console.warn(
+ `Ignoring ${feature} check failure (${OVERRIDE_ENV_VAR_NAME}=${process.env[OVERRIDE_ENV_VAR_NAME]})`
+ )
+ } else {
+ throw err
+ }
+}
+
async function main() {
let mongoClient
try {
@@ -18,8 +46,16 @@ async function main() {
throw err
}
- await checkMongoVersion(mongoClient)
- await checkFeatureCompatibilityVersion(mongoClient)
+ try {
+ await checkMongoVersion(mongoClient)
+ } catch (err) {
+ handleUnauthorizedError(err, 'MongoDB version')
+ }
+ try {
+ await checkFeatureCompatibilityVersion(mongoClient)
+ } catch (err) {
+ handleUnauthorizedError(err, 'MongoDB feature compatibility version')
+ }
try {
await testTransactions(mongoClient)