pythondockercontainersaptpgp

How do I add a public PGP key from a internal apt mirror inside python3.10-slim image?


I need to set up apt inside of our container images to use our internal apt mirror. This will require changing the apt sources, copying over the public key, adjusting apt to use a proxy, and then running apt update

I have read many solutions line. Problem is, all of them either have apt-key or gpg. The image I have is python3.10-slim, it does not. And I cant apt install anything until I get the mirrors set up to do any installs. So I am left to using whatever is on this image.

I have the public pgp key, I can copy it to the container. How do I force apt to trust it?


Solution

  • Just modify your apt source line(s) (perhaps /etc/apt/sources.list) for the initial fetch!

    deb [trusted=yes] http://repo distro component
    

    in your Dockerfile, this could be

    RUN sed -i 's/^deb /deb [trusted=yes] /' "$PATH"
    

    To be more secure, consider a strategy of download, verify (Python itself may provide some has functions in your container if you can't install), install, and the reverse sed command to restore it once you can, though this might be excessive in a closed network

    apt-get download gpg
    # verify checksum
    apt-get install ./gpg*.deb  # apt needs '/' to know it's local