Skip to content

Commit d225311

Browse files
authored
Add caching proxy for libcdb debuginfod files to CI (#2487)
1 parent a3b22b7 commit d225311

File tree

4 files changed

+124
-6
lines changed

4 files changed

+124
-6
lines changed

.github/workflows/ci.yml

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@ jobs:
1212
os: ubuntu-22.04
1313
runs-on: ${{ matrix.os }}
1414
timeout-minutes: 30
15+
services:
16+
libcdb-cache:
17+
image: nginx
18+
volumes:
19+
- /home/runner/libcdb-cache:/var/cache/nginx
20+
ports:
21+
- 3000:3000 # https://debuginfod.elfutils.org proxy cache
22+
- 3001:3001 # https://libc.rip/ proxy cache
23+
- 3002:3002 # http://archive.ubuntu.com/ proxy cache
24+
- 3003:3003 # https://gitlab.com/ proxy cache
25+
env:
26+
DEBUGINFOD_URLS: http://localhost:3000/
27+
PWN_LIBCRIP_URL: http://localhost:3001/
28+
PWN_UBUNTU_ARCHIVE_URL: http://localhost:3002/
29+
PWN_GITLAB_LIBCDB_URL: http://localhost:3003/
1530
steps:
1631
- uses: actions/checkout@v4
1732
with:
@@ -21,6 +36,28 @@ jobs:
2136
run: |
2237
git fetch origin
2338
git log --oneline --graph -10
39+
40+
- name: Fix libcdb-cache permissions
41+
id: fix-perms
42+
run: |
43+
sudo chown -R runner:runner /home/runner/libcdb-cache
44+
echo "date=$(/bin/date -u "+%Y%m%d%H%M%S")" >> $GITHUB_OUTPUT
45+
46+
- name: Cache for libcdb requests
47+
uses: actions/cache@v4
48+
with:
49+
path: ~/libcdb-cache
50+
key: libcdb-python${{ matrix.python_version }}-${{ steps.fix-perms.outputs.date }}
51+
restore-keys: |
52+
libcdb-python${{ matrix.python_version }}-
53+
libcdb-
54+
55+
- name: Install libcdb-cache service config
56+
run: |
57+
sudo chown -R 101:101 /home/runner/libcdb-cache
58+
container_id=$(docker ps --all --filter volume=/home/runner/libcdb-cache --no-trunc --format "{{.ID}}")
59+
docker cp ./travis/libcdb_nginx_cache.conf $container_id:/etc/nginx/nginx.conf
60+
docker restart $container_id
2461
2562
- name: Install RPyC for gdb
2663
run: |
@@ -29,11 +66,10 @@ jobs:
2966
sudo apt-get update && sudo apt-get install -y python3-pip gdb gdbserver
3067
/usr/bin/python -m pip install --break-system-packages rpyc || /usr/bin/python -m pip install rpyc
3168
gdb --batch --quiet --nx --nh --ex 'py import rpyc; print(rpyc.version.version)'
32-
69+
3370
- name: Cache for pip
3471
uses: actions/cache@v4
3572
if: matrix.python_version == '2.7'
36-
id: cache-pip
3773
with:
3874
path: ~/.cache/pip
3975
key: ${{ matrix.os }}-${{ matrix.python_version }}-cache-pip-${{ hashFiles('**/pyproject.toml', '**/requirements*.txt') }}
@@ -224,6 +260,12 @@ jobs:
224260
name: coverage-${{ matrix.python_version }}
225261
path: .coverage*
226262
include-hidden-files: true
263+
264+
- name: Fix libcdb-cache permissions
265+
run: |
266+
container_id=$(docker ps --filter volume=/home/runner/libcdb-cache --no-trunc --format "{{.ID}}")
267+
docker stop $container_id
268+
sudo chown -R runner:runner /home/runner/libcdb-cache
227269
228270
windows-test:
229271
runs-on: windows-latest

pwnlib/dynelf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ def _dynamic_load_dynelf(self, libname):
652652
break
653653

654654
if name:
655-
self.status('Skipping %s' % name)
655+
self.status('Skipping %r' % name)
656656

657657
cur = leak.field(cur, LinkMap.l_next)
658658
else:

pwnlib/libcdb.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ def _turbofast_extract_build_id(path):
7272
urls = os.environ['DEBUGINFOD_URLS'].split(' ')
7373
DEBUGINFOD_SERVERS = urls + DEBUGINFOD_SERVERS
7474

75+
# Allow to override url with a caching proxy in CI
76+
LIBC_RIP_URL = os.environ.get("PWN_LIBCRIP_URL", "https://libc.rip").rstrip("/")
77+
GITLAB_LIBCDB_URL = os.environ.get("PWN_GITLAB_LIBCDB_URL", "https://gitlab.com").rstrip("/")
78+
7579
# Retry failed lookups after some time
7680
NEGATIVE_CACHE_EXPIRY = 60 * 60 * 24 * 7 # 1 week
7781

@@ -86,7 +90,7 @@ def provider_libcdb(hex_encoded_id, search_type):
8690
from six.moves import urllib
8791

8892
# Build the URL using the requested hash type
89-
url_base = "https://gitlab.com/libcdb/libcdb/raw/master/hashes/%s/" % search_type
93+
url_base = "{}/libcdb/libcdb/raw/master/hashes/{}/".format(GITLAB_LIBCDB_URL, search_type)
9094
url = urllib.parse.urljoin(url_base, hex_encoded_id)
9195

9296
data = b""
@@ -111,7 +115,7 @@ def query_libc_rip(params):
111115
# Deferred import because it's slow
112116
import requests
113117

114-
url = "https://libc.rip/api/find"
118+
url = "{}/api/find".format(LIBC_RIP_URL)
115119
try:
116120
result = requests.post(url, json=params, timeout=20)
117121
result.raise_for_status()
@@ -143,6 +147,7 @@ def provider_libc_rip(search_target, search_type):
143147

144148
url = libc_match[0]['download_url']
145149
log.debug("Downloading data from libc.rip: %s", url)
150+
url = url.replace("https://libc.rip", LIBC_RIP_URL)
146151
data = wget(url, timeout=20)
147152

148153
if not data:
@@ -529,7 +534,9 @@ def _find_libc_package_lib_url(libc):
529534
libc_match = query_libc_rip({'buildid': enhex(libc.buildid)})
530535
if libc_match is not None:
531536
for match in libc_match:
532-
yield match['libs_url']
537+
# Allow to override url with a caching proxy in CI
538+
ubuntu_archive_url = os.environ.get('PWN_UBUNTU_ARCHIVE_URL', 'http://archive.ubuntu.com').rstrip('/')
539+
yield match['libs_url'].replace('http://archive.ubuntu.com', ubuntu_archive_url)
533540

534541
# Check launchpad.net if it's an Ubuntu libc
535542
# GNU C Library (Ubuntu GLIBC 2.36-0ubuntu4)

travis/libcdb_nginx_cache.conf

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
events {
2+
worker_connections 1024;
3+
}
4+
5+
http {
6+
proxy_cache_path /var/cache/nginx keys_zone=my_cache:1m max_size=1g inactive=12w use_temp_path=off;
7+
log_format cache_st '$remote_addr - $remote_user - $upstream_cache_status [$time_local] '
8+
'"$request" $status $body_bytes_sent '
9+
'"$http_referer" "$http_user_agent"';
10+
access_log /dev/stdout cache_st;
11+
12+
server {
13+
listen 3000;
14+
proxy_cache my_cache;
15+
16+
location / {
17+
proxy_set_header Host debuginfod.elfutils.org;
18+
proxy_cache_revalidate on;
19+
proxy_cache_key $scheme://$host$uri$is_args$query_string;
20+
proxy_cache_valid 200 404 12w;
21+
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504 http_429;
22+
proxy_pass https://debuginfod.elfutils.org/;
23+
}
24+
}
25+
26+
server {
27+
listen 3001;
28+
proxy_cache my_cache;
29+
30+
location / {
31+
proxy_set_header Host libc.rip;
32+
proxy_cache_methods GET HEAD POST;
33+
proxy_cache_revalidate on;
34+
proxy_cache_key $scheme://$host$uri$is_args$query_string$request_body;
35+
proxy_cache_valid 200 404 12w;
36+
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504 http_429;
37+
proxy_pass https://libc.rip/;
38+
}
39+
}
40+
41+
server {
42+
listen 3002;
43+
proxy_cache my_cache;
44+
45+
location / {
46+
proxy_set_header Host archive.ubuntu.com;
47+
proxy_cache_revalidate on;
48+
proxy_cache_key $scheme://$host$uri$is_args$query_string;
49+
proxy_cache_valid 200 404 12w;
50+
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504 http_429;
51+
proxy_pass http://archive.ubuntu.com/;
52+
}
53+
}
54+
55+
server {
56+
listen 3003;
57+
proxy_cache my_cache;
58+
59+
location / {
60+
proxy_set_header Host gitlab.com;
61+
proxy_ssl_server_name on;
62+
proxy_cache_revalidate on;
63+
proxy_cache_key $scheme://$host$uri$is_args$query_string;
64+
proxy_cache_valid 200 404 12w;
65+
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504 http_429;
66+
proxy_pass https://gitlab.com/;
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)