How to use podman's ssh build flag?

Viewed 645

I have been using the docker build --ssh flag to give builds access to my keys from ssh-agent.

When I try the same thing with podman it does not work. I am working on macOS Monterey 12.0.1. Intel chip. I have also reproduced this on Ubuntu and WSL2.

❯ podman --version
podman version 3.4.4

This is an example Dockerfile:

FROM python:3.10

RUN mkdir -p -m 0600 ~/.ssh \
    && ssh-keyscan github.com >> ~/.ssh/known_hosts

RUN --mount=type=ssh git clone git@github.com:ruarfff/a-private-repo-of-mine.git

When I run DOCKER_BUILDKIT=1 docker build --ssh default . it works i.e. the build succeeds, the repo is cloned and the ssh key is not baked into the image.

When I run podman build --ssh default . the build fails with:

git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Error: error building at STEP "RUN --mount=type=ssh git clone git@github.com:ruarfff/a-private-repo-of-mine.git": error while running runtime: exit status 128

I have just begun playing around with podman. Looking at the docs, that flag does appear to be supported. I have tried playing around with the format a little, specifying the id directly for example but no variation of specifying the flag or the mount has worked so far. Is there something about how podman works that I may be missing that explains this?

Adding this line as suggested in the comments:

RUN --mount=type=ssh ssh-add -l 

Results in this error:

STEP 4/5: RUN --mount=type=ssh ssh-add -l 
Could not open a connection to your authentication agent.
Error: error building at STEP "RUN --mount=type=ssh ssh-add -l": error while running runtime: exit status 2

Edit:

I belive this may have something to do with this issue in buildah. A fix has been merged but has not been released yet as far as I can see.

0 Answers
Related