Skip to content
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

[FTR] add service to test user roles on serverless #170417

Merged
merged 83 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from 78 commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
ceca2c3
add service
dmlemeshko Nov 2, 2023
b135763
set cookie as role login in Kibana
dmlemeshko Nov 2, 2023
64f5beb
add saml auth and fetch cookie for Kibana
dmlemeshko Nov 8, 2023
0cbd39b
add error handling for Cloud env
dmlemeshko Nov 8, 2023
f110d7c
Merge branch 'main' into ftr/serverless-user-manager
dmlemeshko Nov 8, 2023
7db971b
add support for API int tests
dmlemeshko Nov 9, 2023
197b7d8
Merge branch 'ftr/serverless-user-manager' of github.com:dmlemeshko/k…
dmlemeshko Nov 9, 2023
aaf36c9
Merge branch 'main' into ftr/serverless-user-manager
dmlemeshko Nov 9, 2023
9307083
add saml auth for local run
dmlemeshko Nov 9, 2023
3c30ba7
Merge branch 'ftr/serverless-user-manager' of github.com:dmlemeshko/k…
dmlemeshko Nov 9, 2023
29e1478
Merge branch 'main' into ftr/serverless-user-manager
dmlemeshko Nov 9, 2023
2be38cb
generate local users from roles list
dmlemeshko Nov 10, 2023
faa02c9
Merge branch 'ftr/serverless-user-manager' of github.com:dmlemeshko/k…
dmlemeshko Nov 10, 2023
8807b3b
Merge branch 'main' into ftr/serverless-user-manager
dmlemeshko Nov 10, 2023
b28042e
Merge branch 'main' into ftr/serverless-user-manager
dmlemeshko Nov 10, 2023
450418f
return fullName & fix reading roles resource
dmlemeshko Nov 13, 2023
5211b0d
Merge branch 'ftr/serverless-user-manager' of github.com:dmlemeshko/k…
dmlemeshko Nov 13, 2023
90a1e52
Merge branch 'main' into ftr/serverless-user-manager
dmlemeshko Nov 13, 2023
bdafb7c
add doc
dmlemeshko Nov 13, 2023
8ed71f3
Merge branch 'main' into ftr/serverless-user-manager
dmlemeshko Nov 13, 2023
6fb9d59
Merge branch 'ftr/serverless-user-manager' of github.com:dmlemeshko/k…
dmlemeshko Nov 13, 2023
ef40778
Merge remote-tracking branch 'upstream/main' into ftr/serverless-user…
dmlemeshko Nov 14, 2023
14730ef
address review comments
dmlemeshko Nov 14, 2023
f8e57eb
Merge remote-tracking branch 'upstream/main' into ftr/serverless-user…
dmlemeshko Nov 14, 2023
081f399
fix fullname reading
dmlemeshko Nov 14, 2023
0c8b23f
Merge branch 'main' into ftr/serverless-user-manager
dmlemeshko Nov 14, 2023
e9310eb
Merge branch 'ftr/serverless-user-manager' of github.com:dmlemeshko/k…
dmlemeshko Nov 14, 2023
9be2ac0
Update x-pack/test_serverless/functional/page_objects/svl_common_page.ts
dmlemeshko Nov 14, 2023
ec7c342
Update x-pack/test_serverless/functional/page_objects/svl_common_page.ts
dmlemeshko Nov 14, 2023
fe91719
clean code
dmlemeshko Nov 14, 2023
dee727e
Merge branch 'ftr/serverless-user-manager' of github.com:dmlemeshko/k…
dmlemeshko Nov 14, 2023
4a44f71
Merge remote-tracking branch 'upstream/main' into ftr/serverless-user…
dmlemeshko Nov 15, 2023
1c4e8c2
uncomment mocked SAML for local run
dmlemeshko Nov 15, 2023
ebdf8b9
pass httpAgent with cert for Kibana in TLS mode
dmlemeshko Nov 15, 2023
7fd14e6
fix SAML hanshake for both MKI & local
dmlemeshko Nov 16, 2023
5c56018
[kbn-test] disable TLS mode for svl Kibana
dmlemeshko Nov 16, 2023
fdcaa7f
Merge branch 'main' into ftr/serverless-user-manager
dmlemeshko Nov 23, 2023
2a1fcc9
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Nov 23, 2023
45d0779
add test examples
dmlemeshko Nov 23, 2023
ba40c38
fix saml config
dmlemeshko Nov 24, 2023
a931eb2
update test
dmlemeshko Nov 24, 2023
8d178e6
Merge branch 'main' into ftr/serverless-user-manager
dmlemeshko Nov 24, 2023
4bb177d
remove disabling welcome screen
dmlemeshko Nov 24, 2023
f95139a
fix test
dmlemeshko Nov 24, 2023
3169e53
Merge branch 'ftr/serverless-user-manager' of github.com:dmlemeshko/k…
dmlemeshko Nov 24, 2023
efcf626
Merge branch 'main' into ftr/serverless-user-manager
dmlemeshko Nov 24, 2023
71e4c9f
update tests
dmlemeshko Nov 28, 2023
2e8aa89
add tests to other projects
dmlemeshko Nov 28, 2023
1cda908
[supertest] override TestAgent to not cache cookie
dmlemeshko Nov 28, 2023
634e0df
Merge branch 'ftr/serverless-user-manager' of github.com:dmlemeshko/k…
dmlemeshko Nov 28, 2023
f8b6dbd
Merge remote-tracking branch 'upstream/main' into ftr/serverless-user…
dmlemeshko Nov 28, 2023
2dc3546
[ftr] update supertest
dmlemeshko Nov 28, 2023
7985902
remove callback arg
dmlemeshko Nov 28, 2023
5b7c4e8
add patch method
dmlemeshko Nov 28, 2023
36f5397
add users file to gitignore
dmlemeshko Nov 28, 2023
8ad1b7e
remove hosts
dmlemeshko Nov 28, 2023
2e6636d
fix SuperTest typing
dmlemeshko Nov 28, 2023
f1e0ceb
fix type issue
dmlemeshko Nov 28, 2023
736eafb
Merge branch 'main' into ftr/serverless-user-manager
dmlemeshko Nov 28, 2023
32888e3
Revert "fix type issue"
dmlemeshko Nov 29, 2023
8f6ac62
Revert "fix SuperTest typing"
dmlemeshko Nov 29, 2023
943c197
remove cert as we start Kibana without TLS
dmlemeshko Nov 29, 2023
5fb5c8b
Merge remote-tracking branch 'upstream/main' into ftr/serverless-user…
dmlemeshko Nov 29, 2023
bbe4387
add comment about cookies/certificate
dmlemeshko Nov 29, 2023
b6b8824
move test example to common/platform_security
dmlemeshko Nov 30, 2023
3e60a77
Update x-pack/test_serverless/shared/services/user_manager/saml_auth.ts
dmlemeshko Nov 30, 2023
2b93cec
rename methods, check token
dmlemeshko Nov 30, 2023
0bbab6d
Merge branch 'ftr/serverless-user-manager' of github.com:dmlemeshko/k…
dmlemeshko Nov 30, 2023
be22aaa
return email for fullname if first & last empty
dmlemeshko Nov 30, 2023
ecbf5f1
change username to email for Cloud auth
dmlemeshko Nov 30, 2023
35cfadf
refactor to expose less
dmlemeshko Nov 30, 2023
8a091b2
fix imports
dmlemeshko Nov 30, 2023
c5235d3
Merge remote-tracking branch 'upstream/main' into ftr/serverless-user…
dmlemeshko Nov 30, 2023
be5552d
improve error handling
dmlemeshko Nov 30, 2023
099e0d0
Merge remote-tracking branch 'upstream/main' into ftr/serverless-user…
dmlemeshko Nov 30, 2023
2a94eaf
redact axios errors
dmlemeshko Nov 30, 2023
c478991
Merge remote-tracking branch 'upstream/main' into ftr/serverless-user…
dmlemeshko Nov 30, 2023
923e071
Merge branch 'main' into ftr/serverless-user-manager
dmlemeshko Nov 30, 2023
d0ee6ff
Merge remote-tracking branch 'upstream/main' into ftr/serverless-user…
dmlemeshko Dec 4, 2023
8cc5da6
clean all cookies before adding the new one
dmlemeshko Dec 4, 2023
84cf0a8
check via API that cookie from the browser is set for the correct role
dmlemeshko Dec 4, 2023
484af20
Merge remote-tracking branch 'upstream/main' into ftr/serverless-user…
dmlemeshko Dec 4, 2023
f789475
Merge branch 'main' into ftr/serverless-user-manager
dmlemeshko Dec 4, 2023
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,7 @@ fleet-server.yml
**/.journeys/
x-pack/test/security_api_integration/plugins/audit_log/audit.log

# ignore FTR temp directory
.ftr
role_users.json

4 changes: 2 additions & 2 deletions packages/kbn-es/src/utils/docker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,9 @@ describe('resolveEsArgs()', () => {
"--env",
"xpack.security.authc.realms.saml.mock-idp.attributes.groups=http://saml.elastic-cloud.com/attributes/roles",
"--env",
"xpack.security.authc.realms.saml.mock-idp.attributes.name=http://saml.elastic-cloud.com/attributes/email",
"xpack.security.authc.realms.saml.mock-idp.attributes.name=http://saml.elastic-cloud.com/attributes/name",
"--env",
"xpack.security.authc.realms.saml.mock-idp.attributes.mail=http://saml.elastic-cloud.com/attributes/name",
"xpack.security.authc.realms.saml.mock-idp.attributes.mail=http://saml.elastic-cloud.com/attributes/email",
]
`);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-es/src/utils/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,11 +508,11 @@ export function resolveEsArgs(
);
esArgs.set(
`xpack.security.authc.realms.saml.${MOCK_IDP_REALM_NAME}.attributes.name`,
MOCK_IDP_ATTRIBUTE_EMAIL
MOCK_IDP_ATTRIBUTE_NAME
);
esArgs.set(
`xpack.security.authc.realms.saml.${MOCK_IDP_REALM_NAME}.attributes.mail`,
MOCK_IDP_ATTRIBUTE_NAME
MOCK_IDP_ATTRIBUTE_EMAIL
);
}

Expand Down
12 changes: 12 additions & 0 deletions test/functional/services/common/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,18 @@ class BrowserService extends FtrService {
return await this.driver.get(url);
}

/**
* Adds a cookie to the current browsing context. You need to be on the domain that the cookie will be valid for.
* https://www.selenium.dev/documentation/webdriver/interactions/cookies/#add-cookie
*
* @param {string} name
* @param {string} value
* @return {Promise<void>}
*/
public async setCookie(name: string, value: string) {
await this.driver.manage().addCookie({ name, value });
}

/**
* Retrieves the cookie with the given name. Returns null if there is no such cookie. The cookie will be returned as
* a JSON object as described by the WebDriver wire protocol.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default function ({ loadTestFile }: FtrProviderContext) {
loadTestFile(require.resolve('./role_mappings'));
loadTestFile(require.resolve('./sessions'));
loadTestFile(require.resolve('./users'));
loadTestFile(require.resolve('./request_as_viewer'));
loadTestFile(require.resolve('./user_profiles'));
loadTestFile(require.resolve('./views'));
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import expect from '@kbn/expect';
import type { FtrProviderContext } from '../../../ftr_provider_context';

export default function ({ getService }: FtrProviderContext) {
describe('security/request as viewer', () => {
const svlUserManager = getService('svlUserManager');
const supertestWithoutAuth = getService('supertestWithoutAuth');
let credentials: { Cookie: string };

before(async () => {
// get auth header for Viewer role
credentials = await svlUserManager.getApiCredentialsForRole('viewer');
});

it('returns full status payload for authenticated request', async () => {
const { body } = await supertestWithoutAuth
.get('/api/status')
.set(credentials)
.set('kbn-xsrf', 'kibana');

expect(body.name).to.be.a('string');
expect(body.uuid).to.be.a('string');
expect(body.version.number).to.be.a('string');
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,33 @@ export function SvlCommonPageProvider({ getService, getPageObjects }: FtrProvide
const deployment = getService('deployment');
const log = getService('log');
const browser = getService('browser');
const svlUserManager = getService('svlUserManager');

const delay = (ms: number) =>
new Promise((resolve) => {
setTimeout(resolve, ms);
});

return {
async loginWithRole(role: string) {
log.debug(`Logging in by setting browser cookie for '${role}' role`);
const sidCookie = await svlUserManager.getSessionCookieForRole(role);
// Loading bootstrap.js in order to be on the domain that the cookie will be set for.
await browser.get(deployment.getHostPort() + '/bootstrap.js');
dmlemeshko marked this conversation as resolved.
Show resolved Hide resolved
await browser.setCookie('sid', sidCookie);
// Cookie should be already set in the browsing context, navigating to the Home page
await browser.get(deployment.getHostPort());
// Verifying that we are logged in
if (await testSubjects.exists('userMenuButton', { timeout: 10_000 })) {
log.debug('userMenuButton found, login passed');
} else {
throw new Error(`Failed to login with cookie for '${role}' role`);
}
},

async navigateToLoginForm() {
const url = deployment.getHostPort() + '/login';
await browser.get(url);
// ensure welcome screen won't be shown. This is relevant for environments which don't allow
// to use the yml setting, e.g. cloud
await browser.setLocalStorageItem('home:welcome:show', 'false');

log.debug('Waiting for Login Form to appear.');
await retry.waitForWithTimeout('login form', 10_000, async () => {
return await pageObjects.security.isLoginFormVisible();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { FtrProviderContext } from '../../../ftr_provider_context';

export default function ({ loadTestFile }: FtrProviderContext) {
describe('Serverless Common UI - Platform Security', function () {
loadTestFile(require.resolve('./viewer_role_login'));
loadTestFile(require.resolve('./api_keys'));
loadTestFile(require.resolve('./navigation/avatar_menu'));
loadTestFile(require.resolve('./user_profiles/user_profiles'));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../ftr_provider_context';

const VIEWER_ROLE = 'viewer';

export default function ({ getPageObject, getService }: FtrProviderContext) {
describe(`Login as ${VIEWER_ROLE}`, function () {
const svlCommonPage = getPageObject('svlCommonPage');
const testSubjects = getService('testSubjects');
const svlUserManager = getService('svlUserManager');

before(async () => {
await svlCommonPage.loginWithRole(VIEWER_ROLE);
});

it('should be able to see correct profile', async () => {
await svlCommonPage.assertProjectHeaderExists();
await svlCommonPage.assertUserAvatarExists();
await svlCommonPage.clickUserAvatar();
await svlCommonPage.assertUserMenuExists();
const actualFullname = await testSubjects.getVisibleText('contextMenuPanelTitle');
const userData = await svlUserManager.getUserData(VIEWER_ROLE);
expect(actualFullname).to.be(userData.fullname);
});
});
}
2 changes: 2 additions & 0 deletions x-pack/test_serverless/shared/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import { SvlReportingServiceProvider } from './svl_reporting';
import { SupertestProvider, SupertestWithoutAuthProvider } from './supertest';
import { SvlCommonApiServiceProvider } from './svl_common_api';
import { SvlUserManagerProvider } from './user_manager/svl_user_manager';

export const services = {
supertest: SupertestProvider,
supertestWithoutAuth: SupertestWithoutAuthProvider,
svlCommonApi: SvlCommonApiServiceProvider,
svlReportingApi: SvlReportingServiceProvider,
svlUserManager: SvlUserManagerProvider,
};
16 changes: 12 additions & 4 deletions x-pack/test_serverless/shared/services/supertest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,29 @@ import { format as formatUrl } from 'url';
import supertest from 'supertest';
import { FtrProviderContext } from '../../functional/ftr_provider_context';

/**
* Returns supertest.SuperTest<supertest.Test> instance that will not persist cookie between API requests.
*/
export function SupertestProvider({ getService }: FtrProviderContext) {
const config = getService('config');
const kbnUrl = formatUrl(config.get('servers.kibana'));
const ca = config.get('servers.kibana').certificateAuthorities;

return supertest.agent(kbnUrl, { ca });
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we run Kibana without TLS, there is no need to pass certificate

return supertest(kbnUrl);
}

/**
* Returns supertest.SuperTest<supertest.Test> instance that will not persist cookie between API requests.
* If you need to pass certificate, do the following:
* await supertestWithoutAuth
* .get('/abc')
* .ca(CA_CERT)
*/
export function SupertestWithoutAuthProvider({ getService }: FtrProviderContext) {
const config = getService('config');
const kbnUrl = formatUrl({
...config.get('servers.kibana'),
auth: false,
});
const ca = config.get('servers.kibana').certificateAuthorities;

return supertest.agent(kbnUrl, { ca });
return supertest(kbnUrl);
}
Loading