Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cbe07261b1 | ||
|
|
27d20ed11c |
+5
-19
@@ -29,13 +29,10 @@ env:
|
|||||||
CARGO_NET_RETRY: "10"
|
CARGO_NET_RETRY: "10"
|
||||||
CARGO_HTTP_MULTIPLEXING: "false"
|
CARGO_HTTP_MULTIPLEXING: "false"
|
||||||
|
|
||||||
# Cancel superseded PR runs, but NEVER cancel main-branch runs — those build and
|
# Cancel in-progress runs for the same branch/PR
|
||||||
# deploy per-service images, and cancelling one merge's deploy when the next
|
|
||||||
# merge lands leaves a service un-deployed (as happened between two back-to-back
|
|
||||||
# merges). So cancel-in-progress only for pull_request events.
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
@@ -194,18 +191,13 @@ jobs:
|
|||||||
image: docker:27-cli
|
image: docker:27-cli
|
||||||
steps:
|
steps:
|
||||||
- name: Build, push and trigger orca redeploy
|
- name: Build, push and trigger orca redeploy
|
||||||
env:
|
|
||||||
# PAT for fetching the private tramiton-core git dependency during the
|
|
||||||
# image build (injected as a BuildKit secret, never baked into a layer).
|
|
||||||
TRAMITON_FETCH_TOKEN: ${{ secrets.TRAMITON_FETCH_TOKEN }}
|
|
||||||
run: |
|
run: |
|
||||||
apk add --no-cache git curl openssl
|
apk add --no-cache git curl openssl
|
||||||
git init && git remote add origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
|
git init && git remote add origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
|
||||||
git fetch --depth=1 origin "${GITHUB_SHA}" && git checkout FETCH_HEAD
|
git fetch --depth=1 origin "${GITHUB_SHA}" && git checkout FETCH_HEAD
|
||||||
IMAGE=registry.meghsakha.com/compliance-agent
|
IMAGE=registry.meghsakha.com/compliance-agent
|
||||||
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login registry.meghsakha.com -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin
|
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login registry.meghsakha.com -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin
|
||||||
DOCKER_BUILDKIT=1 docker build --secret id=tramiton_token,env=TRAMITON_FETCH_TOKEN \
|
docker build -f Dockerfile.agent -t "$IMAGE:latest" -t "$IMAGE:${GITHUB_SHA}" .
|
||||||
-f Dockerfile.agent -t "$IMAGE:latest" -t "$IMAGE:${GITHUB_SHA}" .
|
|
||||||
docker push "$IMAGE:latest" && docker push "$IMAGE:${GITHUB_SHA}"
|
docker push "$IMAGE:latest" && docker push "$IMAGE:${GITHUB_SHA}"
|
||||||
PAYLOAD=$(printf '{"ref":"refs/heads/main","repository":{"full_name":"sharang/compliance-scanner-agent"},"head_commit":{"id":"%s","message":"deploy agent"}}' "${GITHUB_SHA}")
|
PAYLOAD=$(printf '{"ref":"refs/heads/main","repository":{"full_name":"sharang/compliance-scanner-agent"},"head_commit":{"id":"%s","message":"deploy agent"}}' "${GITHUB_SHA}")
|
||||||
SIG=$(printf '%s' "$PAYLOAD" | openssl dgst -sha256 -hmac "${{ secrets.ORCA_WEBHOOK_SECRET }}" | awk '{print $2}')
|
SIG=$(printf '%s' "$PAYLOAD" | openssl dgst -sha256 -hmac "${{ secrets.ORCA_WEBHOOK_SECRET }}" | awk '{print $2}')
|
||||||
@@ -220,16 +212,13 @@ jobs:
|
|||||||
image: docker:27-cli
|
image: docker:27-cli
|
||||||
steps:
|
steps:
|
||||||
- name: Build, push and trigger orca redeploy
|
- name: Build, push and trigger orca redeploy
|
||||||
env:
|
|
||||||
TRAMITON_FETCH_TOKEN: ${{ secrets.TRAMITON_FETCH_TOKEN }}
|
|
||||||
run: |
|
run: |
|
||||||
apk add --no-cache git curl openssl
|
apk add --no-cache git curl openssl
|
||||||
git init && git remote add origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
|
git init && git remote add origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
|
||||||
git fetch --depth=1 origin "${GITHUB_SHA}" && git checkout FETCH_HEAD
|
git fetch --depth=1 origin "${GITHUB_SHA}" && git checkout FETCH_HEAD
|
||||||
IMAGE=registry.meghsakha.com/compliance-dashboard
|
IMAGE=registry.meghsakha.com/compliance-dashboard
|
||||||
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login registry.meghsakha.com -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin
|
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login registry.meghsakha.com -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin
|
||||||
DOCKER_BUILDKIT=1 docker build --secret id=tramiton_token,env=TRAMITON_FETCH_TOKEN \
|
docker build -f Dockerfile.dashboard -t "$IMAGE:latest" -t "$IMAGE:${GITHUB_SHA}" .
|
||||||
-f Dockerfile.dashboard -t "$IMAGE:latest" -t "$IMAGE:${GITHUB_SHA}" .
|
|
||||||
docker push "$IMAGE:latest" && docker push "$IMAGE:${GITHUB_SHA}"
|
docker push "$IMAGE:latest" && docker push "$IMAGE:${GITHUB_SHA}"
|
||||||
PAYLOAD=$(printf '{"ref":"refs/heads/main","repository":{"full_name":"sharang/compliance-scanner-agent"},"head_commit":{"id":"%s","message":"deploy dashboard"}}' "${GITHUB_SHA}")
|
PAYLOAD=$(printf '{"ref":"refs/heads/main","repository":{"full_name":"sharang/compliance-scanner-agent"},"head_commit":{"id":"%s","message":"deploy dashboard"}}' "${GITHUB_SHA}")
|
||||||
SIG=$(printf '%s' "$PAYLOAD" | openssl dgst -sha256 -hmac "${{ secrets.ORCA_WEBHOOK_SECRET }}" | awk '{print $2}')
|
SIG=$(printf '%s' "$PAYLOAD" | openssl dgst -sha256 -hmac "${{ secrets.ORCA_WEBHOOK_SECRET }}" | awk '{print $2}')
|
||||||
@@ -265,16 +254,13 @@ jobs:
|
|||||||
image: docker:27-cli
|
image: docker:27-cli
|
||||||
steps:
|
steps:
|
||||||
- name: Build, push and trigger orca redeploy
|
- name: Build, push and trigger orca redeploy
|
||||||
env:
|
|
||||||
TRAMITON_FETCH_TOKEN: ${{ secrets.TRAMITON_FETCH_TOKEN }}
|
|
||||||
run: |
|
run: |
|
||||||
apk add --no-cache git curl openssl
|
apk add --no-cache git curl openssl
|
||||||
git init && git remote add origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
|
git init && git remote add origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
|
||||||
git fetch --depth=1 origin "${GITHUB_SHA}" && git checkout FETCH_HEAD
|
git fetch --depth=1 origin "${GITHUB_SHA}" && git checkout FETCH_HEAD
|
||||||
IMAGE=registry.meghsakha.com/compliance-mcp
|
IMAGE=registry.meghsakha.com/compliance-mcp
|
||||||
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login registry.meghsakha.com -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin
|
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login registry.meghsakha.com -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin
|
||||||
DOCKER_BUILDKIT=1 docker build --secret id=tramiton_token,env=TRAMITON_FETCH_TOKEN \
|
docker build -f Dockerfile.mcp -t "$IMAGE:latest" -t "$IMAGE:${GITHUB_SHA}" .
|
||||||
-f Dockerfile.mcp -t "$IMAGE:latest" -t "$IMAGE:${GITHUB_SHA}" .
|
|
||||||
docker push "$IMAGE:latest" && docker push "$IMAGE:${GITHUB_SHA}"
|
docker push "$IMAGE:latest" && docker push "$IMAGE:${GITHUB_SHA}"
|
||||||
PAYLOAD=$(printf '{"ref":"refs/heads/main","repository":{"full_name":"sharang/compliance-scanner-agent"},"head_commit":{"id":"%s","message":"deploy mcp"}}' "${GITHUB_SHA}")
|
PAYLOAD=$(printf '{"ref":"refs/heads/main","repository":{"full_name":"sharang/compliance-scanner-agent"},"head_commit":{"id":"%s","message":"deploy mcp"}}' "${GITHUB_SHA}")
|
||||||
SIG=$(printf '%s' "$PAYLOAD" | openssl dgst -sha256 -hmac "${{ secrets.ORCA_WEBHOOK_SECRET }}" | awk '{print $2}')
|
SIG=$(printf '%s' "$PAYLOAD" | openssl dgst -sha256 -hmac "${{ secrets.ORCA_WEBHOOK_SECRET }}" | awk '{print $2}')
|
||||||
|
|||||||
Generated
+9
-48
@@ -693,8 +693,6 @@ dependencies = [
|
|||||||
"tracing",
|
"tracing",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
"tramiton-core",
|
"tramiton-core",
|
||||||
"tramiton-repro",
|
|
||||||
"tramiton-sbom",
|
|
||||||
"urlencoding",
|
"urlencoding",
|
||||||
"uuid",
|
"uuid",
|
||||||
"walkdir",
|
"walkdir",
|
||||||
@@ -2103,7 +2101,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
|
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -3698,7 +3696,7 @@ version = "0.50.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
|
checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-sys 0.60.2",
|
"windows-sys 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -3769,15 +3767,6 @@ dependencies = [
|
|||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "object"
|
|
||||||
version = "0.36.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87"
|
|
||||||
dependencies = [
|
|
||||||
"memchr",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "octocrab"
|
name = "octocrab"
|
||||||
version = "0.44.1"
|
version = "0.44.1"
|
||||||
@@ -4679,7 +4668,7 @@ dependencies = [
|
|||||||
"errno",
|
"errno",
|
||||||
"libc",
|
"libc",
|
||||||
"linux-raw-sys 0.4.15",
|
"linux-raw-sys 0.4.15",
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -4692,7 +4681,7 @@ dependencies = [
|
|||||||
"errno",
|
"errno",
|
||||||
"libc",
|
"libc",
|
||||||
"linux-raw-sys 0.12.1",
|
"linux-raw-sys 0.12.1",
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -5570,10 +5559,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "82a72c767771b47409d2345987fda8628641887d5466101319899796367354a0"
|
checksum = "82a72c767771b47409d2345987fda8628641887d5466101319899796367354a0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fastrand",
|
"fastrand",
|
||||||
"getrandom 0.3.4",
|
"getrandom 0.4.1",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"rustix 1.1.4",
|
"rustix 1.1.4",
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -6150,8 +6139,8 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tramiton-core"
|
name = "tramiton-core"
|
||||||
version = "0.4.1"
|
version = "0.4.0"
|
||||||
source = "git+ssh://git@gitea.meghsakha.com:22222/sharang/tramiton.git?tag=v0.4.1#ae4fc1376279f9edb9882605b20877335e7ba8ba"
|
source = "git+ssh://git@gitea.meghsakha.com:22222/sharang/tramiton.git?tag=v0.4.0#e3dc1bf7027a2f6d7b1fe43043d6dfa887ce4af3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
@@ -6160,34 +6149,6 @@ dependencies = [
|
|||||||
"walkdir",
|
"walkdir",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tramiton-repro"
|
|
||||||
version = "0.4.1"
|
|
||||||
source = "git+ssh://git@gitea.meghsakha.com:22222/sharang/tramiton.git?tag=v0.4.1#ae4fc1376279f9edb9882605b20877335e7ba8ba"
|
|
||||||
dependencies = [
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
"sha2",
|
|
||||||
"tempfile",
|
|
||||||
"thiserror 1.0.69",
|
|
||||||
"toml",
|
|
||||||
"tramiton-core",
|
|
||||||
"walkdir",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tramiton-sbom"
|
|
||||||
version = "0.4.1"
|
|
||||||
source = "git+ssh://git@gitea.meghsakha.com:22222/sharang/tramiton.git?tag=v0.4.1#ae4fc1376279f9edb9882605b20877335e7ba8ba"
|
|
||||||
dependencies = [
|
|
||||||
"object",
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
"sha2",
|
|
||||||
"tramiton-core",
|
|
||||||
"tramiton-repro",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tree-sitter"
|
name = "tree-sitter"
|
||||||
version = "0.24.7"
|
version = "0.24.7"
|
||||||
@@ -6746,7 +6707,7 @@ version = "0.1.11"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
|
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-sys 0.48.0",
|
"windows-sys 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
+1
-23
@@ -2,16 +2,7 @@ FROM rust:1.94-bookworm AS builder
|
|||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY . .
|
COPY . .
|
||||||
# compliance-agent depends on the private tramiton-core git repo. Authenticate
|
RUN cargo build --release -p compliance-agent
|
||||||
# the fetch with a PAT passed as a BuildKit secret (never baked into a layer).
|
|
||||||
# Build with: DOCKER_BUILDKIT=1 docker build --secret id=tramiton_token,env=TRAMITON_FETCH_TOKEN ...
|
|
||||||
RUN --mount=type=secret,id=tramiton_token \
|
|
||||||
if [ -s /run/secrets/tramiton_token ]; then \
|
|
||||||
git config --global \
|
|
||||||
url."https://sharang:$(cat /run/secrets/tramiton_token)@gitea.meghsakha.com/".insteadOf \
|
|
||||||
"ssh://git@gitea.meghsakha.com:22222/"; \
|
|
||||||
fi && \
|
|
||||||
CARGO_NET_GIT_FETCH_WITH_CLI=true cargo build --release -p compliance-agent
|
|
||||||
|
|
||||||
FROM debian:bookworm-slim
|
FROM debian:bookworm-slim
|
||||||
RUN apt-get update && apt-get install -y ca-certificates libssl3 git curl python3 python3-pip npm golang-go php-cli && rm -rf /var/lib/apt/lists/*
|
RUN apt-get update && apt-get install -y ca-certificates libssl3 git curl python3 python3-pip npm golang-go php-cli && rm -rf /var/lib/apt/lists/*
|
||||||
@@ -40,19 +31,6 @@ RUN pip3 install --break-system-packages semgrep
|
|||||||
# Install ruff for Python linting
|
# Install ruff for Python linting
|
||||||
RUN pip3 install --break-system-packages ruff
|
RUN pip3 install --break-system-packages ruff
|
||||||
|
|
||||||
# Install nix-portable (rootless nix) so the firmware-SBOM pipeline can drive a
|
|
||||||
# tramiton reproducible build (NixBackend). Best-effort: if the download fails,
|
|
||||||
# the agent falls back to analysis-only firmware SBOMs (never breaks a scan).
|
|
||||||
# The nix store lives under NP_LOCATION — mount a PERSISTENT volume there in the
|
|
||||||
# deployment, else every firmware scan re-fetches nixpkgs + cross toolchains.
|
|
||||||
ARG NIX_PORTABLE_VERSION=v012
|
|
||||||
RUN curl -fsSL -o /usr/local/bin/nix-portable \
|
|
||||||
"https://github.com/DavHau/nix-portable/releases/download/${NIX_PORTABLE_VERSION}/nix-portable-x86_64" \
|
|
||||||
&& chmod +x /usr/local/bin/nix-portable \
|
|
||||||
|| { rm -f /usr/local/bin/nix-portable; echo "WARN: nix-portable install skipped; firmware SBOM uses analysis-only fallback"; }
|
|
||||||
ENV NP_LOCATION=/data/compliance-scanner
|
|
||||||
RUN mkdir -p /data/compliance-scanner
|
|
||||||
|
|
||||||
COPY --from=builder /app/target/release/compliance-agent /usr/local/bin/compliance-agent
|
COPY --from=builder /app/target/release/compliance-agent /usr/local/bin/compliance-agent
|
||||||
|
|
||||||
# Copy documentation for the help chat assistant
|
# Copy documentation for the help chat assistant
|
||||||
|
|||||||
+1
-10
@@ -7,16 +7,7 @@ ARG DOCS_URL=/docs
|
|||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY . .
|
COPY . .
|
||||||
ENV DOCS_URL=${DOCS_URL}
|
ENV DOCS_URL=${DOCS_URL}
|
||||||
# compliance-agent (a workspace member) depends on the private tramiton-core git
|
RUN dx build --release --package compliance-dashboard
|
||||||
# repo, so the workspace resolve needs it even to build the dashboard.
|
|
||||||
# Authenticate the fetch with a PAT passed as a BuildKit secret.
|
|
||||||
RUN --mount=type=secret,id=tramiton_token \
|
|
||||||
if [ -s /run/secrets/tramiton_token ]; then \
|
|
||||||
git config --global \
|
|
||||||
url."https://sharang:$(cat /run/secrets/tramiton_token)@gitea.meghsakha.com/".insteadOf \
|
|
||||||
"ssh://git@gitea.meghsakha.com:22222/"; \
|
|
||||||
fi && \
|
|
||||||
CARGO_NET_GIT_FETCH_WITH_CLI=true dx build --release --package compliance-dashboard
|
|
||||||
|
|
||||||
FROM debian:bookworm-slim
|
FROM debian:bookworm-slim
|
||||||
RUN apt-get update && apt-get install -y ca-certificates libssl3 && rm -rf /var/lib/apt/lists/*
|
RUN apt-get update && apt-get install -y ca-certificates libssl3 && rm -rf /var/lib/apt/lists/*
|
||||||
|
|||||||
+1
-10
@@ -2,16 +2,7 @@ FROM rust:1.94-bookworm AS builder
|
|||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY . .
|
COPY . .
|
||||||
# compliance-agent (a workspace member) depends on the private tramiton-core git
|
RUN cargo build --release -p compliance-mcp
|
||||||
# repo, so the workspace resolve needs it even to build the mcp binary.
|
|
||||||
# Authenticate the fetch with a PAT passed as a BuildKit secret.
|
|
||||||
RUN --mount=type=secret,id=tramiton_token \
|
|
||||||
if [ -s /run/secrets/tramiton_token ]; then \
|
|
||||||
git config --global \
|
|
||||||
url."https://sharang:$(cat /run/secrets/tramiton_token)@gitea.meghsakha.com/".insteadOf \
|
|
||||||
"ssh://git@gitea.meghsakha.com:22222/"; \
|
|
||||||
fi && \
|
|
||||||
CARGO_NET_GIT_FETCH_WITH_CLI=true cargo build --release -p compliance-mcp
|
|
||||||
|
|
||||||
FROM debian:bookworm-slim
|
FROM debian:bookworm-slim
|
||||||
RUN apt-get update && apt-get install -y ca-certificates libssl3 && rm -rf /var/lib/apt/lists/*
|
RUN apt-get update && apt-get install -y ca-certificates libssl3 && rm -rf /var/lib/apt/lists/*
|
||||||
|
|||||||
@@ -14,12 +14,7 @@ compliance-dast = { path = "../compliance-dast" }
|
|||||||
# Same-company IP, used directly (not via CLI) so the whole tramiton suite is
|
# Same-company IP, used directly (not via CLI) so the whole tramiton suite is
|
||||||
# available to the onboarding classifier. NOTE: CI must be able to fetch this
|
# available to the onboarding classifier. NOTE: CI must be able to fetch this
|
||||||
# private repo (see the git-auth step in .gitea/workflows/ci.yml).
|
# private repo (see the git-auth step in .gitea/workflows/ci.yml).
|
||||||
tramiton-core = { git = "ssh://git@gitea.meghsakha.com:22222/sharang/tramiton.git", tag = "v0.4.1" }
|
tramiton-core = { git = "ssh://git@gitea.meghsakha.com:22222/sharang/tramiton.git", tag = "v0.4.0" }
|
||||||
# tramiton-repro drives the reproducible build (NixBackend seal_and_build) that
|
|
||||||
# yields a sealed lock; `libraries_from_inputs` is the analysis-only fallback.
|
|
||||||
tramiton-repro = { git = "ssh://git@gitea.meghsakha.com:22222/sharang/tramiton.git", tag = "v0.4.1" }
|
|
||||||
# tramiton-sbom renders the bill of materials from a sealed lock (+ binary SCA).
|
|
||||||
tramiton-sbom = { git = "ssh://git@gitea.meghsakha.com:22222/sharang/tramiton.git", tag = "v0.4.1" }
|
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
tokio = { workspace = true }
|
tokio = { workspace = true }
|
||||||
|
|||||||
@@ -70,26 +70,6 @@ impl ComplianceAgent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Run a scan for an onboarded target through the unified pipeline,
|
|
||||||
/// unconditionally.
|
|
||||||
///
|
|
||||||
/// Unlike [`Self::run_scan`], this does *not* consult the
|
|
||||||
/// `unified_pipeline` transition flag: the caller (the `/targets/{id}/scan`
|
|
||||||
/// endpoint) operates on `onboarded_targets` by construction, so it must
|
|
||||||
/// always dispatch to `run_target` regardless of how the legacy paths
|
|
||||||
/// (scheduler, webhooks, `/repositories/{id}/scan`) are configured.
|
|
||||||
pub async fn run_target_scan(
|
|
||||||
&self,
|
|
||||||
tenant_id: &str,
|
|
||||||
target_id: &str,
|
|
||||||
trigger: compliance_core::models::ScanTrigger,
|
|
||||||
) -> Result<(), crate::error::AgentError> {
|
|
||||||
let db = self.db_pool.for_tenant_id(tenant_id).await?;
|
|
||||||
let orchestrator =
|
|
||||||
PipelineOrchestrator::new(self.config.clone(), db, self.llm.clone(), self.http.clone());
|
|
||||||
orchestrator.run_target(target_id, trigger).await
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Run a PR review: scan the diff and post review comments.
|
/// Run a PR review: scan the diff and post review comments.
|
||||||
pub async fn run_pr_review(
|
pub async fn run_pr_review(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
@@ -348,46 +348,3 @@ pub async fn detect_target(
|
|||||||
page: None,
|
page: None,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// POST /api/v1/targets/{id}/scan — trigger a scan for the target.
|
|
||||||
///
|
|
||||||
/// Dispatches to the unified pipeline when `UNIFIED_PIPELINE` is set (else the
|
|
||||||
/// legacy path). Runs in the background and returns immediately.
|
|
||||||
#[tracing::instrument(skip_all, fields(target_id = %id))]
|
|
||||||
pub async fn trigger_target_scan(
|
|
||||||
Extension(agent): AgentExt,
|
|
||||||
tenant: TenantCtx,
|
|
||||||
Path(id): Path<String>,
|
|
||||||
) -> Result<Json<serde_json::Value>, StatusCode> {
|
|
||||||
let oid = parse_oid(&id)?;
|
|
||||||
let db = tenant_db(&agent, &tenant).await?;
|
|
||||||
// 404 if the target doesn't exist for this tenant.
|
|
||||||
if db
|
|
||||||
.onboarded_targets()
|
|
||||||
.find_one(doc! { "_id": oid })
|
|
||||||
.await
|
|
||||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?
|
|
||||||
.is_none()
|
|
||||||
{
|
|
||||||
return Err(StatusCode::NOT_FOUND);
|
|
||||||
}
|
|
||||||
|
|
||||||
let agent_clone = (*agent).clone();
|
|
||||||
let tenant_id = tenant.0.tenant_id.clone();
|
|
||||||
tokio::spawn(async move {
|
|
||||||
// Always the unified target pipeline — this endpoint is about an
|
|
||||||
// onboarded target by construction, independent of the global
|
|
||||||
// `unified_pipeline` transition flag used by the legacy paths.
|
|
||||||
if let Err(e) = agent_clone
|
|
||||||
.run_target_scan(
|
|
||||||
&tenant_id,
|
|
||||||
&id,
|
|
||||||
compliance_core::models::ScanTrigger::Manual,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
tracing::error!("Manual target scan failed for {id}: {e}");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Ok(Json(serde_json::json!({ "status": "scan_triggered" })))
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -48,10 +48,6 @@ pub fn build_router() -> Router {
|
|||||||
"/api/v1/targets/{id}/detect",
|
"/api/v1/targets/{id}/detect",
|
||||||
post(handlers::onboarding::detect_target),
|
post(handlers::onboarding::detect_target),
|
||||||
)
|
)
|
||||||
.route(
|
|
||||||
"/api/v1/targets/{id}/scan",
|
|
||||||
post(handlers::onboarding::trigger_target_scan),
|
|
||||||
)
|
|
||||||
.route("/api/v1/findings", get(handlers::list_findings))
|
.route("/api/v1/findings", get(handlers::list_findings))
|
||||||
.route("/api/v1/findings/{id}", get(handlers::get_finding))
|
.route("/api/v1/findings/{id}", get(handlers::get_finding))
|
||||||
.route(
|
.route(
|
||||||
|
|||||||
@@ -47,12 +47,9 @@ pub fn load_config() -> Result<AgentConfig, AgentError> {
|
|||||||
.unwrap_or_else(|| "/tmp/compliance-scanner/repos".to_string()),
|
.unwrap_or_else(|| "/tmp/compliance-scanner/repos".to_string()),
|
||||||
artifact_store_base_path: env_var_opt("ARTIFACT_STORE_BASE_PATH")
|
artifact_store_base_path: env_var_opt("ARTIFACT_STORE_BASE_PATH")
|
||||||
.unwrap_or_else(|| "/data/compliance-scanner/artifacts".to_string()),
|
.unwrap_or_else(|| "/data/compliance-scanner/artifacts".to_string()),
|
||||||
// Defaults ON: the unified onboarded-target pipeline is now the primary
|
|
||||||
// path (no legacy `repositories` data in production). Set
|
|
||||||
// `UNIFIED_PIPELINE=0` to fall back to the legacy repository pipeline.
|
|
||||||
unified_pipeline: env_var_opt("UNIFIED_PIPELINE")
|
unified_pipeline: env_var_opt("UNIFIED_PIPELINE")
|
||||||
.map(|v| v == "1" || v.eq_ignore_ascii_case("true"))
|
.map(|v| v == "1" || v.eq_ignore_ascii_case("true"))
|
||||||
.unwrap_or(true),
|
.unwrap_or(false),
|
||||||
ssh_key_path: env_var_opt("SSH_KEY_PATH")
|
ssh_key_path: env_var_opt("SSH_KEY_PATH")
|
||||||
.unwrap_or_else(|| "/data/compliance-scanner/ssh/id_ed25519".to_string()),
|
.unwrap_or_else(|| "/data/compliance-scanner/ssh/id_ed25519".to_string()),
|
||||||
keycloak_url: env_var_opt("KEYCLOAK_URL"),
|
keycloak_url: env_var_opt("KEYCLOAK_URL"),
|
||||||
|
|||||||
@@ -1,152 +0,0 @@
|
|||||||
//! Firmware SBOM via tramiton.
|
|
||||||
//!
|
|
||||||
//! Phase 2 (full, the default): drive a **reproducible build** with tramiton's
|
|
||||||
//! `NixBackend` — `analyze` → `seal_and_build` → a sealed lock whose libraries
|
|
||||||
//! are pinned and whose firmware artifact carries a content hash — then render
|
|
||||||
//! the SBOM from the lock plus deep binary SCA of pre-compiled inputs. This is
|
|
||||||
//! the complete bill of materials (toolchain + every fetched library + the
|
|
||||||
//! firmware image), the same one `tramiton sbom` produces.
|
|
||||||
//!
|
|
||||||
//! Phase 1 fallback (analysis-only): when no nix backend is available or the
|
|
||||||
//! build fails, fall back to the resolvable libraries + toolchain from the build
|
|
||||||
//! plan alone (no build). A scan therefore always yields *something*, and a nix
|
|
||||||
//! that can't run in the deployment never breaks a scan.
|
|
||||||
|
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
use compliance_core::models::{SbomEntry, TargetType};
|
|
||||||
use tramiton_repro::ReproBackend;
|
|
||||||
use tramiton_sbom::ComponentKind;
|
|
||||||
|
|
||||||
/// Whether firmware SBOM applies to this target family.
|
|
||||||
pub fn is_firmware_target(target_type: TargetType) -> bool {
|
|
||||||
matches!(
|
|
||||||
target_type,
|
|
||||||
TargetType::FirmwareBareMetal | TargetType::FirmwareRtos | TargetType::EmbeddedLinuxYocto
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Build SBOM entries for a firmware target from its source tree. Prefers a full
|
|
||||||
/// reproducible build (sealed lock); falls back to analysis-only. Returns an
|
|
||||||
/// empty vector when tramiton cannot even form a build plan.
|
|
||||||
pub async fn firmware_sbom_entries(path: &Path, repo_id: &str) -> Vec<SbomEntry> {
|
|
||||||
let p = path.to_path_buf();
|
|
||||||
let repo = repo_id.to_string();
|
|
||||||
// The whole analyze → seal → build → render sequence is blocking (it shells
|
|
||||||
// out to nix), so keep it off the async runtime. Bound it: a firmware build
|
|
||||||
// that hangs must not wedge the scan (the orphaned task is abandoned).
|
|
||||||
let handle = tokio::task::spawn_blocking(move || build_sbom_blocking(&p, &repo));
|
|
||||||
match tokio::time::timeout(std::time::Duration::from_secs(900), handle).await {
|
|
||||||
Ok(Ok(entries)) => entries,
|
|
||||||
Ok(Err(e)) => {
|
|
||||||
tracing::warn!(repo_id, error = %e, "Firmware SBOM: task join error");
|
|
||||||
Vec::new()
|
|
||||||
}
|
|
||||||
Err(_) => {
|
|
||||||
tracing::warn!(repo_id, "Firmware SBOM: build exceeded 15m; skipping");
|
|
||||||
Vec::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn build_sbom_blocking(path: &Path, repo_id: &str) -> Vec<SbomEntry> {
|
|
||||||
let repo = tramiton_core::Repo::new(path);
|
|
||||||
let plan = match tramiton_core::provider::analyze(&repo) {
|
|
||||||
Ok(Some(bp)) => bp,
|
|
||||||
Ok(None) => return Vec::new(),
|
|
||||||
Err(e) => {
|
|
||||||
tracing::warn!(repo_id, error = %e, "Firmware SBOM: tramiton analyze failed");
|
|
||||||
return Vec::new();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Phase 2: reproducible build → sealed lock → complete SBOM.
|
|
||||||
if let Some(backend) = tramiton_repro::NixBackend::detect() {
|
|
||||||
match tramiton_repro::seal_and_build(&backend, &plan, path) {
|
|
||||||
Ok(lock) => {
|
|
||||||
let mut sbom = tramiton_sbom::Sbom::from_lock(&lock, repo_id);
|
|
||||||
// Deep binary SCA of any pre-compiled inputs in the tree.
|
|
||||||
sbom.components.extend(tramiton_sbom::binary::scan(path));
|
|
||||||
let entries = sbom_to_entries(&sbom, repo_id);
|
|
||||||
tracing::info!(
|
|
||||||
repo_id,
|
|
||||||
backend = backend.name(),
|
|
||||||
count = entries.len(),
|
|
||||||
"Firmware SBOM: sealed reproducible build"
|
|
||||||
);
|
|
||||||
return entries;
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
tracing::warn!(repo_id, error = %e, "Firmware SBOM: reproducible build failed; falling back to analysis-only")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
tracing::info!(
|
|
||||||
repo_id,
|
|
||||||
"Firmware SBOM: no nix backend available; analysis-only SBOM"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Phase 1 fallback: analysis-only (toolchain + resolvable libraries).
|
|
||||||
analysis_entries(&plan, repo_id)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Map a rendered [`tramiton_sbom::Sbom`] (primary firmware + components) into
|
|
||||||
/// our [`SbomEntry`] rows. Source-file (`File`) components are dropped — they are
|
|
||||||
/// build inputs, not a dependency inventory.
|
|
||||||
fn sbom_to_entries(sbom: &tramiton_sbom::Sbom, repo_id: &str) -> Vec<SbomEntry> {
|
|
||||||
let mut entries = Vec::new();
|
|
||||||
if let Some(primary) = &sbom.primary {
|
|
||||||
entries.push(component_to_entry(primary, repo_id));
|
|
||||||
}
|
|
||||||
for c in &sbom.components {
|
|
||||||
if matches!(c.kind, ComponentKind::File) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
entries.push(component_to_entry(c, repo_id));
|
|
||||||
}
|
|
||||||
entries
|
|
||||||
}
|
|
||||||
|
|
||||||
fn component_to_entry(c: &tramiton_sbom::Component, repo_id: &str) -> SbomEntry {
|
|
||||||
let manager = match c.kind {
|
|
||||||
ComponentKind::Firmware => "firmware",
|
|
||||||
ComponentKind::Library => "library",
|
|
||||||
ComponentKind::Toolchain => "toolchain",
|
|
||||||
ComponentKind::File => "file",
|
|
||||||
};
|
|
||||||
let mut entry = SbomEntry::new(
|
|
||||||
repo_id.to_string(),
|
|
||||||
c.name.clone(),
|
|
||||||
c.version.clone().unwrap_or_default(),
|
|
||||||
manager.to_string(),
|
|
||||||
);
|
|
||||||
entry.purl = c.source.clone();
|
|
||||||
entry
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Analysis-only components from the build plan: the cross-toolchain plus the
|
|
||||||
/// resolvable fetched libraries, without a build.
|
|
||||||
fn analysis_entries(bp: &tramiton_core::BuildPlan, repo_id: &str) -> Vec<SbomEntry> {
|
|
||||||
let mut entries = Vec::new();
|
|
||||||
if let Some(id) = bp.toolchain.id.clone() {
|
|
||||||
let version = bp.toolchain.version.clone().unwrap_or_default();
|
|
||||||
entries.push(SbomEntry::new(
|
|
||||||
repo_id.to_string(),
|
|
||||||
id,
|
|
||||||
version,
|
|
||||||
"toolchain".to_string(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
for lib in tramiton_repro::lock::libraries_from_inputs(&bp.inputs) {
|
|
||||||
let mut entry = SbomEntry::new(
|
|
||||||
repo_id.to_string(),
|
|
||||||
lib.name,
|
|
||||||
lib.revision,
|
|
||||||
"library".to_string(),
|
|
||||||
);
|
|
||||||
entry.purl = lib.source;
|
|
||||||
entries.push(entry);
|
|
||||||
}
|
|
||||||
entries
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
pub mod code_review;
|
pub mod code_review;
|
||||||
pub mod cve;
|
pub mod cve;
|
||||||
pub mod dedup;
|
pub mod dedup;
|
||||||
pub mod firmware_sbom;
|
|
||||||
pub mod git;
|
pub mod git;
|
||||||
pub mod gitleaks;
|
pub mod gitleaks;
|
||||||
mod graph_build;
|
mod graph_build;
|
||||||
|
|||||||
@@ -461,25 +461,6 @@ impl PipelineOrchestrator {
|
|||||||
} },
|
} },
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
// Refresh the target's cached findings count. The shared pipeline
|
|
||||||
// (Stage 7) increments `repositories`, which the unified path does
|
|
||||||
// not use, so set the accurate total on the target itself.
|
|
||||||
let total = self
|
|
||||||
.db
|
|
||||||
.findings()
|
|
||||||
.count_documents(doc! { "repo_id": target_id })
|
|
||||||
.await
|
|
||||||
.unwrap_or(*count as u64);
|
|
||||||
self.db
|
|
||||||
.onboarded_targets()
|
|
||||||
.update_one(
|
|
||||||
doc! { "_id": oid },
|
|
||||||
doc! { "$set": {
|
|
||||||
"findings_count": total as i64,
|
|
||||||
"updated_at": mongodb::bson::DateTime::now(),
|
|
||||||
} },
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
tracing::error!(target_id, error = %e, "Unified scan pipeline failed");
|
tracing::error!(target_id, error = %e, "Unified scan pipeline failed");
|
||||||
@@ -517,13 +498,6 @@ impl PipelineOrchestrator {
|
|||||||
"Unified pipeline: scan plan built"
|
"Unified pipeline: scan plan built"
|
||||||
);
|
);
|
||||||
|
|
||||||
// Ingest + classify (tramiton for firmware) and store the detected type.
|
|
||||||
self.classify_and_store(target, &target_id, scan_run_id)
|
|
||||||
.await;
|
|
||||||
// Provision a DAST target from a LiveUrl artifact so DAST fires for
|
|
||||||
// wizard-created targets, not just migrated ones.
|
|
||||||
self.ensure_dast_target(target, &plan).await;
|
|
||||||
|
|
||||||
match target.code_artifact() {
|
match target.code_artifact() {
|
||||||
Some(code) if code.kind == ArtifactKind::GitRepo => {
|
Some(code) if code.kind == ArtifactKind::GitRepo => {
|
||||||
let repo = repo_view_from_target(target, code);
|
let repo = repo_view_from_target(target, code);
|
||||||
@@ -553,151 +527,6 @@ impl PipelineOrchestrator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ingest the target's artifacts, classify (tramiton for firmware/RTOS/Yocto,
|
|
||||||
/// heuristics otherwise), and store the detected classification on the target.
|
|
||||||
/// Best-effort — never fails the scan.
|
|
||||||
async fn classify_and_store(
|
|
||||||
&self,
|
|
||||||
target: &OnboardedTarget,
|
|
||||||
target_id: &str,
|
|
||||||
scan_run_id: &str,
|
|
||||||
) {
|
|
||||||
self.update_phase(scan_run_id, "classification").await;
|
|
||||||
let ctx = crate::ingest::IngestContext::from_config(&self.config, target_id);
|
|
||||||
let ingest_set = match crate::ingest::ingest_all(target, &ctx) {
|
|
||||||
Ok(set) => set,
|
|
||||||
Err(e) => {
|
|
||||||
tracing::warn!(target_id, error = %e, "Unified pipeline: ingest for classification failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let working_paths = ingest_set.working_paths();
|
|
||||||
match crate::classify::classify_target(
|
|
||||||
target,
|
|
||||||
&working_paths,
|
|
||||||
&crate::classify::TramitonNative,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
Ok(classification) => {
|
|
||||||
tracing::info!(
|
|
||||||
target_id,
|
|
||||||
suggested = %classification.suggested,
|
|
||||||
"Unified pipeline: classified target"
|
|
||||||
);
|
|
||||||
if let (Some(oid), Ok(bson)) = (target.id, mongodb::bson::to_bson(&classification))
|
|
||||||
{
|
|
||||||
let _ = self
|
|
||||||
.db
|
|
||||||
.onboarded_targets()
|
|
||||||
.update_one(
|
|
||||||
doc! { "_id": oid },
|
|
||||||
doc! { "$set": { "classification": bson } },
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
tracing::warn!(target_id, error = %e, "Unified pipeline: classification failed")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Analysis-based firmware SBOM: for embedded targets, derive components
|
|
||||||
// (resolved libraries + cross-toolchain) from tramiton's build-plan
|
|
||||||
// analysis over the already-ingested source — no build, no binary
|
|
||||||
// upload. Best-effort; empty when no build plan forms.
|
|
||||||
if crate::pipeline::firmware_sbom::is_firmware_target(target.target_type) {
|
|
||||||
if let Some(code) = target.code_artifact() {
|
|
||||||
if let Some(path) = working_paths.get(&code.id) {
|
|
||||||
let entries =
|
|
||||||
crate::pipeline::firmware_sbom::firmware_sbom_entries(path, target_id)
|
|
||||||
.await;
|
|
||||||
if !entries.is_empty() {
|
|
||||||
let _ = self
|
|
||||||
.db
|
|
||||||
.sbom_entries()
|
|
||||||
.delete_many(doc! { "repo_id": target_id })
|
|
||||||
.await;
|
|
||||||
for entry in &entries {
|
|
||||||
let filter = doc! {
|
|
||||||
"repo_id": &entry.repo_id,
|
|
||||||
"name": &entry.name,
|
|
||||||
"version": &entry.version,
|
|
||||||
};
|
|
||||||
if let Ok(d) = mongodb::bson::to_document(entry) {
|
|
||||||
let _ = self
|
|
||||||
.db
|
|
||||||
.sbom_entries()
|
|
||||||
.update_one(filter, doc! { "$set": d })
|
|
||||||
.upsert(true)
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tracing::info!(
|
|
||||||
target_id,
|
|
||||||
count = entries.len(),
|
|
||||||
"Firmware SBOM: stored components from tramiton analysis"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// If the target has a `LiveUrl` artifact and DAST is planned, provision a
|
|
||||||
/// `DastTarget` (keyed by `repo_id` = target id) so the existing DAST trigger
|
|
||||||
/// fires for wizard-created targets. Idempotent.
|
|
||||||
async fn ensure_dast_target(
|
|
||||||
&self,
|
|
||||||
target: &OnboardedTarget,
|
|
||||||
plan: &crate::pipeline::plan::ScanPlan,
|
|
||||||
) {
|
|
||||||
if !plan.has(ScanType::Dast) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let (Some(url), Some(oid)) = (target.live_url(), target.id) else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
let target_id = oid.to_hex();
|
|
||||||
if self
|
|
||||||
.db
|
|
||||||
.dast_targets()
|
|
||||||
.find_one(doc! { "repo_id": &target_id })
|
|
||||||
.await
|
|
||||||
.ok()
|
|
||||||
.flatten()
|
|
||||||
.is_some()
|
|
||||||
{
|
|
||||||
return; // already provisioned
|
|
||||||
}
|
|
||||||
let kind = url
|
|
||||||
.web
|
|
||||||
.as_ref()
|
|
||||||
.map(|w| w.target_kind.clone())
|
|
||||||
.unwrap_or(DastTargetType::WebApp);
|
|
||||||
let mut dast = DastTarget::new(target.name.clone(), url.source_ref.clone(), kind);
|
|
||||||
dast.repo_id = Some(target_id);
|
|
||||||
if let Some(web) = &url.web {
|
|
||||||
dast.excluded_paths = web.excluded_paths.clone();
|
|
||||||
dast.max_crawl_depth = web.max_crawl_depth;
|
|
||||||
dast.rate_limit = web.rate_limit;
|
|
||||||
dast.allow_destructive = web.allow_destructive;
|
|
||||||
}
|
|
||||||
if let Some(auth) = &url.auth {
|
|
||||||
dast.auth_config = Some(DastAuthConfig {
|
|
||||||
method: auth.method.clone(),
|
|
||||||
login_url: auth.login_url.clone(),
|
|
||||||
username: auth.username.clone(),
|
|
||||||
password: None,
|
|
||||||
token: auth.secret.clone(),
|
|
||||||
headers: auth.headers.clone(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if let Err(e) = self.db.dast_targets().insert_one(&dast).await {
|
|
||||||
tracing::warn!(error = %e, "Unified pipeline: failed to provision DAST target");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sync the onboarded-target document after a scan: bump `findings_count`
|
/// Sync the onboarded-target document after a scan: bump `findings_count`
|
||||||
/// and advance the git artifact's `last_scanned_commit` watermark.
|
/// and advance the git artifact's `last_scanned_commit` watermark.
|
||||||
async fn finalize_target(
|
async fn finalize_target(
|
||||||
|
|||||||
@@ -288,25 +288,25 @@ async fn scan_all_repos(agent: &ComplianceAgent, tenant_id: &str) {
|
|||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
let cursor = match db.onboarded_targets().find(doc! {}).await {
|
let cursor = match db.repositories().find(doc! {}).await {
|
||||||
Ok(c) => c,
|
Ok(c) => c,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
tracing::error!("Failed to list targets for tenant '{tenant_id}': {e}");
|
tracing::error!("Failed to list repos for tenant '{tenant_id}': {e}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let targets: Vec<_> = cursor.filter_map(|r| async { r.ok() }).collect().await;
|
let repos: Vec<_> = cursor.filter_map(|r| async { r.ok() }).collect().await;
|
||||||
|
|
||||||
for target in targets {
|
for repo in repos {
|
||||||
let target_id = target.id.map(|id| id.to_hex()).unwrap_or_default();
|
let repo_id = repo.id.map(|id| id.to_hex()).unwrap_or_default();
|
||||||
if let Err(e) = agent
|
if let Err(e) = agent
|
||||||
.run_target_scan(tenant_id, &target_id, ScanTrigger::Scheduled)
|
.run_scan(tenant_id, &repo_id, ScanTrigger::Scheduled)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
tracing::error!(
|
tracing::error!(
|
||||||
"Scheduled scan failed for {} (tenant '{tenant_id}'): {e}",
|
"Scheduled scan failed for {} (tenant '{tenant_id}'): {e}",
|
||||||
target.name
|
repo.name
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,8 +51,7 @@ pub struct AgentConfig {
|
|||||||
pub tenant_registry_url: Option<String>,
|
pub tenant_registry_url: Option<String>,
|
||||||
/// When true, `run_scan` dispatches to the unified `run_target` pipeline
|
/// When true, `run_scan` dispatches to the unified `run_target` pipeline
|
||||||
/// (reads `onboarded_targets`) instead of the legacy repository pipeline.
|
/// (reads `onboarded_targets`) instead of the legacy repository pipeline.
|
||||||
/// Env `UNIFIED_PIPELINE`. Defaults on; set `UNIFIED_PIPELINE=0` to use the
|
/// Env `UNIFIED_PIPELINE`. Defaults off during the transition.
|
||||||
/// legacy repository pipeline.
|
|
||||||
pub unified_pipeline: bool,
|
pub unified_pipeline: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,10 +12,6 @@ pub enum Route {
|
|||||||
OverviewPage {},
|
OverviewPage {},
|
||||||
#[route("/repositories")]
|
#[route("/repositories")]
|
||||||
RepositoriesPage {},
|
RepositoriesPage {},
|
||||||
#[route("/targets")]
|
|
||||||
TargetsPage {},
|
|
||||||
#[route("/onboard")]
|
|
||||||
OnboardingPage {},
|
|
||||||
#[route("/findings")]
|
#[route("/findings")]
|
||||||
FindingsPage {},
|
FindingsPage {},
|
||||||
#[route("/findings/:id")]
|
#[route("/findings/:id")]
|
||||||
|
|||||||
@@ -24,15 +24,10 @@ pub fn Sidebar() -> Element {
|
|||||||
icon: rsx! { Icon { icon: BsSpeedometer2, width: 18, height: 18 } },
|
icon: rsx! { Icon { icon: BsSpeedometer2, width: 18, height: 18 } },
|
||||||
},
|
},
|
||||||
NavItem {
|
NavItem {
|
||||||
label: "Targets",
|
label: "Repositories",
|
||||||
route: Route::TargetsPage {},
|
route: Route::RepositoriesPage {},
|
||||||
icon: rsx! { Icon { icon: BsFolder2Open, width: 18, height: 18 } },
|
icon: rsx! { Icon { icon: BsFolder2Open, width: 18, height: 18 } },
|
||||||
},
|
},
|
||||||
NavItem {
|
|
||||||
label: "Onboard",
|
|
||||||
route: Route::OnboardingPage {},
|
|
||||||
icon: rsx! { Icon { icon: BsPlusCircle, width: 18, height: 18 } },
|
|
||||||
},
|
|
||||||
NavItem {
|
NavItem {
|
||||||
label: "Findings",
|
label: "Findings",
|
||||||
route: Route::FindingsPage {},
|
route: Route::FindingsPage {},
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ pub mod issues;
|
|||||||
pub mod mcp;
|
pub mod mcp;
|
||||||
pub mod mcp_tokens;
|
pub mod mcp_tokens;
|
||||||
pub mod notifications;
|
pub mod notifications;
|
||||||
pub mod onboarding;
|
|
||||||
pub mod pentest;
|
pub mod pentest;
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub mod repositories;
|
pub mod repositories;
|
||||||
|
|||||||
@@ -1,139 +0,0 @@
|
|||||||
//! Server functions for the onboarding wizard — proxy to the agent's
|
|
||||||
//! `/api/v1/targets` endpoints.
|
|
||||||
|
|
||||||
use dioxus::prelude::*;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
/// One artifact the wizard collects for a target.
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
|
|
||||||
pub struct ArtifactInputDto {
|
|
||||||
pub kind: String,
|
|
||||||
pub source_ref: String,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub branch: Option<String>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub plc_format: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
|
||||||
pub struct TargetsResponse {
|
|
||||||
pub data: Vec<serde_json::Value>,
|
|
||||||
pub total: Option<u64>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
|
||||||
pub struct TargetResponse {
|
|
||||||
pub data: serde_json::Value,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
|
||||||
pub struct ApplicableScansData {
|
|
||||||
#[serde(default)]
|
|
||||||
pub scans: Vec<serde_json::Value>,
|
|
||||||
#[serde(default)]
|
|
||||||
pub pentest_supported: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
|
||||||
pub struct ApplicableScansResponse {
|
|
||||||
pub data: ApplicableScansData,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// List onboarded targets.
|
|
||||||
#[server]
|
|
||||||
pub async fn fetch_targets() -> Result<TargetsResponse, ServerFnError> {
|
|
||||||
let resp = super::agent_client::agent_get("/api/v1/targets")
|
|
||||||
.await?
|
|
||||||
.send()
|
|
||||||
.await
|
|
||||||
.map_err(|e| ServerFnError::new(e.to_string()))?;
|
|
||||||
resp.json()
|
|
||||||
.await
|
|
||||||
.map_err(|e| ServerFnError::new(e.to_string()))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a target with the collected artifacts.
|
|
||||||
#[server]
|
|
||||||
pub async fn create_target(
|
|
||||||
name: String,
|
|
||||||
target_type: String,
|
|
||||||
description: Option<String>,
|
|
||||||
artifacts: Vec<ArtifactInputDto>,
|
|
||||||
) -> Result<TargetResponse, ServerFnError> {
|
|
||||||
let body = serde_json::json!({
|
|
||||||
"name": name,
|
|
||||||
"target_type": target_type,
|
|
||||||
"description": description,
|
|
||||||
"artifacts": artifacts,
|
|
||||||
});
|
|
||||||
let resp = super::agent_client::agent_request(reqwest::Method::POST, "/api/v1/targets")
|
|
||||||
.await?
|
|
||||||
.json(&body)
|
|
||||||
.send()
|
|
||||||
.await
|
|
||||||
.map_err(|e| ServerFnError::new(e.to_string()))?;
|
|
||||||
resp.json()
|
|
||||||
.await
|
|
||||||
.map_err(|e| ServerFnError::new(e.to_string()))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Run kind-based classification on a target.
|
|
||||||
#[server]
|
|
||||||
pub async fn detect_target(id: String) -> Result<TargetResponse, ServerFnError> {
|
|
||||||
let resp = super::agent_client::agent_request(
|
|
||||||
reqwest::Method::POST,
|
|
||||||
&format!("/api/v1/targets/{id}/detect"),
|
|
||||||
)
|
|
||||||
.await?
|
|
||||||
.send()
|
|
||||||
.await
|
|
||||||
.map_err(|e| ServerFnError::new(e.to_string()))?;
|
|
||||||
resp.json()
|
|
||||||
.await
|
|
||||||
.map_err(|e| ServerFnError::new(e.to_string()))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Fetch the scan-applicability matrix for a target.
|
|
||||||
#[server]
|
|
||||||
pub async fn fetch_applicable_scans(id: String) -> Result<ApplicableScansResponse, ServerFnError> {
|
|
||||||
let resp = super::agent_client::agent_get(&format!("/api/v1/targets/{id}/applicable-scans"))
|
|
||||||
.await?
|
|
||||||
.send()
|
|
||||||
.await
|
|
||||||
.map_err(|e| ServerFnError::new(e.to_string()))?;
|
|
||||||
resp.json()
|
|
||||||
.await
|
|
||||||
.map_err(|e| ServerFnError::new(e.to_string()))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Delete a target (and cascade its findings / SBOM / scan runs / CVE alerts).
|
|
||||||
#[server]
|
|
||||||
pub async fn delete_target(id: String) -> Result<serde_json::Value, ServerFnError> {
|
|
||||||
let resp = super::agent_client::agent_request(
|
|
||||||
reqwest::Method::DELETE,
|
|
||||||
&format!("/api/v1/targets/{id}"),
|
|
||||||
)
|
|
||||||
.await?
|
|
||||||
.send()
|
|
||||||
.await
|
|
||||||
.map_err(|e| ServerFnError::new(e.to_string()))?;
|
|
||||||
resp.json()
|
|
||||||
.await
|
|
||||||
.map_err(|e| ServerFnError::new(e.to_string()))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Trigger a scan for a target.
|
|
||||||
#[server]
|
|
||||||
pub async fn trigger_target_scan(id: String) -> Result<serde_json::Value, ServerFnError> {
|
|
||||||
let resp = super::agent_client::agent_request(
|
|
||||||
reqwest::Method::POST,
|
|
||||||
&format!("/api/v1/targets/{id}/scan"),
|
|
||||||
)
|
|
||||||
.await?
|
|
||||||
.send()
|
|
||||||
.await
|
|
||||||
.map_err(|e| ServerFnError::new(e.to_string()))?;
|
|
||||||
resp.json()
|
|
||||||
.await
|
|
||||||
.map_err(|e| ServerFnError::new(e.to_string()))
|
|
||||||
}
|
|
||||||
@@ -20,7 +20,7 @@ pub fn FindingsPage() -> Element {
|
|||||||
let mut selected_ids = use_signal(Vec::<String>::new);
|
let mut selected_ids = use_signal(Vec::<String>::new);
|
||||||
|
|
||||||
let repos = use_resource(|| async {
|
let repos = use_resource(|| async {
|
||||||
crate::infrastructure::onboarding::fetch_targets()
|
crate::infrastructure::repositories::fetch_repositories(1)
|
||||||
.await
|
.await
|
||||||
.ok()
|
.ok()
|
||||||
});
|
});
|
||||||
@@ -86,14 +86,14 @@ pub fn FindingsPage() -> Element {
|
|||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
onchange: move |e| { repo_filter.set(e.value()); page.set(1); },
|
onchange: move |e| { repo_filter.set(e.value()); page.set(1); },
|
||||||
option { value: "", "All Targets" }
|
option { value: "", "All Repositories" }
|
||||||
{
|
{
|
||||||
match &*repos.read() {
|
match &*repos.read() {
|
||||||
Some(Some(resp)) => rsx! {
|
Some(Some(resp)) => rsx! {
|
||||||
for t in &resp.data {
|
for repo in &resp.data {
|
||||||
{
|
{
|
||||||
let id = t.get("_id").and_then(|o| o.get("$oid")).and_then(|s| s.as_str()).unwrap_or_default().to_string();
|
let id = repo.id.as_ref().map(|id| id.to_hex()).unwrap_or_default();
|
||||||
let name = t.get("name").and_then(|n| n.as_str()).unwrap_or_default().to_string();
|
let name = repo.name.clone();
|
||||||
rsx! {
|
rsx! {
|
||||||
option { value: "{id}", "{name}" }
|
option { value: "{id}", "{name}" }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,13 +12,11 @@ pub mod impact_analysis;
|
|||||||
pub mod issues;
|
pub mod issues;
|
||||||
pub mod mcp_servers;
|
pub mod mcp_servers;
|
||||||
pub mod mcp_tokens;
|
pub mod mcp_tokens;
|
||||||
pub mod onboarding;
|
|
||||||
pub mod overview;
|
pub mod overview;
|
||||||
pub mod pentest_dashboard;
|
pub mod pentest_dashboard;
|
||||||
pub mod pentest_session;
|
pub mod pentest_session;
|
||||||
pub mod repositories;
|
pub mod repositories;
|
||||||
pub mod sbom;
|
pub mod sbom;
|
||||||
pub mod targets;
|
|
||||||
|
|
||||||
pub use chat::ChatPage;
|
pub use chat::ChatPage;
|
||||||
pub use chat_index::ChatIndexPage;
|
pub use chat_index::ChatIndexPage;
|
||||||
@@ -34,10 +32,8 @@ pub use impact_analysis::ImpactAnalysisPage;
|
|||||||
pub use issues::IssuesPage;
|
pub use issues::IssuesPage;
|
||||||
pub use mcp_servers::McpServersPage;
|
pub use mcp_servers::McpServersPage;
|
||||||
pub use mcp_tokens::McpTokensPage;
|
pub use mcp_tokens::McpTokensPage;
|
||||||
pub use onboarding::OnboardingPage;
|
|
||||||
pub use overview::OverviewPage;
|
pub use overview::OverviewPage;
|
||||||
pub use pentest_dashboard::PentestDashboardPage;
|
pub use pentest_dashboard::PentestDashboardPage;
|
||||||
pub use pentest_session::PentestSessionPage;
|
pub use pentest_session::PentestSessionPage;
|
||||||
pub use repositories::RepositoriesPage;
|
pub use repositories::RepositoriesPage;
|
||||||
pub use sbom::SbomPage;
|
pub use sbom::SbomPage;
|
||||||
pub use targets::TargetsPage;
|
|
||||||
|
|||||||
@@ -1,402 +0,0 @@
|
|||||||
use dioxus::prelude::*;
|
|
||||||
|
|
||||||
use crate::components::page_header::PageHeader;
|
|
||||||
use crate::infrastructure::onboarding::{
|
|
||||||
create_target, detect_target, fetch_applicable_scans, trigger_target_scan, ArtifactInputDto,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// (value, label, one-line description) for the 9 target families.
|
|
||||||
const TARGET_TYPES: &[(&str, &str, &str)] = &[
|
|
||||||
("web_app", "Web Application", "Front end + server"),
|
|
||||||
("backend_service", "Backend / API", "REST, GraphQL, gRPC"),
|
|
||||||
("desktop_app", "Desktop App", "Windows / macOS / Linux"),
|
|
||||||
("android_app", "Android App", "APK / AAB"),
|
|
||||||
("ios_app", "iOS App", "IPA"),
|
|
||||||
(
|
|
||||||
"firmware_bare_metal",
|
|
||||||
"Firmware — bare metal",
|
|
||||||
"No operating system",
|
|
||||||
),
|
|
||||||
("firmware_rtos", "Firmware — RTOS", "Zephyr, FreeRTOS, ..."),
|
|
||||||
(
|
|
||||||
"embedded_linux_yocto",
|
|
||||||
"Embedded Linux / Yocto",
|
|
||||||
"BSP + image",
|
|
||||||
),
|
|
||||||
("plc_sps", "PLC / SPS", "IEC 61131-3"),
|
|
||||||
];
|
|
||||||
|
|
||||||
/// (value, label) for the artifact kinds a user can attach.
|
|
||||||
const ARTIFACT_KINDS: &[(&str, &str)] = &[
|
|
||||||
("git_repo", "Git repository"),
|
|
||||||
("source_archive", "Source archive (zip)"),
|
|
||||||
("firmware_image", "Firmware image"),
|
|
||||||
("mobile_package", "Mobile package (APK/IPA)"),
|
|
||||||
("container_image", "Container image"),
|
|
||||||
("live_url", "Live URL"),
|
|
||||||
("plc_project", "PLC project"),
|
|
||||||
("plaintext_description", "Description (text)"),
|
|
||||||
];
|
|
||||||
|
|
||||||
const STEP_LABELS: &[&str] = &["Target type", "Artifacts", "Review", "Done"];
|
|
||||||
|
|
||||||
/// One row in the applicable-scans list on the success step.
|
|
||||||
#[component]
|
|
||||||
fn ScanRow(scan: serde_json::Value) -> Element {
|
|
||||||
let name = scan
|
|
||||||
.get("scan")
|
|
||||||
.and_then(|v| v.as_str())
|
|
||||||
.unwrap_or("?")
|
|
||||||
.to_string();
|
|
||||||
let rationale = scan
|
|
||||||
.get("rationale")
|
|
||||||
.and_then(|v| v.as_str())
|
|
||||||
.unwrap_or("")
|
|
||||||
.to_string();
|
|
||||||
let blocked = scan
|
|
||||||
.get("blocked_reason")
|
|
||||||
.and_then(|v| v.as_str())
|
|
||||||
.map(String::from);
|
|
||||||
let default_on = scan
|
|
||||||
.get("default_on")
|
|
||||||
.and_then(|v| v.as_bool())
|
|
||||||
.unwrap_or(false);
|
|
||||||
let badge_class = if blocked.is_some() {
|
|
||||||
"badge badge-info"
|
|
||||||
} else if default_on {
|
|
||||||
"badge badge-success"
|
|
||||||
} else {
|
|
||||||
"badge"
|
|
||||||
};
|
|
||||||
rsx! {
|
|
||||||
div { style: "display: flex; gap: 8px; align-items: center; padding: 6px 0;",
|
|
||||||
span { class: "{badge_class}", "{name}" }
|
|
||||||
span { style: "opacity: 0.8;", "{rationale}" }
|
|
||||||
if let Some(b) = blocked {
|
|
||||||
span { style: "opacity: 0.6; font-style: italic;", "— {b}" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn kind_label(kind: &str) -> &str {
|
|
||||||
ARTIFACT_KINDS
|
|
||||||
.iter()
|
|
||||||
.find(|(v, _)| *v == kind)
|
|
||||||
.map(|(_, l)| *l)
|
|
||||||
.unwrap_or(kind)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn type_label(value: &str) -> &str {
|
|
||||||
TARGET_TYPES
|
|
||||||
.iter()
|
|
||||||
.find(|(v, _, _)| *v == value)
|
|
||||||
.map(|(_, l, _)| *l)
|
|
||||||
.unwrap_or(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[component]
|
|
||||||
pub fn OnboardingPage() -> Element {
|
|
||||||
let mut step = use_signal(|| 0usize);
|
|
||||||
let mut name = use_signal(String::new);
|
|
||||||
let mut target_type = use_signal(String::new);
|
|
||||||
let mut description = use_signal(String::new);
|
|
||||||
let mut artifacts = use_signal(Vec::<ArtifactInputDto>::new);
|
|
||||||
|
|
||||||
// "Add artifact" mini-form.
|
|
||||||
let mut new_kind = use_signal(|| "git_repo".to_string());
|
|
||||||
let mut new_source = use_signal(String::new);
|
|
||||||
let mut new_branch = use_signal(|| "main".to_string());
|
|
||||||
|
|
||||||
// Create + result state.
|
|
||||||
let mut creating = use_signal(|| false);
|
|
||||||
let mut error = use_signal(|| Option::<String>::None);
|
|
||||||
let mut scans = use_signal(Vec::<serde_json::Value>::new);
|
|
||||||
let mut suggested = use_signal(|| Option::<String>::None);
|
|
||||||
let mut created_id = use_signal(|| Option::<String>::None);
|
|
||||||
let mut scan_msg = use_signal(|| Option::<String>::None);
|
|
||||||
|
|
||||||
let step_now = step();
|
|
||||||
let can_advance_type = !name().trim().is_empty() && !target_type().trim().is_empty();
|
|
||||||
let has_artifacts = !artifacts().is_empty();
|
|
||||||
|
|
||||||
rsx! {
|
|
||||||
PageHeader {
|
|
||||||
title: "Onboard a target",
|
|
||||||
description: "Add a target, attach its artifacts, and see which scans apply.",
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stepper.
|
|
||||||
div { class: "wizard-steps",
|
|
||||||
for (i, label) in STEP_LABELS.iter().enumerate() {
|
|
||||||
div {
|
|
||||||
class: if i == step_now { "wizard-step wizard-step-active" } else { "wizard-step" },
|
|
||||||
span { class: "wizard-step-dot", "{i + 1}" }
|
|
||||||
span { class: "wizard-step-label", "{label}" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(err) = error() {
|
|
||||||
div { class: "card", style: "border-color: var(--danger, #d33); margin-bottom: 12px;",
|
|
||||||
div { class: "card-header", "Error" }
|
|
||||||
div { style: "padding: 12px;", "{err}" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
div { class: "card",
|
|
||||||
// ---- Step 0: target type + name ----
|
|
||||||
if step_now == 0 {
|
|
||||||
div { class: "card-header", "What kind of software is this?" }
|
|
||||||
div { style: "padding: 16px;",
|
|
||||||
div { class: "form-group",
|
|
||||||
label { "Name" }
|
|
||||||
input {
|
|
||||||
r#type: "text",
|
|
||||||
placeholder: "acme-web",
|
|
||||||
value: "{name}",
|
|
||||||
oninput: move |e| name.set(e.value()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
div {
|
|
||||||
style: "display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-top: 12px;",
|
|
||||||
for (value, tlabel, tdesc) in TARGET_TYPES.iter().copied() {
|
|
||||||
div {
|
|
||||||
class: "card",
|
|
||||||
style: if target_type() == value {
|
|
||||||
"padding: 12px; cursor: pointer; border: 2px solid var(--accent, #3b82f6);"
|
|
||||||
} else {
|
|
||||||
"padding: 12px; cursor: pointer;"
|
|
||||||
},
|
|
||||||
onclick: move |_| target_type.set(value.to_string()),
|
|
||||||
div { style: "font-weight: 600;", "{tlabel}" }
|
|
||||||
div { style: "font-size: 0.85em; opacity: 0.7;", "{tdesc}" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---- Step 1: artifacts ----
|
|
||||||
if step_now == 1 {
|
|
||||||
div { class: "card-header", "Attach artifacts" }
|
|
||||||
div { style: "padding: 16px;",
|
|
||||||
div { style: "display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end;",
|
|
||||||
div { class: "form-group", style: "margin: 0;",
|
|
||||||
label { "Kind" }
|
|
||||||
select {
|
|
||||||
value: "{new_kind}",
|
|
||||||
oninput: move |e| new_kind.set(e.value()),
|
|
||||||
for (value, klabel) in ARTIFACT_KINDS.iter().copied() {
|
|
||||||
option { value: "{value}", "{klabel}" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
div { class: "form-group", style: "margin: 0; flex: 1; min-width: 240px;",
|
|
||||||
label { "Reference (URL / path / text)" }
|
|
||||||
input {
|
|
||||||
r#type: "text",
|
|
||||||
placeholder: "https://git.example.com/acme.git",
|
|
||||||
value: "{new_source}",
|
|
||||||
oninput: move |e| new_source.set(e.value()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if new_kind() == "git_repo" {
|
|
||||||
div { class: "form-group", style: "margin: 0;",
|
|
||||||
label { "Branch" }
|
|
||||||
input {
|
|
||||||
r#type: "text",
|
|
||||||
value: "{new_branch}",
|
|
||||||
oninput: move |e| new_branch.set(e.value()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
button {
|
|
||||||
class: "btn btn-secondary",
|
|
||||||
onclick: move |_| {
|
|
||||||
let kind = new_kind();
|
|
||||||
if !new_source().trim().is_empty() {
|
|
||||||
let branch = if kind == "git_repo" { Some(new_branch()) } else { None };
|
|
||||||
artifacts.write().push(ArtifactInputDto {
|
|
||||||
kind,
|
|
||||||
source_ref: new_source(),
|
|
||||||
branch,
|
|
||||||
plc_format: None,
|
|
||||||
});
|
|
||||||
new_source.set(String::new());
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"+ Add"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
div { style: "margin-top: 16px;",
|
|
||||||
if has_artifacts {
|
|
||||||
for (i, a) in artifacts().iter().enumerate() {
|
|
||||||
div {
|
|
||||||
style: "display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border: 1px solid var(--border, #333); border-radius: 6px; margin-bottom: 6px;",
|
|
||||||
span {
|
|
||||||
span { style: "opacity: 0.7;", "{kind_label(&a.kind)}: " }
|
|
||||||
"{a.source_ref}"
|
|
||||||
}
|
|
||||||
button {
|
|
||||||
class: "btn btn-ghost-danger btn-sm",
|
|
||||||
onclick: move |_| { artifacts.write().remove(i); },
|
|
||||||
"Remove"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
div { style: "opacity: 0.6;", "No artifacts yet. Add at least one." }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---- Step 2: review + create ----
|
|
||||||
if step_now == 2 {
|
|
||||||
div { class: "card-header", "Review" }
|
|
||||||
div { style: "padding: 16px;",
|
|
||||||
div { class: "wizard-summary",
|
|
||||||
div { strong { "Name: " } "{name()}" }
|
|
||||||
div { strong { "Type: " } "{type_label(&target_type())}" }
|
|
||||||
div { strong { "Artifacts:" } }
|
|
||||||
ul {
|
|
||||||
for a in artifacts() {
|
|
||||||
li { "{kind_label(&a.kind)}: {a.source_ref}" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
div { style: "margin-top: 12px; opacity: 0.7; font-size: 0.9em;",
|
|
||||||
"The applicable scans (SAST / DAST / firmware / PLC) are shown after the target is created."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---- Step 3: created ----
|
|
||||||
if step_now == 3 {
|
|
||||||
div { class: "card-header", "Target onboarded" }
|
|
||||||
div { style: "padding: 16px;",
|
|
||||||
p {
|
|
||||||
strong { "{name()}" }
|
|
||||||
" was created."
|
|
||||||
if let Some(s) = suggested() {
|
|
||||||
span { " Suggested type from detection: " strong { "{type_label(&s)}" } "." }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
h4 { style: "margin-top: 16px;", "Applicable scans" }
|
|
||||||
if scans().is_empty() {
|
|
||||||
div { style: "opacity: 0.6;", "No scans available (no code / URL / firmware artifact present)." }
|
|
||||||
} else {
|
|
||||||
for s in scans() {
|
|
||||||
ScanRow { scan: s }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if let Some(msg) = scan_msg() {
|
|
||||||
div { style: "margin-top: 8px; color: var(--success, #2a2);", "{msg}" }
|
|
||||||
}
|
|
||||||
div { style: "margin-top: 16px; display: flex; gap: 8px;",
|
|
||||||
button {
|
|
||||||
class: "btn btn-primary",
|
|
||||||
onclick: move |_| {
|
|
||||||
if let Some(id) = created_id() {
|
|
||||||
scan_msg.set(Some("Scan triggered...".to_string()));
|
|
||||||
spawn(async move {
|
|
||||||
match trigger_target_scan(id).await {
|
|
||||||
Ok(_) => scan_msg.set(Some(
|
|
||||||
"Scan started — findings will appear as it runs.".to_string(),
|
|
||||||
)),
|
|
||||||
Err(e) => scan_msg.set(Some(format!("Failed to start scan: {e}"))),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"Run scan"
|
|
||||||
}
|
|
||||||
button {
|
|
||||||
class: "btn btn-secondary",
|
|
||||||
onclick: move |_| {
|
|
||||||
step.set(0);
|
|
||||||
name.set(String::new());
|
|
||||||
target_type.set(String::new());
|
|
||||||
description.set(String::new());
|
|
||||||
artifacts.write().clear();
|
|
||||||
scans.write().clear();
|
|
||||||
suggested.set(None);
|
|
||||||
created_id.set(None);
|
|
||||||
scan_msg.set(None);
|
|
||||||
error.set(None);
|
|
||||||
},
|
|
||||||
"Onboard another"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---- Footer navigation ----
|
|
||||||
if step_now < 3 {
|
|
||||||
div { style: "display: flex; justify-content: space-between; margin-top: 16px;",
|
|
||||||
button {
|
|
||||||
class: "btn btn-back",
|
|
||||||
disabled: step_now == 0,
|
|
||||||
onclick: move |_| { if step() > 0 { step.set(step() - 1); } },
|
|
||||||
"Back"
|
|
||||||
}
|
|
||||||
if step_now < 2 {
|
|
||||||
button {
|
|
||||||
class: "btn btn-primary",
|
|
||||||
disabled: (step_now == 0 && !can_advance_type) || (step_now == 1 && !has_artifacts),
|
|
||||||
onclick: move |_| step.set(step() + 1),
|
|
||||||
"Next"
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
button {
|
|
||||||
class: "btn btn-primary",
|
|
||||||
disabled: creating(),
|
|
||||||
onclick: move |_| {
|
|
||||||
let n = name();
|
|
||||||
let tt = target_type();
|
|
||||||
let desc = description();
|
|
||||||
let arts = artifacts();
|
|
||||||
let d = if desc.trim().is_empty() { None } else { Some(desc) };
|
|
||||||
creating.set(true);
|
|
||||||
error.set(None);
|
|
||||||
spawn(async move {
|
|
||||||
match create_target(n, tt, d, arts).await {
|
|
||||||
Ok(resp) => {
|
|
||||||
let id = resp
|
|
||||||
.data
|
|
||||||
.get("_id")
|
|
||||||
.and_then(|o| o.get("$oid"))
|
|
||||||
.and_then(|s| s.as_str())
|
|
||||||
.map(String::from);
|
|
||||||
if let Some(id) = id {
|
|
||||||
created_id.set(Some(id.clone()));
|
|
||||||
if let Ok(sc) = fetch_applicable_scans(id.clone()).await {
|
|
||||||
scans.set(sc.data.scans);
|
|
||||||
}
|
|
||||||
if let Ok(det) = detect_target(id).await {
|
|
||||||
suggested.set(
|
|
||||||
det.data
|
|
||||||
.get("classification")
|
|
||||||
.and_then(|c| c.get("suggested"))
|
|
||||||
.and_then(|s| s.as_str())
|
|
||||||
.map(String::from),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
step.set(3);
|
|
||||||
}
|
|
||||||
Err(e) => error.set(Some(e.to_string())),
|
|
||||||
}
|
|
||||||
creating.set(false);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
if creating() { "Creating..." } else { "Create target" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -23,6 +23,20 @@ async fn async_sleep_5s() {
|
|||||||
#[component]
|
#[component]
|
||||||
pub fn RepositoriesPage() -> Element {
|
pub fn RepositoriesPage() -> Element {
|
||||||
let mut page = use_signal(|| 1u64);
|
let mut page = use_signal(|| 1u64);
|
||||||
|
let mut show_add_form = use_signal(|| false);
|
||||||
|
let mut name = use_signal(String::new);
|
||||||
|
let mut git_url = use_signal(String::new);
|
||||||
|
let mut branch = use_signal(|| "main".to_string());
|
||||||
|
let mut auth_token = use_signal(String::new);
|
||||||
|
let mut auth_username = use_signal(String::new);
|
||||||
|
let mut show_auth = use_signal(|| false);
|
||||||
|
let mut ssh_public_key = use_signal(String::new);
|
||||||
|
let mut show_tracker = use_signal(|| false);
|
||||||
|
let mut tracker_type_val = use_signal(String::new);
|
||||||
|
let mut tracker_owner_val = use_signal(String::new);
|
||||||
|
let mut tracker_repo_val = use_signal(String::new);
|
||||||
|
let mut tracker_token_val = use_signal(String::new);
|
||||||
|
let mut adding = use_signal(|| false);
|
||||||
let mut toasts = use_context::<Toasts>();
|
let mut toasts = use_context::<Toasts>();
|
||||||
let mut confirm_delete = use_signal(|| Option::<(String, String)>::None); // (id, name)
|
let mut confirm_delete = use_signal(|| Option::<(String, String)>::None); // (id, name)
|
||||||
let mut edit_repo_id = use_signal(|| Option::<String>::None);
|
let mut edit_repo_id = use_signal(|| Option::<String>::None);
|
||||||
@@ -50,7 +64,222 @@ pub fn RepositoriesPage() -> Element {
|
|||||||
rsx! {
|
rsx! {
|
||||||
PageHeader {
|
PageHeader {
|
||||||
title: "Repositories",
|
title: "Repositories",
|
||||||
description: "Legacy git repositories. Onboard new targets from Targets / Onboard.",
|
description: "Tracked git repositories",
|
||||||
|
}
|
||||||
|
|
||||||
|
div { style: "margin-bottom: 16px;",
|
||||||
|
button {
|
||||||
|
class: "btn btn-primary",
|
||||||
|
onclick: move |_| show_add_form.toggle(),
|
||||||
|
if show_add_form() { "Cancel" } else { "+ Add Repository" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if show_add_form() {
|
||||||
|
div { class: "card",
|
||||||
|
div { class: "card-header", "Add Repository" }
|
||||||
|
div { class: "form-group",
|
||||||
|
label { "Name" }
|
||||||
|
input {
|
||||||
|
r#type: "text",
|
||||||
|
placeholder: "my-project",
|
||||||
|
value: "{name}",
|
||||||
|
oninput: move |e| name.set(e.value()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
div { class: "form-group",
|
||||||
|
label { "Git URL" }
|
||||||
|
input {
|
||||||
|
r#type: "text",
|
||||||
|
placeholder: "https://github.com/org/repo.git or git@github.com:org/repo.git",
|
||||||
|
value: "{git_url}",
|
||||||
|
oninput: move |e| git_url.set(e.value()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
div { class: "form-group",
|
||||||
|
label { "Default Branch" }
|
||||||
|
input {
|
||||||
|
r#type: "text",
|
||||||
|
placeholder: "main",
|
||||||
|
value: "{branch}",
|
||||||
|
oninput: move |e| branch.set(e.value()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Private repo auth section
|
||||||
|
div { style: "margin-top: 8px;",
|
||||||
|
button {
|
||||||
|
class: "btn btn-ghost",
|
||||||
|
style: "font-size: 12px; padding: 4px 8px;",
|
||||||
|
onclick: move |_| {
|
||||||
|
let opening = !show_auth();
|
||||||
|
show_auth.toggle();
|
||||||
|
if opening {
|
||||||
|
// Fetch SSH key every time the section opens
|
||||||
|
ssh_public_key.set(String::new());
|
||||||
|
spawn(async move {
|
||||||
|
match crate::infrastructure::repositories::fetch_ssh_public_key().await {
|
||||||
|
Ok(key) => ssh_public_key.set(key),
|
||||||
|
Err(_) => ssh_public_key.set("(not available)".to_string()),
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
if show_auth() { "Hide auth options" } else { "Private repository?" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if show_auth() {
|
||||||
|
div { class: "auth-section", style: "margin-top: 12px; padding: 12px; border: 1px solid var(--border-subtle); border-radius: 8px;",
|
||||||
|
// SSH deploy key display
|
||||||
|
div { style: "margin-bottom: 12px;",
|
||||||
|
label { style: "font-size: 12px; color: var(--text-secondary);",
|
||||||
|
"For SSH URLs: add this deploy key (read-only) to your repository"
|
||||||
|
}
|
||||||
|
div {
|
||||||
|
class: "copyable",
|
||||||
|
style: "margin-top: 4px; padding: 8px; background: var(--bg-secondary); border-radius: 4px;",
|
||||||
|
code {
|
||||||
|
style: "font-size: 11px; word-break: break-all; user-select: all;",
|
||||||
|
if ssh_public_key().is_empty() {
|
||||||
|
"Loading..."
|
||||||
|
} else {
|
||||||
|
"{ssh_public_key}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !ssh_public_key().is_empty() {
|
||||||
|
crate::components::copy_button::CopyButton { value: ssh_public_key(), small: true }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HTTPS auth fields
|
||||||
|
p { style: "font-size: 12px; color: var(--text-secondary); margin-bottom: 8px;",
|
||||||
|
"For HTTPS URLs: provide an access token (PAT) or username/password"
|
||||||
|
}
|
||||||
|
div { class: "form-group",
|
||||||
|
label { "Auth Token / Password" }
|
||||||
|
input {
|
||||||
|
r#type: "password",
|
||||||
|
placeholder: "ghp_xxxx or personal access token",
|
||||||
|
value: "{auth_token}",
|
||||||
|
oninput: move |e| auth_token.set(e.value()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
div { class: "form-group",
|
||||||
|
label { "Username (optional, defaults to x-access-token)" }
|
||||||
|
input {
|
||||||
|
r#type: "text",
|
||||||
|
placeholder: "x-access-token",
|
||||||
|
value: "{auth_username}",
|
||||||
|
oninput: move |e| auth_username.set(e.value()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Issue tracker config section
|
||||||
|
div { style: "margin-top: 8px;",
|
||||||
|
button {
|
||||||
|
class: "btn btn-ghost",
|
||||||
|
style: "font-size: 12px; padding: 4px 8px;",
|
||||||
|
onclick: move |_| show_tracker.toggle(),
|
||||||
|
if show_tracker() { "Hide tracker options" } else { "Issue tracker?" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if show_tracker() {
|
||||||
|
div { class: "auth-section", style: "margin-top: 12px; padding: 12px; border: 1px solid var(--border-subtle); border-radius: 8px;",
|
||||||
|
p { style: "font-size: 12px; color: var(--text-secondary); margin-bottom: 8px;",
|
||||||
|
"Configure an issue tracker to auto-create issues from findings"
|
||||||
|
}
|
||||||
|
div { class: "form-group",
|
||||||
|
label { "Tracker Type" }
|
||||||
|
select {
|
||||||
|
value: "{tracker_type_val}",
|
||||||
|
onchange: move |e| tracker_type_val.set(e.value()),
|
||||||
|
option { value: "", "None" }
|
||||||
|
option { value: "github", "GitHub" }
|
||||||
|
option { value: "gitlab", "GitLab" }
|
||||||
|
option { value: "gitea", "Gitea" }
|
||||||
|
option { value: "jira", "Jira" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
div { class: "form-group",
|
||||||
|
label { "Owner / Namespace" }
|
||||||
|
input {
|
||||||
|
r#type: "text",
|
||||||
|
placeholder: "org-name",
|
||||||
|
value: "{tracker_owner_val}",
|
||||||
|
oninput: move |e| tracker_owner_val.set(e.value()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
div { class: "form-group",
|
||||||
|
label { "Repository / Project" }
|
||||||
|
input {
|
||||||
|
r#type: "text",
|
||||||
|
placeholder: "repo-name",
|
||||||
|
value: "{tracker_repo_val}",
|
||||||
|
oninput: move |e| tracker_repo_val.set(e.value()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
div { class: "form-group",
|
||||||
|
label { "Tracker Token (PAT)" }
|
||||||
|
input {
|
||||||
|
r#type: "password",
|
||||||
|
placeholder: "ghp_xxxx / glpat-xxxx",
|
||||||
|
value: "{tracker_token_val}",
|
||||||
|
oninput: move |e| tracker_token_val.set(e.value()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
class: "btn btn-primary",
|
||||||
|
disabled: adding(),
|
||||||
|
onclick: move |_| {
|
||||||
|
let n = name();
|
||||||
|
let u = git_url();
|
||||||
|
let b = branch();
|
||||||
|
let tok = {
|
||||||
|
let v = auth_token();
|
||||||
|
if v.is_empty() { None } else { Some(v) }
|
||||||
|
};
|
||||||
|
let usr = {
|
||||||
|
let v = auth_username();
|
||||||
|
if v.is_empty() { None } else { Some(v) }
|
||||||
|
};
|
||||||
|
let tt = { let v = tracker_type_val(); if v.is_empty() { None } else { Some(v) } };
|
||||||
|
let t_owner = { let v = tracker_owner_val(); if v.is_empty() { None } else { Some(v) } };
|
||||||
|
let t_repo = { let v = tracker_repo_val(); if v.is_empty() { None } else { Some(v) } };
|
||||||
|
let t_tok = { let v = tracker_token_val(); if v.is_empty() { None } else { Some(v) } };
|
||||||
|
adding.set(true);
|
||||||
|
spawn(async move {
|
||||||
|
match crate::infrastructure::repositories::add_repository(n, u, b, tok, usr, tt, t_owner, t_repo, t_tok).await {
|
||||||
|
Ok(_) => {
|
||||||
|
toasts.push(ToastType::Success, "Repository added");
|
||||||
|
repos.restart();
|
||||||
|
}
|
||||||
|
Err(e) => toasts.push(ToastType::Error, e.to_string()),
|
||||||
|
}
|
||||||
|
adding.set(false);
|
||||||
|
});
|
||||||
|
show_add_form.set(false);
|
||||||
|
show_auth.set(false);
|
||||||
|
show_tracker.set(false);
|
||||||
|
name.set(String::new());
|
||||||
|
git_url.set(String::new());
|
||||||
|
auth_token.set(String::new());
|
||||||
|
auth_username.set(String::new());
|
||||||
|
tracker_type_val.set(String::new());
|
||||||
|
tracker_owner_val.set(String::new());
|
||||||
|
tracker_repo_val.set(String::new());
|
||||||
|
tracker_token_val.set(String::new());
|
||||||
|
},
|
||||||
|
if adding() { "Validating..." } else { "Add" }
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Delete confirmation dialog ──
|
// ── Delete confirmation dialog ──
|
||||||
|
|||||||
@@ -28,9 +28,9 @@ pub fn SbomPage() -> Element {
|
|||||||
let mut diff_repo_a = use_signal(String::new);
|
let mut diff_repo_a = use_signal(String::new);
|
||||||
let mut diff_repo_b = use_signal(String::new);
|
let mut diff_repo_b = use_signal(String::new);
|
||||||
|
|
||||||
// ── Targets for dropdowns ──
|
// ── Repos for dropdowns ──
|
||||||
let repos = use_resource(|| async {
|
let repos = use_resource(|| async {
|
||||||
crate::infrastructure::onboarding::fetch_targets()
|
crate::infrastructure::repositories::fetch_repositories(1)
|
||||||
.await
|
.await
|
||||||
.ok()
|
.ok()
|
||||||
});
|
});
|
||||||
@@ -114,14 +114,14 @@ pub fn SbomPage() -> Element {
|
|||||||
select {
|
select {
|
||||||
class: "sbom-filter-select",
|
class: "sbom-filter-select",
|
||||||
onchange: move |e| { repo_filter.set(e.value()); page.set(1); },
|
onchange: move |e| { repo_filter.set(e.value()); page.set(1); },
|
||||||
option { value: "", "All Targets" }
|
option { value: "", "All Repositories" }
|
||||||
{
|
{
|
||||||
match &*repos.read() {
|
match &*repos.read() {
|
||||||
Some(Some(resp)) => rsx! {
|
Some(Some(resp)) => rsx! {
|
||||||
for repo in &resp.data {
|
for repo in &resp.data {
|
||||||
{
|
{
|
||||||
let id = repo.get("_id").and_then(|o| o.get("$oid")).and_then(|s| s.as_str()).unwrap_or_default().to_string();
|
let id = repo.id.as_ref().map(|id| id.to_hex()).unwrap_or_default();
|
||||||
let name = repo.get("name").and_then(|n| n.as_str()).unwrap_or_default().to_string();
|
let name = repo.name.clone();
|
||||||
rsx! { option { value: "{id}", "{name}" } }
|
rsx! { option { value: "{id}", "{name}" } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -476,8 +476,8 @@ pub fn SbomPage() -> Element {
|
|||||||
Some(Some(resp)) => rsx! {
|
Some(Some(resp)) => rsx! {
|
||||||
for repo in &resp.data {
|
for repo in &resp.data {
|
||||||
{
|
{
|
||||||
let id = repo.get("_id").and_then(|o| o.get("$oid")).and_then(|s| s.as_str()).unwrap_or_default().to_string();
|
let id = repo.id.as_ref().map(|id| id.to_hex()).unwrap_or_default();
|
||||||
let name = repo.get("name").and_then(|n| n.as_str()).unwrap_or_default().to_string();
|
let name = repo.name.clone();
|
||||||
rsx! { option { value: "{id}", "{name}" } }
|
rsx! { option { value: "{id}", "{name}" } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -498,8 +498,8 @@ pub fn SbomPage() -> Element {
|
|||||||
Some(Some(resp)) => rsx! {
|
Some(Some(resp)) => rsx! {
|
||||||
for repo in &resp.data {
|
for repo in &resp.data {
|
||||||
{
|
{
|
||||||
let id = repo.get("_id").and_then(|o| o.get("$oid")).and_then(|s| s.as_str()).unwrap_or_default().to_string();
|
let id = repo.id.as_ref().map(|id| id.to_hex()).unwrap_or_default();
|
||||||
let name = repo.get("name").and_then(|n| n.as_str()).unwrap_or_default().to_string();
|
let name = repo.name.clone();
|
||||||
rsx! { option { value: "{id}", "{name}" } }
|
rsx! { option { value: "{id}", "{name}" } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,339 +0,0 @@
|
|||||||
//! Targets page — lists onboarded targets (the unified `OnboardedTarget`
|
|
||||||
//! records the wizard creates) and lets the user run a scan, inspect the
|
|
||||||
//! classification / applicable scans, or delete a target.
|
|
||||||
//!
|
|
||||||
//! Creation lives in the Onboard wizard (`/onboard`); this page is the
|
|
||||||
//! "where is my target, and what did the scan find" surface.
|
|
||||||
|
|
||||||
use dioxus::prelude::*;
|
|
||||||
use dioxus_free_icons::icons::bs_icons::*;
|
|
||||||
use dioxus_free_icons::Icon;
|
|
||||||
|
|
||||||
use crate::components::page_header::PageHeader;
|
|
||||||
use crate::components::toast::{ToastType, Toasts};
|
|
||||||
use crate::infrastructure::onboarding::{
|
|
||||||
delete_target, fetch_applicable_scans, fetch_targets, trigger_target_scan,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Prettify a snake_case target-type value into a human label.
|
|
||||||
fn pretty_type(v: &str) -> String {
|
|
||||||
match v {
|
|
||||||
"web_app" => "Web Application".into(),
|
|
||||||
"backend_service" => "Backend / API".into(),
|
|
||||||
"desktop_app" => "Desktop App".into(),
|
|
||||||
"android_app" => "Android App".into(),
|
|
||||||
"ios_app" => "iOS App".into(),
|
|
||||||
"firmware_bare_metal" => "Firmware — bare metal".into(),
|
|
||||||
"firmware_rtos" => "Firmware — RTOS".into(),
|
|
||||||
"embedded_linux_yocto" => "Embedded Linux / Yocto".into(),
|
|
||||||
"plc_sps" => "PLC / SPS".into(),
|
|
||||||
other => other.replace('_', " "),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn str_at<'a>(v: &'a serde_json::Value, key: &str) -> &'a str {
|
|
||||||
v.get(key).and_then(|x| x.as_str()).unwrap_or("")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn target_id(t: &serde_json::Value) -> String {
|
|
||||||
t.get("_id")
|
|
||||||
.and_then(|o| o.get("$oid"))
|
|
||||||
.and_then(|s| s.as_str())
|
|
||||||
.unwrap_or_default()
|
|
||||||
.to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The applicable-scans matrix for one target, fetched on expand.
|
|
||||||
#[component]
|
|
||||||
fn TargetScans(id: String) -> Element {
|
|
||||||
let scan_id = id.clone();
|
|
||||||
let scans = use_resource(move || {
|
|
||||||
let id = scan_id.clone();
|
|
||||||
async move { fetch_applicable_scans(id).await.ok() }
|
|
||||||
});
|
|
||||||
|
|
||||||
let snapshot = scans.read().clone();
|
|
||||||
match &snapshot {
|
|
||||||
Some(Some(resp)) => {
|
|
||||||
let rows = resp.data.scans.clone();
|
|
||||||
let pentest = resp.data.pentest_supported;
|
|
||||||
rsx! {
|
|
||||||
div { style: "margin-top: 8px;",
|
|
||||||
if rows.is_empty() {
|
|
||||||
div { style: "opacity: 0.6;", "No scans available (no code / URL / firmware artifact present)." }
|
|
||||||
}
|
|
||||||
for s in rows {
|
|
||||||
{
|
|
||||||
let name = str_at(&s, "scan").to_string();
|
|
||||||
let rationale = str_at(&s, "rationale").to_string();
|
|
||||||
let blocked = s.get("blocked_reason").and_then(|b| b.as_str()).map(String::from);
|
|
||||||
let default_on = s.get("default_on").and_then(|b| b.as_bool()).unwrap_or(false);
|
|
||||||
let badge = if blocked.is_some() {
|
|
||||||
"badge badge-info"
|
|
||||||
} else if default_on {
|
|
||||||
"badge badge-success"
|
|
||||||
} else {
|
|
||||||
"badge"
|
|
||||||
};
|
|
||||||
rsx! {
|
|
||||||
div { style: "display: flex; gap: 8px; align-items: center; padding: 4px 0;",
|
|
||||||
span { class: "{badge}", "{name}" }
|
|
||||||
span { style: "opacity: 0.8; font-size: 0.9em;", "{rationale}" }
|
|
||||||
if let Some(b) = blocked {
|
|
||||||
span { style: "opacity: 0.6; font-style: italic; font-size: 0.9em;", "— {b}" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if pentest {
|
|
||||||
div { style: "margin-top: 6px; opacity: 0.75; font-size: 0.85em;",
|
|
||||||
"Active pentest is supported for this target type."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some(None) => rsx! { div { style: "opacity: 0.6;", "Failed to load applicable scans." } },
|
|
||||||
None => rsx! { div { style: "opacity: 0.6;", "Loading scans..." } },
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[component]
|
|
||||||
pub fn TargetsPage() -> Element {
|
|
||||||
let mut toasts = use_context::<Toasts>();
|
|
||||||
let mut scanning_ids = use_signal(Vec::<String>::new);
|
|
||||||
let mut expanded_ids = use_signal(Vec::<String>::new);
|
|
||||||
let mut confirm_delete = use_signal(|| Option::<(String, String)>::None);
|
|
||||||
|
|
||||||
let mut targets = use_resource(move || async move { fetch_targets().await.ok() });
|
|
||||||
|
|
||||||
rsx! {
|
|
||||||
PageHeader {
|
|
||||||
title: "Targets",
|
|
||||||
description: "Onboarded targets and what their scans found. Add new targets from Onboard.",
|
|
||||||
}
|
|
||||||
|
|
||||||
div { style: "margin-bottom: 16px; display: flex; gap: 8px;",
|
|
||||||
Link { to: crate::app::Route::OnboardingPage {}, class: "btn btn-primary",
|
|
||||||
"+ Onboard a target"
|
|
||||||
}
|
|
||||||
button {
|
|
||||||
class: "btn btn-secondary",
|
|
||||||
onclick: move |_| targets.restart(),
|
|
||||||
"Refresh"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Delete confirmation ──
|
|
||||||
if let Some((del_id, del_name)) = confirm_delete() {
|
|
||||||
div { class: "modal-overlay",
|
|
||||||
div { class: "modal-dialog",
|
|
||||||
h3 { "Delete Target" }
|
|
||||||
p { "Delete " strong { "{del_name}" } "?" }
|
|
||||||
p { class: "modal-warning",
|
|
||||||
"This permanently removes the target and its findings, SBOM entries, scan runs, and CVE alerts."
|
|
||||||
}
|
|
||||||
div { class: "modal-actions",
|
|
||||||
button {
|
|
||||||
class: "btn btn-secondary",
|
|
||||||
onclick: move |_| confirm_delete.set(None),
|
|
||||||
"Cancel"
|
|
||||||
}
|
|
||||||
button {
|
|
||||||
class: "btn btn-danger",
|
|
||||||
onclick: move |_| {
|
|
||||||
let id = del_id.clone();
|
|
||||||
let name = del_name.clone();
|
|
||||||
confirm_delete.set(None);
|
|
||||||
spawn(async move {
|
|
||||||
match delete_target(id).await {
|
|
||||||
Ok(_) => {
|
|
||||||
toasts.push(ToastType::Success, format!("{name} deleted"));
|
|
||||||
targets.restart();
|
|
||||||
}
|
|
||||||
Err(e) => toasts.push(ToastType::Error, e.to_string()),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
"Delete"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
let targets_snapshot = targets.read().clone();
|
|
||||||
match &targets_snapshot {
|
|
||||||
Some(Some(resp)) => {
|
|
||||||
let rows = resp.data.clone();
|
|
||||||
if rows.is_empty() {
|
|
||||||
rsx! {
|
|
||||||
div { class: "card", style: "padding: 24px; text-align: center;",
|
|
||||||
p { style: "opacity: 0.7;", "No targets yet." }
|
|
||||||
Link { to: crate::app::Route::OnboardingPage {}, class: "btn btn-primary",
|
|
||||||
"Onboard your first target"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
rsx! {
|
|
||||||
div { class: "card",
|
|
||||||
div { class: "table-wrapper",
|
|
||||||
table {
|
|
||||||
thead {
|
|
||||||
tr {
|
|
||||||
th { "Name" }
|
|
||||||
th { "Type" }
|
|
||||||
th { "Detected" }
|
|
||||||
th { "Artifacts" }
|
|
||||||
th { "Findings" }
|
|
||||||
th { "Actions" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tbody {
|
|
||||||
for t in rows {
|
|
||||||
{
|
|
||||||
let id = target_id(&t);
|
|
||||||
let name = str_at(&t, "name").to_string();
|
|
||||||
let ttype = pretty_type(str_at(&t, "target_type"));
|
|
||||||
let suggested = t
|
|
||||||
.get("classification")
|
|
||||||
.and_then(|c| c.get("suggested"))
|
|
||||||
.and_then(|s| s.as_str())
|
|
||||||
.map(pretty_type);
|
|
||||||
let artifacts = t
|
|
||||||
.get("artifacts")
|
|
||||||
.and_then(|a| a.as_array())
|
|
||||||
.cloned()
|
|
||||||
.unwrap_or_default();
|
|
||||||
let findings = t
|
|
||||||
.get("findings_count")
|
|
||||||
.and_then(|n| n.as_u64())
|
|
||||||
.unwrap_or(0);
|
|
||||||
let facts = t
|
|
||||||
.get("classification")
|
|
||||||
.and_then(|c| c.get("facts"))
|
|
||||||
.and_then(|f| f.as_array())
|
|
||||||
.cloned()
|
|
||||||
.unwrap_or_default();
|
|
||||||
let is_scanning = scanning_ids().contains(&id);
|
|
||||||
let is_expanded = expanded_ids().contains(&id);
|
|
||||||
let id_scan = id.clone();
|
|
||||||
let id_exp = id.clone();
|
|
||||||
let id_del = id.clone();
|
|
||||||
let name_del = name.clone();
|
|
||||||
let artifacts_detail = artifacts.clone();
|
|
||||||
rsx! {
|
|
||||||
tr {
|
|
||||||
td { strong { "{name}" } }
|
|
||||||
td { "{ttype}" }
|
|
||||||
td {
|
|
||||||
if let Some(sug) = suggested.clone() {
|
|
||||||
span { class: "badge badge-success", "{sug}" }
|
|
||||||
} else {
|
|
||||||
span { style: "opacity: 0.5;", "—" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
td { "{artifacts.len()}" }
|
|
||||||
td { "{findings}" }
|
|
||||||
td { style: "display: flex; gap: 4px;",
|
|
||||||
button {
|
|
||||||
class: "btn btn-ghost",
|
|
||||||
title: "Details",
|
|
||||||
onclick: move |_| {
|
|
||||||
let mut ids = expanded_ids();
|
|
||||||
if ids.contains(&id_exp) {
|
|
||||||
ids.retain(|i| i != &id_exp);
|
|
||||||
} else {
|
|
||||||
ids.push(id_exp.clone());
|
|
||||||
}
|
|
||||||
expanded_ids.set(ids);
|
|
||||||
},
|
|
||||||
Icon { icon: BsInfoCircle, width: 16, height: 16 }
|
|
||||||
}
|
|
||||||
button {
|
|
||||||
class: if is_scanning { "btn btn-ghost btn-scanning" } else { "btn btn-ghost" },
|
|
||||||
title: "Run scan",
|
|
||||||
disabled: is_scanning,
|
|
||||||
onclick: move |_| {
|
|
||||||
let id = id_scan.clone();
|
|
||||||
let mut ids = scanning_ids();
|
|
||||||
ids.push(id.clone());
|
|
||||||
scanning_ids.set(ids);
|
|
||||||
spawn(async move {
|
|
||||||
match trigger_target_scan(id.clone()).await {
|
|
||||||
Ok(_) => toasts.push(ToastType::Success, "Scan triggered — findings appear as it runs. Use Refresh."),
|
|
||||||
Err(e) => toasts.push(ToastType::Error, e.to_string()),
|
|
||||||
}
|
|
||||||
let mut ids = scanning_ids();
|
|
||||||
ids.retain(|i| i != &id);
|
|
||||||
scanning_ids.set(ids);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
if is_scanning {
|
|
||||||
span { class: "spinner" }
|
|
||||||
} else {
|
|
||||||
Icon { icon: BsPlayCircle, width: 16, height: 16 }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
button {
|
|
||||||
class: "btn btn-ghost btn-ghost-danger",
|
|
||||||
title: "Delete target",
|
|
||||||
onclick: move |_| {
|
|
||||||
confirm_delete.set(Some((id_del.clone(), name_del.clone())));
|
|
||||||
},
|
|
||||||
Icon { icon: BsTrash, width: 16, height: 16 }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if is_expanded {
|
|
||||||
tr {
|
|
||||||
td { colspan: "6",
|
|
||||||
div { style: "padding: 12px 8px;",
|
|
||||||
h4 { style: "margin: 0 0 6px;", "Artifacts" }
|
|
||||||
if artifacts_detail.is_empty() {
|
|
||||||
div { style: "opacity: 0.6;", "No artifacts." }
|
|
||||||
}
|
|
||||||
for a in artifacts_detail {
|
|
||||||
div { style: "font-size: 0.9em; padding: 2px 0;",
|
|
||||||
span { style: "opacity: 0.7;", "{str_at(&a, \"kind\")}: " }
|
|
||||||
span { style: "font-family: monospace;", "{str_at(&a, \"source_ref\")}" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !facts.is_empty() {
|
|
||||||
h4 { style: "margin: 12px 0 6px;", "Detected facts" }
|
|
||||||
for f in facts {
|
|
||||||
div { style: "font-size: 0.9em; padding: 2px 0;",
|
|
||||||
span { style: "font-family: monospace;", "{str_at(&f, \"key\")}={str_at(&f, \"value\")}" }
|
|
||||||
span { style: "opacity: 0.5;", " ({str_at(&f, \"source\")})" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
h4 { style: "margin: 12px 0 6px;", "Applicable scans" }
|
|
||||||
TargetScans { id: id.clone() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some(None) => rsx! {
|
|
||||||
div { class: "card", p { "Failed to load targets." } }
|
|
||||||
},
|
|
||||||
None => rsx! {
|
|
||||||
div { class: "loading", "Loading targets..." }
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user