How to import MariaDB apt repository key behind an outgoing HTTP proxy

Written by - 0 comments

Published on May 1st 2021 - Listed in Linux MariaDB Internet

When installing MariaDB from their official apt repositories or mirrors, the documentation mentions the following commands to add the APT repository on a Debian Buster system:

sudo apt-get install software-properties-common dirmngr
sudo apt-key adv --fetch-keys ''
sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] buster main'

However there's a catch when an outgoing http(s) proxy is used!

apt-key error: unable to fetch URI

When using an outgoing http proxy, the apt-key adv command fails, even though APT's configuration contains a valid configuration for using a http proxy:

root@debian:~# cat /etc/apt/apt.conf.d/10proxy
Acquire::http::Proxy "";
Acquire::https::Proxy "";

root@debian:~# sudo apt-key adv --fetch-keys ''
Executing: /tmp/apt-key-gpghome.3k01JC7Nya/ --fetch-keys
gpg: requesting key from ''
gpg: WARNING: unable to fetch URI Connection refused

It seems as if apt-key is ignoring the proxy configuration. The same error also happens when using the http proxy in environment variable:

root@debian:~# export https_proxy=
root@debian:~# export http_proxy=
root@debian:~# sudo apt-key adv --fetch-keys ''
Executing: /tmp/apt-key-gpghome.ZzWxUKXMku/ --fetch-keys
gpg: requesting key from ''
gpg: WARNING: unable to fetch URI Connection refused

So is apt-key actually ignoring all http proxy settings?

Kind of yes, kind of no.

http vs. hkp

The APT proxy settings and http proxy environment variables are applied when accessing URLs starting with http:// or https:// - using the http or https protocols. But fetching the apt keys is using a different protocol in the background: hkp (the OpenPGP HTTP Keyserver Protocol). Although hkp (or hkps) use the same ports as http and https, the protocol is different and this causes to "ignore" the http/https proxy settings.

Using proxy server in hkp request

But how does one tell the apt-key command to use a http proxy instead? The best way found so far is the accepted solution, provided by Rui F. Ribeiro, on the StackExchange question: debian - Unable to add gpg key with apt-key behind a proxy. By appending the parameter --keyserver-options, a http-proxy can be defined. But in that example the apt-key command actually connected to a keyserver using the --keyserver parameter. For the MariaDB case above, the GPG key is directly requested without going through a keyserver. Can this still be applied? Yes!

Looking for MariaDB GPG results in a dedicated MariaDB KB article: GPG. Here the relevant information about the used GPG keys (to sign the packages) are shown, including the relevant GPG Key ID on the Ubuntu keyservers:

With this information, we can now run apt-key command again with the http-proxy option:

root@debian:~# sudo apt-key adv --keyserver --keyserver-options http-proxy= --recv-keys 0xF1656F24C74CD1D8
Executing: /tmp/apt-key-gpghome.02G0vZChBs/ --keyserver --keyserver-options http-proxy= --recv-keys 0xF1656F24C74CD1D8
gpg: key F1656F24C74CD1D8: public key "MariaDB Signing Key <>" imported
gpg: Total number processed: 1
gpg:               imported: 1


Add a comment

Show form to leave a comment

Comments (newest first)

No comments yet.