Docs
CI/CD Integration
Run Mikoshi in any CI/CD pipeline
Mikoshi runs in headless mode for automated pipelines.
Headless Mode
Use the -n or --non-interactive flag:
mikoshi -n --target ./app --scan-mode quickFor pull-request style CI runs, Mikoshi automatically scopes quick scans to changed files. You can force this behavior and set a base ref explicitly:
mikoshi -n --target ./app --scan-mode quick --scope-mode diff --diff-base origin/mainExit Codes
| Code | Meaning |
|---|---|
| 0 | No vulnerabilities found (with --fail-on, none at or above the threshold) |
| 1 | Execution error |
| 2 | Vulnerabilities found (with --fail-on, at least one at or above the threshold) |
To fail only on serious findings, pass --fail-on with a minimum severity. Lower findings are still reported but exit 0, so a passing job does not mean the report is empty.:
mikoshi -n --target ./app --scan-mode quick --fail-on highPull-request review comments (GitHub)
With --pr-comments, a headless scan posts its findings to the pull request as one GitHub review when it ends:
- Findings whose code location is on a line changed by the PR (an added or context line inside a diff hunk) become inline comments on that line.
- Everything else (dynamic/endpoint findings, lines outside the diff, files the PR does not touch) is listed in the review summary, with severity counts and the path of each full write-up in the run directory.
- Every finding is counted and listed, including the same issue on several hosts, ports or targets. When two findings would anchor to the same changed line with the same rule, one gets the inline comment and the other is listed in the summary. Text taken from findings (titles, descriptions, paths, ids, severities) is rendered inert: HTML, images,
@mentionsand hidden markers are neutralized. - Re-runs do not duplicate anything. Each inline comment carries a hidden marker, so findings that already have a comment are skipped. Only markers posted by the token's own account count, so markers typed by anyone else (people or other bots) are ignored; see Which account Mikoshi posts as. The summary review is edited in place, and a short follow-up review is posted only when there are new inline findings or changes newly need requesting. A review creation that times out or gets a 5xx is not blindly resent: Mikoshi first re-reads the reviews to check whether GitHub created it.
- The review is a
COMMENTby default. Add--pr-request-changesto submitREQUEST_CHANGESwhen findings meet--fail-on(any finding without it). Changes are requested once; later runs with the same findings only update the summary. GitHub does not allow requesting changes on your own PR; Mikoshi falls back toCOMMENTthere. Once a later run has no finding at or above the threshold, Mikoshi dismisses its own earlierREQUEST_CHANGESreviews (only reviews posted by the token's account with Mikoshi's summary or follow-up marker; other reviews are never touched). If GitHub refuses the dismissal (for example, branch protection limits who may dismiss reviews), the run does not fail: the summary review says a maintainer must dismiss it manually, a warning is printed, and the review ids are recorded underpr_comments.dismissal_failedinrun.json(pr_comments.dismissed_reviewslists successful dismissals). - If the PR head moved after the scan started (a push during the scan), the review is pinned to the scanned commit and inline comments are placed using that commit's diff, so they land on the lines that were scanned; GitHub shows them as outdated where the newer push changed those lines. If that diff cannot be read, every finding is listed in the summary instead. The summary says which commit was scanned. If the scanned commit is no longer part of the PR at all (the branch was force-pushed during the scan) and GitHub refuses a review on it, the review is attached to the current head instead, every finding is listed in the summary, and the summary and a warning say why.
- Posting never changes the exit code. A failure (missing token or permission, API error, unreadable reply) is printed to stderr and recorded under
pr_commentsinrun.json. The token is never logged: every printed or recorded message is scrubbed of the token in use and of the values ofGITHUB_TOKEN,GH_TOKENand the--token-envvariable.
In GitHub Actions everything is detected from the environment: GITHUB_TOKEN, GITHUB_REPOSITORY, GITHUB_EVENT_PATH (PR number and head commit) and GITHUB_API_URL (GitHub Enterprise Server). The job needs pull-requests: write:
name: Security Scan
on:
pull_request:
permissions:
contents: read
pull-requests: write
# One run per PR at a time: two runs racing would each post a summary.
concurrency:
group: mikoshi-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
mikoshi-scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Mikoshi
run: curl -sSL https://www.mikoshi.digital/install | bash
- name: Run Security Scan
env:
MIKOSHI_LLM: ${{ secrets.MIKOSHI_LLM }}
LLM_API_KEY: ${{ secrets.LLM_API_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: mikoshi -n -t ./ --scan-mode quick --fail-on high --pr-comments
- name: Upload run artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: mikoshi-report
path: mikoshi_runsWhich account Mikoshi posts as
Mikoshi reuses its own earlier comments (finding markers, the sticky summary, follow-ups) and dismisses its own requests for changes. To do that safely it must know which account the token posts as; a marker from any other author is never trusted. The account is resolved in this order:
MIKOSHI_PR_BOT_LOGIN, if set: the exact login as REST shows it on the account's comments, for examplemy-app[bot]or, for an Enterprise Managed User,jane_acme. A malformed value fails a real post; a--dry-runignores it with a warning.GET /user, for personal access tokens and other user tokens.- The GraphQL
viewer, for installation tokens (GitHub Apps andGITHUB_TOKEN), which cannot read/userand post as their<app-slug>[bot]account. GraphQL names a bot by its bare slug (github-actions), so when the viewer is aBotMikoshi adds the[bot]suffix REST uses; aUserlogin is taken as is. This read-only query is retried after a timeout or server error like any other read. - In GitHub Actions, when the token comes from the
GITHUB_TOKENvariable:github-actions[bot].
If the account still cannot be determined, Mikoshi trusts no marker at all: it does not skip findings that seem to be commented already, does not edit an earlier summary and never dismisses a review. Each run then posts a fresh review, and a warning (also recorded under pr_comments.warnings in run.json) names the login GitHub attributed the new review to, so you can set MIKOSHI_PR_BOT_LOGIN. If the assumed account turns out to differ from the review's author, the run warns as well. A review is also checked against the posting app when GitHub reports one (performed_via_github_app).
Posting a finished run
mikoshi pr-comment posts (or re-posts) any run without scanning again, for example from a later job that downloaded the run directory as an artifact:
mikoshi pr-comment mikoshi_runs/<run-name> # everything from the Actions environment
mikoshi pr-comment <run-name> --repo owner/name --pr 42 --sha <head-sha> --token-env MY_TOKEN
mikoshi pr-comment <run-name> --dry-run --diff-file <(git diff origin/main...HEAD) # print the review JSON, no network| Option | Meaning |
|---|---|
--repo OWNER/NAME | Repository (default GITHUB_REPOSITORY) |
--pr N | Pull request number (default: from the event file or refs/pull/N/...) |
--sha SHA | Head commit, full or abbreviated (7+ hex digits; default: from the event, else read from the PR). An abbreviation of the PR's current head counts as the head, and the review uses the full SHA |
--token-env VAR | Variable holding the token (default GITHUB_TOKEN, then GH_TOKEN) |
--api-url URL | API base URL (default GITHUB_API_URL or https://api.github.com) |
--fail-on SEVERITY / --request-changes | Submit REQUEST_CHANGES when findings meet the threshold |
--dry-run [--diff-file PATH] | Print the review JSON without any network call; the diff decides inline placement |
Exit codes: 0 posted, updated, nothing to post or dry run; 1 error (any failure, recorded under pr_comments in run.json when the run directory was found); 2 usage.
GitLab CI
security-scan:
image: docker:latest
services:
- docker:dind
variables:
MIKOSHI_LLM: $MIKOSHI_LLM
LLM_API_KEY: $LLM_API_KEY
script:
- curl -sSL https://www.mikoshi.digital/install | bash
- mikoshi -n -t ./ --scan-mode quickJenkins
pipeline {
agent any
environment {
MIKOSHI_LLM = credentials('mikoshi-llm')
LLM_API_KEY = credentials('llm-api-key')
}
stages {
stage('Security Scan') {
steps {
sh 'curl -sSL https://www.mikoshi.digital/install | bash'
sh 'mikoshi -n -t ./ --scan-mode quick'
}
}
}
}CircleCI
version: 2.1
jobs:
security-scan:
docker:
- image: cimg/base:current
steps:
- checkout
- setup_remote_docker
- run:
name: Install Mikoshi
command: curl -sSL https://www.mikoshi.digital/install | bash
- run:
name: Run Scan
command: mikoshi -n -t ./ --scan-mode quick