Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(rbac): keep a project's own default from being overridden (#85351)

Alex Liderdee0815fd8bc
diff --git a/ee/api/rbac/test/test_access_control.py b/ee/api/rbac/test/test_access_control.py
index e7fd2151b379..370d7b358a3a 100644
--- a/ee/api/rbac/test/test_access_control.py
+++ b/ee/api/rbac/test/test_access_control.py
@@ -2234,7 +2234,11 @@ class TestAccessControlMembersEndpoint(BaseAccessControlTest):
# Create another team and set different member override directly in DB
other_team = Team.objects.create(organization=self.organization, name="Other Team")
AccessControl.objects.create(
- team=other_team, resource="project", organization_member=self.user2_membership, access_level="admin"
+ team=other_team,
+ resource="project",
+ resource_id=str(other_team.id),
+ organization_member=self.user2_membership,
+ access_level="admin",
)
# Request should only return current team's member overrides
diff --git a/posthog/api/test/test_integration.py b/posthog/api/test/test_integration.py
index 70345c03a249..ba49f212c526 100644
--- a/posthog/api/test/test_integration.py
+++ b/posthog/api/test/test_integration.py
@@ -3492,7 +3492,7 @@ class TestGitHubTeamIntegrationComplete:
def _sibling_github_integration(self, name: str, installation_id: str, private: bool = False) -> Integration:
team = Team.objects.create(organization=self.organization, name=name)
if private:
- AccessControl.objects.create(team=team, resource="project", access_level="none")
+ AccessControl.objects.create(team=team, resource="project", resource_id=str(team.id), access_level="none")
return Integration.objects.create(
team=team,
kind="github",
diff --git a/posthog/api/test/test_organization.py b/posthog/api/test/test_organization.py
index 918152a28c8a..c12df897b51c 100644
--- a/posthog/api/test/test_organization.py
+++ b/posthog/api/test/test_organization.py
@@ -977,7 +977,9 @@ class TestOrganizationSerializer(APIBaseTest):
[
(
"access_control",
- lambda self: AccessControl.objects.create(team=self.team, access_level="member", resource="project"),
+ lambda self: AccessControl.objects.create(
+ team=self.team, access_level="member", resource="project", resource_id=str(self.team.id)
+ ),
),
(
"explicit_team_membership",
diff --git a/posthog/rbac/test/test_user_access_control.py b/posthog/rbac/test/test_user_access_control.py
index b56410fbbfd3..f33529dd6ee1 100644
--- a/posthog/rbac/test/test_user_access_control.py
+++ b/posthog/rbac/test/test_user_access_control.py
@@ -225,6 +225,16 @@ class TestUserAccessControl(BaseUserAccessControlTest):
is True # This is the default
) # Fix this - need to load all access controls...
+ def test_project_default_survives_a_resource_level_project_rule(self):
+ # A rule about "project" written without a resource_id is not a shape the product writes,
+ # and enforcement never reads it. It must not send the walk to the resource tier, which
+ # answers with the built-in project default and would promote everyone to admin
+ self._create_access_control(resource="project", resource_id=self.team.id, access_level="member")
+ self._create_access_control(resource="project", resource_id=None, access_level="none")
+ self._clear_uac_caches()
+
+ assert self.user_access_control.get_user_access_level(self.team) == "member"
+
def test_ac_object_project_access_control(self):
# Setup no access by default
ac = self._create_access_control(resource_id=self.team.id, access_level="none")
diff --git a/posthog/rbac/user_access_control.py b/posthog/rbac/user_access_control.py
index 4b39174e5954..7d6fe6f5493f 100644
--- a/posthog/rbac/user_access_control.py
+++ b/posthog/rbac/user_access_control.py
@@ -961,6 +961,13 @@ class UserAccessControl:
# If there is no team, then there can't be any access controls on this resource
return False
+ # A resource that carries no resource-level controls has no such rules to find, whatever
+ # rows exist. Answering True for one sends the object walk to `access_level_for_resource`,
+ # which returns the built-in default for these resources — that would override the rules
+ # written about the object itself, e.g. a project's own default.
+ if resource in RESOURCES_WITHOUT_RESOURCE_LEVEL_CONTROLS:
+ return False
+
# Inheriting children (e.g. warehouse_view -> warehouse_objects) intentionally
# bypass their own resource-level rows: only the parent (umbrella) is consulted.
# This keeps the AC picker simple — admins configure one umbrella scope instead