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
128 changes: 127 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
python-version: "3.11"

- name: Install Dependencies
run: pnpm install --no-frozen-lockfile
run: pnpm install --frozen-lockfile

- name: Verify Code Quality & Style
run: pnpm run check
Expand All @@ -68,3 +68,129 @@ jobs:

- name: Verify Tarball Packaging Gate
run: npm pack --dry-run

rust-core:
name: Rust Core Tests (dbshield-core)
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout Code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Setup Rust Toolchain
uses: dtolnay/rust-toolchain@df2a88e9fe4098bad09cb42c3dec7187f15861fc # master
with:
toolchain: stable

- name: Run Rust Core Tests
working-directory: crates/dbshield-core
run: cargo test

live-db-mcp-coverage:
name: Live PostgreSQL, MCP E2E & Coverage Gate
runs-on: ubuntu-latest
permissions:
contents: read
services:
postgres:
image: postgres:16-alpine
env:
POSTGRES_USER: dbshield
POSTGRES_PASSWORD: dbshield_ci_password
POSTGRES_DB: dbshield_ci
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U dbshield -d dbshield_ci"
--health-interval 5s
--health-timeout 5s
--health-retries 10
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Install pnpm
uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1
with:
version: 9

- name: Setup Node.js 22
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: "22"
cache: "pnpm"

- name: Install Dependencies
run: pnpm install --frozen-lockfile

- name: Build TypeScript
run: pnpm run build

- name: Run Test Suite with Coverage Threshold
run: >-
npx tsx --test --test-concurrency=4 --experimental-test-coverage
--test-coverage-lines=40 --test-coverage-exclude="tests/**"

- name: Verify Live PostgreSQL Guardrail E2E
env:
DATABASE_URL: postgres://dbshield:dbshield_ci_password@localhost:5432/dbshield_ci
run: |
node --input-type=module -e '
import assert from "node:assert/strict";
import pg from "pg";
import { loadConfig } from "./dist/config/index.js";
import { SqlGuardEngine } from "./dist/guard/engine.js";
const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL });
await pool.query("CREATE TABLE IF NOT EXISTS ci_items (id SERIAL PRIMARY KEY, name TEXT NOT NULL)");
await pool.query("INSERT INTO ci_items (name) VALUES ($1)", ["dbshield-e2e"]);
const res = await pool.query("SELECT id, name FROM ci_items LIMIT 1");
assert.equal(res.rows[0].name, "dbshield-e2e");
const cfg = await loadConfig();
const guard = new SqlGuardEngine({ ...cfg, safetyTier: "BALANCED" });
assert.equal(guard.evaluate("SELECT id, name FROM ci_items LIMIT 1").allowed, true);
assert.equal(guard.evaluate("DROP TABLE ci_items").allowed, false);
await pool.end();
'

- name: Verify Live MCP Stdio Handshake
run: |
node --input-type=module -e '
import assert from "node:assert/strict";
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
const transport = new StdioClientTransport({
command: "node",
args: ["dist/cli.js", "start"],
env: { ...process.env, DBSHIELD_STORAGE_PATH: ":memory:" },
});
const client = new Client({ name: "ci-probe", version: "1.0.0" }, { capabilities: {} });
await client.connect(transport);
const res = await client.listTools();
const names = res.tools.map((t) => t.name);
await transport.close();
assert.ok(names.includes("db_query"));
assert.ok(names.includes("db_status"));
'

security:
name: Supply-Chain & Secret Scan
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout Code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0

- name: Run OSV Dependency Vulnerability Scan
run: |
curl -sSfL -o /tmp/osv-scanner https://github.com/google/osv-scanner/releases/download/v2.7.1/osv-scanner_linux_amd64
chmod +x /tmp/osv-scanner
/tmp/osv-scanner scan source -r .

- name: Run Gitleaks Secret Scan
run: |
curl -sSfL -o /tmp/gitleaks.tar.gz https://github.com/gitleaks/gitleaks/releases/download/v8.30.1/gitleaks_8.30.1_linux_x64.tar.gz
tar -xzf /tmp/gitleaks.tar.gz -C /tmp gitleaks
/tmp/gitleaks detect --source . --redact --no-banner
13 changes: 10 additions & 3 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,21 @@ jobs:
context: .
platforms: linux/amd64,linux/arm64
push: true
provenance: true
sbom: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Sign the Published Image with Cosign Keyless OIDC
if: ${{ steps.build-and-push.outputs.imageid != '' }}
if: steps.build-and-push.outputs.digest != ''
run: |
cosign sign --yes "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build-and-push.outputs.digest }}"
env:
COSIGN_EXPERIMENTAL: "1"

- name: Verify Cosign Signature
if: steps.build-and-push.outputs.digest != ''
run: |
cosign verify "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build-and-push.outputs.digest }}" \
--certificate-identity-regexp="https://github.com/RitualDev-Lab/" \
--certificate-oidc-issuer="https://token.actions.githubusercontent.com"
27 changes: 16 additions & 11 deletions .github/workflows/publish-package.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
name: Publish Package & Sigstore Provenance
name: Manual Publish Package & Sigstore Provenance

on:
release:
types: [published]
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+*"
workflow_dispatch:

permissions: read-all
Expand Down Expand Up @@ -33,19 +28,24 @@ jobs:
scope: "@ritualdev-lab"

- name: Install dependencies
run: pnpm install --no-frozen-lockfile
run: pnpm install --frozen-lockfile

- name: Build DBShield
run: pnpm run build

- name: Run Tests
run: pnpm test

- name: Pack Release Tarball
run: |
mkdir -p release-artifacts
pnpm pack --pack-destination release-artifacts

- name: Publish to GitHub Packages
run: |
echo "@ritualdev-lab:registry=https://npm.pkg.github.com" > .npmrc
echo "//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}" >> .npmrc
pnpm publish --no-git-checks --provenance=false
npm publish release-artifacts/*.tgz --provenance=false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -73,20 +73,25 @@ jobs:
registry-url: "https://registry.npmjs.org"

- name: Install dependencies
run: pnpm install --no-frozen-lockfile
run: pnpm install --frozen-lockfile

- name: Build DBShield
run: pnpm run build

- name: Run Test Suite
run: pnpm test

- name: Pack Release Tarball
run: |
mkdir -p release-artifacts
pnpm pack --pack-destination release-artifacts

- name: Generate SLSA Build Provenance Attestation
uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2
with:
subject-path: 'dist/**'
subject-path: 'release-artifacts/*.tgz'

- name: Publish to npm with Sigstore Provenance
run: pnpm publish --no-git-checks --access public --provenance
run: npm publish release-artifacts/*.tgz --access public --provenance
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
27 changes: 25 additions & 2 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
permissions:
id-token: write
contents: read
attestations: write

steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
Expand All @@ -28,16 +29,38 @@ jobs:
with:
python-version: "3.11"

- name: Install build tools
- name: Install build & test dependencies
run: |
python -m pip install --require-hashes -r sdks/python/requirements-build.txt
python -m pip install --require-hashes -r sdks/python/requirements-test.txt
python -m pip install --no-deps -e sdks/python

- name: Run Python SDK Tests
run: python -m pytest sdks/python/tests -q

- name: Build sdist and wheel
run: |
cd sdks/python
python -m build

- name: Publish to PyPI
- name: Attest Python Distribution Provenance
uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2
with:
subject-path: 'sdks/python/dist/*'

- name: Publish to PyPI (OIDC Trusted Publishing)
if: env.HAS_PYPI_TOKEN != 'true'
env:
HAS_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN != '' }}
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
with:
packages-dir: sdks/python/dist/
skip-existing: true

- name: Publish to PyPI (API Token fallback)
if: env.HAS_PYPI_TOKEN == 'true'
env:
HAS_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN != '' }}
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
with:
packages-dir: sdks/python/dist/
Expand Down
25 changes: 14 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
cache: "pnpm"

- name: Install Dependencies
run: pnpm install --no-frozen-lockfile
run: pnpm install --frozen-lockfile

- name: Build TypeScript
run: pnpm run build
Expand Down Expand Up @@ -66,22 +66,27 @@ jobs:
registry-url: "https://registry.npmjs.org"

- name: Install Dependencies
run: pnpm install --no-frozen-lockfile
run: pnpm install --frozen-lockfile

- name: Build TypeScript
run: pnpm run build

- name: Pack Release Tarball
run: |
mkdir -p release-artifacts sboms
pnpm pack --pack-destination release-artifacts

- name: Generate SLSA Build Provenance Attestation
uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2
with:
subject-path: 'dist/**'
subject-path: 'release-artifacts/*.tgz'

- name: Generate CycloneDX SBOM
uses: anchore/sbom-action@dfcb83b97731532d72be422cbc51ee64adb6fd56 # v0.24.4
with:
path: ./
format: 'cyclonedx-json'
output-file: 'dist/dbshield-cyclonedx.sbom.json'
output-file: 'sboms/dbshield-cyclonedx.sbom.json'
artifact-name: 'dbshield-cyclonedx.sbom.json'
upload-artifact: true
upload-release-assets: false
Expand All @@ -91,27 +96,25 @@ jobs:
with:
path: ./
format: 'spdx-json'
output-file: 'dist/dbshield-spdx.sbom.json'
output-file: 'sboms/dbshield-spdx.sbom.json'
artifact-name: 'dbshield-spdx.sbom.json'
upload-artifact: true
upload-release-assets: false

- name: Pack Tarball
run: pnpm pack

- name: Create GitHub Release
if: startsWith(github.ref, 'refs/tags/v')
uses: softprops/action-gh-release@c95fe1489396fe8a9ec87454c605fbb0b60764ab # v2.2.1
with:
files: |
*.tgz
dist/**
release-artifacts/*.tgz
sboms/*.sbom.json
generate_release_notes: true
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Publish to npm with Provenance
run: pnpm publish --no-git-checks --access public --provenance
run: npm publish release-artifacts/*.tgz --access public --provenance
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
4 changes: 4 additions & 0 deletions .gitleaksignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Intentional historical test fixtures and example session ID in src/top-monitor.ts / tests/pii.test.ts
3e2a8eeb1400d6eeea13b2047a2b4bf594d5485a:src/top-monitor.ts:generic-api-key:93
477b6b350593764bea034bb3f42d2d142c4b2234:tests/pii.test.ts:stripe-access-token:13
477b6b350593764bea034bb3f42d2d142c4b2234:tests/pii.test.ts:stripe-access-token:34
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN pnpm run build
RUN pnpm prune --prod

# ─── Stage 2: Distroless Minimal Non-Root Runtime ──────────────────────
FROM gcr.io/distroless/nodejs20-debian12:nonroot@sha256:2cd820156cf039c8b54ae2d2a97e424b6729070714de8707a6b79f20d56f6a9a AS runtime
FROM gcr.io/distroless/nodejs22-debian12:nonroot AS runtime

LABEL maintainer="RitualDev Lab <team@ritualdev.com>"
LABEL org.opencontainers.image.title="DBShield"
Expand Down
Loading