forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.6] [Cloud/Security] Fix the server-side import of the contract `Cl…
…oudStart` (elastic#149203) (elastic#149251) # Backport This will backport the following commits from `main` to `8.6`: - [[Cloud/Security] Fix the server-side import of the contract `CloudStart` (elastic#149203)](elastic#149203) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Alejandro Fernández Haro","email":"alejandro.haro@elastic.co"},"sourceCommit":{"committedDate":"2023-01-19T17:49:34Z","message":"[Cloud/Security] Fix the server-side import of the contract `CloudStart` (elastic#149203)\n\nCo-authored-by: Aleh Zasypkin <aleh.zasypkin@elastic.co>\r\nResolves https://github.com/elastic/kibana/issues/149204","sha":"f0b5db6f7013275b41bcbdfbaa8b4e0f67b7629d","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Core","release_note:fix","Team:Security","backport:prev-minor","ci:cloud-deploy","v8.7.0"],"number":149203,"url":"https://github.com/elastic/kibana/pull/149203","mergeCommit":{"message":"[Cloud/Security] Fix the server-side import of the contract `CloudStart` (elastic#149203)\n\nCo-authored-by: Aleh Zasypkin <aleh.zasypkin@elastic.co>\r\nResolves https://github.com/elastic/kibana/issues/149204","sha":"f0b5db6f7013275b41bcbdfbaa8b4e0f67b7629d"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/149203","number":149203,"mergeCommit":{"message":"[Cloud/Security] Fix the server-side import of the contract `CloudStart` (elastic#149203)\n\nCo-authored-by: Aleh Zasypkin <aleh.zasypkin@elastic.co>\r\nResolves https://github.com/elastic/kibana/issues/149204","sha":"f0b5db6f7013275b41bcbdfbaa8b4e0f67b7629d"}}]}] BACKPORT--> Co-authored-by: Alejandro Fernández Haro <alejandro.haro@elastic.co>
- Loading branch information
1 parent
3cfd246
commit 84833d2
Showing
8 changed files
with
186 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* 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 { resolve } from 'path'; | ||
import { FtrConfigProviderContext } from '@kbn/test'; | ||
import { services } from './services'; | ||
|
||
export default async function ({ readConfigFile }: FtrConfigProviderContext) { | ||
const xPackAPITestsConfig = await readConfigFile(require.resolve('../api_integration/config.ts')); | ||
|
||
const kibanaPort = xPackAPITestsConfig.get('servers.kibana.port'); | ||
const idpPath = resolve(__dirname, './fixtures/saml/idp_metadata.xml'); | ||
|
||
return { | ||
testFiles: [require.resolve('./tests/saml_cloud')], | ||
servers: xPackAPITestsConfig.get('servers'), | ||
security: { disableTestUser: true }, | ||
services, | ||
junit: { | ||
reportName: 'X-Pack Security API Integration Tests (Cloud SAML)', | ||
}, | ||
|
||
esTestCluster: { | ||
...xPackAPITestsConfig.get('esTestCluster'), | ||
serverArgs: [ | ||
...xPackAPITestsConfig.get('esTestCluster.serverArgs'), | ||
'xpack.security.authc.token.enabled=true', | ||
'xpack.security.authc.token.timeout=15s', | ||
'xpack.security.authc.realms.saml.cloud-saml-kibana.order=0', | ||
`xpack.security.authc.realms.saml.cloud-saml-kibana.idp.metadata.path=${idpPath}`, | ||
'xpack.security.authc.realms.saml.cloud-saml-kibana.idp.entity_id=http://www.elastic.co/saml1', | ||
`xpack.security.authc.realms.saml.cloud-saml-kibana.sp.entity_id=http://localhost:${kibanaPort}`, | ||
`xpack.security.authc.realms.saml.cloud-saml-kibana.sp.logout=http://localhost:${kibanaPort}/logout`, | ||
`xpack.security.authc.realms.saml.cloud-saml-kibana.sp.acs=http://localhost:${kibanaPort}/api/security/saml/callback`, | ||
'xpack.security.authc.realms.saml.cloud-saml-kibana.attributes.principal=urn:oid:0.0.7', | ||
], | ||
}, | ||
|
||
kbnTestServer: { | ||
...xPackAPITestsConfig.get('kbnTestServer'), | ||
serverArgs: [ | ||
...xPackAPITestsConfig.get('kbnTestServer.serverArgs'), | ||
'--xpack.cloud.id=ftr_fake_cloud_id', | ||
`--xpack.security.authc.providers=${JSON.stringify({ | ||
basic: { 'cloud-basic': { order: 0 } }, | ||
saml: { 'cloud-saml-kibana': { order: 1, realm: 'cloud-saml-kibana' } }, | ||
})}`, | ||
], | ||
}, | ||
}; | ||
} |
14 changes: 14 additions & 0 deletions
14
x-pack/test/security_api_integration/tests/saml_cloud/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* 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 { FtrProviderContext } from '../../ftr_provider_context'; | ||
|
||
export default function ({ loadTestFile }: FtrProviderContext) { | ||
describe('security APIs - Cloud SAML', function () { | ||
loadTestFile(require.resolve('./saml_login')); | ||
}); | ||
} |
75 changes: 75 additions & 0 deletions
75
x-pack/test/security_api_integration/tests/saml_cloud/saml_login.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* 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 { parse as parseCookie, Cookie } from 'tough-cookie'; | ||
import { getSAMLResponse } from '../../fixtures/saml/saml_tools'; | ||
import { FtrProviderContext } from '../../ftr_provider_context'; | ||
|
||
export default function ({ getService }: FtrProviderContext) { | ||
const randomness = getService('randomness'); | ||
const supertest = getService('supertestWithoutAuth'); | ||
const config = getService('config'); | ||
|
||
const kibanaServerConfig = config.get('servers.kibana'); | ||
|
||
function createSAMLResponse(options = {}) { | ||
return getSAMLResponse({ | ||
destination: `http://localhost:${kibanaServerConfig.port}/api/security/saml/callback`, | ||
sessionIndex: String(randomness.naturalNumber()), | ||
...options, | ||
}); | ||
} | ||
|
||
async function checkSessionCookie(sessionCookie: Cookie, username = 'a@b.c') { | ||
const apiResponse = await supertest | ||
.get('/internal/security/me') | ||
.set('kbn-xsrf', 'xxx') | ||
.set('Cookie', sessionCookie.cookieString()) | ||
.expect(200); | ||
|
||
expect(apiResponse.body.username).to.be(username); | ||
expect(apiResponse.body.elastic_cloud_user).to.be(true); | ||
expect(apiResponse.body.authentication_realm).to.eql({ | ||
type: 'saml', | ||
name: 'cloud-saml-kibana', | ||
}); | ||
expect(apiResponse.body.authentication_provider).to.eql({ | ||
type: 'saml', | ||
name: 'cloud-saml-kibana', | ||
}); | ||
expect(apiResponse.body.authentication_type).to.be('token'); | ||
} | ||
|
||
describe('Cloud SAML authentication', () => { | ||
let sessionCookie: Cookie; | ||
|
||
beforeEach(async () => { | ||
// Cloud SAML relies on IdP initiated login. | ||
const samlAuthenticationResponse = await supertest | ||
.post('/api/security/saml/callback') | ||
.send({ SAMLResponse: await createSAMLResponse({ username: 'a@b.c' }) }) | ||
.expect(302); | ||
|
||
expect(samlAuthenticationResponse.headers.location).to.be('/'); | ||
|
||
sessionCookie = parseCookie(samlAuthenticationResponse.headers['set-cookie'][0])!; | ||
}); | ||
|
||
it('should properly set `elastic_cloud_user` user property', async () => { | ||
// Same user, same provider - session ID hasn't changed and cookie should still be valid. | ||
await supertest | ||
.get('/internal/security/me') | ||
.set('kbn-xsrf', 'xxx') | ||
.set('Cookie', sessionCookie.cookieString()) | ||
.expect(200); | ||
|
||
// Check that all properties of the cloud saml user are properly set. | ||
await checkSessionCookie(sessionCookie); | ||
}); | ||
}); | ||
} |