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

[gitlab] Fix GitLab internal project visibility#54426

Merged
pjlast merged 13 commits into
mainfrom
pjlast/gitlab-internal-repo-perms-fix
Jul 27, 2023
Merged

[gitlab] Fix GitLab internal project visibility#54426
pjlast merged 13 commits into
mainfrom
pjlast/gitlab-internal-repo-perms-fix

Conversation

@pjlast

@pjlast pjlast commented Jun 29, 2023

Copy link
Copy Markdown
Contributor

Original Slack thread here

Before this PR

We use a min_access_level=20 check on GitLab project queries, because access_level 10 is GUEST, and users with GUEST access cannot see repo contents, so we don't want to give access to those repos on Sourcegraph
HOWEVER, for Internal repos on GitLab, users can see the contents of the repo depending on how the repo is configured, regardless of their access level. So this puts us in a conundrum. If we have min_access_level=20, users can't see repos they should be able to see, but if we remove it, users can see repos they shouldn't be able to see

After this PR

Adds a feature flag named "gitLabProjectVisibilityExperimental". When set to true:

@indradhanush and I diffed some responses from the GitLab API, depending on whether or not you are part of the GitLab group or not, whether the project is visible or not, etc. etc. and there is a common field:
default_branch is only visible in the project API response if the user is able to see the contents of the project. If they cannot see the contents of the project, they cannot see the default branch of the project.
So by removing min_access_level=20 and checking for the presence of default_branch on the returned project list, we can determine whether or not the user should be able to see the repo contents or not

Test plan

VCR tests should be updated

@sourcegraph-bot

sourcegraph-bot commented Jun 29, 2023

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in CODENOTIFY files for diff 0b1f669...204d404.

Notify File(s)
@eseliger internal/extsvc/gitlab/projects.go
@indradhanush internal/repos/gitlab_test.go
@sashaostrikov internal/extsvc/gitlab/projects.go
internal/repos/gitlab_test.go
@unknwon internal/authz/providers/gitlab/BUILD.bazel
internal/authz/providers/gitlab/BUILD.bazel
internal/authz/providers/gitlab/oauth_test.go
internal/authz/providers/gitlab/oauth_test.go
internal/authz/providers/gitlab/sudo.go
internal/authz/providers/gitlab/sudo.go
internal/authz/providers/gitlab/sudo_test.go
internal/authz/providers/gitlab/sudo_test.go

@pjlast pjlast requested a review from a team June 29, 2023 11:59
@indradhanush indradhanush added the team/source Tickets under the purview of Source - the one Source to graph it all label Jun 29, 2023

@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.

LGTM as we paired on it. 😆

@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! Let's add a comment directly in code?


for _, p := range projects {
projectIDs = append(projectIDs, extsvc.RepoID(strconv.Itoa(p.ID)))
if p.DefaultBranch != "" {

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'd add a nice comment that you had in Slack/PR here as well

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.

+500. This feels like a tripwire for future us.

I'd also love to see a test for this change.

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.

+1024 really nice trick but even Cody won't be able to explain this 😂

@BolajiOlajide BolajiOlajide 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.

+1 to @sashaostrikov's comment.

Asides that, this looks good to me.

return p.Visibility == "private" || p.Visibility == "internal"
}

// ContentsVisible reports whether or not the repository contents of this project is visible to the user.

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.

NICE!

@pjlast pjlast force-pushed the pjlast/gitlab-internal-repo-perms-fix branch from eb14c81 to 6da60d3 Compare July 27, 2023 07:09
@pjlast pjlast merged commit 8cb61f8 into main Jul 27, 2023
@pjlast pjlast deleted the pjlast/gitlab-internal-repo-perms-fix branch July 27, 2023 13:13
github-actions Bot pushed a commit that referenced this pull request Jul 27, 2023
Original Slack thread
[here](https://sourcegraph.slack.com/archives/C05EMJM2SLR/p1687969384430849)

## Before this PR

We use a `min_access_level=20` check on GitLab project queries, because
`access_level` 10 is GUEST, and users with GUEST access cannot see repo
contents, so we don't want to give access to those repos on Sourcegraph
HOWEVER, for Internal repos on GitLab, users can see the contents of the
repo depending on how the repo is configured, regardless of their access
level. So this puts us in a conundrum. If we have `min_access_level=20`,
users can't see repos they should be able to see, but if we remove it,
users can see repos they shouldn't be able to see

## After this PR

Adds a feature flag named "gitLabProjectVisibilityExperimental". When
set to true:

@indradhanush and I diffed some responses from the GitLab API, depending
on whether or not you are part of the GitLab group or not, whether the
project is visible or not, etc. etc. and there is a common field:
`default_branch` is only visible in the project API response if the user
is able to see the contents of the project. If they cannot see the
contents of the project, they cannot see the default branch of the
project.
So by removing `min_access_level=20` and checking for the presence of
`default_branch` on the returned project list, we can determine whether
or not the user should be able to see the repo contents or not

## Test plan

VCR tests should be updated

<!-- All pull requests REQUIRE a test plan:
https://docs.sourcegraph.com/dev/background-information/testing_principles
-->

(cherry picked from commit 8cb61f8)
MaedahBatool pushed a commit that referenced this pull request Jul 28, 2023
Original Slack thread
[here](https://sourcegraph.slack.com/archives/C05EMJM2SLR/p1687969384430849)

## Before this PR

We use a `min_access_level=20` check on GitLab project queries, because
`access_level` 10 is GUEST, and users with GUEST access cannot see repo
contents, so we don't want to give access to those repos on Sourcegraph
HOWEVER, for Internal repos on GitLab, users can see the contents of the
repo depending on how the repo is configured, regardless of their access
level. So this puts us in a conundrum. If we have `min_access_level=20`,
users can't see repos they should be able to see, but if we remove it,
users can see repos they shouldn't be able to see

## After this PR

Adds a feature flag named "gitLabProjectVisibilityExperimental". When
set to true:

@indradhanush and I diffed some responses from the GitLab API, depending
on whether or not you are part of the GitLab group or not, whether the
project is visible or not, etc. etc. and there is a common field:
`default_branch` is only visible in the project API response if the user
is able to see the contents of the project. If they cannot see the
contents of the project, they cannot see the default branch of the
project.
So by removing `min_access_level=20` and checking for the presence of
`default_branch` on the returned project list, we can determine whether
or not the user should be able to see the repo contents or not

## Test plan

VCR tests should be updated

<!-- All pull requests REQUIRE a test plan:
https://docs.sourcegraph.com/dev/background-information/testing_principles
-->
coury-clark pushed a commit that referenced this pull request Aug 1, 2023
Original Slack thread
[here](https://sourcegraph.slack.com/archives/C05EMJM2SLR/p1687969384430849)

## Before this PR

We use a `min_access_level=20` check on GitLab project queries, because
`access_level` 10 is GUEST, and users with GUEST access cannot see repo
contents, so we don&#39;t want to give access to those repos on
Sourcegraph
HOWEVER, for Internal repos on GitLab, users can see the contents of the
repo depending on how the repo is configured, regardless of their access
level. So this puts us in a conundrum. If we have `min_access_level=20`,
users can&#39;t see repos they should be able to see, but if we remove
it, users can see repos they shouldn&#39;t be able to see

## After this PR

Adds a feature flag named
&quot;gitLabProjectVisibilityExperimental&quot;. When set to true:

@indradhanush and I diffed some responses from the GitLab API, depending
on whether or not you are part of the GitLab group or not, whether the
project is visible or not, etc. etc. and there is a common field:
`default_branch` is only visible in the project API response if the user
is able to see the contents of the project. If they cannot see the
contents of the project, they cannot see the default branch of the
project.
So by removing `min_access_level=20` and checking for the presence of
`default_branch` on the returned project list, we can determine whether
or not the user should be able to see the repo contents or not

## Test plan

VCR tests should be updated

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

Co-authored-by: Petri-Johan Last <petri.last@sourcegraph.com>
davejrt pushed a commit that referenced this pull request Aug 9, 2023
Original Slack thread
[here](https://sourcegraph.slack.com/archives/C05EMJM2SLR/p1687969384430849)

## Before this PR

We use a `min_access_level=20` check on GitLab project queries, because
`access_level` 10 is GUEST, and users with GUEST access cannot see repo
contents, so we don't want to give access to those repos on Sourcegraph
HOWEVER, for Internal repos on GitLab, users can see the contents of the
repo depending on how the repo is configured, regardless of their access
level. So this puts us in a conundrum. If we have `min_access_level=20`,
users can't see repos they should be able to see, but if we remove it,
users can see repos they shouldn't be able to see

## After this PR

Adds a feature flag named "gitLabProjectVisibilityExperimental". When
set to true:

@indradhanush and I diffed some responses from the GitLab API, depending
on whether or not you are part of the GitLab group or not, whether the
project is visible or not, etc. etc. and there is a common field:
`default_branch` is only visible in the project API response if the user
is able to see the contents of the project. If they cannot see the
contents of the project, they cannot see the default branch of the
project.
So by removing `min_access_level=20` and checking for the presence of
`default_branch` on the returned project list, we can determine whether
or not the user should be able to see the repo contents or not

## Test plan

VCR tests should be updated

<!-- All pull requests REQUIRE a test plan:
https://docs.sourcegraph.com/dev/background-information/testing_principles
-->
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla-signed team/source Tickets under the purview of Source - the one Source to graph it all

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants