|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Copyright 2025 HAProxy Technologies |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http:#www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | + |
| 18 | +# This module will launch 2 extra containers needed for ACME tests: |
| 19 | +# - pebble - the "official" ACME test server from LetsEncrypt |
| 20 | +# - challserv - pebble's companion used to fake DNS challenges |
| 21 | +# |
| 22 | +# Those containers can be accessed via their respective variables: |
| 23 | +# - ACME_DIR_CONTAINER_NAME=pebble |
| 24 | +# - ACME_DNS_CONTAINER_NAME=challtestsrv |
| 25 | + |
| 26 | +load '../../libs/haproxy_version' |
| 27 | + |
| 28 | +# ACME is available starting with HAProxy 3.2, |
| 29 | +# but became compatible with pebble in version 3.3. |
| 30 | +ACME=false |
| 31 | +if haproxy_version_ge 3.3; then |
| 32 | + ACME=true |
| 33 | + ACME_DIR_CONTAINER_NAME=pebble |
| 34 | + ACME_DNS_CONTAINER_NAME=challtestsrv |
| 35 | + PEBBLE_IMAGE="ghcr.io/letsencrypt/pebble:latest" |
| 36 | + CHALLTESTSRV_IMAGE="ghcr.io/letsencrypt/pebble-challtestsrv:latest" |
| 37 | +fi |
| 38 | + |
| 39 | +setup_file() { |
| 40 | + $ACME || return 0 |
| 41 | + |
| 42 | + echo '>>> Setting up ACME challtestsrv' >&3 |
| 43 | + # Start challtestsrv -- https://github.com/letsencrypt/pebble/blob/main/cmd/pebble-challtestsrv/README.md |
| 44 | + docker pull "$CHALLTESTSRV_IMAGE" >/dev/null |
| 45 | + docker run -d --name "$ACME_DNS_CONTAINER_NAME" --net "$DOCKER_NETWORK" \ |
| 46 | + -p 5001:5001 -p 5002:5002 -p 5003:5003 -p 8053:8053 -p 8055:8055 \ |
| 47 | + "$CHALLTESTSRV_IMAGE" |
| 48 | + |
| 49 | + echo '>>> Setting up ACME directory: pebble' >&3 |
| 50 | + docker pull "$PEBBLE_IMAGE" >/dev/null |
| 51 | + docker run -d --name "$ACME_DIR_CONTAINER_NAME" --net "$DOCKER_NETWORK" \ |
| 52 | + -p 14000:14000 -p 15000:15000 -v "${E2E_DIR}/fixtures/pebble:/mnt:ro" \ |
| 53 | + -e PEBBLE_VA_NOSLEEP=1 -e PEBBLE_VA_ALWAYS_VALID=1 -e PEBBLE_WFE_NONCEREJECT=0 \ |
| 54 | + "$PEBBLE_IMAGE" -config /mnt/pebble-config.json -strict -dnsserver $ACME_DNS_CONTAINER_NAME:8053 |
| 55 | + sleep 1 |
| 56 | + |
| 57 | + # Allow HAProxy's HTTPS client to connect to Pebble (the fake ACME server) |
| 58 | + docker cp "${E2E_DIR}/fixtures/pebble/pebble.minica.pem" ${DOCKER_CONTAINER_NAME}:/var/lib/haproxy/pebble.minica.pem |
| 59 | +} |
| 60 | + |
| 61 | +teardown_file() { |
| 62 | + $ACME || return 0 |
| 63 | + |
| 64 | + for c in "$ACME_DIR_CONTAINER_NAME" "$ACME_DNS_CONTAINER_NAME"; do |
| 65 | + echo ">>> Shutting down ACME container $c" >&3 |
| 66 | + mkdir -p "$E2E_DIR/logs" |
| 67 | + docker logs "$c" &> "$E2E_DIR/logs/$c.log" |
| 68 | + docker stop "$c" |
| 69 | + docker rm -f "$c" |
| 70 | + done |
| 71 | +} |
0 commit comments