Skip to content

Commit 566a7fe

Browse files
committed
Mount the entire user SSH directory into build container
This enables the user to use an key file format (RSA, ED25519, ...). Additionally, it allows more complex workflows (such as different SSH keys for specfic sites, such as Github or Bitbucket), since the .ssh/config file is also mounted into the container. Fixes serverless#488
1 parent b652947 commit 566a7fe

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ custom:
7171
dockerSsh: true
7272
```
7373

74-
The `dockerSsh` option will mount your `$HOME/.ssh/id_rsa` and `$HOME/.ssh/known_hosts` as a
74+
The `dockerSsh` option will mount your `$HOME/.ssh/` directory as a
7575
volume in the docker container. If your SSH key is password protected, you can use `ssh-agent`
7676
because `$SSH_AUTH_SOCK` is also mounted & the env var set.
7777
It is important that the host of your private repositories has already been added in your

lib/pip.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,21 @@ function installRequirements(targetFolder, serverless, options) {
204204
// Mount necessary ssh files to work with private repos
205205
dockerCmd.push(
206206
'-v',
207-
`${process.env.HOME}/.ssh/id_rsa:/root/.ssh/id_rsa:z`,
208-
'-v',
209-
`${process.env.HOME}/.ssh/known_hosts:/root/.ssh/known_hosts:z`,
207+
`${process.env.HOME}/.ssh/:/root/.ssh/:z`,
210208
'-v',
211209
`${process.env.SSH_AUTH_SOCK}:/tmp/ssh_sock:z`,
212210
'-e',
213211
'SSH_AUTH_SOCK=/tmp/ssh_sock'
214212
);
213+
214+
// If the user has a SSH_CONFIG file, it won't have the correct permissions
215+
// inside the docker container, and the ssh command will fail with
216+
// > Bad owner or permissions on /root/.ssh/config
217+
// However, if the we specify the SSH_CONFIG file with -F explicitly,
218+
// ssh does not check the ownership of the file.
219+
if (fse.existsSync(`${process.env.HOME}/.ssh/config`)) {
220+
dockerCmd.push('-e', 'GIT_SSH_COMMAND=ssh -F /root/.ssh/config');
221+
}
215222
}
216223

217224
// If we want a download cache...

0 commit comments

Comments
 (0)