Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
go-sso
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
id
go-sso
Commits
7fec26e6
Commit
7fec26e6
authored
6 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
Allow enabling keystore on a group basis
Using the new configuration variable 'keystore_enable_groups'.
parent
bad3b6bd
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/config.go
+1
-0
1 addition, 0 deletions
server/config.go
server/http.go
+42
-13
42 additions, 13 deletions
server/http.go
with
43 additions
and
13 deletions
server/config.go
+
1
−
0
View file @
7fec26e6
...
...
@@ -38,6 +38,7 @@ type Config struct {
URLPrefix
string
`yaml:"url_path_prefix"`
DeviceManager
*
device
.
Config
`yaml:"device_manager"`
KeyStore
*
clientutil
.
BackendConfig
`yaml:"keystore"`
KeyStoreEnableGroups
[]
string
`yaml:"keystore_enable_groups"`
allowedServicesRx
[]
*
regexp
.
Regexp
}
...
...
This diff is collapsed.
Click to expand it.
server/http.go
+
42
−
13
View file @
7fec26e6
...
...
@@ -4,6 +4,7 @@ package server
//go:generate go-bindata --nocompress --pkg server static/... templates/...
import
(
"context"
"encoding/gob"
"encoding/json"
"fmt"
...
...
@@ -88,6 +89,7 @@ type Server struct {
loginHandler
*
loginHandler
loginService
*
LoginService
keystore
ksclient
.
Client
keystoreGroups
[]
string
csrfSecret
[]
byte
tpl
*
template
.
Template
urlPrefix
string
...
...
@@ -134,6 +136,7 @@ func New(loginService *LoginService, authClient authclient.Client, config *Confi
}
log
.
Printf
(
"keystore client enabled"
)
s
.
keystore
=
ks
s
.
keystoreGroups
=
config
.
KeyStoreEnableGroups
}
devMgr
,
err
:=
device
.
New
(
config
.
DeviceManager
)
...
...
@@ -145,25 +148,51 @@ func New(loginService *LoginService, authClient authclient.Client, config *Confi
return
s
,
nil
}
func
inAnyGroups
(
groups
,
ref
[]
string
)
bool
{
for
_
,
rr
:=
range
ref
{
for
_
,
gg
:=
range
groups
{
if
gg
==
rr
{
return
true
}
}
}
return
false
}
// We unlock the keystore if the following conditions are met:
// keystore_enable_groups is set, userinfo is not nil, and the groups match.
func
(
h
*
Server
)
maybeUnlockKeystore
(
ctx
context
.
Context
,
username
,
password
string
,
userinfo
*
auth
.
UserInfo
)
(
bool
,
error
)
{
if
h
.
keystore
==
nil
{
return
false
,
nil
}
var
shard
string
if
len
(
h
.
keystoreGroups
)
>
0
{
if
userinfo
==
nil
{
return
false
,
nil
}
if
!
inAnyGroups
(
userinfo
.
Groups
,
h
.
keystoreGroups
)
{
return
false
,
nil
}
shard
=
userinfo
.
Shard
}
return
true
,
h
.
keystore
.
Open
(
ctx
,
shard
,
username
,
password
,
int
(
h
.
authSessionLifetime
.
Seconds
()))
}
func
(
h
*
Server
)
loginCallback
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
,
username
,
password
string
,
userinfo
*
auth
.
UserInfo
)
error
{
// Open the keystore for this user with the password used to
// authenticate. Set the TTL to the duration of the
// authenticated session.
var
kmsg
string
if
h
.
keystore
!=
nil
{
var
shard
string
if
userinfo
!=
nil
{
shard
=
userinfo
.
Shard
kmsg
=
fmt
.
Sprintf
(
" (unlocked key on shard %s)"
,
shard
)
}
else
{
kmsg
=
" (unlocked key)"
}
if
err
:=
h
.
keystore
.
Open
(
req
.
Context
(),
shard
,
username
,
password
,
int
(
h
.
authSessionLifetime
.
Seconds
()));
err
!=
nil
{
log
.
Printf
(
"failed to unlock keystore for user %s: %v"
,
username
,
err
)
return
err
}
decrypted
,
err
:=
h
.
maybeUnlockKeystore
(
req
.
Context
(),
username
,
password
,
userinfo
)
if
err
!=
nil
{
log
.
Printf
(
"failed to unlock keystore for user %s: %v"
,
username
,
err
)
return
err
}
var
kmsg
string
if
decrypted
{
kmsg
=
" (key unlocked)"
}
log
.
Printf
(
"successful login for user %s%s"
,
username
,
kmsg
)
// Create cookie-based session for the authenticated user.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment