-
Notifications
You must be signed in to change notification settings - Fork 751
RFE-9146: Docs followup for service account impersonation #17093
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
Changes from all commits
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -31,11 +31,11 @@ import { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { RhUiCloseIcon, RhUiErrorFillIcon } from '@patternfly/react-icons'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useTranslation } from 'react-i18next'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { ResourceDropdown } from '@console/shared/src/components/dropdown/ResourceDropdown'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { GroupModel, ServiceAccountModel } from '../../models'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { GroupModel, NamespaceModel, ServiceAccountModel } from '../../models'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { GroupKind, K8sResourceKind } from '../../module/k8s'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { FieldLevelHelp } from '../utils/field-level-help'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useK8sWatchResource } from '../utils/k8s-watch-hook'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { NsDropdown } from '../utils/list-dropdown'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { NsDropdown, useProjectOrNamespaceModel } from '../utils/list-dropdown'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const SELECT_ALL_KEY = '__select_all__'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const MAX_VISIBLE_CHIPS = 5; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -70,6 +70,20 @@ export const ImpersonateUserModal: FC<ImpersonateUserModalProps> = ({ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [showAllGroups, setShowAllGroups] = useState(false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [groupSearchFilter, setGroupSearchFilter] = useState(''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [projectNamespaceModel, projectNamespaceModelLoaded] = useProjectOrNamespaceModel(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const serviceAccountNamespaceStrings = useMemo(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!projectNamespaceModelLoaded || projectNamespaceModel.kind === NamespaceModel.kind) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| label: t('Service account namespace'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| placeholder: t('Select a namespace'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| label: t('Service account project'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| placeholder: t('Select a project'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, [projectNamespaceModel, projectNamespaceModelLoaded, t]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+73
to
+85
Contributor
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. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Use the model instead of the creation permission to select terminology.
Destructure only the model and guard the empty hook result: Proposed fix- const [projectNamespaceModel, projectNamespaceModelLoaded] = useProjectOrNamespaceModel();
+ const [projectNamespaceModel] = useProjectOrNamespaceModel();
const serviceAccountNamespaceStrings = useMemo(() => {
- if (!projectNamespaceModelLoaded || projectNamespaceModel.kind === NamespaceModel.kind) {
+ if (!projectNamespaceModel || projectNamespaceModel.kind === NamespaceModel.kind) {
return {
label: t('Service account namespace'),
placeholder: t('Select a namespace'),
@@
- }, [projectNamespaceModel, projectNamespaceModelLoaded, t]);
+ }, [projectNamespaceModel, t]);Add a test for Based on 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Fetch available groups from the cluster | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [groups, groupsLoaded, groupsLoadError] = useK8sWatchResource<GroupKind[]>({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| groupVersionKind: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -189,7 +203,7 @@ export const ImpersonateUserModal: FC<ImpersonateUserModalProps> = ({ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| setServiceAccountNameError(''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (impersonateKind === 'User' && !username.trim()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setUsernameError(t('Username is required')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setUsernameError(t('Select a username')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -199,12 +213,12 @@ export const ImpersonateUserModal: FC<ImpersonateUserModalProps> = ({ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| let isValid = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!serviceAccountNamespace.trim()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setServiceAccountNamespaceError(t('Service account namespace is required')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setServiceAccountNamespaceError(serviceAccountNamespaceStrings.placeholder); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isValid = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!serviceAccountName.trim()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setServiceAccountNameError(t('Service account name is required')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setServiceAccountNameError(t('Select a service account')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isValid = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -318,7 +332,7 @@ export const ImpersonateUserModal: FC<ImpersonateUserModalProps> = ({ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| variant={AlertVariant.warning} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isInline | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| title={t( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'Impersonating a user or service account grants you their exact permissions. You must enter a username or service account, but you can also enter a group to simulate the permissions of a member of that group.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'Impersonating a user or service account grants you their exact permissions. You must enter a user name or service account, but you can also enter a group to simulate the permissions of a member of that group.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -339,7 +353,7 @@ export const ImpersonateUserModal: FC<ImpersonateUserModalProps> = ({ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Radio | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id="impersonate-kind-service-account" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name="impersonate-kind" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| label={t('ServiceAccount')} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| label={t('Service account')} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isChecked={impersonateKind === 'ServiceAccount'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onChange={() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setImpersonateKind('ServiceAccount'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -393,7 +407,7 @@ export const ImpersonateUserModal: FC<ImpersonateUserModalProps> = ({ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) : ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <FormGroup | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| label={t('Service account namespace')} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| label={serviceAccountNamespaceStrings.label} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fieldId="impersonate-service-account-namespace" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isRequired | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.