Skip to content

Commit 04aa4d5

Browse files
thquadrichard-cox
authored andcommitted
Automatic disconnect by same url endpoint connect (#4876)
Signed-off-by: Thomas Quandt <[email protected]>
1 parent 1cad542 commit 04aa4d5

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

src/frontend/packages/core/src/shared/components/list/list-types/endpoint/endpoint-list.helpers.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
ConnectEndpointDialogComponent,
1717
} from '../../../../../features/endpoints/connect-endpoint-dialog/connect-endpoint-dialog.component';
1818
import { SessionService } from '../../../../../shared/services/session.service';
19+
import { UserProfileService } from '../../../../../core/user-profile.service';
1920
import { SnackBarService } from '../../../../services/snackbar.service';
2021
import { ConfirmationDialogConfig } from '../../../confirmation-dialog.config';
2122
import { ConfirmationDialogService } from '../../../confirmation-dialog.service';
@@ -68,6 +69,7 @@ export class EndpointListHelper {
6869
private confirmDialog: ConfirmationDialogService,
6970
private snackBarService: SnackBarService,
7071
private sessionService: SessionService,
72+
private userProfileService: UserProfileService
7173
) { }
7274

7375
endpointActions(includeSeparators = false): IListAction<EndpointModel>[] {
@@ -137,11 +139,11 @@ export class EndpointListHelper {
137139
createVisible: (row$: Observable<EndpointModel>) => {
138140
return combineLatest([
139141
this.sessionService.userEndpointsNotDisabled(),
140-
this.currentUserPermissionsService.can(StratosCurrentUserPermissions.EDIT_ADMIN_ENDPOINT),
142+
this.userProfileService.userProfile$,
141143
row$
142144
]).pipe(
143-
map(([userEndpointsEnabled, isAdmin, row]) => {
144-
if (userEndpointsEnabled && !row.creator.admin && isAdmin) {
145+
map(([userEndpointsEnabled, profile, row]) => {
146+
if (userEndpointsEnabled && !row.creator.system && profile.userName !== row.creator.name) {
145147
// Disable connect for admins if the endpoint was not created by them. Otherwise this could result in an admin connecting to
146148
// multiple user endpoints that all have the same url.
147149
return false;

src/jetstream/authcnsi.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,30 @@ func (p *portalProxy) DoLoginToCNSI(c echo.Context, cnsiGUID string, systemShare
151151
}
152152

153153
// admins are note allowed to connect to user created endpoints
154-
if p.GetConfig().UserEndpointsEnabled != config.UserEndpointsConfigEnum.Disabled && len(cnsiRecord.Creator) != 0 {
155-
user, err := p.StratosAuthService.GetUser(userID)
154+
if p.GetConfig().UserEndpointsEnabled != config.UserEndpointsConfigEnum.Disabled {
155+
156+
// search for system or personal endpoints and check if they are connected
157+
// automatically disconnect other endpoint if already connected to same url
158+
cnsiList, err := p.listCNSIByAPIEndpoint(cnsiRecord.APIEndpoint.String())
156159
if err != nil {
157-
return nil, echo.NewHTTPError(http.StatusUnauthorized, "Can not connect - could not check user")
160+
return nil, echo.NewHTTPError(
161+
http.StatusBadRequest,
162+
"Failed to retrieve list of CNSIs",
163+
"Failed to retrieve list of CNSIs: %v", err,
164+
)
158165
}
159166

160-
if user.Admin {
161-
return nil, echo.NewHTTPError(http.StatusUnauthorized, "Can not connect - admins are not allowed to connect to user created endpoints")
167+
for _, cnsi := range cnsiList {
168+
if cnsi.Creator == userID || len(cnsi.Creator) == 0 {
169+
_, ok := p.GetCNSITokenRecord(cnsi.GUID, userID)
170+
if ok {
171+
p.ClearCNSIToken(*cnsi, userID)
172+
}
173+
}
162174
}
163175

164-
if cnsiRecord.Creator != userID {
165-
return nil, echo.NewHTTPError(http.StatusUnauthorized, "Can not connect - non-admins are not allowed to connect to endpoints created by other non-admins")
176+
if len(cnsiRecord.Creator) != 0 && cnsiRecord.Creator != userID {
177+
return nil, echo.NewHTTPError(http.StatusUnauthorized, "Can not connect - users are not allowed to connect to personal endpoints created by other users")
166178
}
167179
}
168180

0 commit comments

Comments
 (0)