Files
integraci-dagger-modules/sbom/README.md
T

77 lines
3.9 KiB
Markdown

# sbom — IntegraCI Dagger module
Engine-agnostic Software Bill of Materials (SBOM) generation. Callable from
any CI engine via `dagger call`. Translates the GitHub-Actions-only intent of
`security_pipeline_adapter.build_sbom_step` into canonical tool CLIs run inside
official containers.
## Verb
### `generate`
```
dagger call generate --source . [--image-ref REF] [--generator NAME]
```
| arg | required | default | description |
| ------------ | -------- | ------- | -------------------------------------------------------- |
| `--source` | yes | — | source directory to analyze |
| `--image-ref`| no | "" | container image to scan instead of the filesystem |
| `--generator`| no | `syft` | `syft \| cyclonedx \| spdx-tools \| trivy \| none` |
| `--registry-insecure` | no | false | the `--image-ref` registry is plain HTTP / self-signed (syft only) |
| `--registry-username` | no | "" | login for pulling `--image-ref` (paired with `--registry-password`) |
| `--registry-password` | no | — | Dagger secret (`env://VAR`), never a literal |
Returns the SBOM document as a `File`.
### Registry login
A registry that authenticates reads (Nexus with `forceBasicAuth`, most private
Harbor projects) refuses an anonymous manifest GET with `UNAUTHORIZED`. Give the
pull the same login the build pushed with:
- `syft` / `spdx-tools`: `SYFT_REGISTRY_AUTH_AUTHORITY` (the registry host of
`--image-ref`), `SYFT_REGISTRY_AUTH_USERNAME`, and `SYFT_REGISTRY_AUTH_PASSWORD`
as a secret variable — the names syft v1.18.1 reads
(`cmd/syft/internal/options/registry.go`).
- `trivy`: NOT `TRIVY_USERNAME`/`TRIVY_PASSWORD`, which trivy presents on every
OCI pull including its vulnerability-DB downloads. The exec line writes a
private `DOCKER_CONFIG` with one `auths` entry for the `--image-ref` host only,
from a secret variable.
- With a login, the repository checkout is **not** mounted and the working
directory is an empty `/work`: the image scan does not need the tree, and a
repository-controlled `.syft.yaml` / `trivy.yaml` could otherwise send the
login over plain HTTP or to another host.
Only both halves turn the login on. A complete pair with an `--image-ref` that
names no registry host is refused rather than sent to a guessed host. The
host-resolution logic lives in the stdlib-only `pullauth/` package so it can be
unit-tested without an engine session.
## Generators
| generator | image | output | notes |
| ------------ | --------------------------- | ----------------------- | -------------------------------------- |
| `syft` | `anchore/syft` | CycloneDX JSON | source dir or `--image-ref` |
| `cyclonedx` | `cyclonedx/cyclonedx-cli` | CycloneDX JSON | converts existing `bom.{xml,json}` |
| `spdx-tools` | `anchore/syft` | SPDX JSON | practical SPDX generator; dir or image |
| `trivy` | `aquasec/trivy` | CycloneDX JSON | `trivy fs`/`trivy image` |
| `none` | `alpine` | skip marker JSON | no-op, mirrors adapter skip intent |
## Examples
```bash
# Default: Syft CycloneDX over the source tree
dagger call generate --source . -o sbom.cdx.json
# Trivy scanning a built image
dagger call generate --source . --image-ref ghcr.io/org/app:tag --generator trivy -o sbom.cdx.json
# Private registry: the password is read from the environment as a secret
dagger call generate --source . --image-ref registry.example.test:8082/app:tag \
--registry-username "$REG_USER" --registry-password env://REG_PASS -o sbom.cdx.json
# SPDX document
dagger call generate --source . --generator spdx-tools -o sbom.spdx.json
```