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

[v16] Web: Add alternate EC2 auto discover flow using AWS Systems Manager (SSM) #42204

Merged
merged 6 commits into from
May 30, 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 @@ -437,7 +437,7 @@ exports[`render with URL loc state set to "server" 1`] = `
<div
class="c22"
>
EC2 Instance
EC2 Auto Enrollment
</div>
</div>
</div>
Expand Down Expand Up @@ -1256,7 +1256,7 @@ exports[`render with all access 1`] = `
<div
class="c16"
>
EC2 Instance
EC2 Auto Enrollment
</div>
</div>
</div>
Expand Down Expand Up @@ -3622,7 +3622,7 @@ exports[`render with no access 1`] = `
<div
class="c19"
>
EC2 Instance
EC2 Auto Enrollment
</div>
</div>
</div>
Expand Down Expand Up @@ -5350,7 +5350,7 @@ exports[`render with partial access 1`] = `
<div
class="c16"
>
EC2 Instance
EC2 Auto Enrollment
</div>
</div>
</div>
Expand Down
15 changes: 11 additions & 4 deletions web/packages/teleport/src/Discover/SelectResource/resources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import { Platform } from 'design/platform';

import { assertUnreachable } from 'shared/utils/assertUnreachable';

import { DiscoverEventResource } from 'teleport/services/userEvent';
import {
DiscoverDiscoveryConfigMethod,
DiscoverEventResource,
} from 'teleport/services/userEvent';

import { ResourceKind } from '../Shared/ResourceKind';

Expand Down Expand Up @@ -81,13 +84,17 @@ export const SERVERS: ResourceSpec[] = [
platform: Platform.macOS,
},
{
name: 'EC2 Instance',
name: 'EC2 Auto Enrollment',
kind: ResourceKind.Server,
keywords:
baseServerKeywords + 'ec2 instance connect endpoint aws amazon eice',
baseServerKeywords +
'ec2 instance aws amazon simple systems manager ssm auto enrollment',
icon: 'Aws',
event: DiscoverEventResource.Ec2Instance,
nodeMeta: { location: ServerLocation.Aws },
nodeMeta: {
location: ServerLocation.Aws,
discoveryConfigMethod: DiscoverDiscoveryConfigMethod.AwsEc2Ssm,
},
},
{
name: 'Connect My Computer',
Expand Down
10 changes: 8 additions & 2 deletions web/packages/teleport/src/Discover/SelectResource/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ import { AuthType } from 'teleport/services/user';

import { ResourceKind } from '../Shared/ResourceKind';

import type { DiscoverEventResource } from 'teleport/services/userEvent';
import type {
DiscoverDiscoveryConfigMethod,
DiscoverEventResource,
} from 'teleport/services/userEvent';

import type { ResourceIconName } from 'design/ResourceIcon';

Expand Down Expand Up @@ -77,8 +80,11 @@ export enum SamlServiceProviderPreset {

export interface ResourceSpec {
dbMeta?: { location: DatabaseLocation; engine: DatabaseEngine };
nodeMeta?: { location: ServerLocation };
appMeta?: { awsConsole?: boolean };
nodeMeta?: {
location: ServerLocation;
discoveryConfigMethod: DiscoverDiscoveryConfigMethod;
};
kubeMeta?: { location: KubeLocation };
samlMeta?: { preset: SamlServiceProviderPreset };
name: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/**
* Teleport
* Copyright (C) 2024 Gravitational, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import React from 'react';
import { MemoryRouter } from 'react-router';

import { ContextProvider } from 'teleport';
import cfg from 'teleport/config';
import { createTeleportContext } from 'teleport/mocks/contexts';
import {
DiscoverProvider,
DiscoverContextState,
} from 'teleport/Discover/useDiscover';
import {
IntegrationKind,
IntegrationStatusCode,
} from 'teleport/services/integrations';
import { ResourceKind } from 'teleport/Discover/Shared';
import {
DiscoverDiscoveryConfigMethod,
DiscoverEventResource,
} from 'teleport/services/userEvent';
import { ServerLocation } from 'teleport/Discover/SelectResource';

import { ConfigureDiscoveryService as Comp } from './ConfigureDiscoveryService';

export default {
title: 'Teleport/Discover/Server/EC2',
};

export const ConfigureDiscoveryService = () => {
return <Component />;
};

const Component = () => {
const ctx = createTeleportContext();
const discoverCtx: DiscoverContextState = {
agentMeta: {
resourceName: 'aws-console',
agentMatcherLabels: [],
awsRegion: 'ap-south-1',
awsIntegration: {
kind: IntegrationKind.AwsOidc,
name: 'some-oidc-name',
resourceType: 'integration',
spec: {
roleArn: 'arn:aws:iam::123456789012:role/test-role-arn',
issuerS3Bucket: '',
issuerS3Prefix: '',
},
statusCode: IntegrationStatusCode.Running,
},
autoDiscovery: {
config: {
name: 'discovery-config-name',
discoveryGroup: 'discovery-group-name',
aws: [],
},
},
},
currentStep: 0,
nextStep: () => null,
prevStep: () => null,
onSelectResource: () => null,
resourceSpec: {
name: '',
kind: ResourceKind.Application,
icon: null,
keywords: '',
event: DiscoverEventResource.Ec2Instance,
nodeMeta: {
location: ServerLocation.Aws,
discoveryConfigMethod: DiscoverDiscoveryConfigMethod.AwsEc2Ssm,
},
},
exitFlow: () => null,
viewConfig: null,
indexedViews: [],
setResourceSpec: () => null,
updateAgentMeta: () => null,
emitErrorEvent: () => null,
emitEvent: () => null,
eventState: null,
};

cfg.proxyCluster = 'localhost';
return (
<MemoryRouter
initialEntries={[
{ pathname: cfg.routes.discover, state: { entity: 'application' } },
]}
>
<ContextProvider ctx={ctx}>
<DiscoverProvider mockCtx={discoverCtx}>
<Comp />
</DiscoverProvider>
</ContextProvider>
</MemoryRouter>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* Teleport
* Copyright (C) 2024 Gravitational, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import React, { useState } from 'react';
import { Box, Text } from 'design';

import { useDiscover } from 'teleport/Discover/useDiscover';
import useTeleport from 'teleport/useTeleport';

import { SelfHostedAutoDiscoverDirections } from 'teleport/Discover/Shared/AutoDiscovery/SelfHostedAutoDiscoverDirections';
import { DEFAULT_DISCOVERY_GROUP_NON_CLOUD } from 'teleport/services/discovery';

import { ActionButtons, Header } from '../../Shared';
import { SingleEc2InstanceInstallation } from '../Shared';

export function ConfigureDiscoveryService() {
const { nextStep, prevStep, agentMeta, updateAgentMeta } = useDiscover();

const [discoveryGroupName, setDiscoveryGroupName] = useState(
DEFAULT_DISCOVERY_GROUP_NON_CLOUD
);

const { storeUser } = useTeleport();

function handleNextStep() {
updateAgentMeta({
...agentMeta,
autoDiscovery: {
config: { name: '', aws: [], discoveryGroup: discoveryGroupName },
},
});
nextStep();
}

return (
<Box maxWidth="1000px">
<Header>Configure Teleport Discovery Service</Header>
<Text mb={4}>
The Teleport Discovery Service can connect to Amazon EC2 and
automatically discover and enroll EC2 instances.
</Text>
<SingleEc2InstanceInstallation />
<SelfHostedAutoDiscoverDirections
showSubHeader={false}
clusterPublicUrl={storeUser.state.cluster.publicURL}
discoveryGroupName={discoveryGroupName}
setDiscoveryGroupName={setDiscoveryGroupName}
/>
<ActionButtons onProceed={handleNextStep} onPrev={prevStep} />
</Box>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Teleport
* Copyright (C) 2024 Gravitational, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import React from 'react';
import { Text, Flex, ButtonPrimary, Box } from 'design';
import * as Icons from 'design/Icon';
import Dialog, { DialogContent } from 'design/DialogConfirmation';

export function DiscoveryConfigCreatedDialog({
toNextStep,
}: {
toNextStep: () => void;
}) {
return (
<Dialog disableEscapeKeyDown={false} open={true}>
<DialogContent
width="460px"
alignItems="center"
mb={0}
textAlign="center"
>
<Flex mb={5}>
<Icons.Check size="small" ml={1} mr={2} color="success.main" />
<Box>
<Text>Discovery configuration successfully created.</Text>
<Text>
The discovery service can take a few minutes to finish
auto-enrolling resources.
</Text>
</Box>
</Flex>
<ButtonPrimary width="100%" onClick={() => toNextStep()}>
Next
</ButtonPrimary>
</DialogContent>
</Dialog>
);
}
Loading
Loading