Skip to content

Instantly share code, notes, and snippets.

@grepson
Last active February 6, 2025 20:45
Show Gist options
  • Save grepson/c68e8d12dff076d936286364cd21601c to your computer and use it in GitHub Desktop.
Save grepson/c68e8d12dff076d936286364cd21601c to your computer and use it in GitHub Desktop.
Dyrector.io worker node inject custom Certificate Authority (CA)
#!/bin/bash
# This script takes the string that dyrector.io gives when setting up new node and injects custom Certificate Authority
# to docker image provided by dyrectorio. Please use full script given by director.io in <dyrectorio_curl_url>
# USAGE: script.sh <dyrectorio_curl_url> <CA_path>
# Check if the URL is provided as the first argument
if [ $# -eq 0 ]; then
echo "Error: Please provide the full curl command as an argument"
exit 1
fi
# Extract the URL from the provided curl command
url=$(echo "$1" | grep -oP 'https://[^\s]+')
if [ -z "$url" ]; then
echo "Error: Could not extract URL from the provided command"
exit 1
fi
# Download the script
echo "Downloading script from $url"
script_content=$(curl -sL "$url")
if [ -z "$script_content" ]; then
echo "Error: Failed to download the script"
exit 1
fi
# Find the line with the dagent image
dagent_line=$(echo "$script_content" | grep -P 'ghcr\.io/dyrector-io/dyrectorio/agent/dagent:latest')
if [ -z "$dagent_line" ]; then
echo "Error: Could not find dagent image line"
exit 1
fi
# Create a modified script, replace base image
modified_script=$(echo "$script_content" | sed "s|ghcr.io/dyrector-io/dyrectorio/agent/dagent:latest|dagent_ssl:latest|g")
certname=$(basename "$2")
# Add certificate environment variable (dagent is GO container)
modified_script=$(echo "$modified_script" | \
sed -e "/if ! false; then/,/fi/d" \
-e "/-e GRPC_TOKEN=/a \\\
-e SSL_CERT_FILE=/usr/local/share/ca-certificates/$certname \\\\")
# Create a Dockerfile for the custom CA version
cat > dagent_ssl.Dockerfile << EOF
FROM ghcr.io/dyrector-io/dyrectorio/agent/dagent:latest
COPY $2 /usr/local/share/ca-certificates/
EOF
# Build the custom dagent image
docker build -t dagent_ssl:latest -f dagent_ssl.Dockerfile --no-cache .
# Clean up the Dockerfile
#rm -f dagent_ssl.Dockerfile
# Save the modified script
echo "$modified_script" > dagent_ssl.sh
chmod +x dagent_ssl.sh
echo "Script modification complete:"
echo "1. Created Dockerfile.dagent_ssl with custom CA"
echo "2. Built dagent_ssl:latest image"
echo "3. Created modified_script.sh with updated image reference"
# Optional: Uncomment the next line if you want to run the modified script automatically
# ./modified_script.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment