Skip to content

Commit

Permalink
[Cloud] Add configuration for CSP value (elastic#190491)
Browse files Browse the repository at this point in the history
## Summary

Exposes the CSP from the cloud setup plugin contract.

Related elastic#190023

## Notes

Intended for cloud deployments, how/where will this config value be set?


### Checklist

Delete any items that are not applicable to this PR.

- [x]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
  • Loading branch information
jloleysens authored Sep 13, 2024
1 parent c937e95 commit b52695e
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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?)',
Expand Down
6 changes: 6 additions & 0 deletions x-pack/plugins/cloud/public/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('Cloud Plugin', () => {
...baseConfig,
id: 'cloudId',
cname: 'cloud.elastic.co',
csp: 'aws',
...configParts,
});
const plugin = new CloudPlugin(initContext);
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/cloud/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions x-pack/plugins/cloud/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions x-pack/plugins/cloud/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions x-pack/plugins/cloud/server/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('Cloud Plugin', () => {
...baseConfig,
id: 'cloudId',
cname: 'cloud.elastic.co',
csp: 'aws',
...configParts,
});
const plugin = new CloudPlugin(initContext);
Expand Down Expand Up @@ -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',
Expand Down
7 changes: 7 additions & 0 deletions x-pack/plugins/cloud/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit b52695e

Please sign in to comment.