This page will explain how to configure a Jamf bot for slack to query your JAMF Pro server.
A big thanks to taniacomputer (who built this and showed it at JNUC 2019) and to WooSai (in MacAdminSlack) who helped me figure out all the moving parts.
- Administrator permissions on a Jamf Pro server
- Administrator permissions for a Slack instance
- AWS Access (can be an Administrator or have permissions to these services:
- Lambda
- IAM Policy
- SNS Topics
- AWS Secret Manager
- Slack App Setup
- Create Jamf Pro API User
- Setup AWS Secret Manager in AWS
- Setup AWS SNS Topics
- AWS Lambda Function Setup
- Adding custom Extension Attributes to More Info
This step will have us setup out Slackbot/Application that will communicate with AWS Lambda for our Jamf Searches.
- go to
https://api.slack.com/apps
- Click Create new App
- On the next popup select the workspace and name your app.
- Once created, select Slash Commands from the left column, under Features.
- Click create new command and fill out the following information. When done, hit Save.
- Command:
/jamf
- request URL: We will fill this in later, but this is where a request gets sent when we run the command. In this case, a AWS Lambda function. For the time being enter in
https://127.0.0.1/jamf
- Short Description: query Jamf Pro
- Command:
- Under the Settings category on the left, select Basic Information. On the page that opens, copy the Signing Secret value for use later in Secret Manager.
- We will add an interactivity button that sends another request to AWS Lambda, but we have not set that up yet, so we will return here later.
- Lastly create a channel for the Bot to use in Slack (it can be private or public). Visit the channel in a web-browswer and grab the channel ID from the URL. The channel ID is the last set of characters at the end of the URL. Save this for later.
The first step we need to take is to create a user for the Slackbot to query Jamf Pro with.
- Go to https://JSSURL/accounts.html
- Create a new Standard local user account with the following permissions:
- Read ONLY Access to Computers, Computer Extesnion Attributes, Users, User Extension Attributes, Advanced Computer Searches
- Save the username and password information for use later
The Lambda functions require certain API keys and signing secrets to communicate properly with Slack and Jamf Pro. We will use AWS Secret Manager to store these secrets properly so that the functions can use them securely.
- Login into the AWS Console using your administrator account.
- Go to Secret Manager
- Create 2 Secrets by following these steps
- click Store a new secret
- for Secret Type, select "Other type of secrets"
- We are going to add 3 keys/values to this secret
username
:Jamf Pro username you created abovepassword
:Jamf Pro password you created abovesecret
:Slack Signing secret you saved when you created the Slack App.
- Hit Next when you are done
- Enter secret name :
jamf_slack_bot
and add any tags for easy identification. - Hit Next again and make sure automatic rotation is disabled.
- Finally review your settings. At the bottom, there is sample code, copy the keys
secretName
andregion
and save them for later. HitStore
at the bottom when ready.
- In Secrets manager, click into the Secret you just created and copy the value for
Secret Arn
for later use.
Once our endpoints recieve data, they need to know where to send that data. That's where AWS' Simple Notification service comes in handy. We will setup 2 topics.
- Go to Amazon SNS. Once there, select
Topics
from the left column and thenCreate topic
. - Enter the name:
slackJamfInitialTopic
andslackJamfIdSearch
. - You can leave all settings default. Optionally you can add tags for easy identification.
- After you create each topic, make sure you copy the
ARN
from each and save them for later use.
Now we get to create our functions that are going to be doing all the work for the Slackbot.
Go to the AWS Lambda dashboard to begin
- click Create Function
- Select Author from scratch
- name the function
slackApp-01-initialJamfCommand
- select
Python 3.7
as the runtime. - Expand the
Choose or create execution role
section and selectNew role with basic Lambda permissions
- Once the function has been created, go to IAM and find the role that was just created. Click the role.
- Under permissions, select
attach policy
. - Click
Create Policy
. - In the new window that opens up, select the
JSON
tab. Paste in the below JSON You need to input the ARN of the secret you created above into the policy
{
"Version": "2012-10-17",
"Statement": {
"Effect": "Allow",
"Action": "secretsmanager:GetSecretValue",
"Resource": "<arn-of-the-secret-the-app-needs-to-access>"
}
}
- click
Review Policy
and give it a name and description. Then clickCreate policy
. - Go back to the Attach policy tab and hit the reload button in the top right and search for the policy you just created. Check the box to left and hit
Attach policy
. - Go back to Lambda and to the function you just created.
- Paste in the code for the first function into the space provided in the
Function Code
section. - Once pasted in hit
Save
. - We are now going to edit lines 43, 45, 46, 48.
- Line 43 is is the SNS Topic ARN for
slackJamfInitialTopic
topic. - Line 45 is the Secret Manager ARN. It will look like this initially:
"https://secretsmanager.xx-yyyy-z.amazonaws.com"
. Please replace xx-yyyy-z with your region. For example,us-east-2
. - Line 46 is the region, which would be same as the previous step.
- Line 48 is the Slack Channel ID from the Slackbot creation section.
- Line 43 is is the SNS Topic ARN for
- Once edited, hit
Save
. - Scroll up to the
Designer
section of Lambda. ClickAdd Trigger
. From the drop down selectAPI Gateway
. You will see more options now.- Choose to create an API
- set
Security
as open API Type
: REST API Leave all other settings defaults and hit save.
- Once created, select the newly created API Endpoint and hit the error to expand the Endpoint. Copy this URL for later.
- Click
Add destination
and chooseSNS topic
as aDestinition Type
. Configure the following options:- choose
slackJamfInitialTopic
as the destintion topic - set
Source
asAsychronous invocation
- set
Condition
asSuccess
- hit
Save
- choose
- click Create Function
- Select Author from scratch
- name the function
slackApp-02-RunMatchSearchJamf
- select
Python 3.7
as the runtime. - Expand the
Choose or create execution role
section and selectNew role with basic Lambda permissions
- Once the function has been created, go to IAM and find the role that was just created. Click the role.
- Under permissions, select
attach policy
. - Search for the policy you created above for Secret permissions. Check the box to left and hit
Attach policy
. - Go back to Lambda and to the function you just created.
- Paste in the code for the second function into the space provided in the
Function Code
section. - Once pasted in hit
Save
. - Edit lines 16, 19, 20, 22 with the below values
- replace
jamf.com
with your Jamf Pro URL on line 16 - SM_ENDPOINT_URL (replace xx-yyyy-z with your AWS Region (ie us-east-2)
- SM_REGION_NAME (same as above, replace xx-yyyy-z with your AWS Region
- SLACK_CHANNEL_ID is the slack channel ID we replaced in the previous function
- replace
- Hit save once those lines are edited and click Add Trigger.
- Select SNS
- select
slackJamfInitialTopic
from list - make sure
Enabled Trigger
is checked and hitAdd
- click Create Function
- Select Author from scratch
- name the function
slackApp-03-JamfMoreInfo
- select
Python 3.7
as the runtime. - Expand the
Choose or create execution role
section and selectNew role with basic Lambda permissions
- Once the function has been created, go to IAM and find the role that was just created. Click the role.
- Under permissions, select
attach policy
. - Search for the policy you created above for Secret permissions. Check the box to left and hit
Attach policy
. - Go back to Lambda and to the function you just created.
- Paste in the code for the third function into the space provided in the
Function Code
section. - Once pasted in hit
Save
. - Edit lines 19, 22, 23.
- SNS_TOPIC_ARN is ARN from the
slackJamfIdSearch
topic that you saved earlier - SM_ENDPOINT_URL (replace xx-yyyy-z with your AWS Region (ie us-east-2)
- SM_REGION_NAME (same as above, replace xx-yyyy-z with your AWS Region
- SNS_TOPIC_ARN is ARN from the
- Hit
Save
again to save changes. - Go to the
Designer
section of Lambda. ClickAdd Trigger
. From the drop down selectAPI Gateway
. You will see more options now.- Choose to create an API
- set
Security
as open API Type
: REST API Leave all other settings defaults and hit save.
- Once created, select the newly created API Endpoint and hit the error to expand the Endpoint. Copy this URL for later.
- Click
Add destination
and chooseSNS topic
as aDestinition Type
. Configure the following options:- choose
slackJamfIdSearch
as the destintion topic - set
Source
asAsychronous invocation
- set
Condition
asSuccess
- hit
Save
- choose
- click Create Function
- Select Author from scratch
- name the function
slackApp-03-MoreInfoResponse
- select
Python 3.7
as the runtime. - Expand the
Choose or create execution role
section and selectNew role with basic Lambda permissions
- Once the function has been created, go to IAM and find the role that was just created. Click the role.
- Under permissions, select
attach policy
. - Search for the policy you created above for Secret permissions. Check the box to left and hit
Attach policy
. - Go back to Lambda and to the function you just created.
- Paste in the code for the fourth function into the space provided in the
Function Code
section. - Once pasted in hit
Save
. - Edit lines 19, 20, 22, 24
- SM_ENDPOINT_URL (replace xx-yyyy-z with your AWS Region (ie us-east-2)
- SM_REGION_NAME (same as above, replace xx-yyyy-z with your AWS Region
- SLACK_CHANNEL_ID is the slack channel ID we replaced in the previous function
- API_URL is the url of your Jamf Pro server, replace
jamf.com
with your base url.
- Hit save once those lines are edited and click Add Trigger.
- Select SNS
- select
slackJamfIdSearch
from list - make sure
Enabled Trigger
is checked and hitAdd
.
We will now add our API Endpoint URLs in our Slack app so it knows where it send requests.
- go to
https://api.slack.com/apps
- Select the app you created earlier.
- Select
Slash Commands
on the left and hit the pencil to edit. - For request URL, enter in the
API Endpoint URL
from the first Lambda function and hitSave
. - On the left, select
Interactivity & Shortcuts
and toggle the on switch. UnderRequest URL
enter theAPI Endpoint URL
from the third Lambda function. HitSave
at the bottom. - Select
Install App
on the left and then the green button to install the app to your workspace.
You can now test the bot in your slack channel by typing /jamf
and hitting return. It should give you a help page.
To add other information or extension attribute information to the more info query, change the name of the extension attribute to include slack -
. When you hit the more info, you will see the information. If you would like to customize how that information is displayed in slack, within the ` you can different slack emoji's to add that to the response. See below for example:
```echo "<result>:white_check_mark:Password Synced</result>"```