Skip to content

Commit

Permalink
fix(kibana-security-health-check): improve "Dashboard" tracker view
Browse files Browse the repository at this point in the history
  • Loading branch information
azasypkin committed Dec 12, 2023
1 parent 2295472 commit 76edf84
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
30 changes: 24 additions & 6 deletions kibana-security-health-check/src/dashboard.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { KibanaMetadata } from './index';

interface Meta {
lastRevisionId: string;
}
Expand Down Expand Up @@ -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.
Expand Down
23 changes: 23 additions & 0 deletions kibana-security-health-check/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};
}

0 comments on commit 76edf84

Please sign in to comment.