From 76edf84bcbe133a94edc50d4ee9bc8708e2b9b51 Mon Sep 17 00:00:00 2001 From: Aleh Zasypkin Date: Tue, 12 Dec 2023 23:35:46 +0100 Subject: [PATCH] fix(kibana-security-health-check): improve "Dashboard" tracker view --- kibana-security-health-check/src/dashboard.ts | 30 +++++++++++++++---- kibana-security-health-check/src/index.ts | 23 ++++++++++++++ 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/kibana-security-health-check/src/dashboard.ts b/kibana-security-health-check/src/dashboard.ts index c7509e8..c7eb148 100644 --- a/kibana-security-health-check/src/dashboard.ts +++ b/kibana-security-health-check/src/dashboard.ts @@ -1,3 +1,5 @@ +import type { KibanaMetadata } from './index'; + interface Meta { lastRevisionId: string; } @@ -31,21 +33,37 @@ export async function run(previousContent: string | undefined, params: Params): }) ).json()) as WebPageContentRevision[]; - const meta: Meta = { - lastRevisionId: revisions.length > 0 ? revisions[revisions.length - 1].id : '', - }; + if (revisions.length === 0) { + return prependMeta(`:red_circle: Data is not available`, { lastRevisionId: '' }); + } + const lastRevision = revisions[revisions.length - 1]; + const kibanaMetadata = JSON.parse(lastRevision.data) as KibanaMetadata; const state = ` # Project information -:construction: +||| +| ------ | ----------- | +| **Environment** | ${kibanaMetadata.env.mode.name} | +| **Branch** | ${kibanaMetadata.env.packageInfo.branch} | +| **Project ID / Cluster Name** | ${kibanaMetadata.clusterInfo?.cluster_name ?? '?'} | +| **Build Flavour** | ${kibanaMetadata.env.packageInfo.buildFlavor} | +| **Build Date** | ${kibanaMetadata.env.packageInfo.buildDate} | +| **Build Number** | ${kibanaMetadata.env.packageInfo.buildNum} | +| **Build Commit** | [${kibanaMetadata.env.packageInfo.buildSha.slice( + 6, + )}](https://github.com/elastic/kibana/commit/${kibanaMetadata.env.packageInfo.buildSha}) | +| **Version** | ${kibanaMetadata.env.packageInfo.version}| + # Security headers ## Content Security Policy Status: ${ - meta.lastRevisionId === previousMeta?.lastRevisionId || !previousMeta ? ':white_check_mark:' : ':red_circle:' + lastRevision.id === previousMeta?.lastRevisionId || !previousMeta ? ':white_check_mark:' : ':red_circle:' } [view policy](${location.origin}/ws/web_security__csp__policies?x-user-share-id=${params.targetCspShareId}) `; - return prependMeta(state, meta); + return prependMeta(state, { + lastRevisionId: lastRevision.id, + }); } // HACK: Prepend the meta to the markdown content as part of the link to not clutter the markdown. diff --git a/kibana-security-health-check/src/index.ts b/kibana-security-health-check/src/index.ts index d5ede19..085a445 100644 --- a/kibana-security-health-check/src/index.ts +++ b/kibana-security-health-check/src/index.ts @@ -17,3 +17,26 @@ export interface SecurityResponseHeaders { 'x-found-handling-cluster': string; 'x-frame-options': string; } + +export interface KibanaMetadata { + anonymousStatusPage: boolean; + clusterInfo: { + cluster_build_flavor: 'serverless'; + cluster_name: 'b5781f679cf342218a5fb77db34863d2'; + cluster_uuid: '8s9cUhNXR4Wa9oUu_czSPw'; + cluster_version: '8.11.0'; + }; + env: { + mode: { + name: string; + }; + packageInfo: { + branch: string; + buildDate: string; + buildFlavor: string; + buildNum: number; + buildSha: string; + version: string; + }; + }; +}