firebasegoogle-cloud-firestorefirebase-security

How to delete firestore security rules history


so we stumbled over the issue that we hit the quota limit for stored firestore security rules of 2500. During deployment the CLI asks us if we want to delete the oldest 10 rules. Since we want to automate our deployment reacting to a console prompt is not exactly what we want.

Anyone knows how to mass delete the complete firestore security rule history without having to do it manually one by one trough firebase?

I couldn't find any info on that whatsoever from Googles side...


Solution

  • Not sure if you can delete all security rules at once, but as per the documentation, you can avoid manual work by creating a logic to delete the oldest rules:

    For example, to delete ALL rule sets deployed for longer than 30 days:

    const thirtyDays = new Date(Date.now() - THIRTY_DAYS_IN_MILLIS);
    const promises = [];
    allRulesets.forEach((rs) => {
      if (new Date(rs.crateTime) < thirtyDays) {
        promises.push(admin.securityRules().deleteRuleset(rs.name));
      }
    });
    await Promise.all(promises);
    console.log(`Deleted ${promises.length} rulesets.`);