Skip to content

Commit f063ec1

Browse files
authored
Make X509 CodeBuild webhook more resilient (#2680)
### Description of changes: Mainly reorganizes the project to have the x509-limbo and python dependency already setup in a docker container (which will stay updates by our periodic pipeline refreshment). We then use the image and pull in the AWS-LC source and run the harness within that. ### Testing: Verified the changes work with the X509 CodeBuild webhook project. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.
1 parent 5436541 commit f063ec1

File tree

6 files changed

+92
-69
lines changed

6 files changed

+92
-69
lines changed

tests/ci/codebuild/common/run_x509_limbo_reports_target.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ env:
88
GOPROXY: https://proxy.golang.org,direct
99

1010
phases:
11-
install:
12-
commands:
13-
- nohup /usr/bin/dockerd --host=unix:///var/run/docker.sock --host=tcp://127.0.0.1:2375 &
14-
- timeout 15 sh -c "until docker info; do echo .; sleep 1; done"
1511
build:
1612
commands:
1713
- "./${AWS_LC_CI_TARGET}"

tests/ci/docker_images/linux-x86/amazonlinux-2023_base/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ RUN set -ex && \
3333
valgrind \
3434
# valgrind/memcheck.h is provided by the valgrind-devel package on AL2. see P63119011.
3535
valgrind-devel \
36-
unzip && \
36+
unzip \
37+
patch \
38+
jq && \
3739
wget https://raw.githubusercontent.com/aws/aws-codebuild-docker-images/master/al/x86_64/standard/5.0/amazon-ssm-agent.json -P /etc/amazon/ssm/ && \
3840
# Based on https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-linux.html
3941
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0 OR ISC
33

4-
FROM amazonlinux-2023:clang-15x
4+
FROM amazonlinux-2023:gcc-11x
55

66
SHELL ["/bin/bash", "-c"]
77

88
RUN set -ex && \
99
dnf -y upgrade --releasever=latest && dnf install -y \
10-
docker \
11-
openssl-devel \
12-
patch \
13-
jq && \
10+
openssl-devel && \
1411
dnf clean packages && \
1512
dnf clean metadata && \
1613
dnf clean all && \
@@ -21,8 +18,13 @@ RUN curl -fsSL https://pyenv.run | bash
2118

2219
ENV PATH="/root/.pyenv/bin:${PATH}"
2320
RUN eval "$(pyenv init -)" && \
24-
pyenv install 3.13.1
21+
pyenv install 3.13.7
2522

26-
ENV PATH="/root/.pyenv/versions/3.13.1/bin:${PATH}"
27-
ENV CC=clang
28-
ENV CXX=clang++
23+
ENV PATH="/root/.pyenv/versions/3.13.7/bin:${PATH}"
24+
25+
RUN git clone https://github.com/C2SP/x509-limbo.git /x509-limbo && \
26+
cd /x509-limbo && \
27+
python3 -m venv .venv && \
28+
source .venv/bin/activate && \
29+
pip install -e . && \
30+
deactivate

tests/ci/run_x509_limbo.sh

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ source tests/ci/common_posix_setup.sh
1212

1313
SCRATCH_DIR="${SYS_ROOT}/scratch"
1414
X509_CI_DIR="${SRC_ROOT}/tests/ci/x509"
15-
X509_LIMBO_SRC="${SCRATCH_DIR}/x509-limbo"
15+
X509_LIMBO_SRC="${X509_LIMBO_SRC:-/x509-limbo}" # Should be by the docker image
1616
BASE_COMMIT_SRC="${SYS_ROOT}/base-src"
1717

1818
# If BASE_REF is set in the environment we will use that, this provides a mechanism for a user to manually kick off
@@ -23,38 +23,61 @@ BASE_COMMIT_SRC="${SYS_ROOT}/base-src"
2323
BASE_REF="${BASE_REF:-${CODEBUILD_WEBHOOK_BASE_REF:-${CODEBUILD_WEBHOOK_PREV_COMMIT:?}}}"
2424

2525
function build_reporting_tool() {
26-
pushd "${X509_CI_DIR}/limbo-report"
26+
pushd "${X509_CI_DIR}/limbo-report" 2>&1 >/dev/null
2727
make
2828
mv ./limbo-report "${SCRATCH_DIR}/"
29-
popd # "${X509_CI_DIR}/limbo-report"
29+
popd 2>&1 >/dev/null # "${X509_CI_DIR}/limbo-report"
3030
}
3131

3232
function setup_x509_limbo() {
33-
git clone https://github.com/C2SP/x509-limbo.git "${X509_LIMBO_SRC}"
34-
pushd "${X509_LIMBO_SRC}"
33+
pushd "${X509_LIMBO_SRC}" 2>&1 >/dev/null
3534
patch -p1 -i "${X509_CI_DIR}/x509-limbo.patch"
36-
python3 -m venv .venv
37-
source .venv/bin/activate
38-
pip install -e .
39-
popd # "${X509_LIMBO_SRC}"
35+
popd 2>&1 >/dev/null # "${X509_LIMBO_SRC}"
36+
}
37+
38+
function build_aws_lc() {
39+
local BUILD_DIR
40+
BUILD_DIR=$(mktemp -d)
41+
cmake -B "${BUILD_DIR}" -S "${1}" -GNinja \
42+
-DBUILD_SHARED_LIBS=1 \
43+
-DCMAKE_BUILD_TYPE=Debug \
44+
-DCMAKE_INSTALL_PREFIX="${2}"
45+
cmake --build "${BUILD_DIR}"
46+
cmake --install "${BUILD_DIR}"
47+
rm -rf "${BUILD_DIR}"
48+
}
49+
50+
function build_aws_lc_harness() {
51+
local HARNESS_SRC
52+
HARNESS_SRC="${X509_LIMBO_SRC}/harness/aws-lc"
53+
local PKG_CONFIG_PATH
54+
PKG_CONFIG_PATH="${1}/lib64/pkgconfig"
55+
56+
pushd "${HARNESS_SRC}" 2>&1 >/dev/null
57+
PKG_CONFIG_PATH="${PKG_CONFIG_PATH}" make 2>&1 >/dev/null
58+
59+
local HARNESS
60+
HARNESS="$(mktemp harnessXXX)"
61+
62+
mv main "${HARNESS}"
63+
64+
popd 2>&1 >/dev/null # "${HARNESS_SRC}"
65+
66+
echo "${HARNESS_SRC}/${HARNESS}"
4067
}
4168

4269
function run_aws_lc_harness() {
43-
pushd "${X509_LIMBO_SRC}"
70+
pushd "${X509_LIMBO_SRC}" 2>&1 >/dev/null
4471
set +e
45-
AWS_LC_SRC_DIR="${1}" make test-aws-lc
72+
make run ARGS="harness --output ./results/aws-lc.json -- ${1}"
4673
if [ ! -f "${X509_LIMBO_SRC}/results/aws-lc.json" ]; then
47-
echo "Failed to run x509-limbo harness for AWS_LC_SRC_DIR=${1}"
74+
echo "Failed to run x509-limbo harness: ${1}"
4875
exit 1
4976
fi
5077
set -e
51-
popd # "${X509_LIMBO_SRC}"
78+
popd 2>&1 >/dev/null # "${X509_LIMBO_SRC}"
5279
}
5380

54-
# Log Docker hub limit https://docs.docker.com/docker-hub/download-rate-limit/#how-can-i-check-my-current-rate
55-
TOKEN=$(curl "https://auth.docker.io/token?service=registry.docker.io&scope=repository:ratelimitpreview/test:pull" | jq -r .token)
56-
curl --head -H "Authorization: Bearer $TOKEN" https://registry-1.docker.io/v2/ratelimitpreview/test/manifests/latest
57-
5881
git worktree add "${BASE_COMMIT_SRC}" "${BASE_REF:?}"
5982

6083
mkdir -p "${SCRATCH_DIR}"
@@ -68,12 +91,16 @@ REPORTS_DIR="${SRC_ROOT}/x509-limbo-reports"
6891
mkdir -p "${REPORTS_DIR}"
6992

7093
# Build run x509-limbo on current src of event
71-
run_aws_lc_harness "${SRC_ROOT}"
94+
build_aws_lc "${SRC_ROOT}" "/opt/aws-lc-after"
95+
AFTER_HARNESS="$(build_aws_lc_harness "/opt/aws-lc-after")"
96+
run_aws_lc_harness "${AFTER_HARNESS}"
7297
"${SCRATCH_DIR}/limbo-report" annotate "${X509_LIMBO_SRC}/limbo.json" "${X509_LIMBO_SRC}/results/aws-lc.json" > "${REPORTS_DIR}/base.json"
7398
"${SCRATCH_DIR}/limbo-report" annotate -csv "${X509_LIMBO_SRC}/limbo.json" "${X509_LIMBO_SRC}/results/aws-lc.json" > "${REPORTS_DIR}/base.csv"
7499

75100
# Build run x509-limbo on the base src for event
76-
run_aws_lc_harness "${BASE_COMMIT_SRC}"
101+
build_aws_lc "${BASE_COMMIT_SRC}" "/opt/aws-lc-before"
102+
BEFORE_HARNESS="$(build_aws_lc_harness "/opt/aws-lc-before")"
103+
run_aws_lc_harness "${BEFORE_HARNESS}"
77104
"${SCRATCH_DIR}/limbo-report" annotate "${X509_LIMBO_SRC}/limbo.json" "${X509_LIMBO_SRC}/results/aws-lc.json" > "${REPORTS_DIR}/changes.json"
78105
"${SCRATCH_DIR}/limbo-report" annotate -csv "${X509_LIMBO_SRC}/limbo.json" "${X509_LIMBO_SRC}/results/aws-lc.json" > "${REPORTS_DIR}/changes.csv"
79106

tests/ci/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
setuptools.setup(
9-
name="AWS-LC CI",
9+
name="aws-lc-ci",
1010
version="0.0.1",
1111

1212
description="AWS-LC CI python environment.",

tests/ci/x509/x509-limbo.patch

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,5 @@
1-
From c9801cd216fa64be8045d948cc9f73a3fad025a2 Mon Sep 17 00:00:00 2001
2-
From: Sean McGrail <[email protected]>
3-
Date: Mon, 30 Sep 2024 19:29:48 +0000
4-
Subject: [PATCH] Support for AWS Libcrypto (AWS-LC)
5-
6-
---
7-
Makefile | 7 +-
8-
harness/aws-lc/.gitignore | 2 +
9-
harness/aws-lc/Makefile | 26 +
10-
harness/aws-lc/README.md | 26 +
11-
harness/aws-lc/aws-lc.dockerfile | 27 +
12-
harness/aws-lc/date.hpp | 8234 ++++++++++
13-
harness/aws-lc/json.hpp | 24596 +++++++++++++++++++++++++++++
14-
harness/aws-lc/main.cpp | 253 +
15-
8 files changed, 33170 insertions(+), 1 deletion(-)
16-
create mode 100644 harness/aws-lc/.gitignore
17-
create mode 100644 harness/aws-lc/Makefile
18-
create mode 100644 harness/aws-lc/README.md
19-
create mode 100644 harness/aws-lc/aws-lc.dockerfile
20-
create mode 100644 harness/aws-lc/date.hpp
21-
create mode 100644 harness/aws-lc/json.hpp
22-
create mode 100644 harness/aws-lc/main.cpp
23-
241
diff --git a/Makefile b/Makefile
25-
index b81cf83..416c5c8 100644
2+
index ff0e109..53b4611 100644
263
--- a/Makefile
274
+++ b/Makefile
285
@@ -110,8 +110,13 @@ test-certvalidator: $(NEEDS_VENV)
@@ -50,7 +27,7 @@ index 0000000..9bc5102
5027
+results.json
5128
diff --git a/harness/aws-lc/Makefile b/harness/aws-lc/Makefile
5229
new file mode 100644
53-
index 0000000..2305b42
30+
index 0000000..0090d83
5431
--- /dev/null
5532
+++ b/harness/aws-lc/Makefile
5633
@@ -0,0 +1,26 @@
@@ -32990,10 +32967,10 @@ index 0000000..4d1a37a
3299032967
+#endif // INCLUDE_NLOHMANN_JSON_HPP_
3299132968
diff --git a/harness/aws-lc/main.cpp b/harness/aws-lc/main.cpp
3299232969
new file mode 100644
32993-
index 0000000..e4e8519
32970+
index 0000000..ba987cf
3299432971
--- /dev/null
3299532972
+++ b/harness/aws-lc/main.cpp
32996-
@@ -0,0 +1,253 @@
32973+
@@ -0,0 +1,275 @@
3299732974
+#include <cstdlib>
3299832975
+#include <fstream>
3299932976
+#include <iostream>
@@ -33021,6 +32998,7 @@ index 0000000..e4e8519
3302132998
+using STACK_OF_X509_ptr = std::unique_ptr<STACK_OF(X509), decltype(&SK_X509_free)>;
3302232999
+using X509_STORE_ptr = std::unique_ptr<X509_STORE, decltype(&X509_STORE_free)>;
3302333000
+using X509_STORE_CTX_ptr = std::unique_ptr<X509_STORE_CTX, decltype(&X509_STORE_CTX_free)>;
33001+
+using X509_CRL_ptr = std::unique_ptr<X509_CRL, decltype(&X509_CRL_free)>;
3302433002
+
3302533003
+[[noreturn]] void barf(const std::string &msg)
3302633004
+{
@@ -33050,6 +33028,19 @@ index 0000000..e4e8519
3305033028
+ return X509_ptr(cert, X509_free);
3305133029
+}
3305233030
+
33031+
+X509_CRL_ptr pem_to_crl(const std::string &pem)
33032+
+{
33033+
+ X509_CRL *crl = nullptr;
33034+
+ BIO_ptr crl_bio(BIO_new_mem_buf(pem.data(), pem.length()), BIO_free);
33035+
+
33036+
+ if (!PEM_read_bio_X509_CRL(crl_bio.get(), &crl, 0, NULL))
33037+
+ {
33038+
+ barf("failed to parse CRL");
33039+
+ }
33040+
+
33041+
+ return X509_CRL_ptr(crl, X509_CRL_free);
33042+
+}
33043+
+
3305333044
+STACK_OF_X509_ptr x509_stack(const json &certs)
3305433045
+{
3305533046
+ if (!certs.is_array())
@@ -33127,6 +33118,19 @@ index 0000000..e4e8519
3312733118
+ X509_STORE_add_cert(store.get(), cert_x509.get());
3312833119
+ }
3312933120
+
33121+
+ // Add CRLs to the store if present
33122+
+ if (testcase.contains("crls") && !testcase["crls"].empty())
33123+
+ {
33124+
+ for (auto &crl_pem : testcase["crls"])
33125+
+ {
33126+
+ auto crl = pem_to_crl(crl_pem.template get<std::string>());
33127+
+ X509_STORE_add_crl(store.get(), crl.get());
33128+
+ }
33129+
+
33130+
+ // Enable CRL checking
33131+
+ X509_STORE_set_flags(store.get(), X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL);
33132+
+ }
33133+
+
3313033134
+ auto untrusted = x509_stack(testcase["untrusted_intermediates"]);
3313133135
+ auto peer_pem = testcase["peer_certificate"].template get<std::string>();
3313233136
+ auto peer = pem_to_x509(peer_pem);
@@ -33154,11 +33158,6 @@ index 0000000..e4e8519
3315433158
+
3315533159
+ auto param = X509_STORE_CTX_get0_param(ctx.get());
3315633160
+
33157-
+ // The default authentication level is 1, which corresponds to 80 bits
33158-
+ // of security. Level 2 corresponds to 112 bits and includes RSA 2048,
33159-
+ // which brings the validation logic very slightly closer to the Web PKI.
33160-
+ // X509_VERIFY_PARAM_set_auth_level(param, 2);
33161-
+
3316233161
+ if (testcase["expected_peer_name"].is_object())
3316333162
+ {
3316433163
+ auto peer_name = testcase["expected_peer_name"]["value"].template get<std::string>();
@@ -33247,6 +33246,3 @@ index 0000000..e4e8519
3324733246
+
3324833247
+ return 0;
3324933248
+}
33250-
--
33251-
2.40.1
33252-

0 commit comments

Comments
 (0)