-
Notifications
You must be signed in to change notification settings - Fork 259
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
Docker SSH Forward not working #141
Comments
I had to enable buildkit with the |
@FSMaxB Does not work either with: |
@mpdude Yes I use Github Deploy Keys but the version 0.7.0 did not fix the problem on my side. |
It all depends on how you mount the SSH socket into the Docker Build process and/or copy necessary config files into the images. I am afraid that this is nothing this action could do for you. But the linked issues maybe contain configuration examples that show how you can achieve this? |
Not sure if it might help, but does your Dockerfile has these lines? RUN mkdir ~/.ssh
RUN ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
RUN --mount=type=ssh <command to install dependencies> |
@mpdude This is how I mount the ssh into the docker build process and this is working fine on my local machine using mac os 12.6 but not in the CI using multiple deploy keys. When running composer install outside the docker container so basically in the CI it also works but that's not what I want. @d3li0n Yes I have it in my Dockerfile which btw is being used as the base image.
|
you will need to copy SSH and Git config files into the build stage to make deployment key mappings work. Please see the README. However I just notice that the section mentions a specific Docker build action, which you don't use. The problem/solution probably is the same. |
As a side note, personally I'd avoid using Grab and verify the GH host keys once from their website/blog, and directly put it into your Dockerfile. The keys hardly ever change. |
@mpdude @j-riebe What about dev environment. Since I am using the same Dockerfile for dev, ci and production servers, this forces me to create an empty |
Hey @doctenahasib, I'd recommend using different Dockerfiles for your dev environment and the production build/ci process (à la "do one thing and do it well"). Your dev setup would most likely contain additional dev dependencies anyway that need to be handled separately. So you most likely end up building conditional statements into your Dockerfile or just use separate ones. |
As your error description is not pretty verbose, could you try to turn off host key validation during the actual install? RUN --mount=type=ssh GIT_SSH_COMMAND="ssh -v -o StrictHostKeyChecking=no" <INSTALL COMMAND> Just to make sure, that at least the keys and settings are configured correctly. Be aware that using this setting in production also has good chances of "defeating the whole purpose of key-based host authentication". |
@j-riebe I added GIT_SSH_COMMAND and this is the output. Still not working. (Btw I masked some stuff with ***)
|
@doctenahasib Those two lines
seam to me, as if the wrong key was used. Check if the key that was "accepted" there is in fact the deploy key for the repo (masked too in line 1?). In general this problem looks exactly like mentioned in the docs - the first known key might not be the right one. BTW: Did you already try to use the |
And is the workflow at the top exactly what you are using or did you also "mask" some (very essential 😉) parts? If thats the case, you forgot to copy the git and ssh config to your checked out repo. - name: Prepare git and ssh config for build context
run: |
mkdir root-config
cp -r ~/.gitconfig ~/.ssh root-config/ If you don't do that, it doesn't matter what you do, Docker just won't know the files -> see docs regarding docker-build-push + Deploy keys for details. |
@j-riebe Thanks for your help. Finally I was able to make it work by doing simply this: CI workflow file - name: Prepare git and ssh config for build context
run: |
cp -r ~/.gitconfig ~/.ssh root-config/
sed 's|/home/runner|/root|g' -i.bak root-config/.ssh/config
- name: Build docker image
run: docker compose build --ssh default Dockerfile ONBUILD RUN mkdir -p -m 0600 ~/.ssh
ONBUILD COPY root-config /root/
ONBUILD RUN ssh-keyscan github.com >> ~/.ssh/known_hosts I have created an empty |
@j-riebe thank you for the extensive support I was not able to provide! @doctenahasib how could we improve the documentation, what would have helped you? |
Hello I try to forward the SSH Key (multiple deploy keys ${{ secrets.private-key }}) to my
docker compose build
command where inside it does a PHP composer install and fetches private github repositories but without success. It says:Does anyone face the same issue ? I tried from version 0.5.4 and up.
Btw it works locally on my mac.
The text was updated successfully, but these errors were encountered: