Skip to content

Commit 66316d7

Browse files
committed
Fix: allow users with cross-domain role assignments to log in
1 parent f267983 commit 66316d7

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

pkg/api/keystone/keystone_requests.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,36 @@ type auth_response_struct struct {
9393
}
9494

9595
type auth_token_struct struct {
96-
Roles []auth_roles_struct `json:"roles"`
97-
Expires_at string `json:"expires_at"`
96+
Roles []auth_roles_struct `json:"roles"`
97+
Expires_at string `json:"expires_at"`
98+
User auth_user_response_struct `json:"user"`
9899
}
99100

100101
type auth_roles_struct struct {
101102
Id string `json:"id"`
102103
Name string `json:"name"`
103104
}
104105

106+
type auth_user_response_struct struct {
107+
Name string `json:"name"`
108+
Id string `json:"id"`
109+
Domain auth_userdomain_response_struct `json:"domain"`
110+
}
111+
112+
type auth_userdomain_response_struct struct {
113+
Name string `json:"name"`
114+
Id string `json:"id"`
115+
}
116+
105117
// Projects Response
106118
type project_response_struct struct {
107119
Projects []project_struct
108120
}
109121

110122
type project_struct struct {
111-
Name string
112-
Enabled bool
123+
Name string
124+
Enabled bool
125+
DomainId string `json:"domain_id"`
113126
}
114127

115128
////////////////////////
@@ -120,6 +133,7 @@ type project_struct struct {
120133
type Auth_data struct {
121134
Server string
122135
Domain string
136+
DomainId string
123137
Username string
124138
Password string
125139
Project string
@@ -205,6 +219,7 @@ func authenticate(data *Auth_data, b []byte) error {
205219
data.Token = resp.Header.Get("X-Subject-Token")
206220
data.Expiration = auth_response.Token.Expires_at
207221
data.Roles = auth_response.Token.Roles
222+
data.DomainId = auth_response.Token.User.Domain.Id
208223

209224
return nil
210225
}
@@ -225,8 +240,9 @@ func anonymisePasswordsTokens(data *Auth_data, json []byte) []byte {
225240

226241
// Projects Section
227242
type Projects_data struct {
228-
Token string
229-
Server string
243+
Token string
244+
Server string
245+
DomainId string
230246
//response
231247
Projects []string
232248
}
@@ -264,7 +280,7 @@ func GetProjects(data *Projects_data) error {
264280
return err
265281
}
266282
for _, project := range project_response.Projects {
267-
if project.Enabled {
283+
if project.Enabled && (project.DomainId == data.DomainId) {
268284
data.Projects = append(data.Projects, project.Name)
269285
}
270286
}

pkg/login/keystone.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
type keystoneAuther struct {
1414
server string
1515
domainname string
16+
domainId string
1617
defaultrole string
1718
roles map[m.RoleType][]string
1819
admin_roles []string
@@ -67,6 +68,7 @@ func (a *keystoneAuther) authenticate(username, password string) error {
6768
return err
6869
}
6970
a.token = auth.Token
71+
a.domainId = auth.DomainId
7072
return nil
7173
}
7274

@@ -292,8 +294,9 @@ func (a *keystoneAuther) syncOrgRoles(username, password string, user *m.User) e
292294
func (a *keystoneAuther) getProjectList(username, password string) error {
293295
log.Trace("getProjectList() with username %s", username)
294296
projects_data := keystone.Projects_data{
295-
Token: a.token,
296-
Server: a.server,
297+
Token: a.token,
298+
Server: a.server,
299+
DomainId: a.domainId,
297300
}
298301
if err := keystone.GetProjects(&projects_data); err != nil {
299302
return err

0 commit comments

Comments
 (0)