Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce permission edit_default_branch when loading schema #4959

Merged
merged 2 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/infrahub/api/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ async def get_current_user(
if config.SETTINGS.main.allow_anonymous_access and request.method.lower() in ["get", "options"]:
return account_session

if request.method.lower() == "post" and account_session.read_only:
if request.method.lower() == "post" and account_session.read_only and account_session.authenticated:
raise PermissionDeniedError("You are not allowed to perform this operation")

raise AuthorizationError("Authentication is required")
11 changes: 11 additions & 0 deletions backend/infrahub/api/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,17 @@ async def load_schema(
):
raise PermissionDeniedError("You are not allowed to manage the schema")

if branch.name in (GLOBAL_BRANCH_NAME, registry.default_branch) and not await permission_backend.has_permission(
db=db,
account_session=account_session,
permission=GlobalPermission(
action=GlobalPermissions.EDIT_DEFAULT_BRANCH.value,
decision=PermissionDecision.ALLOW_DEFAULT.value,
),
branch=branch,
):
raise PermissionDeniedError("You are not allowed to edit the schema in the default branch")

service: InfrahubServices = request.app.state.service
log.info("schema_load_request", branch=branch.name)

Expand Down
1 change: 1 addition & 0 deletions changelog/+anonymous.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Anonymous user will get a 401 response when trying to load a schema
1 change: 1 addition & 0 deletions changelog/4958.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Permission edit_default_branch is now enforced properly when loading a schema
Loading