-
Notifications
You must be signed in to change notification settings - Fork 179
Added a new template based notification hook (e.g for Slack) #338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
J12934
merged 133 commits into
secureCodeBox:main
from
nigthknight:feature/notification-hook
Apr 19, 2021
Merged
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 ef93e93
Add axios and jest
nigthknight 213a341
Add Mock For Axios
nigthknight f7c2294
Add Failing Tests For Notification Hook
nigthknight af9d32a
Add Mustache
nigthknight fd7f8c1
Update Dependencies
nigthknight f8a558b
Add Lodash
nigthknight dd8fc61
Move Hook To TypeScript
nigthknight 550a19e
Add NotifierFactory
nigthknight e33a01d
Change Import Format
nigthknight c44e0a6
Add Basic jest.config.js
nigthknight 2b7fad9
Remove Unused Import From hook.ts
nigthknight 6d0c2fd
Remove Unused Import
nigthknight f9e3546
Move into src directory
nigthknight 8699f08
Change Dockerfile To Use TypeScript
nigthknight 135f004
Remove Not Existing vars
nigthknight c69741a
Add Option to configure imagePullPolicy
nigthknight 7b78fde
Cleanup handle function for Testing
nigthknight 24e5561
Add Init() Method To Initialize The Notifier
nigthknight dab43bc
Add default Case Throwing Error
nigthknight 532c407
Add Types for Mustache and Lodash
nigthknight 2721dfb
Implement Basic Hook
nigthknight 459aaba
Add Basic Tests for Slack Notifier
nigthknight 13c7ce5
Remove unused Template Var From Factory
nigthknight 826fd89
Add Option For Custom Templates
nigthknight d8394aa
Refactoring AbstractNotifier
nigthknight 8053ac5
Update Test
nigthknight d2608fe
Update SlackNotifier Based on AbstractNotifier
nigthknight 23f1219
Add `templates/slack` With A Basic Slack Template
nigthknight 5eccba4
Change Signature for Interface Methods to Promise
nigthknight 1946c15
Move Loading of Shipped Templates into Notifier
nigthknight 0238c93
Refactoring
nigthknight c407cc3
Change Method Signature to Return Promise
nigthknight 456bec3
Fix Mustache Import
nigthknight 8c6e8f3
Rename `templateName` --> `templatType`
nigthknight 4a1096b
Load All Templates From Same Directory
nigthknight 56762cd
Move Template Rendering To AbstractNotifier
nigthknight 3ccc71a
Remove Unused Methods
nigthknight 73dd01a
Update NotificationChannel Model To Pass To Notifier
nigthknight e190a4a
Rename File For Consistency
nigthknight 11a3ee3
Remove Unused Files And Directories
nigthknight 724f8dd
Load NotificationChannel Into Notifiers
nigthknight ad411ed
Update Import
nigthknight eb00115
Add Types for Jest To enable VS Code To Make Suggestions
nigthknight e56bb16
Move Template Into Root Template Dir
nigthknight 3c601a1
Load Template Before Rendering
nigthknight 984a669
Update Tests
nigthknight 0674229
Remove Unused Import
nigthknight 57e0de3
Update Template
nigthknight 79f2ba0
Add js-yaml and TS Types for js-yaml
nigthknight 623b20c
Fix Syntax
nigthknight 8d9e096
Switch To YAML Format
nigthknight 232590f
Update Test
nigthknight 4684fd0
Update Basic Template
nigthknight 3adee04
Pass Scan Data Into Notifier
nigthknight e13fbae
Add kubernetes client to use Interface
nigthknight 9b62ed2
Refactor Class To Interface
nigthknight 6a10409
Add Helper Funtions To Render Template
nigthknight 8be75bc
Enable Failing Tests
nigthknight 10226d1
Rename Notification-Webhook -> Notification-Hook
nigthknight b9d11e3
Add Test To Verify That Minimal Template Is Send
nigthknight ff83661
Remove Test Cases That Do Not Test SlackNotifier
nigthknight 315eed1
Improve Template "Power"
nigthknight 2fdfee8
Log YAML Parse Error
nigthknight 46aafac
Update Tests For MessageCard Template
nigthknight 00bbb8f
Refactoring
nigthknight 8f73b77
Update Matches Function
nigthknight 58aae4b
Remove Test That Test Template Logic
nigthknight 2cc7fc6
Read NotificationChannels From File System
nigthknight 1436d86
Update Jest Types
nigthknight 5428727
Rename Folder To Comply With Hook Name
nigthknight dbdb8fb
Add ConfigMap For NotificationChannels
nigthknight 0f43d65
Add Example Channel Config
nigthknight f4f89e5
Add Volume For Custom Templates
nigthknight 743a575
Add Test To Verify That No Rules Matches All
nigthknight 04da13e
Change templateName -> template
nigthknight 7983b45
Add Test To Verify NotificationChannels Loading
nigthknight 76fbe9b
Remove unused Snapshots
nigthknight a05fe88
Add Testfile to check NotificationChannel Loading
nigthknight a1cb27e
Rename Template To Clarify Notifier
nigthknight 7767e8c
Add Basic NotifierFactory Test
nigthknight 6fe4855
Remove unnecessary Logs
nigthknight 4d9f7c9
Change Path To Enable Testing In Other Dir
nigthknight 20e989a
Refactor Mocking To Use jest.mock()
nigthknight 40f83bc
Add Jest Config To Test TypeScript
nigthknight bca6d2d
Add ts-jest Dependency and Remove Unused
nigthknight f3841c0
Change Templating Engine To Nunjucks
nigthknight fbcf373
Load Args Into Notifier
nigthknight 32620ab
Rename Package
nigthknight 85f3525
Fix Test Params
nigthknight 81b32ec
Transform Hooks into Submodules
nigthknight 70e90fd
Remove Axios Export and Clear Mocks before Test
nigthknight 2167d8a
Revert "Refactor Mocking To Use jest.mock()"
nigthknight c552e52
Inject Axios as Dependency
nigthknight bb9ccf5
Remove `src` Directory
nigthknight 2da09ac
Fix Template Dir And Optimize Imports
nigthknight b5ffe0a
Clear Mocks Before Each Test
nigthknight b864789
Remove Template Validation From Tests
nigthknight 04e37c6
Remove node_modules After Build
nigthknight 15b72f1
Update hooks/notification-hook/helm2.Chart.yaml
nigthknight 4abc66b
Update hooks/notification-hook/Chart.yaml
nigthknight 0f6f0ee
Add Image Build For notification-hook
nigthknight ff8da16
Fix Docker Namespace For Forks
nigthknight fd84a12
Add E2E Test For Notification Hook
nigthknight 3e886f6
Add Documentation For Notification-Hook
nigthknight 0efa348
Fix Nmap E2E Test
nigthknight c0baa01
Append Notification Hook Docs
nigthknight cc20aa1
Update Docs for notification hook
nigthknight d72856f
Disable Custom Templates By Default
nigthknight c6de5fb
Inline Definition For Notification Hook Test Value
nigthknight 76fc38b
Fix Syntax for E2E Test
nigthknight 14e25ae
Add Values File For Notification Hook E2E Test
nigthknight 8c6753c
Wait For Http-Webhook To Be Installed
nigthknight df6e572
Change `helm upgrade --install` to `helm install`
nigthknight 0cd61b0
Fix Helm Install Syntax
nigthknight ae06b2d
Add Newline At EOF To Make GH Happy
nigthknight 2a29280
Remove Unused Testfiles
nigthknight 4f94c28
Ignore .test.ts files in codeclimate
nigthknight f206e5a
Update Chart Description To Reflect Actual Usage
nigthknight c8291f7
Remove Unnecessary Templating String
nigthknight 6d56c33
Remove Unnecessary Quotation Marks
nigthknight c11dfb0
Add Security Notice
nigthknight a8574eb
Remove Unused Import
nigthknight 7b103e0
Read Args From Env
nigthknight 22b0a11
Hide `endPoint` In Secret
nigthknight 3683c2b
Update Notification Hook Docs
nigthknight d514952
Merge branch 'main' into feature/notification-hook
rfelber 913fe8a
Fix Template For Notification Hook
nigthknight 88817bb
Fix Notification Hook Values For E2E Test
nigthknight 444824b
Merge branch 'feature/notification-hook' of github.com:fuhrmeistery/s…
nigthknight c788e1e
Update NOTES.txt
nigthknight a3739f5
Update Install Instructions for Notification Hook
nigthknight 6946182
Update Notification Hook Version
nigthknight File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| module.exports = { | ||
| preset: 'ts-jest', | ||
| testEnvironment: 'node', | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| node_modules/ | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| node_modules | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/ ./ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 :("); | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 :(") | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| export enum NotifierType { | ||
| SLACK = "slack", | ||
| MS_TEAMS = "ms-teams" | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.