-
Notifications
You must be signed in to change notification settings - Fork 749
RFE-9146: Add service account impersonation support #17026
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
540fb93
4f8a9ff
8180289
8ef978a
8ab8c48
74988c2
d4090a8
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 |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { expect, type Locator } from '@playwright/test'; | ||
|
|
||
| import BasePage from './base-page'; | ||
|
|
||
| export class ServiceAccountPage extends BasePage { | ||
| private readonly actionsMenuButton: Locator = this.page.getByTestId('actions-menu-button'); | ||
| private readonly impersonateAction: Locator = this.page.getByRole('menuitem', { | ||
| name: /Impersonate service account/, | ||
| }); | ||
|
|
||
| async navigateToDetails(namespace: string, name: string): Promise<void> { | ||
| await this.goTo(`/k8s/ns/${namespace}/~v1~ServiceAccount/${name}`); | ||
| await expect(this.page.getByRole('heading', { level: 1 }).filter({ hasText: name })).toBeVisible({ | ||
| timeout: 60_000, | ||
| }); | ||
| await this.waitForDetailsActions(this.actionsMenuButton); | ||
| } | ||
|
|
||
| async impersonateFromDetails(): Promise<void> { | ||
| await this.robustClick(this.actionsMenuButton); | ||
| await this.robustClick(this.impersonateAction); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import type { Locator } from '@playwright/test'; | ||
|
|
||
| import { expect } from '../fixtures'; | ||
|
|
||
| import BasePage from './base-page'; | ||
|
|
||
| export class UserPage extends BasePage { | ||
| private readonly actionsMenuButton: Locator = this.page.getByTestId('actions-menu-button'); | ||
| private readonly impersonateAction: Locator = this.page.getByRole('menuitem', { | ||
| name: /Impersonate user/, | ||
| }); | ||
|
|
||
| async navigateToDetails(name: string): Promise<void> { | ||
| await this.goTo(`/k8s/cluster/user.openshift.io~v1~User/${name}`); | ||
| await expect(this.page.getByRole('heading', { level: 1 }).filter({ hasText: name })).toBeVisible({ | ||
| timeout: 60_000, | ||
| }); | ||
| await this.waitForDetailsActions(this.actionsMenuButton); | ||
| } | ||
|
|
||
| async impersonateFromDetails(): Promise<void> { | ||
| await this.robustClick(this.actionsMenuButton); | ||
| await this.robustClick(this.impersonateAction); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,192 @@ | ||
| import { test, expect } from '../../../fixtures'; | ||
| import { warmupSPA } from '../../../pages/base-page'; | ||
| import { MastheadPage } from '../../../pages/masthead-page'; | ||
| import { ServiceAccountPage } from '../../../pages/service-account-page'; | ||
| import { UserPage } from '../../../pages/user-page'; | ||
|
|
||
| test.describe('Impersonation', { tag: ['@admin'] }, () => { | ||
| test('can impersonate users and service accounts with groups', async ({ | ||
| page, | ||
| cleanup, | ||
| k8sClient, | ||
| }) => { | ||
| const suffix = Date.now(); | ||
| const namespace = `sa-impersonation-${suffix}`; | ||
| const serviceAccountName = `impersonation-target-${suffix}`; | ||
| const groupName = `impersonation-group-${suffix}`; | ||
| const secondGroupName = `impersonation-group-two-${suffix}`; | ||
| const username = `impersonation-user-${suffix}`; | ||
| const serviceAccountUsername = `system:serviceaccount:${namespace}:${serviceAccountName}`; | ||
| const masthead = new MastheadPage(page); | ||
| const serviceAccountPage = new ServiceAccountPage(page); | ||
| const userPage = new UserPage(page); | ||
|
|
||
| await test.step('Create service account and group', async () => { | ||
| await k8sClient.createNamespace(namespace); | ||
| await k8sClient.waitForNamespaceReady(namespace); | ||
| cleanup.trackNamespace(namespace); | ||
| await k8sClient.coreV1Api.createNamespacedServiceAccount({ | ||
| namespace, | ||
| body: { metadata: { name: serviceAccountName } }, | ||
| }); | ||
| await k8sClient.customObjectsApi.createClusterCustomObject({ | ||
| group: 'user.openshift.io', | ||
| version: 'v1', | ||
| plural: 'groups', | ||
| body: { | ||
| apiVersion: 'user.openshift.io/v1', | ||
| kind: 'Group', | ||
| metadata: { name: groupName }, | ||
| }, | ||
| }); | ||
| cleanup.trackClusterCustomResource(groupName, 'user.openshift.io', 'v1', 'groups', 'Group'); | ||
| await k8sClient.customObjectsApi.createClusterCustomObject({ | ||
| group: 'user.openshift.io', | ||
| version: 'v1', | ||
| plural: 'groups', | ||
| body: { | ||
| apiVersion: 'user.openshift.io/v1', | ||
| kind: 'Group', | ||
| metadata: { name: secondGroupName }, | ||
| }, | ||
| }); | ||
| cleanup.trackClusterCustomResource( | ||
| secondGroupName, | ||
| 'user.openshift.io', | ||
| 'v1', | ||
| 'groups', | ||
| 'Group', | ||
| ); | ||
| await k8sClient.customObjectsApi.createClusterCustomObject({ | ||
| group: 'user.openshift.io', | ||
| version: 'v1', | ||
| plural: 'users', | ||
| body: { | ||
| apiVersion: 'user.openshift.io/v1', | ||
| kind: 'User', | ||
| metadata: { name: username }, | ||
| }, | ||
| }); | ||
| cleanup.trackClusterCustomResource(username, 'user.openshift.io', 'v1', 'users', 'User'); | ||
| }); | ||
|
|
||
| await test.step('Impersonate user from masthead modal', async () => { | ||
| await warmupSPA(page); | ||
| await masthead.impersonateUser(username); | ||
| await expect(page.getByText(`You are impersonating User ${username}`)).toBeVisible({ | ||
| timeout: 60_000, | ||
| }); | ||
| }); | ||
|
|
||
| await test.step('Stop impersonating user', async () => { | ||
| await masthead.stopImpersonating(); | ||
| await expect(page.getByText(`You are impersonating User ${username}`)).toBeHidden({ | ||
| timeout: 60_000, | ||
| }); | ||
| }); | ||
|
|
||
| await test.step('Impersonate user with group from masthead modal', async () => { | ||
| await masthead.impersonateUser(username, [groupName]); | ||
| await expect(page.getByText(`You are impersonating user ${username}`)).toBeVisible({ | ||
| timeout: 60_000, | ||
| }); | ||
| await expect(page.getByText(`with groups: ${groupName}`)).toBeVisible({ timeout: 60_000 }); | ||
| }); | ||
|
|
||
| await test.step('Stop impersonating user with group', async () => { | ||
| await masthead.stopImpersonating(); | ||
| await expect(page.getByText(`You are impersonating user ${username}`)).toBeHidden({ | ||
| timeout: 60_000, | ||
| }); | ||
| }); | ||
|
|
||
| await test.step('Impersonate user with multiple groups from masthead modal', async () => { | ||
| await masthead.impersonateUser(username, [groupName, secondGroupName]); | ||
| await expect(page.getByText(`You are impersonating user ${username}`)).toBeVisible({ | ||
| timeout: 60_000, | ||
| }); | ||
| await expect( | ||
| page.getByText(`with groups: ${groupName}, ${secondGroupName}`), | ||
| ).toBeVisible({ timeout: 60_000 }); | ||
| }); | ||
|
|
||
| await test.step('Stop impersonating user with multiple groups', async () => { | ||
| await masthead.stopImpersonating(); | ||
| await expect(page.getByText(`You are impersonating user ${username}`)).toBeHidden({ | ||
| timeout: 60_000, | ||
| }); | ||
| }); | ||
|
|
||
| await test.step('Impersonate service account from masthead modal', async () => { | ||
| await masthead.impersonateServiceAccount(namespace, serviceAccountName); | ||
| await expect(page.getByText(`You are impersonating ServiceAccount ${serviceAccountUsername}`)).toBeVisible({ | ||
| timeout: 60_000, | ||
| }); | ||
| }); | ||
|
|
||
| await test.step('Stop impersonating service account', async () => { | ||
| await masthead.stopImpersonating(); | ||
| await expect(page.getByText(`You are impersonating ServiceAccount ${serviceAccountUsername}`)).toBeHidden({ | ||
| timeout: 60_000, | ||
| }); | ||
| }); | ||
|
|
||
| await test.step('Impersonate service account with group from masthead modal', async () => { | ||
| await masthead.impersonateServiceAccount(namespace, serviceAccountName, [groupName]); | ||
| await expect(page.getByText(`You are impersonating ServiceAccount ${serviceAccountUsername}`)).toBeVisible({ | ||
| timeout: 60_000, | ||
| }); | ||
| await expect(page.getByText(`with groups: ${groupName}`)).toBeVisible({ timeout: 60_000 }); | ||
| }); | ||
|
|
||
| await test.step('Stop impersonating service account with group', async () => { | ||
| await masthead.stopImpersonating(); | ||
| await expect(page.getByText(`You are impersonating ServiceAccount ${serviceAccountUsername}`)).toBeHidden({ | ||
| timeout: 60_000, | ||
| }); | ||
| }); | ||
|
|
||
| await test.step('Impersonate service account with multiple groups from masthead modal', async () => { | ||
| await masthead.impersonateServiceAccount(namespace, serviceAccountName, [ | ||
| groupName, | ||
| secondGroupName, | ||
| ]); | ||
| await expect(page.getByText(`You are impersonating ServiceAccount ${serviceAccountUsername}`)).toBeVisible({ | ||
| timeout: 60_000, | ||
| }); | ||
| await expect( | ||
| page.getByText(`with groups: ${groupName}, ${secondGroupName}`), | ||
| ).toBeVisible({ timeout: 60_000 }); | ||
| }); | ||
|
|
||
| await test.step('Stop impersonating service account with multiple groups', async () => { | ||
| await masthead.stopImpersonating(); | ||
| await expect(page.getByText(`You are impersonating ServiceAccount ${serviceAccountUsername}`)).toBeHidden({ | ||
| timeout: 60_000, | ||
| }); | ||
| }); | ||
|
|
||
| await test.step('Impersonate service account from resource details action', async () => { | ||
| await serviceAccountPage.navigateToDetails(namespace, serviceAccountName); | ||
| await serviceAccountPage.impersonateFromDetails(); | ||
| await expect(page.getByText(`You are impersonating ServiceAccount ${serviceAccountUsername}`)).toBeVisible({ | ||
| timeout: 60_000, | ||
| }); | ||
| }); | ||
|
|
||
| await test.step('Stop impersonating service account', async () => { | ||
| await masthead.stopImpersonating(); | ||
| await expect(page.getByText(`You are impersonating ServiceAccount ${serviceAccountUsername}`)).toBeHidden({ | ||
|
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. 122, 129, 136, 144, 154, 164, 172, 179 check for "You are impersonating ServiceAccount {username}" on page. if this reflects actual banner text, is it same "ServiceAccount" one-word casing issue in modal radio label? confirm this is literal rendered text and, if so, should it --> "service account" (lowercase + space)?
Member
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 we can leave this one since the i18n string refers to the specific k8s technical name |
||
| timeout: 60_000, | ||
| }); | ||
| }); | ||
|
|
||
| await test.step('Impersonate user from resource details action', async () => { | ||
| await userPage.navigateToDetails(username); | ||
| await userPage.impersonateFromDetails(); | ||
| await expect(page.getByText(`You are impersonating User ${username}`)).toBeVisible({ | ||
| timeout: 60_000, | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -354,6 +354,7 @@ | |
| "ImageStreams": "ImageStreams", | ||
| "Impersonate {{kind}} \"{{name}}\"": "Impersonate {{kind}} \"{{name}}\"", | ||
| "Impersonate Group {{name}}": "Impersonate Group {{name}}", | ||
| "Impersonate service account {{name}}": "Impersonate service account {{name}}", | ||
|
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. "Impersonate service account {{name}}" is lowercase. line 356 capitalizes "Impersonate Group {{name}}". make capitalization consistent? (Group --> group?) @logonoff |
||
| "Impersonate user {{name}}": "Impersonate user {{name}}", | ||
| "In progress": "In progress", | ||
| "In progress ({{statusCount, number}})": "In progress ({{statusCount, number}})", | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.