diff --git a/.github/actions/setup-public-package-proxies/action.yml b/.github/actions/setup-public-package-proxies/action.yml new file mode 100644 index 00000000..725833cd --- /dev/null +++ b/.github/actions/setup-public-package-proxies/action.yml @@ -0,0 +1,58 @@ +# Copyright (c) 2026 Databricks, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Set up public package proxies +description: Configure unauthenticated Databricks-filtered Cargo and Python package proxies. + +inputs: + cargo: + description: Configure Cargo to use the public Databricks crates proxy. + required: false + default: "false" + uv: + description: Configure uv and pip to use the public Databricks PyPI proxy. + required: false + default: "false" + +runs: + using: composite + steps: + - name: Configure Cargo package proxy + if: inputs.cargo == 'true' + shell: bash + run: | + set -euo pipefail + mkdir -p ~/.cargo + cat > ~/.cargo/config.toml <<'EOF' + [source.crates-io] + replace-with = "databricks-proxy" + + [source.databricks-proxy] + registry = "sparse+https://crates-proxy.cloud.databricks.com/" + + [http] + timeout = 120 + + [net] + git-fetch-with-cli = true + retry = 5 + EOF + + - name: Configure Python package proxy + if: inputs.uv == 'true' + shell: bash + run: | + set -euo pipefail + echo "UV_INDEX_URL=https://pypi-proxy.cloud.databricks.com/simple/" >> "$GITHUB_ENV" + echo "PIP_INDEX_URL=https://pypi-proxy.cloud.databricks.com/simple/" >> "$GITHUB_ENV" diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index e196dcad..1e8acf2a 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -31,6 +31,7 @@ on: - "pyo3/**" - "Cargo.toml" - "Cargo.lock" + - ".github/actions/setup-public-package-proxies/**" - ".github/workflows/coverage.yml" pull_request: branches: [main] @@ -41,6 +42,7 @@ on: - "pyo3/**" - "Cargo.toml" - "Cargo.lock" + - ".github/actions/setup-public-package-proxies/**" - ".github/workflows/coverage.yml" workflow_dispatch: @@ -50,8 +52,6 @@ concurrency: permissions: contents: read - id-token: write - pull-requests: write defaults: run: @@ -71,7 +71,7 @@ jobs: with: fetch-depth: 0 - - uses: ./.github/actions/setup-jfrog + - uses: ./.github/actions/setup-public-package-proxies with: cargo: "true" @@ -95,18 +95,51 @@ jobs: cargo llvm-cov --workspace --lcov --output-path lcov.info cargo llvm-cov --manifest-path adbc/Cargo.toml --features ffi --lcov --output-path adbc-lcov.info - # Codecov upload. - # - # `use_oidc: true` is tokenless, but it requires the repo to be - # enrolled in Codecov's GitHub App with OIDC enabled in the - # Codecov dashboard. Until that is set up, the action falls - # back to anonymous upload which Codecov silently rate-limits - # and may drop. `fail_ci_if_error: false` keeps the job green - # in that case (we don't want a one-off Codecov outage to red- - # light unrelated PRs) — but it does mean coverage data may not - # actually land. Watch for the Codecov check on the first few - # PRs to confirm uploads are flowing. - - name: Upload to Codecov + - name: Store coverage reports for trusted upload + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: coverage-reports + path: | + lcov.info + adbc-lcov.info + if-no-files-found: error + retention-days: 1 + + # Fork PRs cannot receive OIDC permissions. Keep their advisory coverage + # upload in the unprivileged build job instead. + - name: Upload fork coverage anonymously + if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository + uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0 + with: + files: lcov.info,adbc-lcov.info + fail_ci_if_error: false + + upload: + name: Upload coverage to Codecov + needs: coverage + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository + runs-on: + group: databricks-protected-runner-group + labels: linux-ubuntu-latest + permissions: + contents: read + id-token: write + pull-requests: write + steps: + - name: Checkout repository metadata + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Download coverage reports + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + name: coverage-reports + + # This job only handles generated reports, so contributor-controlled + # build scripts cannot access its OIDC mint permission. + - name: Upload to Codecov with OIDC uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0 with: files: lcov.info,adbc-lcov.info diff --git a/.github/workflows/license-check.yml b/.github/workflows/license-check.yml index 1835e142..2bfcea4a 100644 --- a/.github/workflows/license-check.yml +++ b/.github/workflows/license-check.yml @@ -63,9 +63,6 @@ concurrency: permissions: contents: read - # Required for the OIDC token exchange that the - # `.github/actions/setup-jfrog` composite uses. See go/hardened-gha. - id-token: write defaults: run: @@ -80,7 +77,7 @@ jobs: steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - uses: ./.github/actions/setup-jfrog + - uses: ./.github/actions/setup-public-package-proxies with: cargo: "true" diff --git a/.github/workflows/napi-checks.yml b/.github/workflows/napi-checks.yml index 6a31d1ff..72d07c2f 100644 --- a/.github/workflows/napi-checks.yml +++ b/.github/workflows/napi-checks.yml @@ -36,6 +36,7 @@ on: # Root Cargo.toml change can affect napi via its `path = ".."` # kernel dep, so this workflow re-runs to catch mismatches. - "Cargo.toml" + - ".github/actions/setup-public-package-proxies/**" - ".github/workflows/napi-checks.yml" pull_request: branches: [main] @@ -43,6 +44,7 @@ on: - "napi/**" - "src/**" - "Cargo.toml" + - ".github/actions/setup-public-package-proxies/**" - ".github/workflows/napi-checks.yml" concurrency: @@ -51,8 +53,6 @@ concurrency: permissions: contents: read -# `id-token: write` is scoped to the single job that exchanges an OIDC -# token for JFrog access. defaults: run: @@ -61,12 +61,8 @@ defaults: jobs: check-and-test: name: "napi fmt + clippy + test" - # Scoped here (not workflow-wide): `id-token: write` is only needed - # for the OIDC token exchange in `.github/actions/setup-jfrog` that - # authenticates against the JFrog cargo proxy. See go/hardened-gha. permissions: contents: read - id-token: write runs-on: group: databricks-protected-runner-group labels: linux-ubuntu-latest @@ -80,12 +76,10 @@ jobs: steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - # Route cargo through the JFrog crates proxy. The protected - # runner group blocks direct crates.io, so without this every - # cargo command below fails to update the registry index. The - # composite writes ~/.cargo/config.toml (a source replacement), - # which preserves resolved versions, so `--locked` stays valid. - - uses: ./.github/actions/setup-jfrog + # Route cargo through the unauthenticated filtered proxy so fork PRs + # never receive an OIDC mint permission while executing + # contributor-controlled code. + - uses: ./.github/actions/setup-public-package-proxies with: cargo: "true" diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index f07393fe..c9e28d10 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -49,10 +49,6 @@ concurrency: permissions: contents: read - # Required for the OIDC token exchange that the - # `.github/actions/setup-jfrog` composite uses to authenticate - # against the JFrog cargo proxy. See go/hardened-gha. - id-token: write defaults: run: @@ -88,7 +84,7 @@ jobs: steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - uses: ./.github/actions/setup-jfrog + - uses: ./.github/actions/setup-public-package-proxies with: cargo: "true" @@ -114,7 +110,7 @@ jobs: steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - uses: ./.github/actions/setup-jfrog + - uses: ./.github/actions/setup-public-package-proxies with: cargo: "true" @@ -143,7 +139,7 @@ jobs: steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - uses: ./.github/actions/setup-jfrog + - uses: ./.github/actions/setup-public-package-proxies with: cargo: "true" @@ -172,7 +168,7 @@ jobs: steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - uses: ./.github/actions/setup-jfrog + - uses: ./.github/actions/setup-public-package-proxies with: cargo: "true" @@ -211,7 +207,7 @@ jobs: steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - uses: ./.github/actions/setup-jfrog + - uses: ./.github/actions/setup-public-package-proxies with: cargo: "true" diff --git a/.github/workflows/pyo3-checks.yml b/.github/workflows/pyo3-checks.yml index 1dda66f7..19631bb4 100644 --- a/.github/workflows/pyo3-checks.yml +++ b/.github/workflows/pyo3-checks.yml @@ -25,6 +25,8 @@ on: - "src/**" - "Cargo.toml" - "Cargo.lock" + - ".github/actions/setup-jfrog/**" + - ".github/actions/setup-public-package-proxies/**" - ".github/workflows/pyo3-checks.yml" pull_request: branches: [main] @@ -33,6 +35,8 @@ on: - "src/**" - "Cargo.toml" - "Cargo.lock" + - ".github/actions/setup-jfrog/**" + - ".github/actions/setup-public-package-proxies/**" - ".github/workflows/pyo3-checks.yml" concurrency: @@ -41,10 +45,6 @@ concurrency: permissions: contents: read - # Required for the OIDC token exchange that the - # `.github/actions/setup-jfrog` composite uses to authenticate - # against the JFrog cargo + pip proxies. See go/hardened-gha. - id-token: write defaults: run: @@ -53,15 +53,16 @@ defaults: jobs: build-and-test: name: "PyO3 build + test (Python ${{ matrix.python-version }})" + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository + permissions: + contents: read + id-token: write runs-on: group: databricks-protected-runner-group labels: linux-ubuntu-latest - # `azure-prod` holds the Databricks secrets used by the live - # pytest suite below. Fork PRs are paused at "Waiting / approval - # required" until a maintainer clicks through, preventing secret - # exfil. PRs from forks that don't get approval still run the - # cargo-test step (no secrets needed) but the pytest step skips - # the `@live`-marked tests automatically when env vars are unset. + # `azure-prod` holds the Databricks secrets used by the live pytest suite. + # This job only runs for trusted pushes and same-repository PRs; fork PRs + # run the credential-free `fork-build-and-test` job instead. environment: azure-prod env: DATABRICKS_HOST: ${{ secrets.DATABRICKS_HOST }} @@ -166,9 +167,67 @@ jobs: # `@live`; they auto-skip when DATABRICKS_HOST/HTTP_PATH/ # TOKEN are unset. With the env: block above the live tier # runs against the configured warehouse on PRs from this - # repo; on fork PRs without approval, the no-network tier - # (test_module.py + test_auth.py) runs and the live tier - # skips cleanly. + # repo. The separate `fork-build-and-test` job runs the + # no-network tier without these secrets. # The extension and dependencies are already installed above; # avoid another implicit project sync before starting pytest. run: uv run --no-sync pytest -v + + # Keep the build sequence aligned with `build-and-test` above. This variant + # intentionally substitutes the credential-free package proxies and omits + # the azure-prod environment, its secrets, and the live-test tier. + fork-build-and-test: + name: "PyO3 build + test (Python ${{ matrix.python-version }})" + if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository + permissions: + contents: read + runs-on: + group: databricks-protected-runner-group + labels: linux-ubuntu-latest + env: + RUST_LOG: databricks_sql_kernel=info + RUSTC_WRAPPER: sccache + SCCACHE_GHA_ENABLED: "true" + strategy: + fail-fast: false + matrix: + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"] + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - uses: ./.github/actions/setup-public-package-proxies + with: + cargo: "true" + uv: "true" + + - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 + with: + python-version: ${{ matrix.python-version }} + + - uses: actions-rust-lang/setup-rust-toolchain@166cdcfd11aee3cb47222f9ddb555ce30ddb9659 # v1.17.0 + with: + cache-workspaces: "pyo3 -> target" + cache-key: "fork-py${{ matrix.python-version }}" + + - name: Setup sccache + uses: Mozilla-Actions/sccache-action@7d986dd989559c6ecdb630a3fd2557667be217ad # v0.0.9 + + - uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0 + with: + version: "0.11.14" + + - name: Install dev dependencies + working-directory: pyo3 + run: uv sync --group dev --no-install-project + + - name: Cargo unit tests + working-directory: pyo3 + run: cargo test + + - name: Build and install wheel + working-directory: pyo3 + run: uv run --no-sync maturin develop + + - name: Run no-network tests + working-directory: pyo3 + run: uv run --no-sync pytest -v diff --git a/.github/workflows/release-debuginfo.yml b/.github/workflows/release-debuginfo.yml index 7823ef3b..afdae1a4 100644 --- a/.github/workflows/release-debuginfo.yml +++ b/.github/workflows/release-debuginfo.yml @@ -28,7 +28,6 @@ concurrency: permissions: contents: read - id-token: write jobs: # Hosted macOS runners cannot check out this private repository through the @@ -68,7 +67,7 @@ jobs: steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - uses: ./.github/actions/setup-jfrog + - uses: ./.github/actions/setup-public-package-proxies with: cargo: "true" @@ -99,7 +98,7 @@ jobs: rm -f repo-source.tar.gz test -f Cargo.toml - - uses: ./.github/actions/setup-jfrog + - uses: ./.github/actions/setup-public-package-proxies with: cargo: "true" @@ -120,7 +119,7 @@ jobs: steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - uses: ./.github/actions/setup-jfrog + - uses: ./.github/actions/setup-public-package-proxies with: cargo: "true" diff --git a/.github/workflows/rust-e2e.yml b/.github/workflows/rust-e2e.yml index 9568579e..cf0cef74 100644 --- a/.github/workflows/rust-e2e.yml +++ b/.github/workflows/rust-e2e.yml @@ -61,6 +61,7 @@ defaults: jobs: e2e: name: "v0 E2E surface" + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository runs-on: group: databricks-protected-runner-group labels: linux-ubuntu-latest @@ -116,6 +117,7 @@ jobs: # lands, drive the proxy explicitly and add a fourth test. tls: name: "v0 TLS (mitmproxy)" + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository runs-on: group: databricks-protected-runner-group labels: linux-ubuntu-latest diff --git a/.github/workflows/securityScan.yml b/.github/workflows/securityScan.yml index 09cc4203..a0843bf2 100644 --- a/.github/workflows/securityScan.yml +++ b/.github/workflows/securityScan.yml @@ -50,12 +50,9 @@ name: Security Scan # wheel-install time on the consumer. Layer 1 (gh-action-scan at # release time) covers the assembled wheel. # -# Fork-PR coverage gap: this job runs on the protected runner group, -# which (per org policy) does not pick up fork PRs. Fork PRs DO get -# a check-run entry — it stays pending and the required-status-check -# rule blocks merge until a maintainer pushes the same SHA to a -# branch in this repo. Documented; revisit if external contributors -# become common. +# Fork PRs use the unauthenticated Databricks-filtered package proxy and receive +# no OIDC or repository secrets. Repository settings may still require a +# maintainer to approve a first-time contributor's workflow run. on: pull_request: @@ -71,7 +68,6 @@ concurrency: cancel-in-progress: ${{ github.event_name == 'pull_request' }} permissions: - id-token: write contents: read defaults: @@ -93,12 +89,11 @@ jobs: - name: Checkout uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - # JFrog OIDC + cargo proxy: skipped on fork PRs (no OIDC token). - # Fork PRs still resolve crates.io directly; JFrog is a faster - # mirror, not a source of any otherwise-unavailable artifact. - - name: Set up JFrog - if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository - uses: ./.github/actions/setup-jfrog + # Use the same filtered, unauthenticated proxy for internal and fork PRs. + # The job executes contributor-controlled Cargo build scripts, so it must + # not receive an OIDC mint permission. + - name: Set up public package proxy + uses: ./.github/actions/setup-public-package-proxies with: cargo: "true" diff --git a/CLAUDE.md b/CLAUDE.md index 1c1a3d1c..f5123a2d 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -101,39 +101,38 @@ the CI gate lives on `deny.toml`. ## Supply-chain hardening Per [go/hardened-gha](https://docs.google.com/document/d/1zoHgolfZO_IUBIU3w40NmYsoZ9eTRdAmjlfwYOxkj70/edit), -the protected runners block direct access to public package -registries (crates.io, PyPI, npm, etc.). All third-party -dependency fetches route through Databricks' JFrog Artifactory -proxy at `databricks.jfrog.io`. +the protected runners block direct access to public package registries +(crates.io, PyPI, npm, etc.). Third-party dependency fetches route through +Databricks-filtered proxies. How this shows up in the repo: - **GitHub Actions steps** are SHA-pinned, with the version tag in a trailing comment (e.g. `uses: actions/checkout@34e1148... # v4`). -- **Cargo** access goes through `db-cargo-remote`. Workflows that - hit cargo run `./.github/actions/setup-jfrog` with `cargo: "true"` - before `setup-rust-toolchain`. `Cargo.lock` carries per-crate - SHA256 checksums (`source = "registry+..."` + `checksum = "..."`), - which is Cargo's native pinning mechanism. -- **PyPI** access goes through `db-pypi`. The `pyo3-checks.yml` - workflow runs the same composite with `uv: "true"` (exports - `UV_INDEX_URL` + `PIP_INDEX_URL` for fallback compatibility). - The pyo3 sub-crate uses [uv](https://docs.astral.sh/uv/) for - Python env management. +- **Credential-free public dependencies** use + `.github/actions/setup-public-package-proxies`. This credential-free + composite configures Cargo and Python to use the filtered public proxies and + does not require `id-token: write`. Cargo-only CI uses it for trusted pushes, + same-repository PRs, and fork PRs when no private packages are needed. +- **Authenticated or private dependencies** use + `.github/actions/setup-jfrog`. This composite exchanges GitHub OIDC for + access to `db-cargo-remote` and `db-pypi`, so callers must grant + `id-token: write` and must not expose that job to fork-controlled code. +- `Cargo.lock` carries per-crate SHA256 checksums (`source = "registry+..."` + + `checksum = "..."`), which is Cargo's native pinning mechanism. The pyo3 + sub-crate uses [uv](https://docs.astral.sh/uv/) for Python env management. - **Python dep pinning follows the externally-published-library rule from [go/pinning-python-deps](https://docs.google.com/document/d/1thJsoOBW3NzvRV6pWpujcD8mn4KOXgAW8t10iw6Z6LA/edit)**: major-version upper bounds in `pyo3/pyproject.toml` (`pyarrow>=14,<19`), no exact pins, no transitive constraints, no committed lockfile. Exact pins would impede downstream `pip install databricks-sql-kernel` for end-users with their - own pyarrow consumers. The `db-pypi` proxy's 7-day age filter - is the baseline supply-chain protection; `uv sync` re-resolves - each CI run within the major-version bounds. -- **Composite action**: `.github/actions/setup-jfrog/action.yml` - encapsulates the OIDC token exchange (`id-token: write` - permission required) plus the cargo / uv config writes. - Workflows that need registry access reference it with - `uses: ./.github/actions/setup-jfrog`. + own pyarrow consumers. Trusted jobs use `db-pypi`, whose 7-day age filter is + their baseline supply-chain protection. Fork jobs use the credential-free + public proxy; its filtering policy is separate and does not promise the same + 7-day delay. `uv sync` re-resolves each CI run within the major-version bounds. +- **Composite actions**: both proxy setup actions write Cargo and uv/pip + configuration; only `setup-jfrog` performs an OIDC token exchange. ## Local development environment