Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
5e8bb1fc
Commit
5e8bb1fc
authored
Aug 24, 2017
by
Balazs Nagy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for SAML required_groups
parent
43371992
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
113 additions
and
1 deletion
+113
-1
app/controllers/omniauth_callbacks_controller.rb
app/controllers/omniauth_callbacks_controller.rb
+1
-1
changelogs/unreleased-ee/3143-saml_required_groups.yml
changelogs/unreleased-ee/3143-saml_required_groups.yml
+6
-0
doc/integration/saml.md
doc/integration/saml.md
+27
-0
lib/gitlab/saml/config.rb
lib/gitlab/saml/config.rb
+4
-0
lib/gitlab/saml/user.rb
lib/gitlab/saml/user.rb
+30
-0
spec/lib/gitlab/saml/user_spec.rb
spec/lib/gitlab/saml/user_spec.rb
+45
-0
No files found.
app/controllers/omniauth_callbacks_controller.rb
View file @
5e8bb1fc
...
...
@@ -156,7 +156,7 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
message
<<
" Create a GitLab account first, and then connect it to your
#{
label
}
account."
end
flash
[
:
notice
]
=
message
flash
[
:
alert
]
=
message
redirect_to
new_user_session_path
end
...
...
changelogs/unreleased-ee/3143-saml_required_groups.yml
0 → 100644
View file @
5e8bb1fc
---
title
:
julian7 Add required_groups option to SAML config, to restrict access to GitLab
to specific SAML groups.
merge_request
:
3223
author
:
Balazs Nagy
type
:
added
doc/integration/saml.md
View file @
5e8bb1fc
...
...
@@ -176,6 +176,33 @@ tell GitLab which groups are external via the `external_groups:` element:
}
}
```
## Required groups
>**Note:**
This setting is only available on GitLab 10.2 EE and above.
This setting works like
`External Groups`
setting. Just like there, your IdP has to
pass Group Information to GitLab, you have to tell GitLab where to look or the
groups SAML response, and which group membership should be requisite for logging in.
When
`required_groups`
is not set or it is empty, anyone with proper authentication
will be able to use the service.
Example:
```
yaml
{
name
:
'
saml'
,
label
:
'
Our
SAML
Provider'
,
groups_attribute
:
'
Groups'
,
required_groups
:
[
'
Developers'
,
'
Managers'
,
'
Admins'
],
args
:
{
assertion_consumer_service_url
:
'
https://gitlab.example.com/users/auth/saml/callback'
,
idp_cert_fingerprint
:
'
43:51:43:a1:b5:fc:8b:b7:0a:3a:a9:b1:0f:66:73:a8'
,
idp_sso_target_url
:
'
https://login.example.com/idp'
,
issuer
:
'
https://gitlab.example.com'
,
name_identifier_format
:
'
urn:oasis:names:tc:SAML:2.0:nameid-format:transient'
}
}
```
## Admin Groups
>**Note:**
...
...
lib/gitlab/saml/config.rb
View file @
5e8bb1fc
...
...
@@ -14,6 +14,10 @@ module Gitlab
options
[
:external_groups
]
end
def
required_groups
Array
(
options
[
:required_groups
])
end
def
admin_groups
options
[
:admin_groups
]
end
...
...
lib/gitlab/saml/user.rb
View file @
5e8bb1fc
...
...
@@ -17,6 +17,14 @@ module Gitlab
user
||=
find_or_build_ldap_user
if
auto_link_ldap_user?
user
||=
build_new_user
if
signup_enabled?
if
user_in_required_group?
unblock_user
(
user
,
"in required group"
)
if
user
.
persisted?
&&
user
.
blocked?
elsif
user
.
persisted?
block_user
(
user
,
"not in required group"
)
unless
user
.
blocked?
else
user
=
nil
end
if
user
user
.
external
=
!
(
auth_hash
.
groups
&
Gitlab
::
Saml
::
Config
.
external_groups
).
empty?
if
external_users_enabled?
user
.
admin
=
!
(
auth_hash
.
groups
&
Gitlab
::
Saml
::
Config
.
admin_groups
).
empty?
if
admin_groups_enabled?
...
...
@@ -32,6 +40,28 @@ module Gitlab
protected
def
block_user
(
user
,
reason
)
user
.
ldap_block
log_user_changes
(
user
,
"
#{
reason
}
, blocking"
)
end
def
unblock_user
(
user
,
reason
)
user
.
activate
log_user_changes
(
user
,
"
#{
reason
}
, unblocking"
)
end
def
log_user_changes
(
user
,
message
)
Gitlab
::
AppLogger
.
info
(
"SAML(
#{
auth_hash
.
provider
}
) account
\"
#{
auth_hash
.
uid
}
\"
#{
message
}
"
\
"Gitlab user
\"
#{
user
.
name
}
\"
(
#{
user
.
email
}
)"
)
end
def
user_in_required_group?
required_groups
=
Gitlab
::
Saml
::
Config
.
required_groups
required_groups
.
empty?
||
!
(
auth_hash
.
groups
&
required_groups
).
empty?
end
def
auto_link_saml_user?
Gitlab
.
config
.
omniauth
.
auto_link_saml_user
end
...
...
spec/lib/gitlab/saml/user_spec.rb
View file @
5e8bb1fc
...
...
@@ -36,6 +36,10 @@ describe Gitlab::Saml::User do
allow
(
Gitlab
::
Saml
::
Config
).
to
receive_messages
({
options:
{
name:
'saml'
,
groups_attribute:
'groups'
,
external_groups:
groups
,
args:
{}
}
})
end
def
stub_saml_required_group_config
(
groups
)
allow
(
Gitlab
::
Saml
::
Config
).
to
receive_messages
({
options:
{
name:
'saml'
,
groups_attribute:
'groups'
,
required_groups:
groups
,
args:
{}
}
})
end
def
stub_saml_admin_group_config
(
groups
)
allow
(
Gitlab
::
Saml
::
Config
).
to
receive_messages
({
options:
{
name:
'saml'
,
groups_attribute:
'groups'
,
admin_groups:
groups
,
args:
{}
}
})
end
...
...
@@ -185,6 +189,47 @@ describe Gitlab::Saml::User do
end
end
context
'required groups'
do
context
'not defined'
do
it
'lets anyone in'
do
saml_user
.
save
expect
(
gl_user
).
to
be_valid
end
end
context
'are defined'
do
before
do
stub_omniauth_config
(
block_auto_created_users:
false
)
end
it
'lets members in'
do
stub_saml_required_group_config
(
%w(Developers)
)
saml_user
.
save
expect
(
gl_user
).
to
be_valid
end
it
'unblocks already blocked members'
do
stub_saml_required_group_config
(
%w(Developers)
)
saml_user
.
save
.
ldap_block
expect
(
saml_user
.
find_user
).
to
be_active
end
it
'does not allow non-members'
do
stub_saml_required_group_config
(
%w(ArchitectureAstronauts)
)
expect
{
saml_user
.
save
}.
to
raise_error
Gitlab
::
OAuth
::
SignupDisabledError
end
it
'blocks non-members'
do
orig_groups
=
auth_hash
.
extra
.
raw_info
[
"groups"
]
auth_hash
.
extra
.
raw_info
.
add
(
"groups"
,
"ArchitectureAstronauts"
)
stub_saml_required_group_config
(
%w(ArchitectureAstronauts)
)
saml_user
.
save
auth_hash
.
extra
.
raw_info
.
set
(
"groups"
,
orig_groups
)
expect
(
saml_user
.
find_user
).
to
be_ldap_blocked
end
end
end
context
'admin groups'
do
context
'are defined'
do
it
'marks the user as admin'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment