Skip to content
This repository was archived by the owner on Feb 8, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -31,3 +31,17 @@ export const Connect = () => (
authType="local"
/>
);

export const ConnectWithRequestId = () => {
return (
<ConnectDialog
username="yassine"
dbName="aurora"
dbProtocol="postgres"
clusterId="im-a-cluster"
onClose={() => null}
authType="local"
accessRequestId="e1e8072c-1eb8-5df4-a7bd-b6863b19271c"
/>
);
};
13 changes: 11 additions & 2 deletions packages/teleport/src/Databases/ConnectDialog/ConnectDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default function ConnectDialog({
dbName,
onClose,
authType,
accessRequestId,
}: Props) {
const { hostname, port } = window.document.location;
const host = `${hostname}:${port || '443'}`;
Expand All @@ -40,6 +41,10 @@ export default function ConnectDialog({
? `tsh login --proxy=${host}`
: `tsh login --proxy=${host} --auth=local --user=${username}`;

const requestIdFlag = accessRequestId
? ` --request-id=${accessRequestId}`
: '';

return (
<Dialog
dialogCss={() => ({
Expand All @@ -59,14 +64,17 @@ export default function ConnectDialog({
Step 1
</Text>
{' - Login to Teleport'}
<TextSelectCopy mt="2" text={connectCmd} />
<TextSelectCopy mt="2" text={`${connectCmd}${requestIdFlag}`} />
</Box>
<Box mb={4}>
<Text bold as="span">
Step 2
</Text>
{' - Retrieve credentials for the database'}
<TextSelectCopy mt="2" text={`tsh db login [--db-user=<user>] [--db-name=<name>] ${dbName}`} />
<TextSelectCopy
mt="2"
text={`tsh db login [--db-user=<user>] [--db-name=<name>] ${dbName}`}
/>
</Box>
<Box mb={4}>
<Text bold as="span">
Expand Down Expand Up @@ -105,4 +113,5 @@ export type Props = {
username: string;
clusterId: string;
authType: AuthType;
accessRequestId?: string;
};
3 changes: 3 additions & 0 deletions packages/teleport/src/Databases/DatabaseList/DatabaseList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function DatabaseList(props: Props) {
pathname,
replaceHistory,
onLabelClick,
accessRequestId,
} = props;

const [dbConnectInfo, setDbConnectInfo] = useState<{
Expand Down Expand Up @@ -117,6 +118,7 @@ function DatabaseList(props: Props) {
dbProtocol={dbConnectInfo.protocol}
onClose={() => setDbConnectInfo(null)}
authType={authType}
accessRequestId={accessRequestId}
/>
)}
</>
Expand Down Expand Up @@ -165,6 +167,7 @@ type Props = {
pathname: string;
replaceHistory: (path: string) => void;
onLabelClick: (label: AgentLabel) => void;
accessRequestId?: string;
};

export default DatabaseList;
1 change: 1 addition & 0 deletions packages/teleport/src/Databases/Databases.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,5 @@ export const props: State = {
replaceHistory: () => null,
isSearchEmpty: false,
onLabelClick: () => null,
accessRequestId: null,
};
2 changes: 2 additions & 0 deletions packages/teleport/src/Databases/Databases.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export function Databases(props: State) {
fetchStatus,
isSearchEmpty,
onLabelClick,
accessRequestId,
} = props;

const hasNoDatabases =
Expand Down Expand Up @@ -111,6 +112,7 @@ export function Databases(props: State) {
pathname={pathname}
replaceHistory={replaceHistory}
onLabelClick={onLabelClick}
accessRequestId={accessRequestId}
/>
</>
)}
Expand Down
2 changes: 2 additions & 0 deletions packages/teleport/src/Databases/useDatabases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default function useDatabases(ctx: Ctx) {
const isEnterprise = ctx.isEnterprise;
const version = ctx.storeUser.state.cluster.authVersion;
const authType = ctx.storeUser.state.authType;
const accessRequestId = ctx.storeUser.getAccessRequestId();
const [isAddDialogVisible, setIsAddDialogVisible] = useState(false);
const [fetchStatus, setFetchStatus] = useState<FetchStatus>('');
const [params, setParams] = useState<ResourceUrlQueryParams>({
Expand Down Expand Up @@ -173,6 +174,7 @@ export default function useDatabases(ctx: Ctx) {
fetchStatus,
isSearchEmpty,
onLabelClick,
accessRequestId,
};
}

Expand Down
13 changes: 13 additions & 0 deletions packages/teleport/src/Kubes/ConnectDialog/ConnectDialog.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ export const Local = () => {
);
};

export const LocalWithRequestId = () => {
return (
<Component
onClose={() => null}
username={'sam'}
authType={'local'}
kubeConnectName={'tele.logicoma.dev-prod'}
clusterId={'some-cluster-name'}
accessRequestId={'8289cdb1-385c-5b02-85f1-fa2a934b749f'}
/>
);
};

export const Sso = () => {
return (
<Component
Expand Down
23 changes: 19 additions & 4 deletions packages/teleport/src/Kubes/ConnectDialog/ConnectDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,23 @@ import TextSelectCopy from 'teleport/components/TextSelectCopy';
import { AuthType } from 'teleport/services/user';

function ConnectDialog(props: Props) {
const { onClose, username, authType, kubeConnectName, clusterId } = props;
const {
onClose,
username,
authType,
kubeConnectName,
clusterId,
accessRequestId,
} = props;
const { hostname, port } = window.document.location;
const host = `${hostname}:${port || '443'}`;
const authSpec =
authType === 'local' ? `--auth=${authType} --user=${username} ` : '';
const text = `tsh login --proxy=${host} ${authSpec}${clusterId}`;
authType === 'local' ? ` --auth=${authType} --user=${username}` : '';
const text = `tsh login --proxy=${host}${authSpec}`;

const requestIdFlag = accessRequestId
? ` --request-id=${accessRequestId}`
: '';

return (
<Dialog
Expand All @@ -49,7 +60,10 @@ function ConnectDialog(props: Props) {
Step 1
</Text>
{' - Login to Teleport'}
<TextSelectCopy mt="2" text={text} />
<TextSelectCopy
mt="2"
text={`${text}${requestIdFlag} ${clusterId}`}
/>
</Box>
<Box mb={4}>
<Text bold as="span">
Expand Down Expand Up @@ -90,6 +104,7 @@ type Props = {
authType: AuthType;
kubeConnectName: string;
clusterId: string;
accessRequestId?: string;
};

const dialogCss = () => `
Expand Down
3 changes: 3 additions & 0 deletions packages/teleport/src/Kubes/KubeList/KubeList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function KubeList(props: Props) {
pathname,
replaceHistory,
onLabelClick,
accessRequestId,
} = props;

const [kubeConnectName, setKubeConnectName] = useState('');
Expand Down Expand Up @@ -103,6 +104,7 @@ function KubeList(props: Props) {
authType={authType}
kubeConnectName={kubeConnectName}
clusterId={clusterId}
accessRequestId={accessRequestId}
/>
)}
</>
Expand Down Expand Up @@ -141,6 +143,7 @@ type Props = {
pathname: string;
replaceHistory: (path: string) => void;
onLabelClick: (label: AgentLabel) => void;
accessRequestId?: string;
};

export default KubeList;
1 change: 1 addition & 0 deletions packages/teleport/src/Kubes/Kubes.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,5 @@ export const props: State = {
replaceHistory: () => null,
isSearchEmpty: false,
onLabelClick: () => null,
accessRequestId: null,
};
2 changes: 2 additions & 0 deletions packages/teleport/src/Kubes/Kubes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export function Kubes(props: State) {
fetchStatus,
isSearchEmpty,
onLabelClick,
accessRequestId,
} = props;

const [showAddKube, setShowAddKube] = useState(false);
Expand Down Expand Up @@ -110,6 +111,7 @@ export function Kubes(props: State) {
pathname={pathname}
replaceHistory={replaceHistory}
onLabelClick={onLabelClick}
accessRequestId={accessRequestId}
/>
</>
)}
Expand Down
2 changes: 2 additions & 0 deletions packages/teleport/src/Kubes/useKubes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default function useKubes(ctx: TeleportContext) {
const { search, pathname } = useLocation();
const [startKeys, setStartKeys] = useState<string[]>([]);
const canCreate = ctx.storeUser.getTokenAccess().create;
const accessRequestId = ctx.storeUser.getAccessRequestId();
const { attempt, setAttempt } = useAttempt('processing');
const [fetchStatus, setFetchStatus] = useState<FetchStatus>('');
const [params, setParams] = useState<ResourceUrlQueryParams>({
Expand Down Expand Up @@ -155,6 +156,7 @@ export default function useKubes(ctx: TeleportContext) {
fetchStatus,
isSearchEmpty,
onLabelClick,
accessRequestId,
};
}

Expand Down
2 changes: 2 additions & 0 deletions packages/teleport/src/services/user/makeUserContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default function makeUserContext(json: any): UserContext {
json = json || {};
const username = json.userName;
const authType = json.authType;
const accessRequestId = json.accessRequestId;

const cluster = makeCluster(json.cluster);
const acl = makeAcl(json.userAcl);
Expand All @@ -35,6 +36,7 @@ export default function makeUserContext(json: any): UserContext {
cluster,
accessStrategy,
accessCapabilities,
accessRequestId,
};
}

Expand Down
2 changes: 2 additions & 0 deletions packages/teleport/src/services/user/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export interface UserContext {
cluster: Cluster;
accessStrategy: AccessStrategy;
accessCapabilities: AccessCapabilities;
// accessRequestId is the ID of the access request from which additional roles to assume were obtained for the current session.
accessRequestId?: string;
}

export interface Access {
Expand Down
4 changes: 4 additions & 0 deletions packages/teleport/src/stores/storeUserContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,8 @@ export default class StoreUserContext extends Store<UserContext> {
getNodeAccess() {
return this.state.acl.nodes;
}

getAccessRequestId() {
return this.state.accessRequestId;
}
}