slack-to-ssh
Runs an SSH command from Slack interactive message buttons.
Requirements
Installation
$ docker buildx build .
# Port number (required)
export PORT=8080
# TLS certificate and private key (optional; if not specified, application is served over HTTP)
export TLS_CERT=/path/to/tls/cert
export TLS_KEY=/path/to/tls/key
# SSH Hostname (required)
export SSH_HOSTNAME=
# SSH Port (optional; defaults to 22)
export SSH_PORT=
# SSH Username (required)
export SSH_USERNAME=
# SSH Known Hosts (optional; recommended)
export SSH_KNOWN_HOSTS_FILE=/path/to/known_hosts
# SSH Private Key (required)
export SSH_PRIVATE_KEY_FILE=/path/to/private/key
# SSH Private Key Passphrase (required if private key is encrypted)
export SSH_PRIVATE_KEY_PASSPHRASE_FILE=/path/to/passphrase
# Slack App Secret (required)
export SLACK_APP_SECRET=
# nth Action Name (required)
export SLACK_ACTION_0_NAME=
# nth Attachment Text (optional)
export SLACK_ACTION_0_ATTACHMENT_TEXT=
# nth SSH Command to execute (required)
export SLACK_ACTION_0_COMMAND=
Usage
- Send a message to Slack with actions:
{
"text": "Click a button!",
"attachments": [
{
"title": "Questionnaire",
"text": "What's for dinner?",
"actions": [
{
"name": "exec",
"type": "button",
"text": "Beef",
"value": "beef"
},
{
"name": "exec",
"type": "button",
"style": "danger",
"text": "Turkey",
"value": "turkey",
"confirm": {
"title": "Eating turkey?",
"text": "Are you sure you want to eat turkey?",
"ok_text": "OK",
"dismiss_text": "Cancel"
}
}
]
}
]
}
- Serve the action with the following config:
export SSH_HOSTNAME=example.com
export SSH_USERNAME=user
export SSH_KNOWN_HOSTS_FILE=/path/to/known_hosts
export SSH_PRIVATE_KEY_FILE=/path/to/private/key
export SSH_PRIVATE_KEY_PASSPHRASE_FILE=/path/to/passphrase
export SLACK_APP_SECRET=00000000000000000000000000000000
export SLACK_ACTION_0_NAME=beef
export SLACK_ACTION_0_ATTACHMENT_TEXT='Beef is chosen for dinner'
export SLACK_ACTION_0_COMMAND='echo Bonjour, beef | cowsay'
export SLACK_ACTION_1_NAME=turkey
export SLACK_ACTION_1_ATTACHMENT_TEXT='Turkey chosen for dinner'
export SLACK_ACTION_1_COMMAND='echo Hello, turkey | cowsay -f turkey'
- The specified command is executed on the remote server.