Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
8923f8d
[Advanced settings] Add settings allowlist
ElenaStoeva Aug 22, 2023
eb47fb6
Move allowlist APIs to server
ElenaStoeva Aug 23, 2023
1b6cbb6
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Aug 23, 2023
f8dc1bd
Don't allow updating a setting that is not allowlisted
ElenaStoeva Aug 24, 2023
90abe3a
Leverage readonly param and extract settings list into a package
ElenaStoeva Aug 24, 2023
83be210
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Aug 24, 2023
c607959
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine Aug 24, 2023
cd0e954
Expose setupProjectSettings api from serverless plugin
ElenaStoeva Aug 25, 2023
4b2ed8d
Change readonly param and improve settings package readme
ElenaStoeva Aug 25, 2023
96b6d57
Extract search and security settings into packages
ElenaStoeva Aug 29, 2023
4b782a5
Fix types errors
ElenaStoeva Aug 29, 2023
d4c8131
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine Aug 29, 2023
9abdaf9
Merge branch 'main' into advanced_settings/allowlist_for_serverless
ElenaStoeva Aug 30, 2023
e660157
Fix event log tests
ElenaStoeva Aug 30, 2023
eda865e
Merge branch 'main' into advanced_settings/allowlist_for_serverless
kibanamachine Aug 30, 2023
48cb651
Fix alerting test mocks
ElenaStoeva Aug 31, 2023
529f143
Merge branch 'main' into advanced_settings/allowlist_for_serverless
ElenaStoeva Aug 31, 2023
b7a8350
Address CR comments
ElenaStoeva Aug 31, 2023
77481ca
Add setReadonlyMode method and enforcements/validations
ElenaStoeva Sep 1, 2023
9e896ca
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Sep 1, 2023
8da18e3
Add tests for setAllowlist and validateAllowlist
ElenaStoeva Sep 1, 2023
077c7cc
Disable mappings check
ElenaStoeva Sep 4, 2023
69d763c
Merge branch 'main' into advanced_settings/allowlist_for_serverless
ElenaStoeva Sep 4, 2023
905b342
Extract setting ids into a package
ElenaStoeva Sep 4, 2023
d8f4767
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Sep 4, 2023
a2e8920
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Sep 4, 2023
c5c2535
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine Sep 4, 2023
7dfd41a
Fix logic, refactor changes
ElenaStoeva Sep 5, 2023
4e6a8dc
Merge branch 'main' into advanced_settings/allowlist_for_serverless
ElenaStoeva Sep 5, 2023
4db7ca3
Fix actions plugin tests
ElenaStoeva Sep 5, 2023
c3032bf
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Sep 5, 2023
ad880c7
Skip blocking test
ElenaStoeva Sep 5, 2023
67c33ed
Merge branch 'main' into advanced_settings/allowlist_for_serverless
ElenaStoeva Sep 5, 2023
d0665e6
Add tests for applyAllowlist
ElenaStoeva Sep 5, 2023
5da41f8
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Sep 5, 2023
80fdbe8
Add more documentation
ElenaStoeva Sep 5, 2023
f99a6d9
Add serverless plugin test
ElenaStoeva Sep 5, 2023
2b43fe5
Merge branch 'main' into advanced_settings/allowlist_for_serverless
mistic Sep 5, 2023
cfb1646
Fix alerting and event_log tests
ElenaStoeva Sep 5, 2023
a35f47f
Remove unnecessary comments
ElenaStoeva Sep 6, 2023
baf3e79
Fix exporting/importing errors
ElenaStoeva Sep 6, 2023
2f8d2b8
Remove old security setting id
ElenaStoeva Sep 7, 2023
09a4cba
Merge branch 'main' into advanced_settings/allowlist_for_serverless
ElenaStoeva Sep 7, 2023
2f0bf0f
Add functional tests
ElenaStoeva Sep 8, 2023
9e3d630
Merge branch 'advanced_settings/allowlist_for_serverless' of https://…
ElenaStoeva Sep 8, 2023
0e1561a
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Sep 8, 2023
b6e2bb1
Merge branch 'main' into advanced_settings/allowlist_for_serverless
ElenaStoeva Sep 8, 2023
7601a49
Unskip failed tests and disable multi-call check for setAllowlist
ElenaStoeva Sep 8, 2023
8c13f80
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Sep 8, 2023
7eee9a1
Skip test for setAllowlist check
ElenaStoeva Sep 8, 2023
4e4ee30
Fix test descriptions
ElenaStoeva Sep 8, 2023
6bfe3da
Validate allowlist only in development mode
ElenaStoeva Sep 11, 2023
ba8ffec
Merge branch 'main' into advanced_settings/allowlist_for_serverless
ElenaStoeva Sep 11, 2023
efdc13a
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Sep 11, 2023
a272d86
Refactor isDev check
ElenaStoeva Sep 11, 2023
3dfbdb9
Disable Advanced settings app in serverless and skip functional tests
ElenaStoeva Sep 11, 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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ x-pack/plugins/serverless @elastic/appex-sharedux
x-pack/plugins/serverless_observability @elastic/appex-sharedux @elastic/apm-ui
packages/serverless/project_switcher @elastic/appex-sharedux
x-pack/plugins/serverless_search @elastic/enterprise-search-frontend
packages/serverless/settings @elastic/appex-sharedux @elastic/platform-deployment-management
packages/serverless/storybook/config @elastic/appex-sharedux
packages/serverless/types @elastic/appex-sharedux
test/plugin_functional/plugins/session_notifications @elastic/kibana-core
Expand Down
2 changes: 1 addition & 1 deletion config/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ management.deeplinks.navLinkStatus: visible
xpack.canvas.enabled: false
xpack.cloud_integrations.data_migration.enabled: false
data.search.sessions.enabled: false
advanced_settings.enabled: false
advanced_settings.enabled: true
Comment thread
ElenaStoeva marked this conversation as resolved.
Outdated

# Disable UI of security management plugins
xpack.security.ui.userManagementEnabled: false
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@
"@kbn/serverless-observability": "link:x-pack/plugins/serverless_observability",
"@kbn/serverless-project-switcher": "link:packages/serverless/project_switcher",
"@kbn/serverless-search": "link:x-pack/plugins/serverless_search",
"@kbn/serverless-settings": "link:packages/serverless/settings",
"@kbn/serverless-types": "link:packages/serverless/types",
"@kbn/session-notifications-plugin": "link:test/plugin_functional/plugins/session_notifications",
"@kbn/session-view-plugin": "link:x-pack/plugins/session_view",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export function createCoreSetupMock({
const uiSettingsMock = {
register: uiSettingsServiceMock.createSetupContract().register,
registerGlobal: uiSettingsServiceMock.createSetupContract().registerGlobal,
setAllowlist: uiSettingsServiceMock.createSetupContract().setAllowlist,
};

const mock: CoreSetupMockType = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ export function createPluginSetupContext<TPlugin, TPluginDependencies>(
uiSettings: {
register: deps.uiSettings.register,
registerGlobal: deps.uiSettings.registerGlobal,
setAllowlist: deps.uiSettings.setAllowlist,
},
userSettings: {
setUserProfileSettings: deps.userSettings.setUserProfileSettings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ You can use \`IUiSettingsClient.get("${key}", defaultValue)\`, which will just r
return this.isDeclared(key) && Boolean(this.cache[key].isOverridden);
}

isStrictReadonly(key: string) {
return this.isDeclared(key) && Boolean(this.cache[key].readonly === 'strict');
}

getUpdate$() {
return this.update$.asObservable();
}
Expand All @@ -130,6 +134,9 @@ You can use \`IUiSettingsClient.get("${key}", defaultValue)\`, which will just r
`Unable to update "${key}" because its value is overridden by the Kibana server`
);
}
if (this.isStrictReadonly(key)) {
throw new Error(`Unable to update "${key}" because this setting is not in the allowlist.`);
}
}

protected abstract update(key: string, newVal: any): Promise<boolean>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ export interface UiSettingsParams<T = unknown> {
optionLabels?: Record<string, string>;
/** a flag indicating whether new value applying requires page reloading */
requiresPageReload?: boolean;
/** a flag indicating that value cannot be changed */
readonly?: boolean;
/**
* a flag indicating that value cannot be changed
* 'strict' indicates that the value cannot be changed through API and is not displayed in the UI
* 'ui' indicates that the value is just not displayed in the UI
* */
readonly?: 'strict' | 'ui';
Comment thread
ElenaStoeva marked this conversation as resolved.
Outdated
/**
* a flag indicating that value might contain user sensitive data.
* used by telemetry to mask the value of the setting when sent.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { UiSettingsParams } from '@kbn/core-ui-settings-common';
export const getMiscUiSettings = (): Record<string, UiSettingsParams> => {
return {
buildNum: {
readonly: true,
readonly: 'ui',
schema: schema.maybe(schema.number()),
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const getThemeSettings = (
defaultMessage: 'Theme version',
}),
value: 'v8' as ThemeVersion,
readonly: true,
readonly: 'ui',
schema: schema.literal('v8'),
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class UiSettingsService
private readonly uiSettingsDefaults = new Map<string, UiSettingsParams>();
private readonly uiSettingsGlobalDefaults = new Map<string, UiSettingsParams>();
private overrides: Record<string, any> = {};
private allowlist: string[] | null = null;

constructor(private readonly coreContext: CoreContext) {
this.log = coreContext.logger.get('ui-settings-service');
Expand Down Expand Up @@ -94,10 +95,14 @@ export class UiSettingsService
return {
register: this.register,
registerGlobal: this.registerGlobal,
setAllowlist: this.setAllowlist,
Comment thread
ElenaStoeva marked this conversation as resolved.
};
}

public async start(): Promise<InternalUiSettingsServiceStart> {
if (this.allowlist) {
this.applyAllowlist(this.allowlist);
}
this.validatesDefinitions();
this.validatesOverrides();

Expand Down Expand Up @@ -148,6 +153,27 @@ export class UiSettingsService
});
};

private setAllowlist = (keys: string[]) => {
if (!this.allowlist) {
this.allowlist = keys;
} else {
this.allowlist = this.allowlist.concat(keys);
}
};

private applyAllowlist(keys: string[]) {
for (const [key, definition] of this.uiSettingsDefaults) {
Comment thread
ElenaStoeva marked this conversation as resolved.
Outdated
if (!keys.includes(key)) {
definition.readonly = 'strict';
}
}
for (const [key, definition] of this.uiSettingsGlobalDefaults) {
if (!keys.includes(key)) {
definition.readonly = 'strict';
}
}
}

private validatesDefinitions() {
for (const [key, definition] of this.uiSettingsDefaults) {
if (!definition.schema) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const createSetupMock = () => {
const mocked: jest.Mocked<InternalUiSettingsServiceSetup> = {
register: jest.fn(),
registerGlobal: jest.fn(),
setAllowlist: jest.fn(),
};

return mocked;
Expand Down
13 changes: 13 additions & 0 deletions packages/core/ui-settings/core-ui-settings-server/src/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ export interface UiSettingsServiceSetup {
* ```
*/
registerGlobal(settings: Record<string, UiSettingsParams>): void;

/**
* Sets an allowlist of setting keys.
* @param keys
*
* @example
* ```ts
* setup(core: CoreSetup){
* core.uiSettings.setAllowlist(['csv:quoteValues', 'dateFormat:dow']);
* }
* ```
*/
setAllowlist(keys: string[]): void;
}

/** @public */
Expand Down
10 changes: 10 additions & 0 deletions packages/serverless/settings/README.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
id: serverless/packages/settings
slug: /serverless/packages/settings
title: Serverless Advanced Settings
description: A package of common settings for Serverless projects.
tags: ['serverless', 'package']
date: 2023-08-24
---

This package contains common settings for Serverless projects.
Comment thread
ElenaStoeva marked this conversation as resolved.
Outdated
62 changes: 62 additions & 0 deletions packages/serverless/settings/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

const GENERAL_SETTINGS = [
'csv:quoteValues',
'dateFormat:dow',
'dateFormat:scaled',
'dateFormat:tz',
'dateNanosFormat',
'defaultIndex',
'filters:pinnedByDefault',
'format:bytes:defaultPattern',
'format:currency:defaultPattern',
'format:number:defaultLocale',
'format:number:defaultPattern',
'format:percent:defaultPattern',
'metaFields',
'state:storeInSessionStorage',
'timepicker:quickRanges',
'timepicker:timeDefaults',
];

const PRESENTATION_LABS_SETTINGS = ['labs:dashboard:deferBelowFold'];

const ACCESSIBILITY_SETTINGS = ['accessibility:disableAnimations'];

const AUTOCOMPLETE_SETTINGS = ['autocomplete:valueSuggestionMethod'];

const BANNER_SETTINGS = [
'banners:placement',
'banners:textContent',
'banners:textColor',
'banners:backgroundColor',
];

const DISCOVER_SETTINGS = ['defaultColumns'];

const NOTIFICATION_SETTINGS = [
'notifications:banner',
'notifications:lifetime:banner',
'notifications:lifetime:error',
'notifications:lifetime:info',
'notifications:lifetime:warning',
];

const SEARCH_SETTINGS = ['courier:ignoreFilterIfFieldNotInIndex', 'search:timeout'];

export const ALL_ALLOWLIST_SETTINGS = [
...GENERAL_SETTINGS,
...PRESENTATION_LABS_SETTINGS,
...ACCESSIBILITY_SETTINGS,
...AUTOCOMPLETE_SETTINGS,
...BANNER_SETTINGS,
...DISCOVER_SETTINGS,
...NOTIFICATION_SETTINGS,
...SEARCH_SETTINGS,
];
5 changes: 5 additions & 0 deletions packages/serverless/settings/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/serverless-settings",
"owner": "@elastic/appex-sharedux @elastic/platform-deployment-management"
}
6 changes: 6 additions & 0 deletions packages/serverless/settings/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@kbn/serverless-settings",
"private": true,
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0"
}
17 changes: 17 additions & 0 deletions packages/serverless/settings/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node"
]
},
"include": [
"**/*.ts",
],
"exclude": [
"target/**/*"
],
"kbn_references": []
}
2 changes: 2 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,8 @@
"@kbn/serverless-project-switcher/*": ["packages/serverless/project_switcher/*"],
"@kbn/serverless-search": ["x-pack/plugins/serverless_search"],
"@kbn/serverless-search/*": ["x-pack/plugins/serverless_search/*"],
"@kbn/serverless-settings": ["packages/serverless/settings"],
"@kbn/serverless-settings/*": ["packages/serverless/settings/*"],
"@kbn/serverless-storybook-config": ["packages/serverless/storybook/config"],
"@kbn/serverless-storybook-config/*": ["packages/serverless/storybook/config/*"],
"@kbn/serverless-types": ["packages/serverless/types"],
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/serverless/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { schema, TypeOf } from '@kbn/config-schema';
import { getConfigDirectory } from '@kbn/utils';
import { ProjectType } from '@kbn/serverless-types';

import { ALL_ALLOWLIST_SETTINGS } from '@kbn/serverless-settings';
import { ServerlessPluginSetup, ServerlessPluginStart } from './types';
import { ServerlessConfig } from './config';
import { API_SWITCH_PROJECT } from '../common';
Expand Down Expand Up @@ -75,6 +76,8 @@ export class ServerlessPlugin implements Plugin<ServerlessPluginSetup, Serverles
);
}

core.uiSettings.setAllowlist(ALL_ALLOWLIST_SETTINGS);
Comment thread
ElenaStoeva marked this conversation as resolved.
Outdated

return {};
}

Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/serverless/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
"@kbn/core-chrome-browser-internal",
"@kbn/i18n-react",
"@kbn/cloud-plugin",
"@kbn/serverless-settings",
]
}
12 changes: 8 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4748,6 +4748,10 @@
version "0.0.0"
uid ""

"@kbn/lens-embeddable-utils@link:packages/kbn-lens-embeddable-utils":
version "0.0.0"
uid ""

"@kbn/lens-plugin@link:x-pack/plugins/lens":
version "0.0.0"
uid ""
Expand Down Expand Up @@ -5412,6 +5416,10 @@
version "0.0.0"
uid ""

"@kbn/serverless-settings@link:packages/serverless/settings":
version "0.0.0"
uid ""

"@kbn/serverless-storybook-config@link:packages/serverless/storybook/config":
version "0.0.0"
uid ""
Expand Down Expand Up @@ -6020,10 +6028,6 @@
version "0.0.0"
uid ""

"@kbn/lens-embeddable-utils@link:packages/kbn-lens-embeddable-utils":
version "0.0.0"
uid ""

"@kbn/visualizations-plugin@link:src/plugins/visualizations":
version "0.0.0"
uid ""
Expand Down