diff --git a/.github/actions/setup-jfrog/action.yml b/.github/actions/setup-jfrog/action.yml new file mode 100644 index 00000000..9c6e15b0 --- /dev/null +++ b/.github/actions/setup-jfrog/action.yml @@ -0,0 +1,132 @@ +# 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. + +# Configure JFrog Artifactory as the registry proxy for cargo / uv / +# (future) npm. Required by go/hardened-gha: direct access to public +# package registries (crates.io, pypi.org, etc.) is blocked at the +# Databricks-protected runner; everything goes through +# `databricks.jfrog.io`. +# +# Steps: +# +# 1. Exchange the workflow's GitHub OIDC ID token for a JFrog access +# token via `https://databricks.jfrog.io/access/api/v1/oidc/token`. +# 2. Optionally write `~/.cargo/config.toml` pointing at the JFrog +# cargo proxy (`db-cargo-remote`). Replaces direct crates.io +# access for `cargo fetch` / `cargo install` / `cargo deny check`. +# 3. Optionally export `UV_INDEX_URL` (and `PIP_INDEX_URL` for +# fallback compat) pointing at the JFrog PyPI proxy (`db-pypi`). +# Picked up by `uv sync` / `uv pip install` / any plain `pip` +# calls in the job. +# +# Calling workflows MUST add `permissions: id-token: write` to grant +# the OIDC mint capability; without it the curl in step 1 fails 403. +# +# Reference: go/hardened-gha +# https://docs.google.com/document/d/1zoHgolfZO_IUBIU3w40NmYsoZ9eTRdAmjlfwYOxkj70 + +name: Set up JFrog Artifactory access +description: | + Exchange GitHub OIDC for a JFrog token and (optionally) configure + cargo / uv to route through the Databricks JFrog proxy. + +inputs: + cargo: + description: "Set 'true' to configure cargo to use the JFrog crates proxy." + required: false + default: "false" + uv: + description: | + Set 'true' to export UV_INDEX_URL (and PIP_INDEX_URL for compat) + pointing at the JFrog PyPI proxy. uv reads UV_INDEX_URL natively; + PIP_INDEX_URL is set for any tool that falls back to pip. + required: false + default: "false" + +runs: + using: composite + steps: + - name: Get JFrog OIDC token + shell: bash + run: | + set -euo pipefail + + # Mint a GitHub OIDC ID token scoped to the `jfrog-github` + # audience. Requires `permissions: id-token: write` on the + # calling job. + ID_TOKEN=$(curl -sLS \ + -H "User-Agent: actions/oidc-client" \ + -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \ + "${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=jfrog-github" | jq .value | tr -d '"') + echo "::add-mask::${ID_TOKEN}" + + # Exchange for a JFrog access token (RFC 8693 token-exchange). + ACCESS_TOKEN=$(curl -sLS -XPOST -H "Content-Type: application/json" \ + "https://databricks.jfrog.io/access/api/v1/oidc/token" \ + -d "{\"grant_type\": \"urn:ietf:params:oauth:grant-type:token-exchange\", \"subject_token_type\":\"urn:ietf:params:oauth:token-type:id_token\", \"subject_token\": \"${ID_TOKEN}\", \"provider_name\": \"github-actions\"}" | jq .access_token | tr -d '"') + echo "::add-mask::${ACCESS_TOKEN}" + + if [ -z "$ACCESS_TOKEN" ] || [ "$ACCESS_TOKEN" = "null" ]; then + echo "FAIL: Could not extract JFrog access token" + exit 1 + fi + + echo "JFROG_ACCESS_TOKEN=${ACCESS_TOKEN}" >> "$GITHUB_ENV" + echo "JFrog OIDC token obtained successfully" + + - name: Configure cargo to use JFrog + if: inputs.cargo == 'true' + shell: bash + run: | + set -euo pipefail + + mkdir -p ~/.cargo + cat > ~/.cargo/config.toml << 'EOF' + [source.crates-io] + replace-with = "jfrog" + + [source.jfrog] + registry = "sparse+https://databricks.jfrog.io/artifactory/api/cargo/db-cargo-remote/index/" + + [registries.jfrog] + index = "sparse+https://databricks.jfrog.io/artifactory/api/cargo/db-cargo-remote/index/" + credential-provider = ["cargo:token"] + EOF + + cat > ~/.cargo/credentials.toml << EOF + [registries.jfrog] + token = "Bearer ${JFROG_ACCESS_TOKEN}" + EOF + chmod 600 ~/.cargo/credentials.toml + + # Exported for tools like cargo-deny / cargo-llvm-cov that + # may read the env directly rather than the credentials file. + echo "CARGO_REGISTRIES_JFROG_TOKEN=Bearer ${JFROG_ACCESS_TOKEN}" >> "$GITHUB_ENV" + + echo "Cargo configured to use JFrog registry" + + - name: Configure uv / pip to use JFrog + if: inputs.uv == 'true' + shell: bash + run: | + set -euo pipefail + + # uv reads UV_INDEX_URL natively; PIP_INDEX_URL is set for + # fallback compatibility with tools that shell out to pip. + # Both URLs point at db-pypi via the JFrog OIDC service + # account. + INDEX_URL="https://gha-service-account:${JFROG_ACCESS_TOKEN}@databricks.jfrog.io/artifactory/api/pypi/db-pypi/simple" + echo "UV_INDEX_URL=${INDEX_URL}" >> "$GITHUB_ENV" + echo "PIP_INDEX_URL=${INDEX_URL}" >> "$GITHUB_ENV" + echo "uv / pip configured to use JFrog registry" diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index f48a9d7f..183a72c4 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -49,6 +49,10 @@ jobs: with: fetch-depth: 0 + - uses: ./.github/actions/setup-jfrog + with: + cargo: "true" + - uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2 with: toolchain: stable diff --git a/.github/workflows/license-check.yml b/.github/workflows/license-check.yml index fe3a9bf0..646df083 100644 --- a/.github/workflows/license-check.yml +++ b/.github/workflows/license-check.yml @@ -42,6 +42,9 @@ on: 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: @@ -56,6 +59,10 @@ jobs: steps: - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 + - uses: ./.github/actions/setup-jfrog + with: + cargo: "true" + - uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2 - name: Install cargo-deny diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index 87e2b3f8..03b4afc1 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -32,6 +32,10 @@ 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: @@ -62,6 +66,10 @@ jobs: steps: - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 + - uses: ./.github/actions/setup-jfrog + with: + cargo: "true" + - uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2 with: toolchain: stable @@ -78,6 +86,10 @@ jobs: steps: - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 + - uses: ./.github/actions/setup-jfrog + with: + cargo: "true" + - uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2 with: toolchain: stable diff --git a/.github/workflows/pyo3-checks.yml b/.github/workflows/pyo3-checks.yml index a6698540..86cca8c2 100644 --- a/.github/workflows/pyo3-checks.yml +++ b/.github/workflows/pyo3-checks.yml @@ -41,6 +41,10 @@ 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: @@ -99,14 +103,36 @@ jobs: steps: - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 + - uses: ./.github/actions/setup-jfrog + with: + cargo: "true" + uv: "true" + - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 with: python-version: ${{ matrix.python-version }} - uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2 - - name: Install maturin + pytest - run: pip install 'maturin>=1.5,<2.0' pytest + # uv is the Python package manager the kernel pyo3 sub-crate + # uses for env management. uv itself is installed via + # astral-sh/setup-uv (SHA-pinned) rather than via + # `pip install uv` so the bootstrap is also hash-locked. + - uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0 + with: + # Pin uv to a known good version; bump deliberately. + version: "0.11.14" + + - name: Install dev dependencies (uv sync) + # No `--frozen` and no committed lockfile: per go/pinning- + # python-deps the externally-published-library rule says + # *not* to pin transitive deps (it impedes downstream + # `pip install`). The `[project].dependencies` major-version + # bounds in `pyproject.toml` plus the JFrog proxy's 7-day + # age filter on `db-pypi` are the baseline protection. uv + # re-resolves each run within those bounds. + working-directory: pyo3 + run: uv sync --group dev - name: Cargo unit tests (pyo3 crate) # The pyo3 crate's Rust-side unit tests cover the GIL handoff @@ -117,9 +143,9 @@ jobs: - name: "Build + install pyo3 wheel (maturin develop)" working-directory: pyo3 # `develop` builds the extension and installs it into the - # runner's active Python in one step — what `pytest` needs. - # Debug build is fine for tests and ~2x faster than --release. - run: maturin develop --interpreter python${{ matrix.python-version }} + # uv-managed venv from the previous step. Debug build is + # fine for tests and ~2x faster than --release. + run: uv run maturin develop --interpreter python${{ matrix.python-version }} - name: pytest (no-network + live tiers) working-directory: pyo3 @@ -130,4 +156,4 @@ jobs: # repo; on fork PRs without approval, the no-network tier # (test_module.py + test_auth.py) runs and the live tier # skips cleanly. - run: pytest -v + run: uv run pytest -v diff --git a/.github/workflows/rust-e2e.yml b/.github/workflows/rust-e2e.yml index 44c0cb2b..5884eea0 100644 --- a/.github/workflows/rust-e2e.yml +++ b/.github/workflows/rust-e2e.yml @@ -78,6 +78,10 @@ jobs: fetch-depth: 0 persist-credentials: false + - uses: ./.github/actions/setup-jfrog + with: + cargo: "true" + - uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2 - name: Run v0 E2E tests diff --git a/CLAUDE.md b/CLAUDE.md index 486a44a1..7f52b18f 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -93,6 +93,43 @@ permissive licenses must be added to `[licenses].allow` in preserved separately for generating attribution pages on demand; 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`. + +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. +- **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`. + ## Local development environment Connection variables for E2E tests can be set via `.cargo/config.toml` diff --git a/pyo3/pyproject.toml b/pyo3/pyproject.toml index 46c8cb49..81a2cf72 100644 --- a/pyo3/pyproject.toml +++ b/pyo3/pyproject.toml @@ -9,8 +9,21 @@ description = "Python bindings for the Databricks SQL Kernel (PyO3)" requires-python = ">=3.9" license = { text = "Apache-2.0" } authors = [{ name = "Databricks" }] -dependencies = ["pyarrow>=14"] +# Runtime dependency for downstream consumers. Loose major-version +# bound per the published-library guidance — exact pins make this +# wheel harder for end-users to install alongside their own pyarrow +# consumers. The CI environment is fully hash-locked via `uv.lock` +# (see below), separately from this contract. +dependencies = ["pyarrow>=14,<19"] + +# Dev / CI dependencies. PEP 735 standard; uv reads this directly. +# `uv sync --frozen` installs from `uv.lock`, which carries SHA256 +# hashes for every artifact + transitive dep. +[dependency-groups] +dev = [ + "maturin>=1.7,<2.0", + "pytest>=8.3,<9.0", +] [tool.maturin] module-name = "databricks_sql_kernel" -