[ARVADOS-WORKBENCH2] updated: 2.2.1-78-gc331c8cd

Git user git at public.arvados.org
Thu Sep 16 19:57:09 UTC 2021


Summary of changes:
 public/webshell/index.html                                    |  9 ++++++++-
 src/services/auth-service/auth-service.ts                     |  9 +++++++++
 src/store/auth/auth-action.ts                                 |  5 +++--
 src/store/auth/auth-reducer.ts                                |  5 ++++-
 .../virtual-machine-panel/virtual-machine-user-panel.tsx      | 11 ++++++++++-
 5 files changed, 34 insertions(+), 5 deletions(-)

       via  c331c8cdce120fc46e412deea700141267c832e6 (commit)
       via  9b31234e0c5ce4a03318bd0a168ad6fd7a15bf11 (commit)
      from  8faf40308b6ff0e78029a474276cbe9381ee9498 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit c331c8cdce120fc46e412deea700141267c832e6
Author: Stephen Smith <stephen at curii.com>
Date:   Thu Sep 16 15:45:49 2021 -0400

    17229: Webshell use localstorage if available
    
    Arvados-DCO-1.1-Signed-off-by: Stephen Smith <stephen at curii.com>

diff --git a/public/webshell/index.html b/public/webshell/index.html
index 77800137..ce903aa0 100644
--- a/public/webshell/index.html
+++ b/public/webshell/index.html
@@ -43,6 +43,10 @@
           var token = urlParams.get('token');
           if (token) {
             history.replaceState(null, "", `/webshell/?host=${encodeURIComponent(urlParams.get('host'))}&login=${encodeURIComponent(urlParams.get('login'))}`)
+          } else if (localStorage.getItem('apiToken')) {
+            token = localStorage.getItem('apiToken');
+          } else {
+            // No token
           }
           // change this text when PAM is reconfigured to present a
           // password prompt that we can wait for.
diff --git a/src/services/auth-service/auth-service.ts b/src/services/auth-service/auth-service.ts
index 362f7b51..5b975969 100644
--- a/src/services/auth-service/auth-service.ts
+++ b/src/services/auth-service/auth-service.ts
@@ -22,6 +22,8 @@ export const USER_IS_ACTIVE = 'isActive';
 export const USER_USERNAME = 'username';
 export const USER_PREFS = 'prefs';
 export const HOME_CLUSTER = 'homeCluster';
+export const LOCAL_STORAGE = 'localStorage';
+export const SESSION_STORAGE = 'sessionStorage';
 
 export interface UserDetailsResponse {
     email: string;
@@ -50,6 +52,13 @@ export class AuthService {
         return localStorage;
     }
 
+    public getStorageType() {
+        if (this.useSessionStorage) {
+            return SESSION_STORAGE;
+        }
+        return LOCAL_STORAGE;
+    }
+
     public saveApiToken(token: string) {
         this.removeApiToken();
         this.getStorage().setItem(API_TOKEN_KEY, token);
diff --git a/src/store/auth/auth-action.ts b/src/store/auth/auth-action.ts
index 1bdb15d1..c7074704 100644
--- a/src/store/auth/auth-action.ts
+++ b/src/store/auth/auth-action.ts
@@ -24,7 +24,7 @@ export const authActions = unionize({
     SET_CONFIG: ofType<{ config: Config }>(),
     SET_EXTRA_TOKEN: ofType<{ extraApiToken: string, extraApiTokenExpiration?: Date }>(),
     RESET_EXTRA_TOKEN: {},
-    INIT_USER: ofType<{ user: User, token: string, tokenExpiration?: Date }>(),
+    INIT_USER: ofType<{ user: User, token: string, tokenExpiration?: Date, tokenLocation?: string }>(),
     USER_DETAILS_REQUEST: {},
     USER_DETAILS_SUCCESS: ofType<User>(),
     SET_SSH_KEYS: ofType<SshKeyResource[]>(),
@@ -97,7 +97,8 @@ export const saveApiToken = (token: string) => async (dispatch: Dispatch, getSta
         const user = await svc.authService.getUserDetails();
         const client = await svc.apiClientAuthorizationService.get('current');
         const tokenExpiration = client.expiresAt ? new Date(client.expiresAt) : undefined;
-        dispatch(authActions.INIT_USER({ user, token, tokenExpiration }));
+        const tokenLocation = await svc.authService.getStorageType();
+        dispatch(authActions.INIT_USER({ user, token, tokenExpiration, tokenLocation }));
     } catch (e) {
         dispatch(authActions.LOGOUT({ deleteLinkData: false }));
     }
diff --git a/src/store/auth/auth-reducer.ts b/src/store/auth/auth-reducer.ts
index b8746ca5..ce836a55 100644
--- a/src/store/auth/auth-reducer.ts
+++ b/src/store/auth/auth-reducer.ts
@@ -13,6 +13,7 @@ export interface AuthState {
     user?: User;
     apiToken?: string;
     apiTokenExpiration?: Date;
+    apiTokenLocation?: string;
     extraApiToken?: string;
     extraApiTokenExpiration?: Date;
     sshKeys: SshKeyResource[];
@@ -29,6 +30,7 @@ const initialState: AuthState = {
     user: undefined,
     apiToken: undefined,
     apiTokenExpiration: undefined,
+    apiTokenLocation: undefined,
     extraApiToken: undefined,
     extraApiTokenExpiration: undefined,
     sshKeys: [],
@@ -71,11 +73,12 @@ export const authReducer = (services: ServiceRepository) => (state = initialStat
             ({ ...state, extraApiToken, extraApiTokenExpiration }),
         RESET_EXTRA_TOKEN: () =>
             ({ ...state, extraApiToken: undefined, extraApiTokenExpiration: undefined }),
-        INIT_USER: ({ user, token, tokenExpiration }) =>
+        INIT_USER: ({ user, token, tokenExpiration, tokenLocation = state.apiTokenLocation }) =>
             ({ ...state,
                 user,
                 apiToken: token,
                 apiTokenExpiration: tokenExpiration,
+                apiTokenLocation: tokenLocation,
                 homeCluster: user.uuid.substr(0, 5)
             }),
         LOGIN: () => state,
diff --git a/src/views/virtual-machine-panel/virtual-machine-user-panel.tsx b/src/views/virtual-machine-panel/virtual-machine-user-panel.tsx
index 44631ce3..196cba16 100644
--- a/src/views/virtual-machine-panel/virtual-machine-user-panel.tsx
+++ b/src/views/virtual-machine-panel/virtual-machine-user-panel.tsx
@@ -12,10 +12,13 @@ import { saveRequestedDate, loadVirtualMachinesUserData } from 'store/virtual-ma
 import { RootState } from 'store/store';
 import { ListResults } from 'services/common-service/common-service';
 import { HelpIcon } from 'components/icon/icon';
+import { SESSION_STORAGE } from "services/auth-service/auth-service";
 // import * as CopyToClipboard from 'react-copy-to-clipboard';
 
 type CssRules = 'button' | 'codeSnippet' | 'link' | 'linkIcon' | 'rightAlign' | 'cardWithoutMachines' | 'icon';
 
+const EXTRA_TOKEN = "exra";
+
 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     button: {
         marginTop: theme.spacing.unit,
@@ -62,6 +65,7 @@ const mapStateToProps = (state: RootState) => {
         helpText: state.auth.config.clusterConfig.Workbench.SSHHelpPageHTML,
         hostSuffix: state.auth.config.clusterConfig.Workbench.SSHHelpHostSuffix || "",
         token: state.auth.extraApiToken || state.auth.apiToken || '',
+        tokenLocation: state.auth.extraApiToken ? EXTRA_TOKEN : (state.auth.apiTokenLocation || ''),
         webshellUrl: state.auth.config.clusterConfig.Services.WebShell.ExternalURL,
         ...state.virtualMachines
     };
@@ -80,6 +84,7 @@ interface VirtualMachinesPanelDataProps {
     helpText: string;
     hostSuffix: string;
     token: string;
+    tokenLocation: string,
     webshellUrl: string;
 }
 
@@ -176,6 +181,10 @@ const virtualMachinesTable = (props: VirtualMachineProps) =>
                     if (lk.tailUuid === props.userUuid) {
                         const username = lk.properties.username;
                         const command = `ssh ${username}@${it.hostname}${props.hostSuffix}`;
+                        let tokenParam = "";
+                        if (props.tokenLocation === SESSION_STORAGE || props.tokenLocation === EXTRA_TOKEN) {
+                          tokenParam = `&token=${encodeURIComponent(props.token)}`;
+                        }
                         return <TableRow key={lk.uuid}>
                             <TableCell>{it.hostname}</TableCell>
                             <TableCell>{username}</TableCell>
@@ -183,7 +192,7 @@ const virtualMachinesTable = (props: VirtualMachineProps) =>
                                 {command}
                             </TableCell>
                             <TableCell>
-                                <a href={`/webshell/?host=${encodeURIComponent(props.webshellUrl + '/' + it.hostname)}&login=${username}&token=${encodeURIComponent(props.token)}`} target="_blank" rel="noopener noreferrer" className={props.classes.link}>
+                                <a href={`/webshell/?host=${encodeURIComponent(props.webshellUrl + '/' + it.hostname)}&login=${encodeURIComponent(username)}${tokenParam}`} target="_blank" rel="noopener noreferrer" className={props.classes.link}>
                                     Log in as {username}
                                 </a>
                             </TableCell>

commit 9b31234e0c5ce4a03318bd0a168ad6fd7a15bf11
Author: Stephen Smith <stephen at curii.com>
Date:   Thu Sep 16 15:04:21 2021 -0400

    17229: Clear webshell token from url after page loads
    
    Arvados-DCO-1.1-Signed-off-by: Stephen Smith <stephen at curii.com>

diff --git a/public/webshell/index.html b/public/webshell/index.html
index 6fa6f313..77800137 100644
--- a/public/webshell/index.html
+++ b/public/webshell/index.html
@@ -40,9 +40,12 @@
         }
 
         var trySendToken = function() {
+          var token = urlParams.get('token');
+          if (token) {
+            history.replaceState(null, "", `/webshell/?host=${encodeURIComponent(urlParams.get('host'))}&login=${encodeURIComponent(urlParams.get('login'))}`)
+          }
           // change this text when PAM is reconfigured to present a
           // password prompt that we can wait for.
-          var token = urlParams.get('token');
           if (findText("assword:")) {
              sh.keysPressed(token + "\n");
              sh.vt100('(sent authentication token)\n');

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list