Skip to content

Commit 681de0f

Browse files
authored
Merge pull request #10 from VectorInstitute/add_firestore_rules
Add firestore db rules
2 parents 4e1237a + f0ca3f6 commit 681de0f

File tree

7 files changed

+321
-0
lines changed

7 files changed

+321
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ terraform.tfvars
3030
.terraform.tfstate.lock.info
3131

3232
.coder
33+
keys/

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12

config/firestore.rules

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
rules_version = '2';
2+
3+
service cloud.firestore {
4+
match /databases/{database}/documents {
5+
6+
// Helper function to check if user is authenticated
7+
function isAuthenticated() {
8+
return request.auth != null;
9+
}
10+
11+
// Helper function to get GitHub handle from auth
12+
// Assumes GitHub auth is being used with Coder
13+
function getGitHubHandle() {
14+
return request.auth.token.github_handle;
15+
}
16+
17+
// Helper function to get the user's team name from their participant document
18+
function getUserTeam() {
19+
let participantDoc = get(/databases/$(database)/documents/participants/$(getGitHubHandle()));
20+
return participantDoc.data.team_name;
21+
}
22+
23+
// Helper function to check if user belongs to a specific team
24+
function isUserTeam(teamName) {
25+
return isAuthenticated() && getUserTeam() == teamName;
26+
}
27+
28+
// Global keys collection - read-only for all authenticated users
29+
match /global_keys/{document=**} {
30+
allow read: if isAuthenticated();
31+
allow write: if false; // Only admins via backend
32+
}
33+
34+
// Teams collection - users can only read their own team's data
35+
match /teams/{teamId} {
36+
// Users can only read their own team (which contains API keys)
37+
allow read: if isUserTeam(teamId);
38+
allow write: if false; // Only admins via backend
39+
}
40+
41+
// Participants collection
42+
match /participants/{participantId} {
43+
// Users can read their own participant document
44+
allow read: if isAuthenticated() &&
45+
participantId == getGitHubHandle();
46+
47+
// Users can update their own onboarded status and onboarded_at timestamp
48+
allow update: if isAuthenticated() &&
49+
participantId == getGitHubHandle() &&
50+
request.resource.data.diff(resource.data).affectedKeys()
51+
.hasOnly(['onboarded', 'onboarded_at']);
52+
53+
// No create or delete for participants (admin only)
54+
allow create, delete: if false;
55+
}
56+
}
57+
}

config/langfuse_keys.csv.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
team_name,langfuse_secret_key,langfuse_public_key
2+
example-team,sk-lf-example-secret-key-12345,pk-lf-example-public-key-12345
3+
awesome-team,sk-lf-awesome-secret-key-67890,pk-lf-awesome-public-key-67890

config/participants.csv.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
github_handle,team_name,email
2+
alice-smith,example-team,alice.smith@example.com
3+
bob-jones,example-team,bob.jones@example.com
4+
carol-davis,team-alpha,carol.davis@example.com
5+
david-wilson,team-alpha,david.wilson@example.com
6+
eve-martinez,team-beta,eve.martinez@example.com
7+
frank-garcia,team-beta,frank.garcia@example.com

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ requires-python = ">=3.12"
99
dependencies = [
1010
"google-cloud-firestore>=2.18.0",
1111
"google-auth>=2.29.0",
12+
"google-cloud-secret-manager>=2.20.0",
13+
"firebase-admin>=6.5.0",
1214
"openai>=1.0.0",
1315
"weaviate-client>=4.0.0",
1416
"requests>=2.31.0",
1517
"python-dotenv>=1.0.0",
1618
"pandas>=2.0.0",
19+
"rich>=13.0.0",
1720
]
1821

1922
[build-system]

uv.lock

Lines changed: 249 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)