[8.x] [Cloud] Add configuration for CSP value (#190491) (#192821)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Cloud] Add configuration for CSP value
(#190491)](https://github.com/elastic/kibana/pull/190491)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Jean-Louis
Leysens","email":"jeanlouis.leysens@elastic.co"},"sourceCommit":{"committedDate":"2024-09-13T08:55:36Z","message":"[Cloud]
Add configuration for CSP value (#190491)\n\n## Summary\r\n\r\nExposes
the CSP from the cloud setup plugin contract.\r\n\r\nRelated
https://github.com/elastic/kibana/issues/190023\r\n\r\n##
Notes\r\n\r\nIntended for cloud deployments, how/where will this config
value be set?\r\n\r\n\r\n### Checklist\r\n\r\nDelete any items that are
not applicable to this PR.\r\n\r\n-
[x]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [x] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"b52695edfb15e555eedbe0be1ece4a779ddfbd97","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Core","release_note:skip","v9.0.0","v8.16.0"],"title":"[Cloud]
Add configuration for CSP
value","number":190491,"url":"https://github.com/elastic/kibana/pull/190491","mergeCommit":{"message":"[Cloud]
Add configuration for CSP value (#190491)\n\n## Summary\r\n\r\nExposes
the CSP from the cloud setup plugin contract.\r\n\r\nRelated
https://github.com/elastic/kibana/issues/190023\r\n\r\n##
Notes\r\n\r\nIntended for cloud deployments, how/where will this config
value be set?\r\n\r\n\r\n### Checklist\r\n\r\nDelete any items that are
not applicable to this PR.\r\n\r\n-
[x]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [x] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"b52695edfb15e555eedbe0be1ece4a779ddfbd97"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/190491","number":190491,"mergeCommit":{"message":"[Cloud]
Add configuration for CSP value (#190491)\n\n## Summary\r\n\r\nExposes
the CSP from the cloud setup plugin contract.\r\n\r\nRelated
https://github.com/elastic/kibana/issues/190023\r\n\r\n##
Notes\r\n\r\nIntended for cloud deployments, how/where will this config
value be set?\r\n\r\n\r\n### Checklist\r\n\r\nDelete any items that are
not applicable to this PR.\r\n\r\n-
[x]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [x] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"b52695edfb15e555eedbe0be1ece4a779ddfbd97"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Jean-Louis Leysens <jeanlouis.leysens@elastic.co>
This commit is contained in:
Kibana Machine 2024-09-13 20:28:12 +10:00 committed by GitHub
parent 0457580d30
commit 0be79333f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 32 additions and 0 deletions

View file

@ -229,6 +229,7 @@ export default function ({ getService }: PluginFunctionalProviderContext) {
'xpack.ccr.ui.enabled (boolean?)',
'xpack.cloud.base_url (string?)',
'xpack.cloud.cname (string?)',
'xpack.cloud.csp (string?)',
'xpack.cloud.deployment_url (string?)',
'xpack.cloud.deployments_url (string?)',
'xpack.cloud.is_elastic_staff_owned (boolean?)',

View file

@ -31,6 +31,7 @@ describe('Cloud Plugin', () => {
...baseConfig,
id: 'cloudId',
cname: 'cloud.elastic.co',
csp: 'aws',
...configParts,
});
const plugin = new CloudPlugin(initContext);
@ -86,6 +87,11 @@ describe('Cloud Plugin', () => {
expect(setup.cname).toBe('cloud.elastic.co');
});
it('exposes csp', () => {
const { setup } = setupPlugin();
expect(setup.csp).toBe('aws');
});
it('exposes registerCloudService', () => {
const { setup } = setupPlugin();
expect(setup.registerCloudService).toBeDefined();

View file

@ -23,6 +23,7 @@ export interface CloudConfigType {
id?: string;
organization_id?: string;
cname?: string;
csp?: string;
base_url?: string;
profile_url?: string;
deployments_url?: string;
@ -82,6 +83,7 @@ export class CloudPlugin implements Plugin<CloudSetup> {
base_url: baseUrl,
trial_end_date: trialEndDate,
is_elastic_staff_owned: isElasticStaffOwned,
csp,
} = this.config;
let decodedId: DecodedCloudId | undefined;
@ -94,6 +96,7 @@ export class CloudPlugin implements Plugin<CloudSetup> {
organizationId: this.config.organization_id,
deploymentId: parseDeploymentIdFromDeploymentUrl(this.config.deployment_url),
cname,
csp,
baseUrl,
...this.getCloudUrls(),
elasticsearchUrl: decodedId?.elasticsearchUrl,

View file

@ -111,6 +111,12 @@ export interface CloudSetup {
* @example `cloud.elastic.co`
*/
cname?: string;
/**
* The cloud service provider identifier.
*
* @note Expected to be one of `aws`, `gcp` or `azure`, but could be something different.
*/
csp?: string;
/**
* This is the URL of the Cloud interface.
*/

View file

@ -10,6 +10,7 @@ Object {
"cloudDefaultPort": undefined,
"cloudHost": undefined,
"cloudId": "cloudId",
"csp": "aws",
"deploymentId": "deployment-id",
"elasticsearchUrl": undefined,
"instanceSizeMb": undefined,

View file

@ -22,6 +22,7 @@ const configSchema = schema.object({
apm: schema.maybe(apmConfigSchema),
base_url: schema.maybe(schema.string()),
cname: schema.maybe(schema.string()),
csp: schema.maybe(schema.string()),
deployments_url: schema.string({ defaultValue: '/deployments' }),
deployment_url: schema.maybe(schema.string()),
id: schema.maybe(schema.string()),
@ -59,6 +60,7 @@ export const config: PluginConfigDescriptor<CloudConfigType> = {
exposeToBrowser: {
base_url: true,
cname: true,
csp: true,
deployments_url: true,
deployment_url: true,
id: true,

View file

@ -30,6 +30,7 @@ describe('Cloud Plugin', () => {
...baseConfig,
id: 'cloudId',
cname: 'cloud.elastic.co',
csp: 'aws',
...configParts,
});
const plugin = new CloudPlugin(initContext);
@ -77,6 +78,11 @@ describe('Cloud Plugin', () => {
);
});
it('exposes csp', () => {
const { setup } = setupPlugin();
expect(setup.csp).toBe('aws');
});
it('exposes components decoded from the cloudId', () => {
const decodedId: DecodedCloudId = {
defaultPort: '9000',

View file

@ -35,6 +35,12 @@ export interface CloudSetup {
* @note The `cloudId` is a concatenation of the deployment name and a hash. Users can update the deployment name, changing the `cloudId`. However, the changed `cloudId` will not be re-injected into `kibana.yml`. If you need the current `cloudId` the best approach is to split the injected `cloudId` on the semi-colon, and replace the first element with the `persistent.cluster.metadata.display_name` value as provided by a call to `GET _cluster/settings`.
*/
cloudId?: string;
/**
* The cloud service provider identifier.
*
* @note Expected to be one of `aws`, `gcp` or `azure`, but could be something different.
*/
csp?: string;
/**
* The Elastic Cloud Organization that owns this deployment/project.
*/
@ -199,6 +205,7 @@ export class CloudPlugin implements Plugin<CloudSetup, CloudStart> {
return {
...this.getCloudUrls(),
cloudId: this.config.id,
csp: this.config.csp,
organizationId,
instanceSizeMb: readInstanceSizeMb(),
deploymentId,