Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions .github/workflows/go-sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,11 @@ on:
push:
branches:
- "master"
- "sdk-go"
paths:
- "tng-go/**"
- "tng/**"
- "Cargo.toml"
- "Cargo.lock"
- ".github/workflows/go-sdk.yml"
tags:
- "v*.*.*"
pull_request:
branches:
- "master"
- "sdk-go"
paths:
- "tng-go/**"
- "tng/**"
- "Cargo.toml"
- "Cargo.lock"
- ".github/workflows/go-sdk.yml"

jobs:
go-sdk-tests:
Expand All @@ -39,7 +27,15 @@ jobs:
set -x
sed -i -E 's|https?://mirrors.openanolis.cn/anolis/|https://mirrors.aliyun.com/anolis/|g' /etc/yum.repos.d/*.repo
sed -i -E 's|https?://mirrors.cloud.aliyuncs.com/|https://mirrors.aliyun.com/|g' /etc/yum.repos.d/*.repo
yum install -y git make tar clang protobuf-devel jq iptables
# openssl-sys builds OpenSSL from source (vendored) because the
# builtin-as-tdx-rust (dcap-qvl) backend pulls it in; OpenSSL 3.5.x's
# `Configure` requires the IPC::Cmd and Time::Piece Perl modules,
# which on alinux (an8-based) live in their own `perl-IPC-Cmd` and
# `perl-Time-Piece` packages (FindBin / File::Compare / File::Copy
# ship with the base perl-interpreter already present). Without these,
# `perl ./Configure` aborts with "Can't locate IPC/Cmd.pm" /
# "Can't locate Time/Piece.pm".
yum install -y git make tar clang protobuf-devel jq iptables perl-IPC-Cmd perl-Time-Piece

- uses: dtolnay/rust-toolchain@1.89.0

Expand Down
67 changes: 0 additions & 67 deletions .github/workflows/shell-scripts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,70 +30,3 @@ jobs:
echo "=== Checking $f ==="
shellcheck "$f"
done

setup-vendor-config:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6

- name: Run setup-vendor-config tests
run: |
set -e
SCRIPT="scripts/setup-vendor-config"
chmod +x "$SCRIPT"

echo "=== Test: --help exits 0 ==="
"$SCRIPT" --help > /dev/null

echo "=== Test: --list shows aliyun ==="
"$SCRIPT" --list | grep -q "aliyun"

echo "=== Test: aliyun --dry-run exits 0 ==="
"$SCRIPT" aliyun --dry-run > /dev/null

echo "=== Test: aliyun --region cn-beijing --dry-run ==="
output=$("$SCRIPT" aliyun --region cn-beijing --dry-run)
echo "$output" | grep -q "cn-beijing"
echo "$output" | grep -q "cn-beijing.aliyuncs.com"

echo "=== Test: unknown vendor fails ==="
! "$SCRIPT" unknown 2>/dev/null

echo "=== Test: no args fails ==="
! "$SCRIPT" 2>/dev/null

echo "=== Test: unknown option fails ==="
! "$SCRIPT" --foobar 2>/dev/null

echo "=== Test: --region without value fails ==="
! "$SCRIPT" aliyun --region 2>/dev/null

echo "=== Test: --internal without --region fails ==="
! "$SCRIPT" aliyun --internal 2>/dev/null

echo "=== Test: --internal with --region uses VPC endpoint ==="
output=$("$SCRIPT" aliyun --internal --region cn-hangzhou --dry-run)
echo "$output" | grep -q "sgx-dcap-server-vpc.cn-hangzhou.aliyuncs.com"
echo "$output" | grep -q "internal (VPC)"

echo "=== Test: public endpoint (default) ==="
output=$("$SCRIPT" aliyun --region cn-beijing --dry-run)
echo "$output" | grep -q "sgx-dcap-server.cn-beijing.aliyuncs.com"
echo "$output" | grep -q "Endpoint: public"

echo "=== Test: apply and verify config ==="
# Create a temp config file for testing
tmp_conf=$(mktemp)
cat > "$tmp_conf" <<'EOF'
# PCCS server address
PCCS_URL=https://localhost:8081/sgx/certification/v4/
USE_SECURE_CERT=TRUE
EOF

# Use sed with a modified CONFIG_FILE via env override approach
# Since the script hardcodes CONFIG_FILE, we test via dry-run output instead
output=$("$SCRIPT" aliyun --region cn-hangzhou --dry-run)
echo "$output" | grep -q "cn-hangzhou.aliyuncs.com"

echo "All tests passed!"
36 changes: 36 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ When creating or amending commits:

- **Author and committer** must always be taken from the local git config (`git config user.name` / `git config user.email`). Never use Claude's own identity.
- **Never** add `Co-Authored-By:` trailers of any kind.
- **Always** add an `Assisted-by:` trailer to every commit message that Claude authored or co-authored. The trailer is the *only* accepted form of AI attribution. Format:

```
Assisted-by: AGENT_NAME:MODEL_VERSION [TOOL1] [TOOL2] ...
```

Where `AGENT_NAME` is the AI tool name (e.g. `Claude`), `MODEL_VERSION` is the specific model version used (e.g. `claude-opus-4-8`), and the optional bracketed `[TOOL]` entries are specialized analysis tools employed in producing the change (e.g. `coccinelle`, `sparse`, `smatch`, `clang-tidy`). Basic development tools (`git`, `gcc`, `make`, editors) must **not** be listed. Place the trailer as the last line(s) of the commit message body, separated by a blank line from the rest of the message. Example:

```
Assisted-by: Claude:claude-opus-4-8 clang-tidy
```

Only one `Assisted-by:` trailer per commit. If no specialized tool was used, omit the bracketed list entirely (`Assisted-by: Claude:claude-opus-4-8`).
- **Never** include any Claude session URLs, session IDs, or links to claude.ai in commit messages or PR descriptions. Commit messages should only describe the code changes.
- **Never** include "🤖 Generated with [Claude Code](https://claude.com/claude-code)" or similar AI attribution footers in PR descriptions or commit messages.
- **Always** use `--no-gpg-sign` to avoid GPG signing.
Expand Down Expand Up @@ -138,6 +151,29 @@ git filter-branch -f --msg-filter 'sed "/Co-Authored-By:/d"' --env-filter '
' <base-commit>..HEAD
```

This rewrites `Co-Authored-By` trailers (forbidden) but **preserves** `Assisted-by:` trailers (expected) — the `sed` only deletes `Co-Authored-By:` lines, so `Assisted-by:` survives untouched. After rewriting, confirm every AI-authored commit still carries its `Assisted-by:` trailer before pushing.


## GitHub Actions Workflow Triggers

When creating or editing `.github/workflows/*.yml`, follow the repo-wide trigger convention: every workflow triggers on `push` to `master` (and tags `v*.*.*`) and on `pull_request` targeting `master` — **without** a `paths:` filter.

**Never add a `paths:` filter** to gate a workflow on a subset of changed files. A `paths` filter silently skips the job when a change lands outside the listed globs — and because tests transitively depend on files outside their own directory (e.g. the Go SDK tests run `cargo test --package tng-testsuite --features go-sdk`, so they also depend on `tng-testsuite/`, `rats-cert/`, the `tng` binary, etc.), a `paths` filter limited to `tng-go/**` lets a real regression ship undetected. Triggering on every push/PR to `master` costs more CI minutes but closes that gap — the tradeoff is intentional.

Do not add per-feature legacy branch triggers (e.g. `sdk-go`) either; `master` is the only branch these workflows target. The canonical `on:` block is:

```yaml
on:
push:
branches:
- "master"
tags:
- "v*.*.*"
pull_request:
branches:
- "master"
```


## API Compatibility

Expand Down
5 changes: 0 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ COPY --from=builder /usr/local/cargo/bin/tng /usr/local/bin/tng
RUN mkdir -p /usr/lib/tng/
COPY --from=builder /code/target/release/libtng_hook.so /usr/lib/tng/libtng_hook.so

# Install vendor config setup tool
COPY scripts/setup-vendor-config /usr/local/bin/setup-vendor-config
RUN chmod +x /usr/local/bin/setup-vendor-config

# install jq for custome shell script
RUN yum install -y jq

CMD ["tng"]
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,27 @@ create-tarball:
# copy untracked (new) files that are not ignored
if [ -n "$$(git ls-files --others --exclude-standard)" ] ; then git ls-files --others --exclude-standard -z | xargs -0 tar -c -f - | tar -x -f - -C /tmp/trusted-network-gateway-tarball/trusted-network-gateway-${VERSION}/src/ ; fi

# attestation-service is a git dep (trustee) that `cargo vendor` packages as just
# its crate dir (vendor/attestation-service-0.1.0/). Its build.rs compiles
# ../protos/reference.proto, but protos/ lives outside the package in the trustee
# repo, so `cargo vendor` omits it and the offline (vendored) build then fails with
# "protoc failed: ../protos/reference.proto: No such file or directory". Extract
# protos/ at the exact rev pinned in Cargo.lock from cargo's trustee git db into
# the vendor dir, so ../protos/ resolves from the vendored crate dir. (Non-vendored
# builds work because the full git checkout keeps protos/ as a sibling.)
@TRUSTEE_REV=$$(sed -n 's|.*trustee/?rev=\([a-f0-9]\{40\}\).*|\1|p' Cargo.lock | head -1); \
PROTOS_OK=0; \
for db in $${CARGO_HOME:-$$HOME/.cargo}/git/db/trustee-*; do \
[ -d "$$db" ] || continue; \
if git --git-dir="$$db" cat-file -e "$$TRUSTEE_REV" 2>/dev/null; then \
git --git-dir="$$db" archive "$$TRUSTEE_REV" protos \
| tar -x -C /tmp/trusted-network-gateway-tarball/trusted-network-gateway-${VERSION}/vendor/ \
&& PROTOS_OK=1 && break; \
fi; \
done; \
[ "$$PROTOS_OK" = 1 ] && [ -f /tmp/trusted-network-gateway-tarball/trusted-network-gateway-${VERSION}/vendor/protos/reference.proto ] \
|| { echo "ERROR: could not extract trustee protos/ for vendored attestation-service (rev $$TRUSTEE_REV)"; exit 1; }

# delete all checksum (this is required due to previous patch work)
sed -i 's/checksum = ".*//g' /tmp/trusted-network-gateway-tarball/trusted-network-gateway-${VERSION}/src/Cargo.lock

Expand Down
7 changes: 5 additions & 2 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1246,9 +1246,12 @@ The **Verifier** receives and verifies Evidence from the Attester, only recogniz
When `as_type` = `"builtin"`, TNG uses the built-in AS to verify Evidence locally without connecting to an external AS. This is suitable for network-isolated, latency-sensitive, or simplified deployment scenarios.

> [!NOTE]
> Builtin mode requires compiling with the corresponding TEE feature enabled (`builtin-as-tdx`, `builtin-as-sgx`, or `builtin-as-snp`). GitHub CI-built RPM packages and binary artifacts do not support this mode; only container images support it.
> To verify TDX Evidence, TNG fetches TDX/SGX collateral directly over HTTPS from a PCCS (Provisioning Certificate Caching Service). Set the `PCCS_URL` environment variable to your cloud provider's PCCS; if unset, it defaults to the Alibaba Cloud PCCS (`https://sgx-dcap-server.cn-beijing.aliyuncs.com`). Both bare-host (`https://sgx-dcap-server.cn-hangzhou.aliyuncs.com`) and path-suffixed (`https://sgx-dcap-server.cn-hangzhou.aliyuncs.com/sgx/certification/v4/`) forms are accepted — the backend normalizes the path. Common Alibaba Cloud endpoints:
>
> For SGX/TDX builtin AS mode, you also need to configure the PCCS URL in `/etc/sgx_default_qcnl.conf` for your cloud provider. See the [Vendor Configuration Setup](setup-vendor-config.md) guide for details.
> | Endpoint | `PCCS_URL` |
> |---|---|
> | Public (region-specific) | `https://sgx-dcap-server.<region>.aliyuncs.com` |
> | VPC internal | `https://sgx-dcap-server-vpc.<region>.aliyuncs.com` |

**PolicyConfig (OPA Policy):**

Expand Down
7 changes: 5 additions & 2 deletions docs/configuration_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -1256,9 +1256,12 @@ Passport 模式适用于网络隔离或性能要求较高的场景,因为它
`as_type` = `"builtin"` 时,TNG 使用内置 AS 在本地直接验证 Evidence,无需连接外部 AS。适用于网络隔离、延迟敏感或简化部署的场景。

> [!NOTE]
> Builtin 模式需在编译时启用对应 TEE 特性(`builtin-as-tdx`、`builtin-as-sgx` 或 `builtin-as-snp`)。GitHub CI 构建的 RPM 包和二进制产物不支持此模式,仅容器镜像支持。
> 当验证TDX Evidence时,TNG会通过 HTTPS 直接从 PCCS(Provisioning Certificate Caching Service)拉取 TDX/SGX collateral。将 `PCCS_URL` 环境变量设为你的云服务商 PCCS;未设置时默认为阿里云 PCCS(`https://sgx-dcap-server.cn-beijing.aliyuncs.com`)。纯主机形式(`https://sgx-dcap-server.cn-hangzhou.aliyuncs.com`)和带路径后缀形式(`https://sgx-dcap-server.cn-hangzhou.aliyuncs.com/sgx/certification/v4/`)都接受——后端会规范化路径。阿里云常用端点:
>
> 对于 SGX/TDX 内置 AS 模式,还需为云服务商配置 `/etc/sgx_default_qcnl.conf` 中的 PCCS URL。详见 [Vendor Configuration Setup](setup-vendor-config.md)。
> | 端点类型 | `PCCS_URL` |
> |---|---|
> | 公网(按地域) | `https://sgx-dcap-server.<region>.aliyuncs.com` |
> | VPC 内网 | `https://sgx-dcap-server-vpc.<region>.aliyuncs.com` |

**PolicyConfig(OPA 策略):**

Expand Down
105 changes: 0 additions & 105 deletions docs/setup-vendor-config.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ phases:
- rustup default 1.91.1
# Change yum source from Anolis to Alinux
- sed -i -E 's|https?://mirrors.openanolis.cn/anolis/|https://mirrors.aliyun.com/anolis/|g' /etc/yum.repos.d/*.repo
# openssl-sys builds OpenSSL from source (vendored); OpenSSL 3.5.x's
# `Configure` requires the IPC::Cmd and Time::Piece Perl modules, which
# on an8 live in their own `perl-IPC-Cmd` and `perl-Time-Piece` packages
# (FindBin/File::Compare/File::Copy ship with the base perl-interpreter
# already present). Without them, `perl ./Configure` aborts with
# "Can't locate IPC/Cmd.pm" / "Can't locate Time/Piece.pm" during
# rpmbuild %build, and rpmbuild's strict BuildRequires check rejects
# perl(IPC::Cmd) / perl(Time::Piece) before %build even runs.
- yum install -y perl-IPC-Cmd perl-Time-Piece
build:
commands:
- rpmbuild --define "_topdir /tmp/rpmbuild" -ba /tmp/rpmbuild/SPECS/trusted-network-gateway.spec --define 'with_rustup 1'
Expand Down
Loading
Loading