Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions .github/workflows/verify-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,33 @@ jobs:
run: |
& "C:\Program Files\Git\usr\bin\openssl.exe" genrsa -out private-key.pem 3072

# The agent (automatic SBOM generation) is Linux-only, so on Windows
# an SBOM comes from another tool and is signed via the `sbom` input.
# A minimal CycloneDX document stands in for a real generator here.
- name: Write sample CycloneDX SBOM
shell: pwsh
run: |
@'
{"bomFormat":"CycloneDX","specVersion":"1.5","version":1,"components":[{"type":"application","name":"sample","version":"0.0.1"}]}
'@ | Set-Content -Path sbom.cdx.json

- name: Cimon Attest (Windows, keyed)
uses: ./attest
with:
client-id: ${{ secrets.CIMON_CLIENT_ID }}
secret: ${{ secrets.CIMON_SECRET }}
subjects: dist\sample.exe
sign-key: private-key.pem
sbom: sbom.cdx.json
report-job-summary: true
report-artifact: true
fail-on-error: true

- name: Show provenance
- name: Show provenance and SBOM attestation
shell: pwsh
run: Get-Content provenance.intoto.jsonl
run: |
Get-Content provenance.intoto.jsonl
Get-Item sbom.intoto.jsonl.sig | Select-Object FullName, Length

verify:
runs-on: ubuntu-22.04
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@ This action helps seamlessly deploy the agent into any desired GitHub Actions bu

Learn more about Cimon in our [docs](https://docs.cimon.build).

## 🖥️ Supported platforms

| Runner OS | `cycodelabs/cimon-action` (agent) | `cycodelabs/cimon-action/attest` |
| --------- | --------------------------------- | -------------------------------- |
| Linux | ✅ | ✅ |
| Windows | ❌ | ✅ |
| macOS | ❌ | ✅ |

The agent deployed by this action (runtime monitoring, hardening, process and
file reports, automatic SBOM generation and the `CIMON_SBOM_*` settings) is
built on eBPF and runs **only on Linux runners**. On any other OS the action
stops before installing anything and logs an explanatory error (the step
fails with `fail-on-error: true`).

The Windows and macOS releases of `cimon` are attest-only builds. Use the
[attest sub-action](./attest/README.md) there to generate and sign SLSA
provenance, and to sign an SBOM produced by another tool with
`cimon attest sbom`.

## 🏃‍♂️ Getting Started with Cimon

Getting started with Cimon is as simple as introducing a single step in the pipeline. Cimon Action should be the first step in each of your jobs.
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Cimon by Cycode
description: Runtime Security Solution for your CI/CD Pipeline
description: Runtime Security Solution for your CI/CD Pipeline. Linux runners only; use cimon-action/attest on Windows and macOS.
branding:
icon: shield
color: green
Expand Down
54 changes: 54 additions & 0 deletions attest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,51 @@ matching `cimon` binary (`cimon.exe` on Windows). It uses
`$RUNNER_TEMP` so it cooperates with on-prem GHES self-hosted runners
that may not have `/tmp` writable.

## SBOM attestation (Windows, macOS, or any tool-generated SBOM)

The Cimon agent that generates SBOMs automatically is Linux-only. On any
runner you can instead produce an SBOM with the tool of your choice and
have Cimon sign it as an in-toto attestation over the same artifacts, next
to the provenance, by passing it through the `sbom` input:

```yaml
- name: Generate SBOM
shell: pwsh
run: syft dir:dist -o cyclonedx-json=sbom.cdx.json # any generator works

- uses: cycodelabs/cimon-action/attest@v1
with:
client-id: ${{ secrets.CIMON_CLIENT_ID }}
secret: ${{ secrets.CIMON_SECRET }}
subjects: dist\my-app.exe dist\my-app.dll
sbom: sbom.cdx.json
sign-key: private-key.pem
signed-sbom-output: sbom.intoto.jsonl.sig
```

Accepted SBOM formats: CycloneDX (JSON or XML) and SPDX 2.x (JSON, YAML or
tag-value). The SBOM is signed with the same `sign-key` / `keyless`
settings as the provenance. Verify it with:

```bash
cimon attest verify --client-id "$CIMON_CLIENT_ID" --secret "$CIMON_SECRET" \
--type sbom --subjects "dist/my-app.exe dist/my-app.dll" \
--key public-key.pem --signed-prov sbom.intoto.jsonl.sig
```

The same can be done by hand after the action, since it exports the binary
as `CIMON_PATH` and on `PATH`:

```bash
cimon attest sbom --client-id "$CIMON_CLIENT_ID" --secret "$CIMON_SECRET" \
--sbom sbom.cdx.json --subjects "dist/my-app.exe dist/my-app.dll" \
--key private-key.pem
```

`cimon attest sbom` and `cimon attest verify` need the Cycode credentials
either as `--client-id` / `--secret` or as the `CIMON_CLIENT_ID` /
`CIMON_SECRET` environment variables. Requires cimon v1.0.27 or later.

## GHES support

The action honors `GITHUB_API_URL` and `GITHUB_SERVER_URL` (set
Expand Down Expand Up @@ -98,12 +143,21 @@ releases accept these inputs and produce no timestamp.
| `allow-submit-data-to-public-sigstore` | **Keyless only.** Required when using public Sigstore | `false` |
| `provenance-output` | Path for unsigned provenance | `provenance.intoto.jsonl` |
| `signed-provenance-output` | Path for signed provenance | `provenance.intoto.jsonl.sig` |
| `sbom` | Path to an SBOM produced by another tool (CycloneDX JSON/XML or SPDX 2.x JSON/YAML/tag-value) to sign as an SBOM attestation over the same subjects. Requires cimon v1.0.27 or later | — |
| `signed-sbom-output` | Path for the signed SBOM attestation. Used only when `sbom` is set | `sbom.intoto.jsonl.sig` |
| `report-job-summary` | Render provenance in the workflow job summary | `true` |
| `report-artifact` | Upload provenance as a workflow artifact | `true` |
| `github-token` | Token used for build metadata enrichment | `${{ github.token }}` |
| `log-level` | `trace` / `debug` / `info` | `info` |
| `fail-on-error` | Fail the step on attestation errors | `false` |

## Outputs

| Name | Description |
|---|---|
| `cimon-path` | Absolute path to the installed `cimon` / `cimon.exe` binary (also exported as `CIMON_PATH` and added to `PATH`) |
| `signed-sbom-path` | Path of the signed SBOM attestation. Empty unless `sbom` is set |

## Development

After editing `index.js`, rebuild the bundled distribution:
Expand Down
20 changes: 20 additions & 0 deletions attest/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,22 @@ inputs:
description: Signed provenance output path. Can be absolute path, or relative path to the default working directory
required: false
default: 'provenance.intoto.jsonl.sig'
sbom:
description: |
Path to an SBOM produced by another tool (syft, Microsoft sbom-tool,
cyclonedx-py, ...) to attest alongside the provenance. Accepts
CycloneDX (JSON or XML) and SPDX 2.x (JSON, YAML or tag-value). When
set, the action runs `cimon attest sbom` over the same subjects with
the same signing settings after the provenance run. Requires cimon
v1.0.27 or later. This is the way to get a signed SBOM attestation
on Windows and macOS, where the Cimon agent (automatic SBOM
generation) is not available.
required: false
default: ''
signed-sbom-output:
description: Signed SBOM attestation output path. Can be absolute path, or relative path to the default working directory. Used only when sbom is set
required: false
default: 'sbom.intoto.jsonl.sig'
github-token:
description: GitHub token for enriching build information
required: false
Expand Down Expand Up @@ -106,6 +122,10 @@ outputs:
this action invocation. Downstream steps in the same job can also
reach the binary via the CIMON_PATH env var, or call `cimon` /
`cimon.exe` directly since the action adds the install dir to PATH.
signed-sbom-path:
description: |
Path of the signed SBOM attestation written by `cimon attest sbom`.
Empty when the sbom input is not set.

runs:
using: node20
Expand Down
170 changes: 117 additions & 53 deletions attest/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127706,6 +127706,8 @@ function getActionConfig() {
skipSourceTreeCheck: _actions_core__WEBPACK_IMPORTED_MODULE_0__.getBooleanInput(
'skip-source-tree-check'
),
sbom: _actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput('sbom'),
signedSbomOutput: _actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput('signed-sbom-output'),
},
report: {
reportJobSummary: _actions_core__WEBPACK_IMPORTED_MODULE_0__.getBooleanInput('report-job-summary'),
Expand All @@ -127714,6 +127716,60 @@ function getActionConfig() {
};
}

// backendArgs returns the Cycode backend and logging flags shared by every
// `cimon attest` subcommand.
function backendArgs(config) {
const args = [];
if (config.cimon.clientId !== '')
args.push('--client-id', config.cimon.clientId);
if (config.cimon.secret !== '') args.push('--secret', config.cimon.secret);
if (config.cimon.url !== '') args.push('--url', config.cimon.url);
if (config.cimon.logLevel !== '')
args.push('--log-level', config.cimon.logLevel);
return args;
}

// signingArgs returns the key / keyless / Sigstore / timestamp flags shared
// by `attest generate-and-sign` and `attest sbom`, so both attestations are
// signed the same way.
function signingArgs(config) {
const args = [];
if (config.attest.signKey !== '') args.push('--key', config.attest.signKey);
if (config.attest.keyless) {
args.push('--keyless');

args.push(`--tlog-upload=${config.attest.tlogUpload}`);
args.push(`--include-timestamp=${config.attest.includeTimestamp}`);
args.push(`--yes=${config.attest.allowSubmitDataToPublicSigstore}`);

if (config.attest.fulcioServerUrl !== '') {
args.push(`--fulcio-server-url=${config.attest.fulcioServerUrl}`);
}

if (config.attest.rekorServerUrl !== '') {
args.push(`--rekor-server-url=${config.attest.rekorServerUrl}`);
}

if (config.attest.timestampServerUrl !== '') {
args.push(
`--timestamp-server-url=${config.attest.timestampServerUrl}`
);
}
} else if (config.attest.signKey !== '' && config.attest.includeTimestamp) {
// Key-based signing only timestamps on an explicit request, so the
// inputs are forwarded only when include-timestamp is true. Older
// cimon releases accept and ignore them.
args.push('--include-timestamp=true');

if (config.attest.timestampServerUrl !== '') {
args.push(
`--timestamp-server-url=${config.attest.timestampServerUrl}`
);
}
}
return args;
}

async function run(config) {
let releasePath;

Expand Down Expand Up @@ -127784,71 +127840,40 @@ async function run(config) {
config.attest.subjects = config.attest.imageRef;
}

// Prepare CLI arguments conditionally
const args = ['attest', 'generate-and-sign'];
const provenanceArgs = ['attest', 'generate-and-sign'];
if (config.attest.subjects !== '')
args.push('--subjects', config.attest.subjects);
provenanceArgs.push('--subjects', config.attest.subjects);
if (config.attest.provenanceOutput !== '')
args.push('--output-prov', config.attest.provenanceOutput);
provenanceArgs.push('--output-prov', config.attest.provenanceOutput);
if (config.attest.signedProvenanceOutput !== '')
args.push('--output-signed-prov', config.attest.signedProvenanceOutput);
if (config.attest.signKey !== '') args.push('--key', config.attest.signKey);
provenanceArgs.push(
'--output-signed-prov',
config.attest.signedProvenanceOutput
);
if (config.attest.sourcePath !== '')
args.push('--source-path', config.attest.sourcePath);
provenanceArgs.push('--source-path', config.attest.sourcePath);
if (config.attest.skipSourceTreeCheck)
args.push('--skip-source-tree-check');
if (config.cimon.clientId !== '')
args.push('--client-id', config.cimon.clientId);
if (config.cimon.secret !== '') args.push('--secret', config.cimon.secret);
if (config.cimon.url !== '') args.push('--url', config.cimon.url);
if (config.cimon.logLevel !== '')
args.push('--log-level', config.cimon.logLevel);
if (config.report.reportJobSummary) args.push('--report-job-summary');
if (config.attest.keyless) {
args.push('--keyless');

args.push(`--tlog-upload=${config.attest.tlogUpload}`);
args.push(`--include-timestamp=${config.attest.includeTimestamp}`);
args.push(`--yes=${config.attest.allowSubmitDataToPublicSigstore}`);

if (config.attest.fulcioServerUrl !== '') {
args.push(`--fulcio-server-url=${config.attest.fulcioServerUrl}`);
}
provenanceArgs.push('--skip-source-tree-check');
if (config.report.reportJobSummary)
provenanceArgs.push('--report-job-summary');
provenanceArgs.push(...backendArgs(config), ...signingArgs(config));

if (config.attest.rekorServerUrl !== '') {
args.push(`--rekor-server-url=${config.attest.rekorServerUrl}`);
}

if (config.attest.timestampServerUrl !== '') {
args.push(
`--timestamp-server-url=${config.attest.timestampServerUrl}`
);
}
} else if (config.attest.signKey !== '' && config.attest.includeTimestamp) {
// Key-based signing only timestamps on an explicit request, so the
// inputs are forwarded only when include-timestamp is true. Older
// cimon releases accept and ignore them.
args.push('--include-timestamp=true');

if (config.attest.timestampServerUrl !== '') {
args.push(
`--timestamp-server-url=${config.attest.timestampServerUrl}`
);
}
}

await _actions_exec__WEBPACK_IMPORTED_MODULE_1__.exec(releasePath, args, {
const execOptions = {
env: {
...process.env,
GITHUB_TOKEN: config.github.token,
},
});
};

await _actions_exec__WEBPACK_IMPORTED_MODULE_1__.exec(releasePath, provenanceArgs, execOptions);

if (config.report.reportArtifact) {
const client = new _actions_artifact__WEBPACK_IMPORTED_MODULE_3__.DefaultArtifactClient();
const jobId = process.env.GITHUB_JOB;
const randomSuffix = Math.floor(Math.random() * 1000);
const client = config.report.reportArtifact
? new _actions_artifact__WEBPACK_IMPORTED_MODULE_3__.DefaultArtifactClient()
: null;
const jobId = process.env.GITHUB_JOB;
const randomSuffix = Math.floor(Math.random() * 1000);

if (client) {
client.uploadArtifact(
`provenance-${jobId}-${randomSuffix}`,
[config.attest.provenanceOutput],
Expand All @@ -127866,6 +127891,45 @@ async function run(config) {
}

_actions_core__WEBPACK_IMPORTED_MODULE_0__.info(`Build runtime SLSA provenance finished successfully`);

// Optional SBOM attestation: wrap an SBOM produced by another tool in a
// signed in-toto statement over the same subjects. On Windows/macOS
// the agent (automatic SBOM generation) does not exist, so this is the
// only way to get an SBOM attestation there. The path is checked only
// here, after the provenance run, so a bad value for this optional
// input never blocks the provenance attestation.
if (config.attest.sbom !== '') {
if (!fs__WEBPACK_IMPORTED_MODULE_6__.existsSync(config.attest.sbom)) {
throw new Error(
`SBOM file does not exist: ${config.attest.sbom}. Generate it ` +
`with an SBOM tool (syft, sbom-tool, cyclonedx-py, ...) in an ` +
`earlier step, or unset the sbom input.`
);
}

const sbomArgs = ['attest', 'sbom', '--sbom', config.attest.sbom];
if (config.attest.subjects !== '')
sbomArgs.push('--subjects', config.attest.subjects);
if (config.attest.signedSbomOutput !== '')
sbomArgs.push('--output-signed-sbom', config.attest.signedSbomOutput);
sbomArgs.push(...backendArgs(config), ...signingArgs(config));

await _actions_exec__WEBPACK_IMPORTED_MODULE_1__.exec(releasePath, sbomArgs, execOptions);

if (config.attest.signedSbomOutput !== '') {
_actions_core__WEBPACK_IMPORTED_MODULE_0__.setOutput('signed-sbom-path', config.attest.signedSbomOutput);
if (client) {
client.uploadArtifact(
`signed-sbom-${jobId}-${randomSuffix}`,
[config.attest.signedSbomOutput],
path__WEBPACK_IMPORTED_MODULE_5__.dirname(config.attest.signedSbomOutput),
{ continueOnError: true }
);
}
}

_actions_core__WEBPACK_IMPORTED_MODULE_0__.info(`SBOM attestation finished successfully`);
}
}

try {
Expand Down
Loading