Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

[permissions] Revert default behaviour for explicit permissions#54419

Merged
pjlast merged 10 commits into
mainfrom
pjlast/explicit-permissions-fix
Jun 29, 2023
Merged

[permissions] Revert default behaviour for explicit permissions#54419
pjlast merged 10 commits into
mainfrom
pjlast/explicit-permissions-fix

Conversation

@pjlast

@pjlast pjlast commented Jun 29, 2023

Copy link
Copy Markdown
Contributor

With the switch to the user_repo_permissions table, the default behaviour for explicit permissions changed. Previously, if explicit permissions API was enabled, then all repositories would be treated as restricted, regardless of code host connection configurations.

The user_repo_permissions table allows us to run permissions syncs and explicit permissions in parallel, but the default behaviour was to have code host connections be marked as unrestricted, unless authorization is enabled. However, not all code hosts support authorization, leading to connections that are always left unrestricted, even if explicit permissions are being used.

This PR reverts the default behaviour back to treating a repository as restricted if explicit permissions are enabled.

Test plan

Added unit tests for the new Unrestricted logic. Also tested locally with an "Other Git code host" connection.

@cla-bot cla-bot Bot added the cla-signed label Jun 29, 2023
@pjlast pjlast requested a review from a team June 29, 2023 08:35
@sourcegraph-bot

sourcegraph-bot commented Jun 29, 2023

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in CODENOTIFY files for diff 9e78e1c...c3c33c9.

Notify File(s)
@eseliger internal/database/external_services.go
internal/database/external_services_test.go
@indradhanush internal/repos/awscodecommit.go
internal/repos/gitolite.go
internal/repos/other.go
internal/repos/phabricator.go
@sashaostrikov internal/repos/awscodecommit.go
internal/repos/gitolite.go
internal/repos/other.go
internal/repos/phabricator.go
@sourcegraph/delivery doc/admin/permissions/index.md

@indradhanush indradhanush left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks good to me, but this is tricky and another pair of eyes for confirmation would be nice.

Comment thread doc/admin/permissions/api.md Outdated
Comment thread internal/database/external_services.go Outdated
Comment thread internal/database/external_services_test.go Outdated
Comment thread doc/admin/permissions/api.md Outdated

@sashaostrikov sashaostrikov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Co-authored-by: Thorsten Ball <mrnugget@gmail.com>
Comment thread schema/other_external_service.schema.json Outdated
@pjlast pjlast merged commit 5ad2474 into main Jun 29, 2023
@pjlast pjlast deleted the pjlast/explicit-permissions-fix branch June 29, 2023 14:33
github-actions Bot pushed a commit that referenced this pull request Jun 29, 2023

if tc.explicitPermsEnabled {
globals.SetPermissionsUserMapping(&schema.PermissionsUserMapping{
BindID: "email",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get a test for all the bind types? As I understand the offending type was username binding.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bind types wouldn't affect anything here, as they're just used to determine what goes into the table.

The issue is what happens once things are already in the table, which is that the table is not being applied at all because the code host connection itself is marked as Unrestricted.

coury-clark pushed a commit that referenced this pull request Jun 29, 2023
…rmissions (#54439)

With the switch to the `user_repo_permissions` table, the default
behaviour for explicit permissions changed. Previously, if explicit
permissions API was enabled, then all repositories would be treated as
restricted, regardless of code host connection configurations.

The `user_repo_permissions` table allows us to run permissions syncs and
explicit permissions in parallel, but the default behaviour was to have
code host connections be marked as unrestricted, unless authorization is
enabled. However, not all code hosts support authorization, leading to
connections that are always left unrestricted, even if explicit
permissions are being used.

This PR reverts the default behaviour back to treating a repository as
restricted if explicit permissions are enabled.

## Test plan

Added unit tests for the new Unrestricted logic. Also tested locally
with an &quot;Other Git code host&quot; connection.

&lt;!-- All pull requests REQUIRE a test plan:
https://docs.sourcegraph.com/dev/background-information/testing_principles
--&gt;
 <br> Backport 5ad2474 from #54419

Co-authored-by: Petri-Johan Last <petri.last@sourcegraph.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants