Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v17] [WebUI] Handle AWS Identity Center app launch URL #50232

Merged
merged 4 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export class AwsLaunchButton extends React.Component<Props> {

render() {
const { open } = this.state;
const { awsRoles, getLaunchUrl, onLaunchUrl } = this.props;
const { awsRoles, getLaunchUrl, onLaunchUrl, isAwsIdentityCenterApp } =
this.props;
return (
<>
<ButtonBorder
Expand Down Expand Up @@ -94,6 +95,7 @@ export class AwsLaunchButton extends React.Component<Props> {
onLaunchUrl={onLaunchUrl}
closeMenu={this.onClose}
onChange={this.onChange}
isAwsIdentityCenterApp={isAwsIdentityCenterApp}
/>
</Menu>
</>
Expand All @@ -107,6 +109,7 @@ function RoleItemList({
closeMenu,
onChange,
onLaunchUrl,
isAwsIdentityCenterApp,
}: Props & {
closeMenu: () => void;
onChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
Expand All @@ -118,6 +121,9 @@ function RoleItemList({
if (display !== name) {
text = `${text} (${name})`;
}
if (isAwsIdentityCenterApp) {
text = name;
}
return (
<StyledMenuItem
as="a"
Expand Down Expand Up @@ -181,6 +187,7 @@ type Props = {
getLaunchUrl(arn: string): string;
onLaunchUrl?(arn: string): void;
width?: string;
isAwsIdentityCenterApp?: boolean;
};

const StyledMenuItem = styled(MenuItem)(
Expand Down
45 changes: 34 additions & 11 deletions web/packages/teleport/src/UnifiedResources/ResourceActionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
MenuLogin,
} from 'shared/components/MenuLogin';
import { AwsLaunchButton } from 'shared/components/AwsLaunchButton';
import { AwsRole } from 'shared/services/apps';

import { UnifiedResource } from 'teleport/services/agents';
import cfg from 'teleport/config';
Expand All @@ -36,7 +37,7 @@ import DbConnectDialog from 'teleport/Databases/ConnectDialog';
import KubeConnectDialog from 'teleport/Kubes/ConnectDialog';
import useStickyClusterId from 'teleport/useStickyClusterId';
import { Node, sortNodeLogins } from 'teleport/services/nodes';
import { App } from 'teleport/services/apps';
import { App, AppSubKind } from 'teleport/services/apps';
import { ResourceKind } from 'teleport/Discover/Shared';
import { DiscoverEventResource } from 'teleport/services/userEvent';
import { useSamlAppAction } from 'teleport/SamlApplications/useSamlAppActions';
Expand Down Expand Up @@ -162,21 +163,43 @@ const AppLaunch = ({ app }: AppLaunchProps) => {
samlApp,
samlAppSsoUrl,
samlAppPreset,
subKind,
permissionSets,
} = app;
const { actions, userSamlIdPPerm } = useSamlAppAction();
if (awsConsole) {

const isAwsIdentityCenterApp = subKind === AppSubKind.AwsIcAccount;
function getAwsLaunchUrl(arnOrPermSetName: string) {
if (isAwsIdentityCenterApp) {
return `${publicAddr}&role_name=${arnOrPermSetName}`;
} else {
return cfg.getAppLauncherRoute({
fqdn,
clusterId,
publicAddr,
arn: arnOrPermSetName,
});
}
}
if (awsConsole || isAwsIdentityCenterApp) {
let awsConsoleOrIdentityCenterRoles: AwsRole[] = awsRoles;
if (isAwsIdentityCenterApp) {
awsConsoleOrIdentityCenterRoles = permissionSets.map(
(ps): AwsRole => ({
name: ps.name,
arn: ps.name,
display: ps.name,
accountId: name,
})
);
}

return (
<AwsLaunchButton
width="123px"
awsRoles={awsRoles}
getLaunchUrl={arn =>
cfg.getAppLauncherRoute({
fqdn,
clusterId,
publicAddr,
arn,
})
}
awsRoles={awsConsoleOrIdentityCenterRoles}
getLaunchUrl={getAwsLaunchUrl}
isAwsIdentityCenterApp={isAwsIdentityCenterApp}
/>
);
}
Expand Down
4 changes: 4 additions & 0 deletions web/packages/teleport/src/services/apps/apps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ test('correct formatting of apps fetch response', async () => {
samlApp: false,
samlAppSsoUrl: '',
integration: '',
permissionSets: [],
},
{
kind: 'app',
Expand All @@ -69,6 +70,7 @@ test('correct formatting of apps fetch response', async () => {
samlApp: false,
samlAppSsoUrl: '',
integration: '',
permissionSets: [],
},
{
kind: 'app',
Expand All @@ -90,6 +92,7 @@ test('correct formatting of apps fetch response', async () => {
samlApp: false,
samlAppSsoUrl: '',
integration: '',
permissionSets: [],
},
{
kind: 'app',
Expand All @@ -112,6 +115,7 @@ test('correct formatting of apps fetch response', async () => {
samlAppSsoUrl: 'http://localhost/enterprise/saml-idp/login/saml-app',
samlAppPreset: 'gcp-workforce',
integration: '',
permissionSets: [],
},
],
startKey: mockResponse.startKey,
Expand Down
4 changes: 2 additions & 2 deletions web/packages/teleport/src/services/apps/makeApps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { AwsRole } from 'shared/services/apps';

import cfg from 'teleport/config';

import { App } from './types';
import { App, PermissionSet } from './types';

export default function makeApp(json: any): App {
json = json || {};
Expand All @@ -38,7 +38,6 @@ export default function makeApp(json: any): App {
integration = '',
samlAppPreset,
subKind,
permissionSets,
} = json;

const canCreateUrl = fqdn && clusterId && publicAddr;
Expand All @@ -49,6 +48,7 @@ export default function makeApp(json: any): App {
const labels = json.labels || [];
const awsRoles: AwsRole[] = json.awsRoles || [];
const userGroups = json.userGroups || [];
const permissionSets: PermissionSet[] = json.permissionSets || [];

const isTcp = uri && uri.startsWith('tcp://');
const isCloud = uri && uri.startsWith('cloud://');
Expand Down
Loading