-1

I'm trying to install a pip package from a private, secure repo with pip inside a Dockerfile

I have created a id_rsa key and added as a deploy key to that repo.

I'm trying to COPY these keys inside the container and running pip afterward.

Dockerfile relevant parts:

# Saving custom SSH key for git
RUN mkdir -p /root/.ssh && chmod 0700 /root/.ssh && ssh-keyscan -v -p 10223 -T 240 gitea.****.**** > /root/.ssh/known_hosts
# Copy private key
COPY ./keys/id_rsa /root/.ssh/id_rsa
# Copy public key
COPY ./keys/id_rsa.pub /root/.ssh/id_rsa.pub
# Changing permissions
RUN chmod 0600 /root/.ssh/id_rsa && chmod 0600 /root/.ssh/id_rsa.pub

RUN pip install --upgrade pip
COPY ./requirements ./requirements
RUN pip install -r ./requirements/requirements.txt

The output when I try to run docker build:

  Cloning ssh://****@gitea.****.****:10223/****/****.git (to revision master) to ./src/package
  Running command git clone --filter=blob:none --quiet 'ssh://****@gitea.*****.****:10223/******/*******.git' /usr/src/app/src/package
  Warning: Permanently added the ECDSA host key for IP address '[XXX.XXX.XXX.XXX]:10223' to the list of known hosts.
  Load key "/root/.ssh/id_rsa": invalid format
  git@gitea.marinero.hu: Permission denied (publickey).
  fatal: Could not read from remote repository.

  Please make sure you have the correct access rights
  and the repository exists.
  error: subprocess-exited-with-error

Kristof Rado
  • 164
  • 2
  • 11

1 Answers1

-1

The problem was really with the format of the private key. I don't know why, but locally it worked with openssh private key format, inside docker it only works with RSA key.

Converting the like this helped: Openssh Private Key to RSA Private Key

Kristof Rado
  • 164
  • 2
  • 11
  • It could be due to variety of reasons, like version of openssh or it's default configuration. We cannot see the source image used in this Dockerfile therefore we can only be guessing the root cause. – tymik May 31 '22 at 09:32
  • The image is from ```FROM python:3``` which is Ubuntu based if I'm right. The host where I tried is also an Ubuntu server. – Kristof Rado May 31 '22 at 09:39