Skip to content

eBPF-based security platform

testing: cover S3 export URL and retry edges

John Fastabend905f371eb2b8
diff --git a/testing/otel/t0014-otel-map.sh b/testing/otel/t0014-otel-map.sh
index 3c97083c..51de4b80 100644
--- a/testing/otel/t0014-otel-map.sh
+++ b/testing/otel/t0014-otel-map.sh
@@ -458,6 +458,78 @@ assert m["put_attempts"] == 2 and puts[0]["path"] == puts[1]["path"]
wait $server && test -s s3.log
'
+test_expect_success '--otel=s3 encodes prefixes and falls back to AWS_DEFAULT_REGION' '
+ rm -f s3.port s3.snapshot s3.log s3.meta;
+ python3 ../helper/otel-s3-mock.py success s3.port s3.snapshot s3.log s3.meta &
+ server=$!;
+ i=0; while test ! -s s3.port && test $i -lt 50; do i=$((i+1)); sleep .02; done &&
+ port=$(cat s3.port) &&
+ AWS_ACCESS_KEY_ID=test AWS_SECRET_ACCESS_KEY=secret AWS_REGION= \
+ AWS_DEFAULT_REGION=us-west-2 \
+ SHIRUDO_TEST_S3_URI="s3://test-bucket/prefix with space" \
+ OTEL_EXPORTER_OTLP_LOGS_ENDPOINT="http://127.0.0.1:$port/v1/logs" \
+ "$H" send-s3 "http://127.0.0.1:$port" 0 &&
+ wait $server &&
+ python3 -c '\''
+import json
+m=json.load(open("s3.meta")); put,post=m["requests"]
+assert put["sigv4_valid"] and put["region"] == "us-west-2"
+assert "/prefix%20with%20space/" in put["path"]
+assert post["path"] == "/v1/logs"
+'\''
+'
+
+test_expect_success '--otel=s3 retries each retryable PUT response' '
+ for status in 408 409 500 502 503 504
+ do
+ rm -f s3.port s3.snapshot s3.log s3.meta
+ python3 ../helper/otel-s3-mock.py "s3-retry-$status" s3.port s3.snapshot s3.log s3.meta &
+ server=$!
+ i=0; while test ! -s s3.port && test "$i" -lt 50; do i=$((i+1)); sleep .02; done
+ port=$(cat s3.port) &&
+ AWS_ACCESS_KEY_ID=test AWS_SECRET_ACCESS_KEY=secret AWS_REGION=us-east-1 \
+ OTEL_EXPORTER_OTLP_LOGS_ENDPOINT="http://127.0.0.1:$port/v1/logs" \
+ "$H" send-s3 "http://127.0.0.1:$port" 1 && wait "$server" &&
+ python3 -c '\''import json; assert json.load(open("s3.meta"))["put_attempts"] == 2'\'' || return 1
+ done
+'
+
+test_expect_success '--otel=s3 exhausts PUT retries without posting a reference' '
+ rm -f s3.port s3.snapshot s3.log s3.meta;
+ python3 ../helper/otel-s3-mock.py s3-exhaust s3.port s3.snapshot s3.log s3.meta &
+ server=$!;
+ i=0; while test ! -s s3.port && test $i -lt 50; do i=$((i+1)); sleep .02; done &&
+ port=$(cat s3.port) &&
+ ! AWS_ACCESS_KEY_ID=test AWS_SECRET_ACCESS_KEY=secret AWS_REGION=us-east-1 \
+ OTEL_EXPORTER_OTLP_LOGS_ENDPOINT="http://127.0.0.1:$port/v1/logs" \
+ "$H" send-s3 "http://127.0.0.1:$port" 1 &&
+ wait $server &&
+ python3 -c '\''
+import json
+m=json.load(open("s3.meta"))
+assert m["put_attempts"] == 2
+assert all(r["method"] == "PUT" for r in m["requests"])
+'\''
+'
+
+test_expect_success '--otel=s3 retries collector reference without uploading twice' '
+ rm -f s3.port s3.snapshot s3.log s3.meta;
+ python3 ../helper/otel-s3-mock.py otel-retry s3.port s3.snapshot s3.log s3.meta &
+ server=$!;
+ i=0; while test ! -s s3.port && test $i -lt 50; do i=$((i+1)); sleep .02; done &&
+ port=$(cat s3.port) &&
+ AWS_ACCESS_KEY_ID=test AWS_SECRET_ACCESS_KEY=secret AWS_REGION=us-east-1 \
+ OTEL_EXPORTER_OTLP_LOGS_ENDPOINT="http://127.0.0.1:$port/v1/logs" \
+ "$H" send-s3 "http://127.0.0.1:$port" 1 &&
+ wait $server &&
+ python3 -c '\''
+import json
+m=json.load(open("s3.meta"))
+assert m["put_attempts"] == 1
+assert sum(r["method"] == "POST" for r in m["requests"]) == 2
+'\''
+'
+
test_expect_success '--otel=s3 preserves upload-before-reference failure ordering' '
rm -f s3.port s3.snapshot s3.log s3.meta;
python3 ../helper/otel-s3-mock.py s3-fail s3.port s3.snapshot s3.log s3.meta &
diff --git a/testing/otel/test.plan.md b/testing/otel/test.plan.md
new file mode 100644
index 00000000..6e354e9b
--- /dev/null
+++ b/testing/otel/test.plan.md
@@ -0,0 +1,41 @@
+# OTEL test plan
+
+## Scope
+
+This plan records coverage for OpenTelemetry export across host-side serialization and transport, target map export, status keepalives, systemd/package wiring, and the shared TLS policy. Tests live primarily in `testing/otel/`; related coverage includes `testing/t0030-tls-policy.sh`, `testing/t0005-upatch-decoders.sh`, and `testing/fuzz/fuzz-otel.c`.
+
+## Coverage
+
+| Area | Checks |
+| --- | --- |
+| CLI and configuration | Invalid OTEL option combinations; map-export defaults, valid values, invalid values, bounds, unknown keys, tenant ID syntax, and duplicate handling. |
+| Map classification and local rendering | Structural classification of unsigned per-CPU integer maps as metrics and other map categories as logs; aligned per-CPU strides in local JSON and OTLP log output. |
+| OTLP payloads | Nested log body and map/upatch attributes; absent location; gauge and cumulative monotonic counter payloads; metric start time; selected logs/metrics paths and endpoint suffixing. |
+| OTLP transport | JSON requests, decoded authorization, gzip, retry success, retryable status matrix (429/502/503/504), fatal statuses, retry exhaustion, partial rejection, zero-rejection partial success, malformed response, disconnect, timeout, delta/date `Retry-After` and cap, loopback cleartext policy, HTTPS verification and insecure override. |
+| OTEL environment | Signal-specific endpoint, protocol, compression, and headers override generic values; explicit custom endpoints and base URL signal suffix behavior. |
+| Payload limits | Decoded record and OTLP request accepted at and above a measured boundary, rejected one byte below, with no HTTP request for rejected payloads. Mock records decoded payload size after gzip. |
+| Tenant handling | Header decoding and validation, configured tenant and CLI override on target mixed log/metric `--all`, and no tenant leakage into S3 PUT while applying it to the OTLP reference. |
+| S3 export | Credential and bucket/region validation; path traversal and query rejection; escaped prefix; `AWS_DEFAULT_REGION` fallback; gzip snapshot, digest/checksum, SigV4, session token and metadata; compact reference; large serialized snapshot; retryable PUT status matrix (408/409/429/500/502/503/504), duplicate object, exhausted retries, reference retry without duplicate upload, and upload/reference failure ordering. |
+| Status keepalive | Deterministic severity/body mapping for all documented statuses; status/version fields; no stdout output; JSON output retained with `--json --otel`; no implicit endpoint when none is configured. |
+| Target map export | Detailed JSON records, JSON-lines append and I/O failure, mixed log/metric automatic export, CLI endpoint over config, and tenant propagation. |
+| Target service and timer | Installed map-export service delivers decoder-backed maps; slow collector fixture checks the timer does not overlap an active export. |
+| Serialized metrics | Two serializer pages, repeated peek, drain, subsequent empty interval, reload reset, and service export of decoder-backed cumulative metrics. |
+| Services and packaging | Static service/timer ordering, conditions, environment file, command, cadence, install paths, operator exclusion, and Debian/RPM scriptlets. |
+| TLS policy | `testing/t0030-tls-policy.sh` covers shared TLS policy; OTEL host tests independently check certificate verification and insecure mode where TLS prerequisites are available. |
+
+## Remaining gaps
+
+The suggested execution order has been implemented. Useful follow-up coverage remains:
+
+1. Full endpoint precedence across CLI, signal-specific environment, generic environment, config, and defaults, plus separate metrics-signal precedence.
+2. OTEL endpoint precedence for signal-specific CA, client certificate/key, timeout, and header edge cases such as malformed escapes, reserved names, and duplicate tenant sources.
+3. Exact payload-schema assertions for every documented resource, scope, map attribute, metric name/kind combination, and multiple datapoints; broader empty/large/signed map fixtures.
+4. Target export failure/drain behavior across timer intervals, timer-delivered keepalive integration, optional system fields, and service failure status reporting.
+5. S3 `AWS_CA_BUNDLE` TLS verification, partial collector reference responses, and exact reference/snapshot size metadata assertions.
+6. Explicit upper bound and malformed configuration tests for transport timeouts, response-buffer boundary cases, and compression-size semantics beyond the current decoded payload assertions.
+
+These are coverage opportunities, not findings that the implementation is incorrect. Do not count prerequisite-skipped TLS or target tests as exercising their assertions.
+
+## Test commands
+
+Host coverage is selected by `testing/run-tests.sh` (`testing/otel/t0[0-9][0-9]-*.sh`). Target integration scripts `t1115`, `t1116`, and `t1117` require an initialized test VM and fixtures in `SHIRUDO_TEST_FIXTURES_DIR`. The shared TLS test is `testing/t0030-tls-policy.sh`. Run with the repository's documented `make -C testing test-op` and target harness when runtime validation is requested.
diff --git a/util/upatch_maps_otel.c b/util/upatch_maps_otel.c
index d6f5bdb9..8e90d1ed 100644
--- a/util/upatch_maps_otel.c
+++ b/util/upatch_maps_otel.c
@@ -2325,8 +2325,12 @@ static int parse_s3_spec(struct otel_s3_state *st, const char *spec)
if ((__u8)prefix[i] < 0x20 || prefix[i] == '?' ||
prefix[i] == '#')
return -EINVAL;
- if (prefix[i] == '.' && (i == 0 || prefix[i - 1] == '/') &&
- (i + 1 == prefix_len || prefix[i + 1] == '/'))
+ if ((prefix[i] == '.' && (i == 0 || prefix[i - 1] == '/') &&
+ (i + 1 == prefix_len || prefix[i + 1] == '/')) ||
+ (prefix[i] == '.' && i + 1 < prefix_len &&
+ prefix[i + 1] == '.' &&
+ (i == 0 || prefix[i - 1] == '/') &&
+ (i + 2 == prefix_len || prefix[i + 2] == '/')))
return -EINVAL;
}
memcpy(st->prefix, prefix, prefix_len);