|
| 1 | +--- |
| 2 | +display_name: JFrog Xray Integration |
| 3 | +description: Display container image vulnerability scan results from JFrog Xray in workspace metadata |
| 4 | +icon: /icon/security.svg |
| 5 | +maintainer_github: coder |
| 6 | +verified: true |
| 7 | +tags: [security, scanning, jfrog, xray, vulnerabilities] |
| 8 | +--- |
| 9 | + |
| 10 | +# JFrog Xray Integration |
| 11 | + |
| 12 | +This module integrates JFrog Xray vulnerability scanning results into Coder workspace metadata. It displays vulnerability counts (Critical, High, Medium, Low) for container images directly on the workspace page. |
| 13 | + |
| 14 | +## Features |
| 15 | + |
| 16 | +- **Automatic Vulnerability Display**: Shows vulnerability counts from JFrog Xray scans |
| 17 | +- **Real-time Results**: Fetches latest scan results during workspace provisioning |
| 18 | +- **Flexible Image Specification**: Supports various image path formats |
| 19 | +- **Secure Token Handling**: Sensitive token management with Terraform |
| 20 | +- **Universal Compatibility**: Works with any workspace type that uses container images |
| 21 | + |
| 22 | +## Prerequisites |
| 23 | + |
| 24 | +1. **JFrog Artifactory**: Container images must be stored in JFrog Artifactory |
| 25 | +2. **JFrog Xray**: Xray must be configured to scan your repositories |
| 26 | +3. **Access Token**: Valid JFrog access token with Xray read permissions |
| 27 | +4. **Scanned Images**: Images must have been scanned by Xray (scans can be triggered automatically or manually) |
| 28 | + |
| 29 | +## Usage |
| 30 | + |
| 31 | +### Basic Usage |
| 32 | + |
| 33 | +```hcl |
| 34 | +module "jfrog_xray" { |
| 35 | + source = "registry.coder.com/modules/jfrog-xray/coder" |
| 36 | + version = "1.0.0" |
| 37 | + |
| 38 | + resource_id = docker_container.workspace.id |
| 39 | + xray_url = "https://example.jfrog.io/xray" |
| 40 | + xray_token = var.jfrog_access_token |
| 41 | + image = "docker-local/codercom/enterprise-base:latest" |
| 42 | +} |
| 43 | +``` |
| 44 | + |
| 45 | +### Advanced Usage with Custom Configuration |
| 46 | + |
| 47 | +```hcl |
| 48 | +module "jfrog_xray" { |
| 49 | + source = "registry.coder.com/modules/jfrog-xray/coder" |
| 50 | + version = "1.0.0" |
| 51 | + |
| 52 | + resource_id = docker_container.workspace.id |
| 53 | + xray_url = "https://example.jfrog.io/xray" |
| 54 | + xray_token = var.jfrog_access_token |
| 55 | + |
| 56 | + # Specify repo and path separately for more control |
| 57 | + repo = "docker-local" |
| 58 | + repo_path = "/codercom/enterprise-base:v2.1.0" |
| 59 | + |
| 60 | + display_name = "Container Security Scan" |
| 61 | + icon = "/icon/shield.svg" |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +### Complete Workspace Template Example |
| 66 | + |
| 67 | +```hcl |
| 68 | +terraform { |
| 69 | + required_providers { |
| 70 | + coder = { |
| 71 | + source = "coder/coder" |
| 72 | + } |
| 73 | + docker = { |
| 74 | + source = "kreuzwerker/docker" |
| 75 | + } |
| 76 | + } |
| 77 | +} |
| 78 | +
|
| 79 | +variable "jfrog_access_token" { |
| 80 | + description = "JFrog access token for Xray API" |
| 81 | + type = string |
| 82 | + sensitive = true |
| 83 | +} |
| 84 | +
|
| 85 | +data "coder_workspace" "me" {} |
| 86 | +
|
| 87 | +resource "docker_container" "workspace" { |
| 88 | + count = data.coder_workspace.me.start_count |
| 89 | + image = "example.jfrog.io/docker-local/codercom/enterprise-base:latest" |
| 90 | + name = "coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}" |
| 91 | + |
| 92 | + # Container configuration... |
| 93 | +} |
| 94 | +
|
| 95 | +# Add Xray vulnerability scanning |
| 96 | +module "jfrog_xray" { |
| 97 | + source = "registry.coder.com/modules/jfrog-xray/coder" |
| 98 | + version = "1.0.0" |
| 99 | + |
| 100 | + resource_id = docker_container.workspace[0].id |
| 101 | + xray_url = "https://example.jfrog.io/xray" |
| 102 | + xray_token = var.jfrog_access_token |
| 103 | + image = "docker-local/codercom/enterprise-base:latest" |
| 104 | +} |
| 105 | +``` |
| 106 | + |
| 107 | +## Variables |
| 108 | + |
| 109 | +| Name | Description | Type | Default | Required | |
| 110 | +|------|-------------|------|---------|----------| |
| 111 | +| `resource_id` | The resource ID to attach the vulnerability metadata to | `string` | n/a | yes | |
| 112 | +| `xray_url` | The URL of the JFrog Xray instance | `string` | n/a | yes | |
| 113 | +| `xray_token` | The access token for JFrog Xray authentication | `string` | n/a | yes | |
| 114 | +| `image` | The container image to scan in format 'repo/path:tag' | `string` | n/a | yes | |
| 115 | +| `repo` | The JFrog Artifactory repository name (auto-extracted if not provided) | `string` | `""` | no | |
| 116 | +| `repo_path` | The repository path with image name and tag (auto-extracted if not provided) | `string` | `""` | no | |
| 117 | +| `display_name` | The display name for the vulnerability metadata section | `string` | `"Security Vulnerabilities"` | no | |
| 118 | +| `icon` | The icon to display for the vulnerability metadata | `string` | `"/icon/security.svg"` | no | |
| 119 | + |
| 120 | +## Outputs |
| 121 | + |
| 122 | +This module creates workspace metadata that displays: |
| 123 | + |
| 124 | +- **Image**: The scanned container image |
| 125 | +- **Total Vulnerabilities**: Total count of all vulnerabilities |
| 126 | +- **Critical**: Count of critical severity vulnerabilities |
| 127 | +- **High**: Count of high severity vulnerabilities |
| 128 | +- **Medium**: Count of medium severity vulnerabilities |
| 129 | +- **Low**: Count of low severity vulnerabilities |
| 130 | + |
| 131 | +## Image Format Examples |
| 132 | + |
| 133 | +The module supports various image path formats: |
| 134 | + |
| 135 | +```hcl |
| 136 | +# Standard format |
| 137 | +image = "docker-local/codercom/enterprise-base:latest" |
| 138 | +
|
| 139 | +# With registry URL (will extract repo and path) |
| 140 | +image = "docker-local/myorg/myapp:v1.2.3" |
| 141 | +
|
| 142 | +# Complex nested paths |
| 143 | +image = "docker-local/team/project/service:main-abc123" |
| 144 | +``` |
| 145 | + |
| 146 | +## Security Considerations |
| 147 | + |
| 148 | +1. **Token Security**: Always use Terraform variables or external secret management for the `xray_token` |
| 149 | +2. **Network Access**: Ensure Coder can reach your JFrog Xray instance |
| 150 | +3. **Permissions**: The access token needs read permissions for Xray scan results |
| 151 | +4. **Scan Coverage**: Ensure your images are being scanned by Xray policies |
| 152 | + |
| 153 | +## Troubleshooting |
| 154 | + |
| 155 | +### Common Issues |
| 156 | + |
| 157 | +**"No scan results found"** |
| 158 | +- Verify the image exists in Artifactory |
| 159 | +- Check that Xray has scanned the image |
| 160 | +- Confirm the image path format is correct |
| 161 | + |
| 162 | +**"Authentication failed"** |
| 163 | +- Verify the access token is valid |
| 164 | +- Check token permissions include Xray read access |
| 165 | +- Ensure the Xray URL is correct |
| 166 | + |
| 167 | +**"Module fails to apply"** |
| 168 | +- Verify network connectivity to JFrog instance |
| 169 | +- Check Terraform provider versions |
| 170 | +- Review Coder logs for detailed error messages |
| 171 | + |
| 172 | +### Debugging |
| 173 | + |
| 174 | +Enable Terraform debugging to see detailed API calls: |
| 175 | + |
| 176 | +```bash |
| 177 | +export TF_LOG=DEBUG |
| 178 | +coder templates plan <template-name> |
| 179 | +``` |
| 180 | + |
| 181 | +## Integration with Existing Guides |
| 182 | + |
| 183 | +This module complements the existing [JFrog Xray integration guide](https://coder.com/docs/v2/latest/guides/xray-integration) by providing a Terraform-native approach that: |
| 184 | + |
| 185 | +- Works with all workspace types (not just Kubernetes) |
| 186 | +- Doesn't require deploying additional services |
| 187 | +- Integrates directly into workspace templates |
| 188 | +- Provides real-time vulnerability information |
| 189 | + |
| 190 | +## Related Resources |
| 191 | + |
| 192 | +- [JFrog Artifactory Integration Guide](https://coder.com/docs/v2/latest/guides/artifactory-integration) |
| 193 | +- [Coder Metadata Resource Documentation](https://registry.terraform.io/providers/coder/coder/latest/docs/resources/metadata) |
| 194 | +- [JFrog Xray Terraform Provider](https://registry.terraform.io/providers/jfrog/xray/latest) |
0 commit comments