Skip to content

Mount the entire user SSH directory into build container #489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

jacksgt
Copy link
Contributor

@jacksgt jacksgt commented Mar 9, 2020

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 #488

Copy link
Contributor

@miketheman miketheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this may work, however I don’t think any of our existing tests cover this behavior. Have you considered adding some to ensure this works as intended? The tests.js file has a bunch tagged with canUseDocker as examples.

@jacksgt
Copy link
Contributor Author

jacksgt commented Mar 9, 2020

Adding some tests sounds like a good idea, however I'm not very experienced with JS tests.
Basically what I would do is the following:

  1. create a file in ~/.ssh/id_foobar
  2. run sls with dockerizePip option
  3. check if the file is mounted inside the docker container

@jacksgt jacksgt force-pushed the mount-ssh-dir branch 7 times, most recently from e1d74fb to 43d0469 Compare March 16, 2020 10:42
@jacksgt
Copy link
Contributor Author

jacksgt commented Mar 16, 2020

@miketheman Hey, I tried adding a test, but I'm not sure why the test does not produce a ZIP file (and subsequently fails).
Could you look into it?

@jacksgt jacksgt force-pushed the mount-ssh-dir branch 8 times, most recently from d285c58 to 3be471f Compare March 18, 2020 15:38
@jacksgt
Copy link
Contributor Author

jacksgt commented Mar 18, 2020

@miketheman After a few more attempts I got it working. Could you review the PR again when you find the time? Thanks.

miketheman
miketheman previously approved these changes Mar 29, 2020
Copy link
Contributor

@miketheman miketheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thanks for taking the time to write the test!
I know that this branch is out of date from master and @bsamuel-ui has been focusing on changing the CI/CD from CircleCI to GitHub Actions - so I'd recommend rebasing/merging after that PR is on master so as to exercise this one more time in the new CI before merging.

@miketheman miketheman added the bug-fix PR that fixes a bug. label Mar 29, 2020
@jacksgt jacksgt force-pushed the mount-ssh-dir branch 2 times, most recently from 040adee to 12326b5 Compare April 3, 2020 06:44
@jacksgt
Copy link
Contributor Author

jacksgt commented Apr 14, 2020

Since there hasn't been any activity on the github actions PR for a two weeks now, could we merge this one in anyway?

@bsamuel-ui
Copy link
Contributor

@jacksgt I was looking at that merge conflict, I could sort of resolve that through the editor, but I'm just as likely to screw it up. You just need to make sure your new test is present and is async, and as soon as you can do that we can merge this.

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
This test makes sure the plugin actually mounts the SSH directory into
the container, if the dockerizePip and dockerSsh are given.
It does this by creating a new known_hosts file and placing the RSA
fingerprint of Github inside, then installing a package via Git, which
requires this fingerprint to be present in known_hosts.
If it is not present, the process will fail.

This patch also adds minor debugging output, in case no
requirements.txt is found.
@jacksgt
Copy link
Contributor Author

jacksgt commented Sep 21, 2020

@bsamuel-ui Hey, thanks for getting back on this one and keeping the project going!

I rebased on master, but now the test is failing with a git error code that seems to indicate there is no public/private ssh key present on the host machine.
Since the testcase worked on the old CI, I assume that something changed in the setup.
Any idea how to fix this?

@bsamuel-ui
Copy link
Contributor

Seeing a bunch of issues here that aren't in other branches. I'm going to take some time to dig into it on Tuesday per #550

t.true(zipfiles.includes(`boto3/__init__.py`), 'boto3 is packaged via ssh');
t.end();
},
{ skip: !canUseDocker() }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested this on Windows?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, not sure if its gonna work on Windows.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then the skip section should be skipping the test on Windows, and you can create an issue noting that this functionality doesn't work on Windows yet.

@tonythree
Copy link

tonythree commented Apr 15, 2021

Hey, having this issue as well.
Is this going to be merged at some point?
also, is there any workaround for this?
Thanks a lot for the hard work.

EDIT
Tried to Workaround by simply creating an id_rsa key and attaching as a new key to github.
https://docs.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent

ssh-keygen -t rsa -b 4096 -C "[email protected]"

But having the same issue. So this does not solve the problem :(

@martinezpl
Copy link
Contributor

martinezpl commented Feb 3, 2022

Any move with this? Something I can help with to have this eligible for merge? This is the current source code:

// Mount necessary ssh files to work with private repos
      if (options.dockerSsh) {
        // Mount necessary ssh files to work with private repos
        dockerCmd.push(
          '-v',
          `${process.env.HOME}/.ssh/id_rsa:/root/.ssh/id_rsa:z`,
          '-v',
          `${process.env.HOME}/.ssh/known_hosts:/root/.ssh/known_hosts:z`,
          '-v',
          `${process.env.SSH_AUTH_SOCK}:/tmp/ssh_sock:z`,
          '-e',
          'SSH_AUTH_SOCK=/tmp/ssh_sock'
        );
      }

RSA keys are considered legacy, I don't think it's reasonable to continue expecting (or forcing, pretty much) this format.

EDIT Tried to Workaround by simply creating an id_rsa key and attaching as a new key to github. https://docs.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
But having the same issue. So this does not solve the problem :(

Creating a new RSA key and registering it to my GH account worked for me.

@pgrzesik
Copy link
Contributor

pgrzesik commented Feb 3, 2022

Hey @martinezpl - this PR has been dead for a long time - if you'd like to take over and propose a new one, feel free to do so 💯

@pgrzesik
Copy link
Contributor

Hey @jacksgt - it's been a long time since this PR was proposed. I'm going to close it, if you feel like the issue is valid, please open a new issue or a new PR against the latest main branch. Thanks 🙇

@pgrzesik pgrzesik closed this Sep 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-fix PR that fixes a bug. Docker
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dockerSsh option fails to mount non-RSA keys into container
6 participants