Skip to content

Commit

Permalink
Merge branch 'main' of github.com:elastic/kibana into removes-version…
Browse files Browse the repository at this point in the history
…-bump
  • Loading branch information
spong committed Mar 23, 2023
2 parents a38bc4b + 58b3636 commit 5648323
Show file tree
Hide file tree
Showing 38 changed files with 841 additions and 698 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ export async function mountManagementSection(
params.setBreadcrumbs(crumb);
const [{ settings, notifications, docLinks, application, chrome }] = await getStartServices();

const canSave = application.capabilities.advancedSettings.save as boolean;
const { advancedSettings, globalSettings } = application.capabilities;
const canSaveAdvancedSettings = advancedSettings.save as boolean;
const canSaveGlobalSettings = globalSettings.save as boolean;
const canShowGlobalSettings = globalSettings.show as boolean;
const trackUiMetric = usageCollection?.reportUiCounter.bind(usageCollection, 'advanced_settings');

if (!canSave) {
if (!canSaveAdvancedSettings || (!canSaveGlobalSettings && canShowGlobalSettings)) {
chrome.setBadge(readOnlyBadge);
}

Expand All @@ -82,7 +84,8 @@ export async function mountManagementSection(
<Route path="/">
<Settings
history={params.history}
enableSaving={canSave}
enableSaving={{ namespace: canSaveAdvancedSettings, global: canSaveGlobalSettings }}
enableShowing={{ namespace: true, global: canShowGlobalSettings }}
toasts={notifications.toasts}
docLinks={docLinks.links}
settingsService={settings}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from '@kbn/core/public/mocks';
import { ComponentRegistry } from '../component_registry';
import { Search } from './components/search';
import { EuiTab } from '@elastic/eui';

jest.mock('./components/field', () => ({
Field: () => {
Expand Down Expand Up @@ -251,7 +252,8 @@ describe('Settings', () => {
const component = mountWithI18nProvider(
<Settings
history={mockHistory}
enableSaving={true}
enableSaving={{ global: true, namespace: true }}
enableShowing={{ global: true, namespace: true }}
toasts={notificationServiceMock.createStartContract().toasts}
docLinks={docLinksServiceMock.createStartContract().links}
settingsService={mockConfig().core.settings}
Expand All @@ -269,7 +271,7 @@ describe('Settings', () => {
).toHaveLength(1);
});

it('should should not render a custom setting', async () => {
it('should not render a custom setting', async () => {
// The manual mock for the uiSettings client returns false for isConfig, override that
const uiSettings = mockConfig().core.settings.client;
uiSettings.isCustom = (key) => true;
Expand All @@ -279,7 +281,8 @@ describe('Settings', () => {
const component = mountWithI18nProvider(
<Settings
history={mockHistory}
enableSaving={true}
enableSaving={{ global: true, namespace: true }}
enableShowing={{ global: true, namespace: true }}
toasts={notificationServiceMock.createStartContract().toasts}
docLinks={docLinksServiceMock.createStartContract().links}
settingsService={mockConfig().core.settings}
Expand All @@ -304,7 +307,8 @@ describe('Settings', () => {
const component = mountWithI18nProvider(
<Settings
history={mockHistory}
enableSaving={false}
enableSaving={{ global: true, namespace: false }}
enableShowing={{ global: true, namespace: true }}
toasts={notificationServiceMock.createStartContract().toasts}
docLinks={docLinksServiceMock.createStartContract().links}
settingsService={mockConfig().core.settings}
Expand Down Expand Up @@ -332,7 +336,8 @@ describe('Settings', () => {
const component = mountWithI18nProvider(
<Settings
history={mockHistory}
enableSaving={false}
enableSaving={{ global: false, namespace: false }}
enableShowing={{ global: true, namespace: true }}
toasts={toasts}
docLinks={docLinksServiceMock.createStartContract().links}
settingsService={mockConfig().core.settings}
Expand All @@ -344,4 +349,26 @@ describe('Settings', () => {
expect(toasts.addWarning).toHaveBeenCalledTimes(1);
expect(component.find(Search).prop('query').text).toEqual('');
});

it('does not render global settings if show is set to false', async () => {
const badQuery = 'category:(accessibility))';
mockQuery(badQuery);
const { toasts } = notificationServiceMock.createStartContract();

const component = mountWithI18nProvider(
<Settings
history={mockHistory}
enableSaving={{ global: false, namespace: false }}
enableShowing={{ global: false, namespace: true }}
toasts={toasts}
docLinks={docLinksServiceMock.createStartContract().links}
settingsService={mockConfig().core.settings}
componentRegistry={new ComponentRegistry().start}
theme={themeServiceMock.createStartContract().theme$}
/>
);

expect(component.find(EuiTab).length).toEqual(1);
expect(component.find(EuiTab).at(0).text()).toEqual('Space Settings');
});
});
15 changes: 10 additions & 5 deletions src/plugins/advanced_settings/public/management_app/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export type GroupedSettings = Record<string, FieldSetting[]>;

interface Props {
history: ScopedHistory;
enableSaving: boolean;
enableSaving: Record<UiSettingsScope, boolean>;
enableShowing: Record<UiSettingsScope, boolean>;
settingsService: SettingsStart;
docLinks: DocLinksStart['links'];
toasts: ToastsStart;
Expand All @@ -58,7 +59,8 @@ const SPACE_SETTINGS_ID = 'space-settings';
const GLOBAL_SETTINGS_ID = 'global-settings';

export const Settings = (props: Props) => {
const { componentRegistry, history, settingsService, ...rest } = props;
const { componentRegistry, history, settingsService, enableSaving, enableShowing, ...rest } =
props;
const uiSettings = settingsService.client;
const globalUiSettings = settingsService.globalClient;

Expand Down Expand Up @@ -210,6 +212,7 @@ export const Settings = (props: Props) => {
callOutSubtitle={callOutSubtitle(scope)}
settingsService={settingsService}
uiSettingsClient={getClientForScope(scope)}
enableSaving={enableSaving[scope]}
{...rest}
/>
);
Expand All @@ -227,7 +230,9 @@ export const Settings = (props: Props) => {
) : null,
content: renderAdvancedSettings('namespace'),
},
{
];
if (enableShowing.global) {
tabs.push({
id: GLOBAL_SETTINGS_ID,
name: i18nTexts.globalTabTitle,
append:
Expand All @@ -238,8 +243,8 @@ export const Settings = (props: Props) => {
</EuiNotificationBadge>
) : null,
content: renderAdvancedSettings('global'),
},
];
});
}

const [selectedTabId, setSelectedTabId] = useState(SPACE_SETTINGS_ID);

Expand Down
11 changes: 9 additions & 2 deletions x-pack/plugins/alerting/server/rules_client/methods/bulk_edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
getBulkSnoozeAttributes,
getBulkUnsnoozeAttributes,
verifySnoozeScheduleLimit,
injectReferencesIntoParams,
} from '../common';
import {
alertingAuthorizationFilterOpts,
Expand Down Expand Up @@ -435,10 +436,16 @@ async function updateRuleAttributesAndParamsInMemory<Params extends RuleTypePara

validateScheduleInterval(context, attributes.schedule.interval, ruleType.id, rule.id);

const params = injectReferencesIntoParams<Params, RuleTypeParams>(
rule.id,
ruleType,
attributes.params,
rule.references || []
);
const { modifiedParams: ruleParams, isParamsUpdateSkipped } = paramsModifier
? await paramsModifier(attributes.params as Params)
? await paramsModifier(params)
: {
modifiedParams: attributes.params as Params,
modifiedParams: params,
isParamsUpdateSkipped: true,
};

Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/cloud_security_posture/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export const CSP_LATEST_VULNERABILITIES_INGEST_TIMESTAMP_PIPELINE =
export const RULE_PASSED = `passed`;
export const RULE_FAILED = `failed`;

export const POSTURE_TYPE_ALL = 'all';

// A mapping of in-development features to their status. These features should be hidden from users but can be easily
// activated via a simple code change in a single location.
export const INTERNAL_FEATURE_FLAGS = {
Expand Down
29 changes: 13 additions & 16 deletions x-pack/plugins/cloud_security_posture/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { SUPPORTED_CLOUDBEAT_INPUTS, SUPPORTED_POLICY_TEMPLATES } from './consta
import { CspRuleTemplateMetadata } from './schemas/csp_rule_template_metadata';

export type Evaluation = 'passed' | 'failed' | 'NA';

export type PostureTypes = 'cspm' | 'kspm' | 'all';
/** number between 1-100 */
export type Score = number;

Expand Down Expand Up @@ -59,7 +61,8 @@ export type CspStatusCode =
| 'unprivileged' // user lacks privileges for the latest findings index
| 'index-timeout' // index timeout was surpassed since installation
| 'not-deployed' // no healthy agents were deployed
| 'not-installed'; // number of installed csp integrations is 0;
| 'not-installed' // number of installed csp integrations is 0;
| 'waiting_for_results'; // have healthy agents but no findings at all, assumes data is being indexed for the 1st time

export type IndexStatus =
| 'not-empty' // Index contains documents
Expand All @@ -71,27 +74,21 @@ export interface IndexDetails {
status: IndexStatus;
}

interface BaseCspSetupStatus {
indicesDetails: IndexDetails[];
latestPackageVersion: string;
interface BaseCspSetupBothPolicy {
status: CspStatusCode;
installedPackagePolicies: number;
healthyAgents: number;
isPluginInitialized: boolean;
installedPolicyTemplates: CloudSecurityPolicyTemplate[];
}

interface CspSetupNotInstalledStatus extends BaseCspSetupStatus {
status: Extract<CspStatusCode, 'not-installed'>;
}

interface CspSetupInstalledStatus extends BaseCspSetupStatus {
status: Exclude<CspStatusCode, 'not-installed'>;
// if installedPackageVersion == undefined but status != 'not-installed' it means the integration was installed in the past and findings were found
// status can be `indexed` but return with undefined package information in this case
installedPackageVersion: string | undefined;
export interface BaseCspSetupStatus {
indicesDetails: IndexDetails[];
latestPackageVersion: string;
cspm: BaseCspSetupBothPolicy;
kspm: BaseCspSetupBothPolicy;
isPluginInitialized: boolean;
}

export type CspSetupStatus = CspSetupInstalledStatus | CspSetupNotInstalledStatus;
export type CspSetupStatus = BaseCspSetupStatus;

export type AgentPolicyStatus = Pick<AgentPolicy, 'id' | 'name'> & { agents: number };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { useQuery, type UseQueryOptions } from '@tanstack/react-query';
import { useKibana } from '../hooks/use_kibana';
import { CspSetupStatus } from '../../../common/types';
import { type CspSetupStatus } from '../../../common/types';
import { STATUS_ROUTE_PATH } from '../../../common/constants';

const getCspSetupStatusQueryKey = 'csp_status_key';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,14 @@ describe('<CloudPosturePage />', () => {
(useCspSetupStatusApi as jest.Mock).mockImplementation(() =>
createReactQueryResponse({
status: 'success',
data: { status: 'not-installed' },
data: {
kspm: { status: 'not-installed' },
cspm: { status: 'not-installed' },
indicesDetails: [
{ index: 'logs-cloud_security_posture.findings_latest-default', status: 'empty' },
{ index: 'logs-cloud_security_posture.findings-default*', status: 'empty' },
],
},
})
);
(useCspIntegrationLink as jest.Mock).mockImplementation(() => chance.url());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,12 @@ export const CloudPosturePage = <TData, TError>({
return defaultLoadingRenderer();
}

if (getSetupStatus.data.status === 'not-installed') {
/* Checks if its a completely new user which means no integration has been installed and no latest findings default index has been found */
if (
getSetupStatus.data?.kspm?.status === 'not-installed' &&
getSetupStatus.data?.cspm?.status === 'not-installed' &&
getSetupStatus.data?.indicesDetails[0].status === 'empty'
) {
return packageNotInstalledRenderer({ kspmIntegrationLink, cspmIntegrationLink });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ import { useCISIntegrationPoliciesLink } from '../common/navigation/use_navigate
import { NO_FINDINGS_STATUS_TEST_SUBJ } from './test_subjects';
import { CloudPosturePage } from './cloud_posture_page';
import { useCspSetupStatusApi } from '../common/api/use_setup_status_api';
import type { IndexDetails } from '../../common/types';
import type { CloudSecurityPolicyTemplate, IndexDetails } from '../../common/types';

const REFETCH_INTERVAL_MS = 20000;

interface PostureTypes {
posturetype: CloudSecurityPolicyTemplate;
}

const NotDeployed = () => {
// using an existing hook to get agent id and package policy id
const benchmarks = useCspBenchmarkIntegrations({
Expand Down Expand Up @@ -176,19 +180,20 @@ const Unprivileged = ({ unprivilegedIndices }: { unprivilegedIndices: string[] }
* This component will return the render states based on cloud posture setup status API
* since 'not-installed' is being checked globally by CloudPosturePage and 'indexed' is the pass condition, those states won't be handled here
* */
export const NoFindingsStates = () => {
export const NoFindingsStates = (posturetype?: PostureTypes) => {
const getSetupStatus = useCspSetupStatusApi({
options: { refetchInterval: REFETCH_INTERVAL_MS },
});
const status = getSetupStatus.data?.status;
const statusKspm = getSetupStatus.data?.kspm?.status;
const statusCspm = getSetupStatus.data?.cspm?.status;
const indicesStatus = getSetupStatus.data?.indicesDetails;
const status = posturetype?.posturetype === 'cspm' ? statusCspm : statusKspm;
const unprivilegedIndices =
indicesStatus &&
indicesStatus
.filter((idxDetails) => idxDetails.status === 'unprivileged')
.map((idxDetails: IndexDetails) => idxDetails.index)
.sort((a, b) => a.localeCompare(b));

const render = () => {
if (status === 'not-deployed') return <NotDeployed />; // integration installed, but no agents added
if (status === 'indexing') return <Indexing />; // agent added, index timeout hasn't passed since installation
Expand Down
Loading

0 comments on commit 5648323

Please sign in to comment.