Skip to content

Commit 7b4b95f

Browse files
authored
Merge pull request #10 from sysdiglabs/dev-custom-backlink
Add custom backlink settings and multiple values for Runtime VM annotations [1.2.0]
2 parents 113ab7a + c343758 commit 7b4b95f

File tree

10 files changed

+70
-33
lines changed

10 files changed

+70
-33
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ proxy:
8383

8484
+ sysdig:
8585
+ endpoint: ${SYSDIG_SECURE_ENDPOINT}
86+
+ backlink: https://... # Optional override base link for backlinks. Must end in '/'.
8687
```
8788

8889
- Set the environment variable `SYSDIG_SECURE_ENDPOINT` to your Sysdig Secure Endpoint.
8990
- Likewise, set `SYSDIG_SECURE_TOKEN` to your Sysdig Secure API Token.
9091

91-
9292
## How to annotate services
9393

9494
All added annotations are available and documented in the [source file](./src/lib/annotations.ts).

config.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,11 @@ export interface Config {
2121
* @visibility frontend
2222
*/
2323
endpoint: string;
24+
25+
/**
26+
* Custom backlink to Sysdig Secure.
27+
* @visibility frontend
28+
*/
29+
backlink: string;
2430
};
2531
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sysdig/backstage-plugin-sysdig",
3-
"version": "1.1.1",
3+
"version": "1.2.0",
44
"main": "dist/index.esm.js",
55
"types": "dist/index.d.ts",
66
"license": "Apache-2.0",

src/components/SysdigPostureFetchComponent/SysdigPostureFetchComponent.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import {
5959

6060
API_PROXY_BASE_PATH,
6161
API_INVENTORY,
62-
BACKLINK_INVENTORY
62+
getBacklink
6363
} from '../../lib'
6464

6565

@@ -212,8 +212,10 @@ export const DenseTable = ({ postureScans, title }: DenseTableProps) => {
212212
export const SysdigPostureFetchComponent = () => {
213213
const { entity } = useEntity();
214214
const backendUrl = useApi(configApiRef).getString('backend.baseUrl');
215-
var backlink = useApi(configApiRef).getString('sysdig.endpoint') + BACKLINK_INVENTORY;
215+
let endpoint: string | undefined = useApi(configApiRef).getOptionalString("sysdig.endpoint");
216+
let backlink_config: string | undefined = useApi(configApiRef).getOptionalString("sysdig.backlink");
216217

218+
var backlink = getBacklink(endpoint, backlink_config, "inventory");
217219
const annotations = entity.metadata.annotations;
218220

219221
let uri = backendUrl + API_PROXY_BASE_PATH + API_INVENTORY;

src/components/SysdigVMPipelineFetchComponent/SysdigVMPipelineFetchComponent.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131

3232
API_PROXY_BASE_PATH,
3333
API_VULN_PIPELINE,
34-
BACKLINK_VULN_PIPELINE
34+
getBacklink
3535
} from '../../lib'
3636

3737
type PipelineScan = {
@@ -114,7 +114,10 @@ export const DenseTable = ({ pipelineScans, title }: DenseTableProps) => {
114114
export const SysdigVMPipelineFetchComponent = () => {
115115
const { entity } = useEntity();
116116
const backendUrl = useApi(configApiRef).getString('backend.baseUrl');
117-
var backlink = useApi(configApiRef).getString('sysdig.endpoint') + BACKLINK_VULN_PIPELINE;
117+
let endpoint: string | undefined = useApi(configApiRef).getOptionalString("sysdig.endpoint");
118+
let backlink_config: string | undefined = useApi(configApiRef).getOptionalString("sysdig.backlink");
119+
120+
var backlink = getBacklink(endpoint, backlink_config, "vm-pipeline");
118121

119122
let uri = backendUrl + API_PROXY_BASE_PATH + API_VULN_PIPELINE;
120123
let filter = '?filter=';

src/components/SysdigVMRegistryFetchComponent/SysdigVMRegistryFetchComponent.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131

3232
API_PROXY_BASE_PATH,
3333
API_VULN_REGISTRY,
34-
BACKLINK_VULN_REGISTRY
34+
getBacklink
3535
} from '../../lib'
3636

3737

@@ -103,7 +103,10 @@ export const DenseTable = ({ registryScans, title }: DenseTableProps) => {
103103
export const SysdigVMRegistryFetchComponent = () => {
104104
const { entity } = useEntity();
105105
const backendUrl = useApi(configApiRef).getString('backend.baseUrl');
106-
var backlink = useApi(configApiRef).getString('sysdig.endpoint') + BACKLINK_VULN_REGISTRY;
106+
let endpoint: string | undefined = useApi(configApiRef).getOptionalString("sysdig.endpoint");
107+
let backlink_config: string | undefined = useApi(configApiRef).getOptionalString("sysdig.backlink");
108+
109+
var backlink = getBacklink(endpoint, backlink_config, "vm-registry");
107110

108111
let uri = backendUrl + API_PROXY_BASE_PATH + API_VULN_REGISTRY;
109112
let filter = '?filter=';

src/components/SysdigVMRuntimeFetchComponent/SysdigVMRuntimeFetchComponent.tsx

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import {
3737

3838
API_PROXY_BASE_PATH,
3939
API_VULN_RUNTIME,
40-
BACKLINK_VULN_RUNTIME
40+
getBacklink
4141
} from '../../lib'
4242

4343

@@ -154,11 +154,14 @@ export const DenseTable = ({ runtimeScans, title }: DenseTableProps) => {
154154
export const SysdigVMRuntimeFetchComponent = () => {
155155
const { entity } = useEntity();
156156
const backendUrl = useApi(configApiRef).getString('backend.baseUrl');
157-
var backlink = useApi(configApiRef).getString('sysdig.endpoint') + BACKLINK_VULN_RUNTIME;
157+
let endpoint: string | undefined = useApi(configApiRef).getOptionalString("sysdig.endpoint");
158+
let backlink_config: string | undefined = useApi(configApiRef).getOptionalString("sysdig.backlink");
159+
160+
var backlink = getBacklink(endpoint, backlink_config, "vm-runtime");
158161

159162
let uri = backendUrl + API_PROXY_BASE_PATH + API_VULN_RUNTIME;
160163
let filter = '?filter=';
161-
var name;
164+
var names;
162165

163166
const annotations = entity.metadata.annotations;
164167
if (annotations) {
@@ -170,28 +173,28 @@ export const SysdigVMRuntimeFetchComponent = () => {
170173
var filters = []
171174

172175
if (SYSDIG_CLUSTER_NAME_ANNOTATION in annotations) {
173-
name = annotations[SYSDIG_CLUSTER_NAME_ANNOTATION]
174-
filters.push('kubernetes.cluster.name="' + name + '"');
176+
names = annotations[SYSDIG_CLUSTER_NAME_ANNOTATION].split(',').map(w => `"${w.trim()}"`).join(', ');
177+
filters.push(`kubernetes.cluster.name in (${names})`);
175178
}
176179

177180
if (SYSDIG_NAMESPACE_ANNOTATION in annotations) {
178-
name = annotations[SYSDIG_NAMESPACE_ANNOTATION]
179-
filters.push('kubernetes.namespace.name="' + name + '"');
181+
names = annotations[SYSDIG_NAMESPACE_ANNOTATION].split(',').map(w => `"${w.trim()}"`).join(', ');
182+
filters.push(`kubernetes.namespace.name in (${names})`);
180183
}
181184

182185
if (SYSDIG_WORKLOAD_ANNOTATION in annotations) {
183-
name = annotations[SYSDIG_WORKLOAD_ANNOTATION]
184-
filters.push('kubernetes.workload.name="' + name + '"');
186+
names = annotations[SYSDIG_WORKLOAD_ANNOTATION].split(',').map(w => `"${w.trim()}"`).join(', ');
187+
filters.push(`kubernetes.workload.name in (${names})`);
185188
}
186189

187190
if (SYSDIG_WORKLOAD_TYPE_ANNOTATION in annotations) {
188-
name = annotations[SYSDIG_WORKLOAD_TYPE_ANNOTATION]
189-
filters.push('kubernetes.workload.type="' + name + '"');
191+
names = annotations[SYSDIG_WORKLOAD_TYPE_ANNOTATION].split(',').map(w => `"${w.trim()}"`).join(', ');
192+
filters.push(`kubernetes.workload.type in (${names})`);
190193
}
191194

192195
if (SYSDIG_CONTAINER_ANNOTATION in annotations) {
193-
name = annotations[SYSDIG_CONTAINER_ANNOTATION]
194-
filters.push('kubernetes.pod.container.name="' + name + '"');
196+
names = annotations[SYSDIG_CONTAINER_ANNOTATION].split(',').map(w => `"${w.trim()}"`).join(', ');
197+
filters.push(`kubernetes.pod.container.name in (${names})`);
195198
}
196199

197200
if (filters.length == 0) {

src/lib/annotations.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ export const SYSDIG_SOURCE_TYPE_ANNOTATION = "sysdigcloud.com/source-type";
8383
* Runtime
8484
*/
8585

86+
// Runtime annotation values also support comma separated values. Example "prod-gke,prod-eks"
87+
8688
// The cluster that will be included in the results. Example: "prod-gke"
8789
export const SYSDIG_CLUSTER_NAME_ANNOTATION = "sysdigcloud.com/kubernetes-cluster-name";
8890

src/lib/endpoints.ts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,36 @@ export const API_INVENTORY = "/api/cspm/v1/inventory/resources";
2222
/*
2323
* Backlink paths to product
2424
*/
25+
let DEFAULT_BACKLINK_BASE: string = "https://secure.sysdig.com/"
2526

26-
// Backlink path to Vulnerability Management at Runtime
27-
export const BACKLINK_VULN_RUNTIME = "#/vulnerabilities/runtime/";
27+
const BACKLINKS: Record<string, string> = {
28+
// Backlink path to Vulnerability Management at Runtime
29+
"vm-runtime": "#/vulnerabilities/runtime/",
2830

29-
// Backlink path to Vulnerability Management at Registry
30-
export const BACKLINK_VULN_REGISTRY = "#/vulnerabilities/registry/";
31+
// Backlink path to Vulnerability Management at Registry
32+
"vm-registry": "#/vulnerabilities/registry/",
3133

32-
// Backlink path to Vulnerability Management at Pipeline
33-
export const BACKLINK_VULN_PIPELINE = "#/vulnerabilities/pipeline/";
34+
// Backlink path to Vulnerability Management at Pipeline
35+
"vm-pipeline": "#/vulnerabilities/pipeline/",
3436

35-
// Backlink path to Inventory
36-
export const BACKLINK_INVENTORY = "#/inventory";
37+
// Backlink path to Inventory
38+
"inventory": "#/inventory"
39+
}
40+
41+
export function getBacklink(endpoint: string | undefined, backlink: string | undefined, section: string) : string {
42+
var backlink_base : string = DEFAULT_BACKLINK_BASE;
43+
44+
if (backlink != undefined) {
45+
backlink_base = backlink
46+
} else if (endpoint != undefined) {
47+
backlink_base = endpoint
48+
}
49+
50+
let backlink_section : string = BACKLINKS[section];
51+
52+
if (backlink_section === undefined) {
53+
return "";
54+
}
55+
56+
return backlink_base + backlink_section;
57+
}

src/lib/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,5 @@ export {
5353
API_VULN_REGISTRY,
5454
API_VULN_PIPELINE,
5555
API_INVENTORY,
56-
BACKLINK_VULN_RUNTIME,
57-
BACKLINK_VULN_REGISTRY,
58-
BACKLINK_VULN_PIPELINE,
59-
BACKLINK_INVENTORY
56+
getBacklink
6057
} from './endpoints'

0 commit comments

Comments
 (0)