Add Cloudflares repository during build

Hi there.

I’m really struggling to add cloudflares repository and install cloudflared during iso build.

Below is the instructions to add their repository. I’m really struggling with the cloudflare-main.gpg file. Where should i place it? and what is the path for it when im going to refer to it with --custom-apt-entry

EDIT: Forgot to mention that i’m building in docker

Thanks in advance :slight_smile:

Debian Buster
# Add cloudflare gpg key
sudo mkdir -p --mode=0755 /usr/share/keyrings
curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg | sudo tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null

# Add this repo to your apt repositories
echo 'deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared buster main' | sudo tee /etc/apt/sources.list.d/cloudflared.list

# install cloudflared
sudo apt-get update && sudo apt-get install cloudflared

Im guessing something like this might work:

In the vyos-build clone create this file:

touch data/live-build-config/hooks/live/89-cloudflare.chroot

Then give the 89-cloudflare.chroot file this content:

#!/bin/sh

# Fetch signing key from Cloudflare.
curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg | sudo tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null

# Import the fetched signing key from Cloudflare.
if [ -f /usr/share/keyrings/cloudflare-main.gpg ] ; then
   apt-key add /usr/share/keyrings/cloudflare-main.gpg
else
   echo "ERROR: /usr/share/keyrings/cloudflare-main.gpg is missing!
fi

# Add Cloudflare as apt source.
echo 'deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared bookworm main' | sudo tee /etc/apt/sources.list.d/cloudflared.list

# Install stuff from Cloudflare.
apt-get -y install cloudflared

Then build your iso…

Hi There

I just tried your suggestion. I do however have an issue with the build. It can’t find the cloudflared package. I’m wondering if the repository is saved in the right location during the build?

Warning: apt-key output should not be parsed (stdout is not a terminal)
deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared buster main
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package cloudflared
E: config/hooks/live/89-cloudflare.chroot failed (exit non-zero). You should check for errors.
P: Begin unmounting filesystems...
P: Saving caches...
Reading package lists...
Building dependency tree...
Reading state information...

So in short (if someone finds this thread in future)?

#!/bin/sh

# Fetch signing key from Cloudflare.
curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg | sudo tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null

# Import the fetched signing key from Cloudflare.
if [ -f /usr/share/keyrings/cloudflare-main.gpg ] ; then
   apt-key add /usr/share/keyrings/cloudflare-main.gpg
else
   echo "ERROR: /usr/share/keyrings/cloudflare-main.gpg is missing!
fi

# Add Cloudflare as apt source.
echo 'deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared bookworm main' | sudo tee /etc/apt/sources.list.d/cloudflared.list

# Install stuff from Cloudflare.
apt-get update
apt-get -y install cloudflared

Almost. I have made a few modifications. Pipes are removed and replaced by redirects and i have added a bit of code to make sure the added repository matches the version of Debian used by VyOS.

Here’s the code I ended up with. I have tested it against builds of Equuleus and Sagitta 89-cloudflared.chroot

#!/bin/sh
#
# Purpose: Add Cloudflares repository and install cloudflared during VyOS build
#

# Debian Version
DEBIAN_VERSION=$(lsb_release -cs)

# GPG Key
CF_GPG_KEY="/usr/share/keyrings/cloudflare-main.gpg"

# Fetch signing key from Cloudflare.
curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg -o "${CF_GPG_KEY}"

# Check if cloudflare-main.gpg has been downloaded
if [ ! -f "${CF_GPG_KEY}" ]; then
  echo "ERROR: ${CF_GPG_KEY} is missing!"
  exit
fi

# Import the fetched signing key from Cloudflare.
apt-key add "${CF_GPG_KEY}"

# Add Cloudflare repository.
echo "deb [arch=amd64 signed-by=${CF_GPG_KEY}] https://pkg.cloudflare.com/cloudflared ${DEBIAN_VERSION} main" > /etc/apt/sources.list.d/cloudflared.list

# Install Cloudflared
apt-get update
apt-get -y install cloudflared

Nice!

Personally I would go with ${CF_GPG_KEY} instead of $CF_GPG_KEY but thats me :wink:

1 Like

I will do that and update my answer above… Thank you so much for your help, it’s really appreciated :pray:

1 Like