Skip to content

Commit

Permalink
Address CR
Browse files Browse the repository at this point in the history
  • Loading branch information
kimlisa committed May 30, 2024
1 parent e424e7c commit e3e209b
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 75 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { ServerLocation } from 'teleport/Discover/SelectResource';
import { ConfigureDiscoveryService as Comp } from './ConfigureDiscoveryService';

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

export const ConfigureDiscoveryService = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { ActionButtons, Header } from '../../Shared';
import { SingleEc2InstanceInstallation } from '../Shared';

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

const [discoveryGroupName, setDiscoveryGroupName] = useState(
DEFAULT_DISCOVERY_GROUP_NON_CLOUD
Expand Down Expand Up @@ -61,7 +61,7 @@ export function ConfigureDiscoveryService() {
discoveryGroupName={discoveryGroupName}
setDiscoveryGroupName={setDiscoveryGroupName}
/>
<ActionButtons onProceed={handleNextStep} />
<ActionButtons onProceed={handleNextStep} onPrev={prevStep} />
</Box>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export function DiscoveryConfigCreatedDialog({
<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()}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import React, { useState } from 'react';
import {
Box,
Link as ExternalLink,
Text,
Flex,
ButtonSecondary,
Link,
} from 'design';
import React, { useState, useRef } from 'react';
import { Box, Link as ExternalLink, Text, Flex, ButtonSecondary } from 'design';
import styled from 'styled-components';
import { Danger, Info } from 'design/Alert';
import TextEditor from 'shared/components/TextEditor';
Expand Down Expand Up @@ -58,7 +51,7 @@ import { DiscoveryConfigCreatedDialog } from './DiscoveryConfigCreatedDialog';
const IAM_POLICY_NAME = 'EC2DiscoverWithSSM';

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

const { arnResourceName, awsAccountId } = splitAwsIamArn(
Expand All @@ -72,7 +65,7 @@ export function DiscoveryConfigSsm() {
'TeleportDiscoveryInstaller'
);
const [scriptUrl, setScriptUrl] = useState('');
const [createdToken, setCreatedToken] = useState<JoinToken>();
const joinTokenRef = useRef<JoinToken>();
const [showRestOfSteps, setShowRestOfSteps] = useState(false);

const [attempt, createJoinTokenAndDiscoveryConfig, setAttempt] = useAsync(
Expand All @@ -82,14 +75,12 @@ export function DiscoveryConfigSsm() {
// Don't create another token if token was already created.
// This can happen if creating discovery config attempt failed
// and the user retries.
let joinToken = createdToken;
if (!joinToken) {
joinToken = await joinTokenService.fetchJoinToken({
if (!joinTokenRef.current) {
joinTokenRef.current = await joinTokenService.fetchJoinToken({
roles: ['Node'],
method: 'iam',
rules: [{ awsAccountId }],
});
setCreatedToken(joinToken);
}

const config = await createDiscoveryConfig(clusterId, {
Expand All @@ -107,7 +98,7 @@ export function DiscoveryConfigSsm() {
install: {
enrollMode: InstallParamEnrollMode.Script,
installTeleport: true,
joinToken: joinToken.id,
joinToken: joinTokenRef.current.id,
},
},
],
Expand Down Expand Up @@ -140,7 +131,19 @@ export function DiscoveryConfigSsm() {

function clear() {
setAttempt(makeEmptyAttempt);
setCreatedToken(null);
joinTokenRef.current = undefined;
}

function handleOnSubmit(
e: React.MouseEvent<HTMLButtonElement>,
validator: Validator
) {
e.preventDefault();
if (scriptUrl) {
setScriptUrl('');
return;
}
generateScriptUrl(validator);
}

return (
Expand All @@ -149,12 +152,12 @@ export function DiscoveryConfigSsm() {
{cfg.isCloud ? (
<Text>
The Teleport Discovery Service can connect to Amazon EC2 and
automatically discover and enroll EC2 instances. <SharedText />
automatically discover and enroll EC2 instances. <SsmInfoHeaderText />
</Text>
) : (
<Text>
Discovery config defines the setup that enables Teleport to
automatically discover and register instances. <SharedText />
automatically discover and register instances. <SsmInfoHeaderText />
</Text>
)}
{cfg.isCloud && <SingleEc2InstanceInstallation />}
Expand Down Expand Up @@ -195,32 +198,32 @@ export function DiscoveryConfigSsm() {
<Text bold>Step 2</Text>
<Text typography="subtitle1">
Attach AWS managed{' '}
<Link
<ExternalLink
target="_blank"
href="https://docs.aws.amazon.com/aws-managed-policy/latest/reference/AmazonSSMManagedInstanceCore.html"
>
AmazonSSMManagedInstanceCore
</Link>{' '}
</ExternalLink>{' '}
policy to EC2 instances IAM profile. The policy enables EC2
instances to use SSM core functionality.
</Text>
</StyledBox>
<StyledBox mt={4}>
<Text bold>Step 3</Text>
Each EC2 instance requires{' '}
<Link
<ExternalLink
target="_blank"
href="https://docs.aws.amazon.com/systems-manager/latest/userguide/ssm-agent-status-and-restart.html"
>
SSM Agent
</Link>{' '}
</ExternalLink>{' '}
to be running. The SSM{' '}
<Link
<ExternalLink
target="_blank"
href={`https://${selectedRegion}.console.aws.amazon.com/systems-manager/fleet-manager/managed-nodes?region=${selectedRegion}`}
>
Nodes Manager dashboard
</Link>{' '}
</ExternalLink>{' '}
will list all instances that have SSM agent already running. Ensure
ping statuses are <Mark>Online</Mark>.
<Info mt={3} mb={0}>
Expand All @@ -231,38 +234,39 @@ export function DiscoveryConfigSsm() {
</StyledBox>
<Validation>
{({ validator }) => (
<StyledBox mt={4}>
<Text bold>Step 4</Text>
<Box>
<Text typography="subtitle1" mb={1}>
Give a name for the{' '}
<Link
target="_blank"
href="https://docs.aws.amazon.com/systems-manager/latest/userguide/documents.html"
>
AWS SSM Document
</Link>{' '}
that will be created on your behalf. Required to run the
installer script on each discovered instances.
</Text>
<FieldInput
rule={requiredSsmDocument}
label="SSM Document Name"
value={ssmDocumentName}
onChange={e => setSsmDocumentName(e.target.value)}
placeholder="ssm-document-name"
disabled={!!scriptUrl}
/>
</Box>
<ButtonSecondary
onClick={() =>
scriptUrl ? setScriptUrl('') : generateScriptUrl(validator)
}
disabled={!selectedRegion}
>
{scriptUrl ? 'Edit' : 'Next'}
</ButtonSecondary>
</StyledBox>
<form>
<StyledBox mt={4}>
<Text bold>Step 4</Text>
<Box>
<Text typography="subtitle1" mb={1}>
Give a name for the{' '}
<ExternalLink
target="_blank"
href="https://docs.aws.amazon.com/systems-manager/latest/userguide/documents.html"
>
AWS SSM Document
</ExternalLink>{' '}
that will be created on your behalf. Required to run the
installer script on each discovered instances.
</Text>
<FieldInput
rule={requiredSsmDocument}
label="SSM Document Name"
value={ssmDocumentName}
onChange={e => setSsmDocumentName(e.target.value)}
placeholder="ssm-document-name"
disabled={!!scriptUrl}
/>
</Box>
<ButtonSecondary
type="submit"
onClick={e => handleOnSubmit(e, validator)}
disabled={!selectedRegion}
>
{scriptUrl ? 'Edit' : 'Next'}
</ButtonSecondary>
</StyledBox>
</form>
)}
</Validation>
{scriptUrl && (
Expand Down Expand Up @@ -308,6 +312,7 @@ export function DiscoveryConfigSsm() {

<ActionButtons
onProceed={createJoinTokenAndDiscoveryConfig}
onPrev={prevStep}
disableProceed={attempt.status === 'processing' || !scriptUrl}
/>
</Box>
Expand Down Expand Up @@ -360,7 +365,7 @@ const requiredSsmDocument: Rule = name => () => {
};
};

const SharedText = () => (
const SsmInfoHeaderText = () => (
<>
The service will execute an install script on these discovered instances
using{' '}
Expand Down
2 changes: 1 addition & 1 deletion web/packages/teleport/src/Discover/Server/Shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const SingleEc2InstanceInstallation = () => (
>
Teleport service installation
</InternalLink>{' '}
flow instead.
flow.
</Box>
</OutlineInfo>
);
16 changes: 7 additions & 9 deletions web/packages/teleport/src/services/discovery/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ export type DiscoveryConfig = {
type AwsMatcherTypes = 'rds' | 'eks' | 'ec2';

export enum InstallParamEnrollMode {
'Unspecified' = 0,
'Script' = 1,
'Eice' = 2,
Script = 1,
Eice = 2,
}

// AWSMatcher matches AWS EC2 instances, AWS EKS clusters and AWS Databases
Expand All @@ -50,26 +49,25 @@ export type AwsMatcher = {
// kubeAppDiscovery specifies if Kubernetes App Discovery should be enabled for a discovered cluster.
kubeAppDiscovery?: boolean;
/**
* InstallParams sets the join method when installing on
* install sets the join method when installing on
* discovered EC2 nodes
*/
install?: {
/**
* EnrollMode indicates the mode used to enroll the node into Teleport.
* Valid values: script, eice.
* enrollMode indicates the mode used to enroll the node into Teleport.
*/
enrollMode: InstallParamEnrollMode;
/**
* InstallTeleport disables agentless discovery
* installTeleport disables agentless discovery
*/
installTeleport: boolean;
/**
* JoinToken is the token to use when joining the cluster
* joinToken is the token to use when joining the cluster
*/
joinToken: string;
};
/**
* SSM provides options to use when sending a document command to
* ssm provides options to use when sending a document command to
* an EC2 node
*/
ssm?: { documentName: string };
Expand Down

0 comments on commit e3e209b

Please sign in to comment.