-
Notifications
You must be signed in to change notification settings - Fork 126
feat: add JFrog Xray vulnerability scanning module #410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+464
−0
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
132b900
feat: add JFrog Xray vulnerability scanning module
blink-so[bot] c715cf1
fix: format code with prettier and terraform fmt
blink-so[bot] 1beb3bb
fix: add required Terraform code block to README
blink-so[bot] caef723
fix: format README with prettier
blink-so[bot] a72c36e
fix: remove unsupported check_license argument from xray provider
blink-so[bot] fdc83a3
fix: handle null xray scan results with try() function
blink-so[bot] 43a49cb
fix: remove trailing whitespace in terraform file
blink-so[bot] b0c1593
fix: address review feedback for jfrog-xray module
blink-so[bot] 7b64b7c
fix: add JFrog Xray icon and remove Variables section from README
blink-so[bot] 6703269
fix: align terraform formatting in provider block
blink-so[bot] 8f14131
refactor: remove inline provider and metadata from jfrog-xray module
blink-so[bot] 516b232
feat: enhance jfrog-xray module with improved testing and new features
DevelopmentCats 34a77fd
docs: update README for jfrog-xray module configuration
DevelopmentCats d6c6f00
Merge branch 'main' into blink/jfrog-xray-module
DevelopmentCats 3d55bb1
refactor: update README to clarify examples and clarify tags
DevelopmentCats 6fc47f3
chore: update README for jfrog-xray module with fixed URLs and image …
DevelopmentCats 61d1f23
refactor: update jfrog-xray module configuration and tests
DevelopmentCats File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| --- | ||
| display_name: JFrog Xray | ||
| description: Fetch container image vulnerability scan results from JFrog Xray | ||
| icon: ../../../../.icons/jfrog-xray.svg | ||
| verified: true | ||
| tags: [jfrog, xray] | ||
| --- | ||
|
|
||
| # JFrog Xray | ||
|
|
||
| This module fetches vulnerability scan results from JFrog Xray for container images stored in Artifactory. Use the outputs to display security information as workspace metadata. | ||
|
|
||
| ```tf | ||
| module "jfrog_xray" { | ||
| source = "registry.coder.com/coder/jfrog-xray/coder" | ||
| version = "1.0.0" | ||
|
|
||
| xray_url = "https://example.jfrog.io/xray" | ||
| xray_token = var.artifactory_access_token | ||
| image = "docker-local/myapp/backend:v1.0.0" | ||
| } | ||
|
|
||
| resource "coder_metadata" "xray_scan" { | ||
| count = data.coder_workspace.me.start_count | ||
| resource_id = docker_container.workspace[0].id | ||
| icon = "/icon/shield.svg" | ||
|
|
||
| item { | ||
| key = "Image" | ||
| value = "docker-local/myapp/backend:v1.0.0" | ||
| } | ||
| item { | ||
| key = "Total Vulnerabilities" | ||
| value = module.jfrog_xray.total | ||
| } | ||
| item { | ||
| key = "Critical" | ||
| value = module.jfrog_xray.critical | ||
| } | ||
| item { | ||
| key = "High" | ||
| value = module.jfrog_xray.high | ||
| } | ||
| item { | ||
| key = "Medium" | ||
| value = module.jfrog_xray.medium | ||
| } | ||
| item { | ||
| key = "Low" | ||
| value = module.jfrog_xray.low | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| 1. Container images must be stored in JFrog Artifactory | ||
| 2. JFrog Xray must be configured to scan your repositories | ||
| 3. A valid JFrog access token with Xray read permissions | ||
|
|
||
| ## Remote Repositories | ||
|
|
||
| When scanning images from remote (proxy) repositories, set `use_cache_repo = true`. This is because Artifactory stores cached images in a companion `-cache` repository where Xray indexes the scan results. | ||
|
|
||
| ```tf | ||
| module "jfrog_xray" { | ||
| source = "registry.coder.com/coder/jfrog-xray/coder" | ||
| version = "1.0.0" | ||
|
|
||
| xray_url = "https://example.jfrog.io/xray" | ||
| xray_token = var.artifactory_access_token | ||
| image = "docker-remote/library/nginx:latest" | ||
| use_cache_repo = true | ||
| } | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,244 @@ | ||
| import { serve } from "bun"; | ||
| import { describe, expect, it } from "bun:test"; | ||
| import { createJSONResponse, runTerraformInit, runTerraformApply } from "~test"; | ||
|
|
||
| describe("jfrog-xray", async () => { | ||
| await runTerraformInit(import.meta.dir); | ||
|
|
||
| // Mock server simulating a local repo with direct scan results | ||
| const mockLocalRepo = serve({ | ||
DevelopmentCats marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fetch: (req) => { | ||
| const url = new URL(req.url); | ||
| if (url.pathname === "/xray/api/v1/system/version") | ||
| return createJSONResponse({ | ||
| xray_version: "3.80.0", | ||
| xray_revision: "abc123", | ||
| }); | ||
| if (url.pathname === "/xray/api/v1/artifacts") | ||
| return createJSONResponse({ | ||
| data: [ | ||
| { | ||
| name: "myapp/backend/v1.0.0", | ||
| repo_path: "/myapp/backend/v1.0.0/manifest.json", | ||
| size: "50.00 MB", | ||
| sec_issues: { | ||
| critical: 1, | ||
| high: 3, | ||
| medium: 5, | ||
| low: 10, | ||
| total: 19, | ||
| }, | ||
| scans_status: { | ||
| overall: { | ||
| status: "DONE", | ||
| time: "2026-03-04T22:00:02Z", | ||
| }, | ||
| }, | ||
| violations: 0, | ||
| }, | ||
| ], | ||
| offset: 0, | ||
| }); | ||
| return createJSONResponse({}); | ||
| }, | ||
| port: 0, | ||
| }); | ||
|
|
||
| // Mock server simulating a remote repo with cache behavior | ||
| // Returns both tag manifest (0 vulns, 0 size) and SHA manifest (real vulns, real size) | ||
| const mockRemoteRepo = serve({ | ||
DevelopmentCats marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fetch: (req) => { | ||
| const url = new URL(req.url); | ||
| if (url.pathname === "/xray/api/v1/system/version") | ||
| return createJSONResponse({ | ||
| xray_version: "3.80.0", | ||
| xray_revision: "abc123", | ||
| }); | ||
| if (url.pathname === "/xray/api/v1/artifacts") | ||
| return createJSONResponse({ | ||
| data: [ | ||
| { | ||
| name: "codercom/enterprise-base/ubuntu", | ||
| repo_path: "/codercom/enterprise-base/ubuntu/list.manifest.json", | ||
| size: "0.00 B", | ||
| sec_issues: { total: 0 }, | ||
| scans_status: { | ||
| overall: { status: "DONE" }, | ||
| }, | ||
| violations: 0, | ||
| }, | ||
| { | ||
| name: "codercom/enterprise-base/sha256__abc123def456", | ||
| repo_path: | ||
| "/codercom/enterprise-base/sha256__abc123def456/manifest.json", | ||
| size: "359.33 MB", | ||
| sec_issues: { | ||
| critical: 2, | ||
| high: 6, | ||
| medium: 20, | ||
| low: 23, | ||
| total: 51, | ||
| }, | ||
| scans_status: { | ||
| overall: { status: "DONE" }, | ||
| }, | ||
| violations: 2, | ||
| }, | ||
| ], | ||
| offset: 0, | ||
| }); | ||
| return createJSONResponse({}); | ||
| }, | ||
| port: 0, | ||
| }); | ||
|
|
||
| // Mock server returning empty results (image not scanned) | ||
| const mockEmptyResults = serve({ | ||
DevelopmentCats marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fetch: (req) => { | ||
| const url = new URL(req.url); | ||
| if (url.pathname === "/xray/api/v1/system/version") | ||
| return createJSONResponse({ | ||
| xray_version: "3.80.0", | ||
| xray_revision: "abc123", | ||
| }); | ||
| if (url.pathname === "/xray/api/v1/artifacts") | ||
| return createJSONResponse({ data: [], offset: -1 }); | ||
| return createJSONResponse({}); | ||
| }, | ||
| port: 0, | ||
| }); | ||
|
|
||
| const localRepoUrl = `http://${mockLocalRepo.hostname}:${mockLocalRepo.port}`; | ||
| const remoteRepoUrl = `http://${mockRemoteRepo.hostname}:${mockRemoteRepo.port}`; | ||
| const emptyResultsUrl = `http://${mockEmptyResults.hostname}:${mockEmptyResults.port}`; | ||
|
|
||
| const getProviderEnv = (url: string) => ({ | ||
| XRAY_URL: url, | ||
| XRAY_ACCESS_TOKEN: "test-token", | ||
| }); | ||
|
|
||
| it("validates required variable: xray_url", async () => { | ||
| try { | ||
| await runTerraformApply( | ||
| import.meta.dir, | ||
| { | ||
| xray_token: "test-token", | ||
| image: "docker-local/test/image:latest", | ||
| }, | ||
| getProviderEnv(localRepoUrl), | ||
| ); | ||
| throw new Error("Expected apply to fail without xray_url"); | ||
| } catch (ex) { | ||
| if (!(ex instanceof Error)) throw new Error("Unknown error"); | ||
| expect(ex.message).toContain('input variable "xray_url" is not set'); | ||
| } | ||
| }); | ||
|
|
||
| it("validates required variable: xray_token", async () => { | ||
| try { | ||
| await runTerraformApply( | ||
| import.meta.dir, | ||
| { | ||
| xray_url: localRepoUrl, | ||
| image: "docker-local/test/image:latest", | ||
| }, | ||
| getProviderEnv(localRepoUrl), | ||
| ); | ||
| throw new Error("Expected apply to fail without xray_token"); | ||
| } catch (ex) { | ||
| if (!(ex instanceof Error)) throw new Error("Unknown error"); | ||
| expect(ex.message).toContain('input variable "xray_token" is not set'); | ||
| } | ||
| }); | ||
|
|
||
| it("validates required variable: image", async () => { | ||
| try { | ||
| await runTerraformApply( | ||
| import.meta.dir, | ||
| { | ||
| xray_url: localRepoUrl, | ||
| xray_token: "test-token", | ||
| }, | ||
| getProviderEnv(localRepoUrl), | ||
| ); | ||
| throw new Error("Expected apply to fail without image"); | ||
| } catch (ex) { | ||
| if (!(ex instanceof Error)) throw new Error("Unknown error"); | ||
| expect(ex.message).toContain('input variable "image" is not set'); | ||
| } | ||
| }); | ||
|
|
||
| it("returns vulnerability counts for local repository", async () => { | ||
| const state = await runTerraformApply( | ||
| import.meta.dir, | ||
| { | ||
| xray_url: localRepoUrl, | ||
| xray_token: "test-token", | ||
| image: "docker-local/myapp/backend:v1.0.0", | ||
| }, | ||
| getProviderEnv(localRepoUrl), | ||
| ); | ||
|
|
||
| expect(state.outputs.critical.value).toBe(1); | ||
| expect(state.outputs.high.value).toBe(3); | ||
| expect(state.outputs.medium.value).toBe(5); | ||
| expect(state.outputs.low.value).toBe(10); | ||
| expect(state.outputs.total.value).toBe(19); | ||
| }); | ||
|
|
||
| it("returns zero counts when image has no scan results", async () => { | ||
| const state = await runTerraformApply( | ||
| import.meta.dir, | ||
| { | ||
| xray_url: emptyResultsUrl, | ||
| xray_token: "test-token", | ||
| image: "docker-local/unscanned/image:latest", | ||
| }, | ||
| getProviderEnv(emptyResultsUrl), | ||
| ); | ||
|
|
||
| expect(state.outputs.critical.value).toBe(0); | ||
| expect(state.outputs.high.value).toBe(0); | ||
| expect(state.outputs.medium.value).toBe(0); | ||
| expect(state.outputs.low.value).toBe(0); | ||
| expect(state.outputs.total.value).toBe(0); | ||
| }); | ||
|
|
||
| it("uses cache repo when use_cache_repo is enabled", async () => { | ||
| const state = await runTerraformApply( | ||
| import.meta.dir, | ||
| { | ||
| xray_url: remoteRepoUrl, | ||
| xray_token: "test-token", | ||
| image: "docker-remote/codercom/enterprise-base:ubuntu", | ||
| use_cache_repo: true, | ||
| }, | ||
| getProviderEnv(remoteRepoUrl), | ||
| ); | ||
|
|
||
| // Should find the SHA artifact with actual vulnerabilities | ||
| expect(state.outputs.critical.value).toBe(2); | ||
| expect(state.outputs.high.value).toBe(6); | ||
| expect(state.outputs.medium.value).toBe(20); | ||
| expect(state.outputs.low.value).toBe(23); | ||
| expect(state.outputs.total.value).toBe(51); | ||
| expect(state.outputs.violations.value).toBe(2); | ||
| expect(state.outputs.artifact_name.value).toContain("sha256__"); | ||
| }); | ||
|
|
||
| it("allows custom repo and repo_path override", async () => { | ||
| const state = await runTerraformApply( | ||
| import.meta.dir, | ||
| { | ||
| xray_url: localRepoUrl, | ||
| xray_token: "test-token", | ||
| image: "ignored/path:tag", | ||
| repo: "docker-local", | ||
| repo_path: "/myapp/backend/v1.0.0", | ||
| }, | ||
| getProviderEnv(localRepoUrl), | ||
| ); | ||
|
|
||
| expect(state.outputs.total.value).toBe(19); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.