Skip to content

Commit

Permalink
fix(jmxauth): remove references to client-side localstorage JMX crede…
Browse files Browse the repository at this point in the history
…ntial passthrough
  • Loading branch information
andrewazores committed Apr 16, 2024
1 parent c93e6b4 commit 1893151
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 771 deletions.
7 changes: 1 addition & 6 deletions src/app/AppLayout/AuthModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,7 @@ export const AuthModal: React.FC<AuthModalProps> = ({ onDismiss, onSave: onProps
<Link onClick={onDismiss} to="/security">
Security
</Link>{' '}
to add a credential matching multiple targets. Visit{' '}
<Link onClick={onDismiss} to="/settings">
Settings
</Link>{' '}
to confirm and configure whether these credentials will be held only for this browser session or stored
encrypted in the Cryostat backend.
to add a credential matching multiple targets.
</Text>
}
>
Expand Down
13 changes: 4 additions & 9 deletions src/app/SecurityPanel/Credentials/StoreCredentials.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import {
import { OutlinedQuestionCircleIcon, SearchIcon } from '@patternfly/react-icons';
import { ExpandableRowContent, TableComposable, Tbody, Td, Th, Thead, Tr } from '@patternfly/react-table';
import * as React from 'react';
import { Link } from 'react-router-dom';
import { forkJoin } from 'rxjs';
import { SecurityCard } from '../types';
import { CreateCredentialModal } from './CreateCredentialModal';
Expand Down Expand Up @@ -179,7 +178,7 @@ const tableColumns: TableColumn[] = [

const tableTitle = 'Stored Credentials';

export const StoreCredentials = () => {
export const StoredCredentials = () => {
const context = React.useContext(ServiceContext);
const [state, dispatch] = React.useReducer(reducer, {
credentials: [] as StoredCredential[],
Expand Down Expand Up @@ -519,7 +518,7 @@ export const CheckBoxActions: React.FC<CheckBoxActionsProps> = ({
);
};

export const StoreCredentialsCard: SecurityCard = {
export const StoredCredentialsCard: SecurityCard = {
key: 'credentials',
title: (
<Text>
Expand All @@ -535,13 +534,9 @@ export const StoreCredentialsCard: SecurityCard = {
<TextContent>
<Text component={TextVariants.small}>
Credentials that Cryostat uses to connect to Cryostat agents or target JVMs over JMX are stored in encrypted
storage.
</Text>
<Text component={TextVariants.small}>
The locally-stored client credentials held by your browser session are not displayed here. See{' '}
<Link to="/settings?tab=advanced">Settings</Link> to configure locally-stored credentials.
storage managed by the Cryostat server.
</Text>
</TextContent>
),
content: StoreCredentials,
content: StoredCredentials,
};
4 changes: 2 additions & 2 deletions src/app/SecurityPanel/SecurityPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
import { BreadcrumbPage } from '@app/BreadcrumbPage/BreadcrumbPage';
import { Card, CardBody, CardTitle, Text, TextVariants } from '@patternfly/react-core';
import * as React from 'react';
import { StoreCredentialsCard } from './Credentials/StoreCredentials';
import { StoredCredentialsCard } from './Credentials/StoreCredentials';
import { ImportCertificate } from './ImportCertificate';

export interface SecurityPanelProps {}

export const SecurityPanel: React.FC<SecurityPanelProps> = (_) => {
const securityCards = [ImportCertificate, StoreCredentialsCard].map((c) => ({
const securityCards = [ImportCertificate, StoredCredentialsCard].map((c) => ({
key: c.key,
title: c.title,
description: c.description,
Expand Down
112 changes: 0 additions & 112 deletions src/app/Settings/Config/CredentialsStorage.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions src/app/Settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import { useLocation, useNavigate } from 'react-router-dom';
import { AutomatedAnalysis } from './Config/AutomatedAnalysis';
import { AutoRefresh } from './Config/AutoRefresh';
import { ChartCards } from './Config/ChartCards';
import { CredentialsStorage } from './Config/CredentialsStorage';
import { DatetimeControl } from './Config/DatetimeControl';
import { DeletionDialogControl } from './Config/DeletionDialogControl';
import { FeatureLevels } from './Config/FeatureLevels';
Expand All @@ -62,7 +61,6 @@ export const Settings: React.FC<SettingsProps> = (_) => {
NotificationControl,
AutomatedAnalysis,
ChartCards,
CredentialsStorage,
DeletionDialogControl,
WebSocketDebounce,
AutoRefresh,
Expand Down
32 changes: 4 additions & 28 deletions src/app/Shared/Services/AuthCredentials.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Locations } from '@app/Settings/Config/CredentialsStorage';
import { getFromLocalStorage } from '@app/utils/LocalStorage';
import { Observable, of } from 'rxjs';
import type { ApiService } from './Api.service';
import { Credential } from './service.types';

export class AuthCredentials {
// TODO replace with Redux?
private readonly store = new Map<string, Credential>();

constructor(private readonly api: () => ApiService) {}

setCredential(targetId: string, username: string, password: string): Observable<boolean> {
const location = getFromLocalStorage('CREDENTIAL_LOCATION', Locations.BACKEND.key);
switch (location) {
case Locations.BACKEND.key:
return this.api().postCredentials(`target.connectUrl == "${targetId}"`, username, password);
case Locations.BROWSER_SESSION.key:
this.store.set(targetId, { username, password });
return of(true);
default:
console.warn('Unknown storage location', location);
return of(false);
}
return this.api().postCredentials(`target.connectUrl == "${targetId}"`, username, password);
}

getCredential(targetId: string): Observable<Credential | undefined> {
const location = getFromLocalStorage('CREDENTIAL_LOCATION', Locations.BACKEND.key);
switch (location) {
case Locations.BACKEND.key:
// if this is stored on the backend then Cryostat should be using those and not prompting us to request from the user
return of(undefined);
case Locations.BROWSER_SESSION.key:
return of(this.store.get(targetId));
default:
console.warn('Unknown storage location', location);
return of(undefined);
}
getCredential(_: string): Observable<Credential | undefined> {
// if this is stored on the backend then Cryostat should be using those and not prompting us to request from the user
return of(undefined);
}
}
5 changes: 1 addition & 4 deletions src/app/Topology/Actions/CreateTarget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@

import openjdkSvg from '@app/assets/openjdk.svg';
import { BreadcrumbPage } from '@app/BreadcrumbPage/BreadcrumbPage';
import { Locations } from '@app/Settings/Config/CredentialsStorage';
import { LinearDotSpinner } from '@app/Shared/Components/LinearDotSpinner';
import { LoadingProps } from '@app/Shared/Components/types';
import { Target } from '@app/Shared/Services/api.types';
import { isHttpOk } from '@app/Shared/Services/api.utils';
import { ServiceContext } from '@app/Shared/Services/Services';
import '@app/Topology/styles/base.css';
import { useSubscriptions } from '@app/utils/hooks/useSubscriptions';
import { getFromLocalStorage } from '@app/utils/LocalStorage';
import { portalRoot } from '@app/utils/utils';
import {
Accordion,
Expand Down Expand Up @@ -171,7 +169,6 @@ export const CreateTarget: React.FC<CreateTargetProps> = ({ prefilled }) => {
const handleSubmit = React.useCallback(() => {
setLoading(true);
// Get storage location
const locationKey = getFromLocalStorage('CREDENTIAL_LOCATION', Locations.BACKEND.key);
addSubscription(
context.api
.createTarget(
Expand All @@ -180,7 +177,7 @@ export const CreateTarget: React.FC<CreateTargetProps> = ({ prefilled }) => {
alias: alias.trim() || connectUrl,
},
credentials,
locationKey === Locations.BACKEND.key,
true,
)
.subscribe(({ status, body }) => {
setLoading(false);
Expand Down
Loading

0 comments on commit 1893151

Please sign in to comment.