-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
WebShared: Update how request checkout handles kube resource related errors #48168
Changes from all commits
d033b53
7411038
17e54e8
b24b5fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -152,15 +152,27 @@ export const FailedResourceRequest = () => ( | |||||
</MemoryRouter> | ||||||
); | ||||||
|
||||||
export const FailedUnsupportedKubeResourceKind = () => ( | ||||||
export const FailedUnsupportedKubeResourceKindWithTooltip = () => ( | ||||||
<MemoryRouter> | ||||||
<RequestCheckoutWithSlider | ||||||
{...baseProps} | ||||||
isResourceRequest={true} | ||||||
fetchResourceRequestRolesAttempt={{ | ||||||
status: 'failed', | ||||||
statusText: | ||||||
'Your Teleport roles request_mode field restricts you from requesting kinds [kube_cluster] for Kubernetes cluster "pumpkin-kube-cluster". Allowed kinds: [pod secret]', | ||||||
statusText: `your Teleport role's "request.kubernetes_resources" field did not allow requesting to some or all of the requested Kubernetes resources. allowed kinds for each requestable roles: test-role-1: [deployment], test-role-2: [pod secret configmap service serviceaccount kube_node persistentvolume persistentvolumeclaim deployment replicaset statefulset daemonset clusterrole kube_role clusterrolebinding rolebinding cronjob job certificatesigningrequest ingress]`, | ||||||
kimlisa marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
}} | ||||||
/> | ||||||
</MemoryRouter> | ||||||
); | ||||||
|
||||||
export const FailedUnsupportedKubeResourceKindWithoutTooltip = () => ( | ||||||
<MemoryRouter> | ||||||
<RequestCheckoutWithSlider | ||||||
{...baseProps} | ||||||
isResourceRequest={true} | ||||||
fetchResourceRequestRolesAttempt={{ | ||||||
status: 'failed', | ||||||
statusText: `your Teleport role's "request.kubernetes_resources" field did not allow requesting to some or all of the requested Kubernetes resources. allowed kinds for each requestable roles: test-role-1: [deployment]`, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a backend error and i was told in one of my backend PRs that error messages are not capitalized... |
||||||
}} | ||||||
/> | ||||||
</MemoryRouter> | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,26 +34,26 @@ import { | |
P3, | ||
Subtitle2, | ||
Text, | ||
Mark, | ||
} from 'design'; | ||
import { ArrowBack, ChevronDown, ChevronRight, Warning } from 'design/Icon'; | ||
import Table, { Cell } from 'design/DataTable'; | ||
import { Danger } from 'design/Alert'; | ||
|
||
import Validation, { useRule, Validator } from 'shared/components/Validation'; | ||
import { Attempt } from 'shared/hooks/useAttemptNext'; | ||
import { listToSentence, pluralize } from 'shared/utils/text'; | ||
import { pluralize } from 'shared/utils/text'; | ||
import { Option } from 'shared/components/Select'; | ||
import { FieldCheckbox } from 'shared/components/FieldCheckbox'; | ||
import { mergeRefs } from 'shared/libs/mergeRefs'; | ||
import { TextSelectCopyMulti } from 'shared/components/TextSelectCopy'; | ||
import { RequestableResourceKind } from 'shared/components/AccessRequests/NewRequest/resource'; | ||
import { HoverTooltip } from 'shared/components/ToolTip'; | ||
|
||
import { CreateRequest } from '../../Shared/types'; | ||
import { AssumeStartTime } from '../../AssumeStartTime/AssumeStartTime'; | ||
import { AccessDurationRequest } from '../../AccessDuration'; | ||
import { | ||
checkForUnsupportedKubeRequestModes, | ||
checkSupportForKubeResources, | ||
isKubeClusterWithNamespaces, | ||
type KubeNamespaceRequest, | ||
} from '../kube'; | ||
|
@@ -191,15 +191,10 @@ export function RequestCheckout<T extends PendingListItem>({ | |
}); | ||
} | ||
|
||
const { | ||
affectedKubeClusterName, | ||
unsupportedKubeRequestModes, | ||
requiresNamespaceSelect, | ||
} = checkForUnsupportedKubeRequestModes(fetchResourceRequestRolesAttempt); | ||
|
||
const hasUnsupportedKubeRequestModes = !!unsupportedKubeRequestModes; | ||
const showRequestRoleErrBanner = | ||
!hasUnsupportedKubeRequestModes && !requiresNamespaceSelect; | ||
const { requestKubeResourceSupported, isRequestKubeResourceError } = | ||
checkSupportForKubeResources(fetchResourceRequestRolesAttempt); | ||
const hasUnsupporteKubeResourceKinds = | ||
!requestKubeResourceSupported && isRequestKubeResourceError; | ||
|
||
const isInvalidRoleSelection = | ||
resourceRequestRoles.length > 0 && | ||
|
@@ -211,8 +206,7 @@ export function RequestCheckout<T extends PendingListItem>({ | |
createAttempt.status === 'processing' || | ||
isInvalidRoleSelection || | ||
(fetchResourceRequestRolesAttempt.status === 'failed' && | ||
hasUnsupportedKubeRequestModes) || | ||
requiresNamespaceSelect || | ||
hasUnsupporteKubeResourceKinds) || | ||
fetchResourceRequestRolesAttempt.status === 'processing'; | ||
|
||
const cancelBtnDisabled = | ||
|
@@ -269,13 +263,8 @@ export function RequestCheckout<T extends PendingListItem>({ | |
<KubeNamespaceSelector | ||
kubeClusterItem={item} | ||
savedResourceItems={pendingAccessRequests} | ||
toggleResource={toggleResource} | ||
fetchKubeNamespaces={fetchKubeNamespaces} | ||
bulkToggleKubeResources={bulkToggleKubeResources} | ||
namespaceRequired={ | ||
requiresNamespaceSelect && | ||
affectedKubeClusterName.includes(item.id) | ||
} | ||
/> | ||
</Flex> | ||
</Flex> | ||
|
@@ -288,21 +277,31 @@ export function RequestCheckout<T extends PendingListItem>({ | |
<Validation> | ||
{({ validator }) => ( | ||
<> | ||
{showRequestRoleErrBanner && | ||
{!isRequestKubeResourceError && | ||
createAttempt.status !== 'failed' && | ||
fetchResourceRequestRolesAttempt.status === 'failed' && ( | ||
<Alert | ||
kind="danger" | ||
children={fetchResourceRequestRolesAttempt.statusText} | ||
/> | ||
)} | ||
{hasUnsupportedKubeRequestModes && ( | ||
{hasUnsupporteKubeResourceKinds && ( | ||
<Alert kind="danger"> | ||
<HoverTooltip | ||
position="left" | ||
tipContent={ | ||
fetchResourceRequestRolesAttempt.statusText.length > 248 | ||
? fetchResourceRequestRolesAttempt.statusText | ||
: null | ||
} | ||
> | ||
<ShortenedText mb={2}> | ||
{fetchResourceRequestRolesAttempt.statusText} | ||
</ShortenedText> | ||
</HoverTooltip> | ||
<Text mb={2}> | ||
You can only request Kubernetes resource{' '} | ||
{pluralize(unsupportedKubeRequestModes.length, 'kind')}{' '} | ||
<Mark>{listToSentence(unsupportedKubeRequestModes)}</Mark> for | ||
cluster <Mark>{affectedKubeClusterName}</Mark>. Requesting those | ||
resource kinds is currently only supported through the{' '} | ||
The listed allowed kinds are currently only supported through | ||
the{' '} | ||
<ExternalLink | ||
target="_blank" | ||
href="https://goteleport.com/docs/connect-your-client/tsh/#installing-tsh" | ||
|
@@ -316,14 +315,14 @@ export function RequestCheckout<T extends PendingListItem>({ | |
> | ||
tsh request search | ||
</ExternalLink>{' '} | ||
command that will help you construct the request. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it should still say "command" no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh what the.... i have minor UX's stuff i need to address, so i'll add it back |
||
that will help you construct the request. | ||
</Text> | ||
<Box width="360px"> | ||
<Box width="325px"> | ||
Example: | ||
<TextSelectCopyMulti | ||
lines={[ | ||
{ | ||
text: `tsh request search --kind=${unsupportedKubeRequestModes[0]} --kube-cluster=${affectedKubeClusterName} --all-kube-namespaces`, | ||
text: `tsh request search --kind=ALLOWED_KIND --kube-cluster=CLUSTER_NAME --all-kube-namespaces`, | ||
}, | ||
]} | ||
/> | ||
|
@@ -863,6 +862,12 @@ const StyledTable = styled(Table)` | |
overflow: hidden; | ||
` as typeof Table; | ||
|
||
const ShortenedText = styled(Text)` | ||
display: -webkit-box; | ||
-webkit-box-orient: vertical; | ||
-webkit-line-clamp: 6; | ||
`; | ||
|
||
export type RequestCheckoutWithSliderProps< | ||
T extends PendingListItem = PendingListItem, | ||
> = { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i had to remove the required checking b/c theres now no clear way to tell if it's required or not.
eg: one role can enforce namespaces only, another role can enforce pods only. it'll be confusing to assume that all kube_cluster resources selected has access to namespaces and mark it
required
(letting user try to create request and backend return an error is better)