Merge branch '__apt_key_mktemp_gpghome' into 'master'

__apt_key: use mktemp for unique temporary gpg home

See merge request ungleich-public/cdist!812
This commit is contained in:
poljakowski 2019-11-21 17:01:10 +01:00
commit 8efd2681db

View file

@ -61,31 +61,29 @@ EOF
echo "curl -s -L '$uri' | apt-key add -" echo "curl -s -L '$uri' | apt-key add -"
fi fi
elif [ -d "$keydir" ]; then elif [ -d "$keydir" ]; then
tmp='/tmp/cdist_apt_key_tmp'
# we need to kill gpg after 30 seconds, because gpg # we need to kill gpg after 30 seconds, because gpg
# can get stuck if keyserver is not responding. # can get stuck if keyserver is not responding.
# exporting env var and not exit 1, # exporting env var and not exit 1,
# because we need to clean up and kill dirmngr. # because we need to clean up and kill dirmngr.
cat << EOF cat << EOF
mkdir -m 700 -p "$tmp" gpgtmphome="\$( mktemp -d )"
if timeout 30s \\ if timeout 30s \\
gpg --homedir "$tmp" \\ gpg --homedir "\$gpgtmphome" \\
--keyserver "$keyserver" \\ --keyserver "$keyserver" \\
--recv-keys "$keyid" --recv-keys "$keyid"
then then
gpg --homedir "$tmp" \\ gpg --homedir "\$gpgtmphome" \\
--export "$keyid" \\ --export "$keyid" \\
> "$keyfile" > "$keyfile"
else else
export GPG_GOT_STUCK=1 export GPG_GOT_STUCK=1
fi fi
GNUPGHOME="$tmp" gpgconf --kill dirmngr GNUPGHOME="\$gpgtmphome" gpgconf --kill dirmngr
rm -rf "$tmp" rm -rf "\$gpgtmphome"
if [ -n "\$GPG_GOT_STUCK" ] if [ -n "\$GPG_GOT_STUCK" ]
then then