In this repo we will be making use of Cloud Function to create a notification receiver for Security Advisor Notification service.
obtainAccessToken: Access token is required to call the Security Advisor notifications API. We use the IAM token endpoint to get the access token for any IBM Cloud account. You need to provide a platform api key from your IBM Cloud account for the same.
downloadPublicKey: Security Advisor notifications are sent as a signed JSON web token (JWT). This allows us to verify that the notification payload was actually sent by our Security Advisor and wasn’t tampered with. In order to verify the signature, we must first get the notifications public key from Security Advisor. We used the Security Advisor Notification API to request the notifications public key for our instance. We specified the key format as pem since that is what the jsonwebtoken package supports. You need to update url property in this function with your values.
createGitHubIssue: If the finding received as part of notification signifies MEDIUM/HIGH severity, then this particular function will be called to create a git hub issue. This function builds issue description and creates an issue in the Git Hub url provided. Before we begin creating GitHub issue, we’ll need to create a repo to send the issues to (or use an existing one) and create a personal GitHub access token. To create the access token, go to https://github.com/settings/tokens and generate a new personal access token. For more information about creating GitHub issues, see this link
sendToSlack: If the finding received as part of notification signifies LOW severity, then this particular function will be called to send a Slack alert. This function builds message with necessary information (example: findings id, source etc) and post it to given Slack channel. Before we begin sent Slack alert, we will need a slack channel and a webhook url for the same. For more information, see this link
main: IBM Cloud Functions requires a function called main to exist as an entry point for the action. The params object contains the body of the incoming request. Security Advisor notification body contains a single JSON object with a single property called data that holds the signed JWT string as its value. When we obtained the public key, we can use it to verify the JWT signature. We’ll use the jsonwebtoken library’s verify function. This function receives the JWT string and a public key and returns the payload decoded if the signature is valid. If not, it will throw an error.
- Download and install
ibmcloud cli
from https://github.com/IBM-Cloud/ibm-cloud-cli-release/releases - Install Cloud Functions plug-in
ibmcloud plugin install cloud-functions
. More details can be found here - Target a namespace for your Cloud Function.
ibmcloud login
ibmcloud target --cf
ibmcloud fn property set --namespace <namespace_name>
- Clone the repo :
git clone git@github.com:ibm-cloud-security/security-advisor-notification-webhook.git
cd security-advisor-notification-webhook
- Install all dependencies locally.
npm install
- Build the webpack bundle.
npm run build
- Create the action.
npm run deploy
- Update
params.json
file with proper values.- apiKey : Provide apikey for your account with Manager access to security advisor service
- iamTokenURL : IAM token endpoint
- notificationChannelUrl : Notification API endpoint,
<region>
values must be us-south or eu-gb - accountId : Provide IBM Cloud account id
- slackEndpoint : Slack webhook url
- slackChannel : Slack channel name
- GITHUB_ACCESS_TOKEN : Developer access token generated using GitHub
- GITHUB_API_URL : GitHub API url for your repo
- Bind parameters to your action.
ibmcloud fn action update security-advisor-notifier --param-file params.json
- Verify using
ibmcloud fn action get security-advisor-notifier parameters
- Get the URL endpoint for your action.
echo `ibmcloud fn action get security-advisor-notifier --url | grep 'https'`'.json'
- To create a Cloud Function, go to the Functions from left nav bar in IBM Cloud Dashboard, select the Actions tab, click the Create button, and then click Create a new action. Give the action a name, chose the default package, select a Node.js runtime (the sample code in this repo
src/notifier.js
is compatible with Node.js 8), and click the Create button. - Copy the code from
src/notifier.js
to your Cloud Function. - Add required parameters mentioned in
params.json
by clickingParameters
from the left nav of the Cloud Functions UI. - Select
Endpoints
from the left nav of the Cloud Functions UI, check the Enable as Web Function checkbox, and click the Save button. Copy the URL that was added at the bottom of the Web Action section.