Skip to content

Commit

Permalink
Disallow sharing of user-endpoints through invites (#4753)
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Quandt <[email protected]>
  • Loading branch information
thquad committed Feb 9, 2021
1 parent fc6a400 commit ec30299
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,15 @@ export class UserInviteService {
map(v => v.entity.metadata && v.entity.metadata.userInviteAllowed === 'true')
);

this.canConfigure$ = combineLatest(
this.canConfigure$ = combineLatest([
waitForCFPermissions(this.store, this.activeRouteCfOrgSpace.cfGuid),
this.store.select('auth')
).pipe(
map(([cf, auth]) =>
this.store.select('auth'),
cfEndpointService.endpoint$
]).pipe(
map(([cf, auth, endpoint]) =>
cf.global.isAdmin &&
auth.sessionData['plugin-config'] && auth.sessionData['plugin-config'].userInvitationsEnabled === 'true')
auth.sessionData['plugin-config'] && auth.sessionData['plugin-config'].userInvitationsEnabled === 'true' &&
endpoint.entity.creator.admin)
);
}

Expand Down
1 change: 1 addition & 0 deletions src/jetstream/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func (p *portalProxy) getInfo(c echo.Context) (*interfaces.Info, error) {
u, err := p.StratosAuthService.GetUser(cnsi.Creator)
if err == nil {
endpoint.Creator.Admin = u.Admin
// dont set username of admins for security reasons
if u.Admin == false {
endpoint.Creator.Name = u.Name
}
Expand Down
5 changes: 5 additions & 0 deletions src/jetstream/plugins/userinvite/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ func (invite *UserInvite) configure(c echo.Context) error {
)
}

_, err := invite.checkEndpointCreator(cfGUID, c)
if err != nil {
return err
}

uaaRecord, _, err := invite.RefreshToken(cfGUID, clientID, clientSecret)
if err != nil {
return err
Expand Down
36 changes: 36 additions & 0 deletions src/jetstream/plugins/userinvite/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,42 @@ func (invite *UserInvite) refreshToken(clientID, clientSecret string, endpoint i
return &uaaResponse, tokenRecord, nil
}

// Check that there is an endpoint with the specified ID and if the creator is an admin
func (invite *UserInvite) checkEndpointCreator(cfGUID string, c echo.Context) (interfaces.CNSIRecord, error) {
endpoint, err := invite.portalProxy.GetCNSIRecord(cfGUID)
if err != nil {
// Could find the endpoint
return interfaces.CNSIRecord{}, interfaces.NewHTTPShadowError(
http.StatusBadRequest,
"Can not find enpoint",
"Can not find enpoint: %s", cfGUID,
)
}

if len(endpoint.Creator) > 0 {
stratosAuthService := invite.portalProxy.GetStratosAuthService()

creator, err := stratosAuthService.GetUser(endpoint.Creator)
if err != nil {
return interfaces.CNSIRecord{}, interfaces.NewHTTPShadowError(
http.StatusBadRequest,
"Can not find creator account",
"Can not find creator account: %s", endpoint.Creator,
)
}

if !creator.Admin {
return interfaces.CNSIRecord{}, interfaces.NewHTTPShadowError(
http.StatusBadRequest,
"Not an admin endpoint",
"Not an admin endpoint: %s", cfGUID,
)
}
}

return endpoint, nil
}

func (invite *UserInvite) checkEndpoint(cfGUID string) (interfaces.CNSIRecord, error) {
// Check that there is an endpoint with the specified ID and that it is a Cloud Foundry endpoint
endpoint, err := invite.portalProxy.GetCNSIRecord(cfGUID)
Expand Down

0 comments on commit ec30299

Please sign in to comment.