By the end of this tutorial your pipeline will scan an image, ask TRUSTIVAN whether that scan satisfied your organisation’s policy, and exit non-zero when it did not, while still telling you the difference between “the build should stop” and “TRUSTIVAN was unreachable”. It takes about twenty minutes. You need an account on TRUSTIVAN and an API key; the Quickstart gets you both.

The division of labour, before you start

Two things happen in this tutorial, and they are done by two different principals on purpose. A human writes the policy. policies:manage is not grantable to an API key. A compromised CI credential that could both request a verdict and rewrite the policy it is judged by is a build grading its own homework, and the entire control collapses to nothing. The pipeline only requests verdicts. Its key holds scans:create, scans:read and verdicts:request, and nothing else. It cannot author a policy, and it cannot suppress the findings that failed it. So steps 1 to 3 are done from a browser session: the dashboard, or curl with the session cookies from the Quickstart. Steps 4 onward are what your CI job runs. There is no TRUSTIVAN CLI. The CI story is curl against a scoped key, which is why everything below is a shell command you can paste.

1. Create a policy

A policy starts disabled and with no rules. A policy that began enforcing the moment it was created would break a pipeline before its author had read it back.
Terminal
Keep the id from the response:
Terminal
The policy’s scope is organization. That is the only scope implemented today, and it is the one a team’s first policy needs: “what do we refuse to ship, anywhere”.

2. Add a version with rules

Rules are declarative structs, not code. There is no expression language and no embedded interpreter: a rule is a set of conditions, all of which must hold for a finding to match, plus an effect.
Terminal
Two rules, because OR is expressed by writing a second rule rather than by an operator. That keeps each rule independently explainable in the verdict, which is what a developer reads when the build stops. Every rule was checked against the same inputs, and every rule is reported back, including the ones that did not fire. Every populated condition on a rule is ANDed: min_severity, kinds, statuses, fixabilities, identifiers, older_than_days and min_count. A rule with no conditions is rejected at authoring time, because it would match every finding, which is never what anyone meant. A policy may hold at most 50 rules, and a version with no rules at all is rejected too. This version is now immutable. A database trigger rejects every UPDATE and DELETE on it, unconditionally. Changing the policy later means adding version 2; version 1 stays readable forever, so a verdict recorded today can still be explained next year.

3. Enable it

Terminal
At most one policy may be enabled per scope, enforced by a partial unique index. Without that, “did this scan pass?” would have as many answers as there are enabled policies.

4. Issue the pipeline’s key

Back to a machine credential, with the smallest set of scopes that does the job.
Terminal
expires_at is optional (omitted, it defaults to 90 days), but expiry itself is not: there is no value meaning never. The secret is in the response and nowhere else, ever. Put it straight into your CI provider’s secret store. Note what is absent. There is no findings:suppress, so this credential cannot silence the findings that fail it. There is no policies:manage, because no credential may hold it.

5. Request a scan

Terminal
202 means the work was accepted, not that it is done. A 200 instead means an existing scan was returned, so a retry that was deduplicated is distinguishable from a fresh request. Use your build identifier as the idempotency key: it is reserved before any work begins, so two concurrent retries cannot both queue a scan.

6. Poll until the scan is terminal

Terminal
Give the loop a real ceiling. Pulling and unpacking a large image takes minutes, and a poll loop with no bound is a build that hangs rather than one that reports a problem. The scan body also carries database_state, which reports how fresh the advisory data behind the result was. A scan run against stale data reports “no vulnerabilities” with exactly the same confidence as a correct one, which is why TRUSTIVAN surfaces the age rather than hiding it.

7. Ask for the verdict

This is the only request the gate itself needs. It never has to look at a single finding.
Terminal
201 when a decision is recorded, 200 when a retry replays the one already recorded. Idempotency here is a unique constraint on (scan, policy version), so a CI job that retries because its pod was preempted gets the same answer rather than a second decision.

8. Branch on the body, not the status line

This is the most important step in the tutorial.
Terminal
A failing verdict is a successful request. The HTTP status describes whether TRUSTIVAN answered; the body describes what the answer was. A pipeline that treated a policy failure as an HTTP error could not distinguish “the build should stop” from “TRUSTIVAN is down”, and those two demand opposite reactions. The first fails the build. The second is retried, or escalated to a human, but it is never quietly interpreted as a pass. result is one of pass, warn or fail. Only fail blocks, and blocking is precomputed in the body so your gate does not reimplement TRUSTIVAN’s opinion about which results stop a deployment. A warning that blocks is a failure with a friendlier name.

9. Read why

When the gate stops a build, the reason is already in the response you have.
Terminal
Every rule is reported, fired or not, with how many findings matched, the threshold it was compared against, and a bounded sample of the findings responsible. A passing verdict explains itself too: “what was checked?” is a real question, especially the first time a policy is turned on.

What you have now

A pipeline that stops on a policy failure, keeps running on a warning, and fails loudly rather than silently when TRUSTIVAN cannot answer. The decision it acted on is recorded, attributed to the key that requested it, and will still be explainable after the policy changes. From here: