Skip to content

Commit 672fc40

Browse files
Dylanclaude
andcommitted
Add Firestore security rules with CD deployment
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 3527002 commit 672fc40

4 files changed

Lines changed: 51 additions & 0 deletions

File tree

.firebaserc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"projects": {
3+
"default": "retrotools-284402"
4+
}
5+
}

.github/workflows/CICD.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,18 @@ jobs:
5454
run: gcloud auth configure-docker us-east1-docker.pkg.dev && docker push us-east1-docker.pkg.dev/${{ secrets.GCP_PROJECT }}/retrograde/retrograde:latest
5555
- name: Deploy new cloudrun revision
5656
run: gcloud run deploy retrotools --image us-east1-docker.pkg.dev/${{ secrets.GCP_PROJECT }}/retrograde/retrograde:latest --platform managed --region=us-east1 --project=${{ secrets.GCP_PROJECT }}
57+
58+
deploy-firestore-rules:
59+
runs-on: ubuntu-latest
60+
needs: ci
61+
if: "!contains(github.event.head_commit.message, '[skip ci]') && github.ref == 'refs/heads/master'"
62+
steps:
63+
- uses: actions/checkout@v1
64+
- id: auth
65+
uses: google-github-actions/auth@v1
66+
with:
67+
credentials_json: "${{ secrets.GCP_ACCOUNT_CREDENTIALS }}"
68+
- name: Install Firebase CLI
69+
run: npm install -g firebase-tools
70+
- name: Deploy Firestore rules
71+
run: firebase deploy --only firestore:rules --project ${{ secrets.GCP_PROJECT }}

firebase.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
"firestore": {
3+
"rules": "firestore.rules"
4+
},
25
"emulators": {
36
"firestore": {
47
"port": 8080

firestore.rules

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
rules_version = '2';
2+
service cloud.firestore {
3+
match /databases/{database}/documents {
4+
// Default deny
5+
match /{document=**} {
6+
allow read, write: if false;
7+
}
8+
9+
// Allow read access if user is a board participant
10+
match /boards/{boardId} {
11+
allow read: if isAuthenticated() && isBoardParticipant(boardId);
12+
}
13+
14+
match /boards/{boardId}/{_=**} {
15+
allow read: if isAuthenticated() && isBoardParticipant(boardId);
16+
}
17+
18+
function isAuthenticated() {
19+
return request.auth != null;
20+
}
21+
22+
function isBoardParticipant(boardId) {
23+
return
24+
exists(/databases/$(database)/documents/participants/$(request.auth.uid)) &&
25+
/databases/%28default%29/documents/boards/$(boardId) in get(/databases/$(database)/documents/participants/$(request.auth.uid)).data.boards
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)