Skip to content
This repository has been archived by the owner on Jan 24, 2019. It is now read-only.

Support for group restriction for Gitlab provider #312

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

JacobAae
Copy link

Should solve issue #311

@rutsky
Copy link

rutsky commented Mar 14, 2017

@jehiah any plans merging this? I would love to see this merged and released.

Copy link

@rutsky rutsky left a comment

Choose a reason for hiding this comment

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

LGTM, except few nitpicks that may be ignored

README.md Outdated
@@ -113,6 +113,10 @@ If you are using GitHub enterprise, make sure you set the following to the appro

Whether you are using GitLab.com or self-hosting GitLab, follow [these steps to add an application](http://doc.gitlab.com/ce/integration/oauth_provider.html)

The GitLab auth provider supports one additional parameters to restrict authentication to a specific group. Restricting by group is normally accompanied with `--email-domain=*`
Copy link

Choose a reason for hiding this comment

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

nitpick: "one additional parameters" or "one additional parameters"

Group string `json:"name"`
}

endpoint := p.ValidateURL.Scheme + "://" + p.ValidateURL.Host + "/api/v3/groups?access_token="+accessToken
Copy link

Choose a reason for hiding this comment

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

nitpick: spaces around +: "+accessToken

}

for _, group := range groups {
if( p.Group == group.Group) {
Copy link

Choose a reason for hiding this comment

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

nitpick: no round brackets required here?

Copy link
Contributor

Choose a reason for hiding this comment

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

probably best to just ask to run "gofmt"

@BenoitKnecht
Copy link

I tested this feature and it works great, except if a user is a member of a lot of groups (or if they're an admin, because in that case the GitLab API returns all the groups, not just those the user is a member of). The GitLab API paginates the list of groups, so I had to add c141ff8 to make it work with more than 20 groups.

@scriptator
Copy link

So this pull request will be included in the next release? When will that be approximately?

@timrosede
Copy link

could any one merge this?

@FUSAKLA
Copy link

FUSAKLA commented Jan 24, 2018

We would also appreciate this feature, without this we cannot use gitlab authentication.
I vote for merge of this feature.

@cnkk
Copy link

cnkk commented Feb 26, 2018

Any news on this?

@nepeat
Copy link

nepeat commented Mar 16, 2018

Been using this in production and I can say that the code has been stable for my setup.

@BenoitKnecht
Copy link

I've also been running this in production (with c141ff8 applied) for a while now, and it's working as expected.

@JacobAae, do you want to add c141ff8 to this PR, if it looks good to you? Otherwise, I can open a new PR, but I think it makes more sense to keep everything in one place.

Let me know if there's anything I can do to help get this merged.

@JacobAae
Copy link
Author

@BenoitKnecht I've created a patch from your commit and applied to include it in the merge request, as it looks fine. I however doubt this will ever be merged, it has been pending for years, but I know several places where it runs in production.

@bgagnon
Copy link

bgagnon commented May 4, 2018

@jehiah any chance this pull request can get merged?

Copy link

@fnkr fnkr left a comment

Choose a reason for hiding this comment

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

I would like to have this too but I think there are still issues left to fix.

func (p *GitLabProvider) hasGroup(accessToken string) (bool, error) {

var groups []struct {
Group string `json:"name"`
Copy link

Choose a reason for hiding this comment

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

This is a serious security issue since the name of a group is only unique within it's namespace. Anyone who can create groups (usually anyone) could dupe this by creating a group with an arbitrary name and then a subgroup with the desired name.

Consider this scenario:

[
    {
        "id": 1,
        "web_url": "https://gitlab.com/groups/admins",
        "name": "admins",
        "path": "admins",
        "description": "",
        "visibility": "private",
        "lfs_enabled": true,
        "avatar_url": null,
        "request_access_enabled": false,
        "full_name": "admins",
        "full_path": "admins",
        "parent_id": null
    },
    {
        "id": 2,
        "web_url": "https://gitlab.com/groups/myfunnyproject",
        "name": "myfunnyproject",
        "path": "myfunnyproject",
        "description": "",
        "visibility": "private",
        "lfs_enabled": true,
        "avatar_url": null,
        "request_access_enabled": false,
        "full_name": "myfunnyproject",
        "full_path": "myfunnyproject",
        "parent_id": null
    },
    {
        "id": 3,
        "web_url": "https://gitlab.com/groups/myfunnyproject/admins",
        "name": "admins",
        "path": "admins",
        "description": "",
        "visibility": "private",
        "lfs_enabled": true,
        "avatar_url": null,
        "request_access_enabled": false,
        "full_name": "myfunnyproject / myfunnyproject",
        "full_path": "myfunnyproject/myfunnyproject",
        "parent_id": 2
    }
]

There are three groups: admins, myfunnyproject and a subgroup of myfunnyproject also named admins. In the current state this would allow both members of admins and members of myfunnyproject/admins to access the site.

I suggest using full_path instead of name.

@@ -31,6 +31,7 @@ type Options struct {
EmailDomains []string `flag:"email-domain" cfg:"email_domains"`
GitHubOrg string `flag:"github-org" cfg:"github_org"`
GitHubTeam string `flag:"github-team" cfg:"github_team"`
GitLabGroup string `flag:"gitlab-group" cfg:"gitlab_group"`
Copy link

Choose a reason for hiding this comment

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

It would be nice if multiple groups could be specified, just like multiple GoogleGroups can be specified.

@martin-loetzsch
Copy link

Fyi: there is an active discussion about forking this (obviously unmaintained) project here: #628

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.