Skip to content

Commit

Permalink
Allow overriding of the socket file (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
kielabokkie authored Apr 1, 2022
1 parent e5c88dc commit 746d00e
Show file tree
Hide file tree
Showing 4 changed files with 2,704 additions and 178 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,34 @@ You can run this action before copying files to an external server using `scp` o

*Optional* Port for key-scanning the server.

* `ssh-socket`

*Optional* The unix file socket that the agent uses for communication with other processes.

## Example usage

Just the required inputs:
```
uses: kielabokkie/ssh-key-and-known-hosts-action@v1
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
ssh-host: your-server.com
```

If your SSH port is different from the default you can change it:
```
uses: kielabokkie/ssh-key-and-known-hosts-action@v1
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
ssh-host: your-server.com
ssh-port: 2222
```

If you are using this action on concurrent builds the `ssh-socket` should be unique to prevent `address in use` issues:
```
uses: kielabokkie/ssh-key-and-known-hosts-action@v1
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
ssh-host: your-server.com
ssh-socket: /tmp/ssh_agent_${{ github.sha }}.sock
```
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ inputs:
ssh-port:
description: 'Port for key-scanning the server'
required: false
default: '22'
ssh-socket:
description: 'The unix file socket that the agent uses for communication with other processes'
required: false
default: '/tmp/ssh-auth.sock'
runs:
using: 'node12'
main: 'dist/main/index.js'
Expand Down
13 changes: 5 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ const fs = promise.promisifyAll(require('fs'))
async function run() {
try {
const privateKey = core.getInput('ssh-private-key', { required: true })
const host = core.getInput('ssh-host', { required: true })
let port = core.getInput('ssh-port')

if (!port) {
port = 22
}
const host = core.getInput('ssh-host', { required: true })
const authSock = core.getInput('ssh-socket')
const port = core.getInput('ssh-port')

// Create the required directory
const sshDir = process.env['HOME'] + '/.ssh'
Expand All @@ -20,7 +17,6 @@ async function run() {
console.log('Starting ssh-agent')

// Start the ssh agent
const authSock = '/tmp/ssh-auth.sock'
await execa('ssh-agent', ['-a', authSock])

core.exportVariable('SSH_AUTH_SOCK', authSock)
Expand All @@ -34,8 +30,9 @@ async function run() {
console.log('Adding host to known_hosts')

// Add the host to the known_hosts file
const {stdout} = await execa('ssh-keyscan', ['-p', port.toString(), host])
const {stdout} = await execa('ssh-keyscan', ['-p', port, host])
const knownHostsFile = sshDir + '/known_hosts'

await fs.appendFileAsync(knownHostsFile, stdout)
await fs.chmodAsync(knownHostsFile, '644')
}
Expand Down
Loading

0 comments on commit 746d00e

Please sign in to comment.