Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
133 commits
Select commit Hold shift + click to select a range
dd571a3
Add Stub For notification-webhook
nigthknight Mar 8, 2021
ef93e93
Add axios and jest
nigthknight Mar 8, 2021
213a341
Add Mock For Axios
nigthknight Mar 8, 2021
f7c2294
Add Failing Tests For Notification Hook
nigthknight Mar 8, 2021
af9d32a
Add Mustache
nigthknight Mar 8, 2021
fd7f8c1
Update Dependencies
nigthknight Mar 10, 2021
f8a558b
Add Lodash
nigthknight Mar 10, 2021
dd8fc61
Move Hook To TypeScript
nigthknight Mar 10, 2021
550a19e
Add NotifierFactory
nigthknight Mar 10, 2021
e33a01d
Change Import Format
nigthknight Mar 10, 2021
c44e0a6
Add Basic jest.config.js
nigthknight Mar 10, 2021
2b7fad9
Remove Unused Import From hook.ts
nigthknight Mar 10, 2021
6d0c2fd
Remove Unused Import
nigthknight Mar 10, 2021
f9e3546
Move into src directory
nigthknight Mar 10, 2021
8699f08
Change Dockerfile To Use TypeScript
nigthknight Mar 10, 2021
135f004
Remove Not Existing vars
nigthknight Mar 10, 2021
c69741a
Add Option to configure imagePullPolicy
nigthknight Mar 10, 2021
7b78fde
Cleanup handle function for Testing
nigthknight Mar 10, 2021
24e5561
Add Init() Method To Initialize The Notifier
nigthknight Mar 15, 2021
dab43bc
Add default Case Throwing Error
nigthknight Mar 15, 2021
532c407
Add Types for Mustache and Lodash
nigthknight Mar 15, 2021
2721dfb
Implement Basic Hook
nigthknight Mar 15, 2021
459aaba
Add Basic Tests for Slack Notifier
nigthknight Mar 15, 2021
13c7ce5
Remove unused Template Var From Factory
nigthknight Mar 15, 2021
826fd89
Add Option For Custom Templates
nigthknight Mar 15, 2021
d8394aa
Refactoring AbstractNotifier
nigthknight Mar 15, 2021
8053ac5
Update Test
nigthknight Mar 15, 2021
d2608fe
Update SlackNotifier Based on AbstractNotifier
nigthknight Mar 15, 2021
23f1219
Add `templates/slack` With A Basic Slack Template
nigthknight Mar 15, 2021
5eccba4
Change Signature for Interface Methods to Promise
nigthknight Mar 15, 2021
1946c15
Move Loading of Shipped Templates into Notifier
nigthknight Mar 15, 2021
0238c93
Refactoring
nigthknight Mar 15, 2021
c407cc3
Change Method Signature to Return Promise
nigthknight Mar 15, 2021
456bec3
Fix Mustache Import
nigthknight Mar 15, 2021
8c6e8f3
Rename `templateName` --> `templatType`
nigthknight Mar 15, 2021
4a1096b
Load All Templates From Same Directory
nigthknight Mar 17, 2021
56762cd
Move Template Rendering To AbstractNotifier
nigthknight Mar 17, 2021
3ccc71a
Remove Unused Methods
nigthknight Mar 17, 2021
73dd01a
Update NotificationChannel Model To Pass To Notifier
nigthknight Mar 17, 2021
e190a4a
Rename File For Consistency
nigthknight Mar 17, 2021
11a3ee3
Remove Unused Files And Directories
nigthknight Mar 17, 2021
724f8dd
Load NotificationChannel Into Notifiers
nigthknight Mar 17, 2021
ad411ed
Update Import
nigthknight Mar 17, 2021
eb00115
Add Types for Jest To enable VS Code To Make Suggestions
nigthknight Mar 17, 2021
e56bb16
Move Template Into Root Template Dir
nigthknight Mar 17, 2021
3c601a1
Load Template Before Rendering
nigthknight Mar 17, 2021
984a669
Update Tests
nigthknight Mar 17, 2021
0674229
Remove Unused Import
nigthknight Mar 17, 2021
57e0de3
Update Template
nigthknight Mar 17, 2021
79f2ba0
Add js-yaml and TS Types for js-yaml
nigthknight Mar 17, 2021
623b20c
Fix Syntax
nigthknight Mar 17, 2021
8d9e096
Switch To YAML Format
nigthknight Mar 17, 2021
232590f
Update Test
nigthknight Mar 17, 2021
4684fd0
Update Basic Template
nigthknight Mar 17, 2021
3adee04
Pass Scan Data Into Notifier
nigthknight Mar 17, 2021
e13fbae
Add kubernetes client to use Interface
nigthknight Mar 17, 2021
9b62ed2
Refactor Class To Interface
nigthknight Mar 17, 2021
6a10409
Add Helper Funtions To Render Template
nigthknight Mar 17, 2021
8be75bc
Enable Failing Tests
nigthknight Mar 17, 2021
10226d1
Rename Notification-Webhook -> Notification-Hook
nigthknight Mar 18, 2021
b9d11e3
Add Test To Verify That Minimal Template Is Send
nigthknight Mar 18, 2021
ff83661
Remove Test Cases That Do Not Test SlackNotifier
nigthknight Mar 18, 2021
315eed1
Improve Template "Power"
nigthknight Mar 18, 2021
2fdfee8
Log YAML Parse Error
nigthknight Mar 19, 2021
46aafac
Update Tests For MessageCard Template
nigthknight Mar 19, 2021
00bbb8f
Refactoring
nigthknight Mar 22, 2021
8f73b77
Update Matches Function
nigthknight Mar 22, 2021
58aae4b
Remove Test That Test Template Logic
nigthknight Mar 22, 2021
2cc7fc6
Read NotificationChannels From File System
nigthknight Mar 22, 2021
1436d86
Update Jest Types
nigthknight Mar 22, 2021
5428727
Rename Folder To Comply With Hook Name
nigthknight Mar 22, 2021
dbdb8fb
Add ConfigMap For NotificationChannels
nigthknight Mar 22, 2021
0f43d65
Add Example Channel Config
nigthknight Mar 22, 2021
f4f89e5
Add Volume For Custom Templates
nigthknight Mar 22, 2021
743a575
Add Test To Verify That No Rules Matches All
nigthknight Mar 22, 2021
04da13e
Change templateName -> template
nigthknight Mar 24, 2021
7983b45
Add Test To Verify NotificationChannels Loading
nigthknight Mar 24, 2021
76fbe9b
Remove unused Snapshots
nigthknight Mar 24, 2021
a05fe88
Add Testfile to check NotificationChannel Loading
nigthknight Mar 24, 2021
a1cb27e
Rename Template To Clarify Notifier
nigthknight Mar 24, 2021
7767e8c
Add Basic NotifierFactory Test
nigthknight Mar 24, 2021
6fe4855
Remove unnecessary Logs
nigthknight Mar 24, 2021
4d9f7c9
Change Path To Enable Testing In Other Dir
nigthknight Mar 26, 2021
20e989a
Refactor Mocking To Use jest.mock()
nigthknight Mar 29, 2021
40f83bc
Add Jest Config To Test TypeScript
nigthknight Mar 29, 2021
bca6d2d
Add ts-jest Dependency and Remove Unused
nigthknight Mar 31, 2021
f3841c0
Change Templating Engine To Nunjucks
nigthknight Mar 31, 2021
fbcf373
Load Args Into Notifier
nigthknight Mar 31, 2021
32620ab
Rename Package
nigthknight Mar 31, 2021
85f3525
Fix Test Params
nigthknight Mar 31, 2021
81b32ec
Transform Hooks into Submodules
nigthknight Mar 31, 2021
70e90fd
Remove Axios Export and Clear Mocks before Test
nigthknight Mar 31, 2021
2167d8a
Revert "Refactor Mocking To Use jest.mock()"
nigthknight Mar 31, 2021
c552e52
Inject Axios as Dependency
nigthknight Mar 31, 2021
bb9ccf5
Remove `src` Directory
nigthknight Apr 6, 2021
2da09ac
Fix Template Dir And Optimize Imports
nigthknight Apr 6, 2021
b5ffe0a
Clear Mocks Before Each Test
nigthknight Apr 6, 2021
b864789
Remove Template Validation From Tests
nigthknight Apr 7, 2021
04e37c6
Remove node_modules After Build
nigthknight Apr 7, 2021
15b72f1
Update hooks/notification-hook/helm2.Chart.yaml
nigthknight Apr 7, 2021
4abc66b
Update hooks/notification-hook/Chart.yaml
nigthknight Apr 7, 2021
0f6f0ee
Add Image Build For notification-hook
nigthknight Apr 7, 2021
ff8da16
Fix Docker Namespace For Forks
nigthknight Apr 7, 2021
fd84a12
Add E2E Test For Notification Hook
nigthknight Apr 7, 2021
3e886f6
Add Documentation For Notification-Hook
nigthknight Apr 7, 2021
0efa348
Fix Nmap E2E Test
nigthknight Apr 7, 2021
c0baa01
Append Notification Hook Docs
nigthknight Apr 7, 2021
cc20aa1
Update Docs for notification hook
nigthknight Apr 7, 2021
d72856f
Disable Custom Templates By Default
nigthknight Apr 7, 2021
c6de5fb
Inline Definition For Notification Hook Test Value
nigthknight Apr 7, 2021
76fc38b
Fix Syntax for E2E Test
nigthknight Apr 12, 2021
14e25ae
Add Values File For Notification Hook E2E Test
nigthknight Apr 12, 2021
8c6753c
Wait For Http-Webhook To Be Installed
nigthknight Apr 12, 2021
df6e572
Change `helm upgrade --install` to `helm install`
nigthknight Apr 12, 2021
0cd61b0
Fix Helm Install Syntax
nigthknight Apr 12, 2021
ae06b2d
Add Newline At EOF To Make GH Happy
nigthknight Apr 12, 2021
2a29280
Remove Unused Testfiles
nigthknight Apr 12, 2021
4f94c28
Ignore .test.ts files in codeclimate
nigthknight Apr 12, 2021
f206e5a
Update Chart Description To Reflect Actual Usage
nigthknight Apr 14, 2021
c8291f7
Remove Unnecessary Templating String
nigthknight Apr 14, 2021
6d56c33
Remove Unnecessary Quotation Marks
nigthknight Apr 14, 2021
c11dfb0
Add Security Notice
nigthknight Apr 14, 2021
a8574eb
Remove Unused Import
nigthknight Apr 14, 2021
7b103e0
Read Args From Env
nigthknight Apr 14, 2021
22b0a11
Hide `endPoint` In Secret
nigthknight Apr 14, 2021
3683c2b
Update Notification Hook Docs
nigthknight Apr 14, 2021
d514952
Merge branch 'main' into feature/notification-hook
rfelber Apr 16, 2021
913fe8a
Fix Template For Notification Hook
nigthknight Apr 19, 2021
88817bb
Fix Notification Hook Values For E2E Test
nigthknight Apr 19, 2021
444824b
Merge branch 'feature/notification-hook' of github.com:fuhrmeistery/s…
nigthknight Apr 19, 2021
c788e1e
Update NOTES.txt
nigthknight Apr 19, 2021
a3739f5
Update Install Instructions for Notification Hook
nigthknight Apr 19, 2021
6946182
Update Notification Hook Version
nigthknight Apr 19, 2021
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 .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ exclude_patterns:
- "**/*_test.go"
- "**/*.deepcopy.go"
- "**/*.test.js"
- "**/*.test.ts"
- "**/*.d.ts"
# Auto Generated by kubernetes java client
- "**/hooks/persistence-defectdojo/src/main/java/io/securecodebox/models/"
56 changes: 38 additions & 18 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ env:

jobs:
# ---- Unit-Test ----

# ---- Unit-Test | Java ----

unit-java:
name: "Unit-Test | Java"
runs-on: ubuntu-latest
strategy:
matrix:
unit: ["persistence-defectdojo"]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: '11' # The JDK version to make available on the path.
java-package: jdk # (jre, jdk, or jdk+fx) - defaults to jdk
architecture: x64 # (x64 or x86) - defaults to x64
- run: |
cd hooks/${{ matrix.unit }}/
./gradlew test
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: "11" # The JDK version to make available on the path.
java-package: jdk # (jre, jdk, or jdk+fx) - defaults to jdk
architecture: x64 # (x64 or x86) - defaults to x64
- run: |
cd hooks/${{ matrix.unit }}/
./gradlew test

# ---- Unit-Test | Python ----

Expand Down Expand Up @@ -227,6 +227,7 @@ jobs:
- declarative-subsequent-scans
- finding-post-processing
- generic-webhook
- notification-hook
- persistence-elastic
- persistence-defectdojo
- update-field
Expand Down Expand Up @@ -414,9 +415,9 @@ jobs:
strategy:
matrix:
scanner:
- git-repo-scanner
- screenshooter
- test-scan
- git-repo-scanner
- screenshooter
- test-scan
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down Expand Up @@ -544,10 +545,10 @@ jobs:
strategy:
matrix:
k8sVersion:
- 1.20.0
- 1.19.4
- 1.18.8
- 1.17.11
- 1.20.0
- 1.19.4
- 1.18.8
- 1.17.11
steps:
- uses: actions/checkout@master
- name: "Start kind cluster"
Expand Down Expand Up @@ -749,6 +750,25 @@ jobs:
cd tests/integration/
npx jest --ci --color scanner/nmap.test.js

# ---- Notification Hook Tests ----

- name: "Notification Hook Tests"
run: |
helm -n integration-tests install test-scan ./scanners/test-scan/ \
--set="image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/scanner-test-scan" \
--set="parserImage.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/parser-test-scan" \
--set="parserImage.tag=sha-$(git rev-parse --short HEAD)" \
--set="image.tag=sha-$(git rev-parse --short HEAD)"
helm -n integration-tests install http-webhook ./demo-apps/http-webhook --wait

helm -n integration-tests install notification-hook ./hooks/notification-hook --values tests/integration/hooks/__testFiles__/notification-hook-values.yaml \
--set="image.repository=docker.io/${{env.DOCKER_NAMESPACE }}/notification-hook" \
--set="image.tag=sha-$(git rev-parse --short HEAD)"

cd tests/integration/
npx jest --ci --color ./hooks/notification-hook.test.js
helm -n integration-tests uninstall test-scan http-webhook notification-hook

# ---- SSH_SCAN Integration Tests ----

- name: "ssh-scan Integration Tests"
Expand Down
1 change: 0 additions & 1 deletion hooks/generic-webhook/__mocks__/axios.js

This file was deleted.

3 changes: 1 addition & 2 deletions hooks/generic-webhook/hook.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const axios = require("axios");

async function handle({
getFindings,
scan,
webhookUrl = process.env["WEBHOOK_URL"],
axios = require('axios')
}) {
const findings = await getFindings();

Expand All @@ -12,4 +12,3 @@ async function handle({
await axios.post(webhookUrl, { scan, findings });
}
module.exports.handle = handle;
module.exports.axios = axios;
7 changes: 4 additions & 3 deletions hooks/generic-webhook/hook.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const { handle, axios } = require("./hook");
const { handle } = require("./hook");
const axios = jest.createMockFromModule('axios')

beforeEach(() => {
axios.post.mockClear();
jest.clearAllMocks();
});

test("should send a post request to the url when fired", async () => {
Expand All @@ -25,7 +26,7 @@ test("should send a post request to the url when fired", async () => {

const webhookUrl = "http://example.com/foo/bar";

await handle({ getFindings, scan, webhookUrl });
await handle({ getFindings, scan, webhookUrl, axios });

expect(axios.post).toBeCalledWith(webhookUrl, {
scan,
Expand Down
4 changes: 4 additions & 0 deletions hooks/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
}
2 changes: 2 additions & 0 deletions hooks/notification-hook/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/

2 changes: 2 additions & 0 deletions hooks/notification-hook/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules

31 changes: 31 additions & 0 deletions hooks/notification-hook/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
# Node.js files
node_modules/*
package.json
package-lock.json
src/*
config/*
Dockerfile
.dockerignore

3 changes: 3 additions & 0 deletions hooks/notification-hook/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies: []
digest: sha256:643d5437104296e21d906ecb15b2c96ad278f20cfc4af53b12bb6069bd853726
generated: "2020-05-26T16:56:03.119255+02:00"
24 changes: 24 additions & 0 deletions hooks/notification-hook/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2020 iteratec GmbH
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: v2
name: notification-hook
description: Lets you send a findings result summary as hook to MS Teams, Slack, e-mail and others after a scan is completed.
type: application

# version - gets automatically set to the secureCodeBox release version when the helm charts gets published
version: v2.7.0-alpha1
kubeVersion: ">=v1.11.0-0"

dependencies: []
34 changes: 34 additions & 0 deletions hooks/notification-hook/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2020 iteratec GmbH
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

ARG namespace
ARG baseImageTag
FROM node:12-alpine as install
RUN mkdir -p /home/app
WORKDIR /home/app
COPY package.json package-lock.json ./
RUN npm ci --production

FROM node:12-alpine as build
RUN mkdir -p /home/app
WORKDIR /home/app
COPY package.json package-lock.json ./
RUN npm ci
COPY ./ ./
RUN npm run build && rm -rf node_modules

FROM ${namespace:-securecodebox}/hook-sdk-nodejs:${baseImageTag:-latest}
WORKDIR /home/app/hook-wrapper/hook/
COPY --from=install --chown=app:app /home/app/node_modules/ ./node_modules/
COPY --from=build --chown=app:app /home/app/ ./
8 changes: 8 additions & 0 deletions hooks/notification-hook/Notifier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Finding } from "./model/Finding"

export interface Notifier {
/**
* Sends a Notification Message to the desired End-Point (e.g. Slack or MS Teams)
*/
sendMessage(): Promise<void>
}
89 changes: 89 additions & 0 deletions hooks/notification-hook/NotifierFactory.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { Finding } from "./model/Finding";
import { NotificationChannel } from "./model/NotificationChannel";
import { Scan } from "./model/Scan";
import { NotifierFactory } from "./NotifierFactory"
import { SlackNotifier } from "./Notifiers/SlackNotifier";
import { NotifierType } from "./NotifierType";

const finding: Finding = {
name: "test finding",
location: "hostname",
category: "Open Port",
severity: "high",
osi_layer: "asdf",
attributes: new Map(),
};

const scan: Scan = {
metadata: {
uid: "09988cdf-1fc7-4f85-95ee-1b1d65dbc7cc",
name: "demo-scan-1601086432",
namespace: "my-scans",
creationTimestamp: new Date("2021-01-01T14:29:25Z"),
labels: {
company: "iteratec",
"attack-surface": "external",
},
},
spec: {
scanType: "Nmap",
parameters: ["-Pn", "localhost"],
},
status: {
findingDownloadLink:
"https://my-secureCodeBox-instance.com/scan-b9as-sdweref--sadf-asdfsdf-dasdgf-asdffdsfa7/findings.json",
findings: {
categories: {
"A Client Error response code was returned by the server": 1,
"Information Disclosure - Sensitive Information in URL": 1,
"Strict-Transport-Security Header Not Set": 1,
},
count: 3,
severities: {
high: 10,
medium: 5,
low: 2,
informational: 1,
},
},
finishedAt: new Date("2020-05-25T02:38:13Z"),
rawResultDownloadLink:
"https://my-secureCodeBox-instance.com/scan-blkfsdg-sdgfsfgd-sfg-sdfg-dfsg-gfs98-e8af2172caa7/zap-results.json?Expires=1601691232",
rawResultFile: "zap-results.json",
rawResultType: "zap-json",
state: "Done",
},
};

test("Should Create Slack Notifier", async () => {
const chan: NotificationChannel = {
name: "slack",
type: NotifierType.SLACK,
template: "template",
rules: [],
endPoint: "some.endpoint"
}
const findings: Finding[] = []
findings.push(finding)
const s = NotifierFactory.create(chan, scan, findings, []);

expect(s instanceof SlackNotifier).toBe(true);
})

test("Should Create MS Teams Notifier", async () => {
const chan: NotificationChannel = {
name: "slack",
type: NotifierType.MS_TEAMS,
template: "template",
rules: [],
endPoint: "some.endpoint"
}
const findings: Finding[] = []
findings.push(finding)

const t = () => {
NotifierFactory.create(chan, scan, findings, []);
}

expect(t).toThrow("This Type is not Implemented :(");
})
17 changes: 17 additions & 0 deletions hooks/notification-hook/NotifierFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Notifier } from "./Notifier"
import { NotifierType } from "./NotifierType";
import { SlackNotifier } from "./Notifiers/SlackNotifier"
import { NotificationChannel } from "./model/NotificationChannel";
import { Scan } from "./model/Scan";
import { Finding } from "./model/Finding";

export class NotifierFactory {
static create(channel: NotificationChannel, scan: Scan, findings: Finding[], args: Object): Notifier {
switch (channel.type) {
case NotifierType.SLACK:
return new SlackNotifier(channel, scan, findings, args);
default:
throw new Error("This Type is not Implemented :(")
}
}
}
4 changes: 4 additions & 0 deletions hooks/notification-hook/NotifierType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum NotifierType {
SLACK = "slack",
MS_TEAMS = "ms-teams"
}
Loading