Skip to content

feat: add JFrog Xray vulnerability scanning module#410

Merged
DevelopmentCats merged 17 commits intomainfrom
blink/jfrog-xray-module
Mar 6, 2026
Merged

feat: add JFrog Xray vulnerability scanning module#410
DevelopmentCats merged 17 commits intomainfrom
blink/jfrog-xray-module

Conversation

@blink-so
Copy link
Copy Markdown
Contributor

@blink-so blink-so Bot commented Sep 4, 2025

This PR adds a new Terraform module that fetches JFrog Xray vulnerability scanning results for container images stored in Artifactory.

Features

  • Fetches vulnerability scan results from JFrog Xray
  • Outputs vulnerability counts (Critical, High, Medium, Low, Total)
  • Supports flexible image path formats
  • Works with any workspace type using container images
  • Provides secure token handling

Design Decisions

During testing, we found two issues with the original approach of defining the xray provider and coder_metadata inside the module:

  1. coder_metadata defined inside modules does not display in the Coder dashboard — this is a known limitation
  2. Inline provider blocks prevent using count/for_each on the module — which is needed when attaching metadata to resources like docker_container that use start_count

The module now outputs vulnerability counts instead, and the caller creates the coder_metadata and configures the xray provider in their root template. This matches the pattern used by other registry modules.

Usage

provider "xray" {
  url                     = "${var.jfrog_url}/xray"
  access_token            = var.artifactory_access_token
  skip_xray_version_check = true
}

module "jfrog_xray" {
  source  = "registry.coder.com/coder/jfrog-xray/coder"
  version = "1.0.0"

  xray_url   = "${var.jfrog_url}/xray"
  xray_token = var.artifactory_access_token
  image      = "docker-local/codercom/enterprise-base:latest"
}

resource "coder_metadata" "xray_vulnerabilities" {
  count       = data.coder_workspace.me.start_count
  resource_id = docker_container.workspace[0].id
  icon        = "/icon/shield.svg"

  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
  }
}

Related Issues

Tested with a JFrog Cloud trial instance using Docker remote repository and Xray scanning.

blink-so Bot and others added 3 commits September 4, 2025 07:08
Adds a Terraform module that integrates JFrog Xray vulnerability scanning
results into Coder workspace metadata. The module:

- Fetches vulnerability scan results from JFrog Xray
- Displays vulnerability counts (Critical, High, Medium, Low) on workspace page
- Supports flexible image path formats
- Works with any workspace type using container images
- Provides secure token handling

Resolves coder/coder#12838 and addresses #65

Co-authored-by: matifali <10648092+matifali@users.noreply.github.com>
Fixes CI formatting checks for the JFrog Xray module.
Adds the required Terraform usage example immediately after the h1 heading
to satisfy the README validation requirements.
blink-so Bot added 4 commits September 4, 2025 07:15
Fixes remaining formatting issues in the README file.
The check_license argument is not supported by the JFrog Xray Terraform
provider, causing test failures. Removing this argument fixes the
Terraform validation.
Adds proper null handling for cases where xray scan results are null,
which was causing Terraform validation failures. Uses try() function
to gracefully handle null values and provide default vulnerability counts.
Fixes terraform formatting issue identified by CI checks.
@matifali matifali requested a review from jatcod3r September 4, 2025 14:51
@matifali
Copy link
Copy Markdown
Member

matifali commented Sep 4, 2025

@jatcod3r can you help me test this if you have s setup ready?

@DevelopmentCats
Copy link
Copy Markdown
Collaborator

@jatcod3r can you help me test this if you have s setup ready?

Since there has not been any activity on this I will see if I can spin up what I need to test this out @matifali

blink-so Bot added 3 commits February 27, 2026 10:17
- Fix icon path to use ../../../../.icons/jfrog.svg (matching other modules)
- Remove unused display_name and icon variables
- Remove provider block anti-pattern, add skip_xray_version_check
- Merge duplicate locals blocks into one
- Use sec_issues.total from the API instead of manual sum
- Add URL validation for xray_url and image format validation
- Improve test with mock Xray server and actual assertions
- Clean up README: remove maintainer_github, fix frontmatter, simplify
- Add dedicated jfrog-xray.svg icon based on official JFrog Xray eye/scan design
- Remove Variables section from README per review feedback
- Update all icon references to use jfrog-xray.svg
@coder coder deleted a comment from blinkagent Bot Mar 4, 2026
The module now outputs vulnerability counts instead of creating
coder_metadata internally. This fixes two issues found during testing:

1. coder_metadata defined inside modules does not display in the
   Coder dashboard
2. Inline provider blocks prevent using count/for_each on the module

The caller is now responsible for:
- Configuring the xray provider
- Creating coder_metadata with the module outputs

This matches the pattern used by other registry modules.
Comment thread registry/coder/modules/jfrog-xray/README.md Outdated
Comment thread registry/coder/modules/jfrog-xray/README.md Outdated
- Introduced mock servers for local and remote repositories to simulate various scan results.
- Added validation tests for required variables: xray_url, xray_token, and image.
- Updated README to reflect changes in usage and configuration, including new `use_cache_repo` variable for remote scanning.
- Enhanced output variables to include artifact name and policy violations detected.
- Improved variable descriptions for clarity and consistency.
Comment thread registry/coder/modules/jfrog-xray/README.md
Comment thread registry/coder/modules/jfrog-xray/README.md Outdated
@DevelopmentCats DevelopmentCats marked this pull request as ready for review March 5, 2026 19:23
Copilot AI review requested due to automatic review settings March 5, 2026 19:23
- Changed the tags in the README to better reflect the module's purpose.
- Updated the image variable to use a dynamic reference instead of a hardcoded value.
- Enhanced the metadata output to include all outputs for reference
@DevelopmentCats
Copy link
Copy Markdown
Collaborator

@matifali

I have tested this, and made the final updates we need for this.

If you can take a last look I can get this merged and released for us

@DevelopmentCats DevelopmentCats requested a review from matifali March 5, 2026 19:49
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@DevelopmentCats DevelopmentCats requested a review from Copilot March 5, 2026 19:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 9 comments.

Comment thread registry/coder/modules/jfrog-xray/main.tf
Comment thread registry/coder/modules/jfrog-xray/main.tf
Comment thread registry/coder/modules/jfrog-xray/main.tf
Comment thread registry/coder/modules/jfrog-xray/main.tf Outdated
Comment thread registry/coder/modules/jfrog-xray/main.tf
Comment thread registry/coder/modules/jfrog-xray/main.test.ts
Comment thread registry/coder/modules/jfrog-xray/main.test.ts
Comment thread registry/coder/modules/jfrog-xray/main.test.ts
Comment thread registry/coder/modules/jfrog-xray/main.test.ts Outdated
- Changed `use_cache_repo` from string to boolean in tests for consistency.
- Added provider configuration for `xray` in main.tf to streamline setup.
- Removed outdated provider configuration examples from README for clarity.
Copy link
Copy Markdown
Member

@matifali matifali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for testing this extensively.

@DevelopmentCats
Copy link
Copy Markdown
Collaborator

LGTM. Thanks for testing this extensively.

No Problem!

Just for visibility in this PR, I went back to using the provider inside the module, but changed it so the metadata is defined outside the module using the outputs. It still seems to work fine, but you cant assign a count to the jfrog_xray module.

Realistically this isn't an issue because all this does is query jfrog and return existing scan results.

@DevelopmentCats DevelopmentCats merged commit 40c2916 into main Mar 6, 2026
4 checks passed
@DevelopmentCats DevelopmentCats deleted the blink/jfrog-xray-module branch March 6, 2026 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JFrog Xray integration

3 participants