Skip to content

Commit 9e2b6ca

Browse files
Jonathan Muchaclaude
andcommitted
feat: add GitLab Security Dashboard integration with Dependency Scanning report output
Adds support for generating GitLab-compatible Dependency Scanning reports that integrate with GitLab's Security Dashboard. This feature enables Socket security findings to be displayed natively in GitLab merge requests and security dashboards. Key Features: - New --enable-gitlab-security flag to generate GitLab reports - New --gitlab-security-file flag for custom output paths (default: gl-dependency-scanning-report.json) - Generates GitLab Dependency Scanning schema v15.0.0 compliant reports - Supports multiple simultaneous output formats (JSON, SARIF, GitLab) - Includes actionable security alerts (error/warn level) in vulnerability reports - Maps Socket severity levels to GitLab severity (Critical, High, Medium, Low) - Extracts CVE identifiers and dependency chain information - Generates deterministic UUIDs for vulnerability tracking Implementation: - Added GitLab report generator in messages.py with helper functions for severity mapping, identifier extraction, and location parsing - Refactored OutputHandler to support multiple simultaneous output formats - Added comprehensive unit tests (test_gitlab_format.py) and integration tests - Updated documentation with usage examples, CI/CD integration guide, and alert filtering details Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent d0886a5 commit 9e2b6ca

File tree

6 files changed

+970
-13
lines changed

6 files changed

+970
-13
lines changed

README.md

Lines changed: 164 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,32 @@ This will:
7979
- Create a repository in Socket named like `my-repo-mobile-web`
8080
- Preserve git context (commits, branch info) from the repository root
8181

82+
**Generate GitLab Security Dashboard report:**
83+
```bash
84+
socketcli --enable-gitlab-security \
85+
--repo owner/repo \
86+
--target-path .
87+
```
88+
89+
This will:
90+
- Scan all manifest files in the current directory
91+
- Generate a GitLab-compatible Dependency Scanning report
92+
- Save to `gl-dependency-scanning-report.json`
93+
- Include all actionable security alerts (error/warn level)
94+
95+
**Multiple output formats:**
96+
```bash
97+
socketcli --enable-json \
98+
--enable-sarif \
99+
--enable-gitlab-security \
100+
--repo owner/repo
101+
```
102+
103+
This will simultaneously generate:
104+
- JSON output to console
105+
- SARIF format to console
106+
- GitLab Security Dashboard report to file
107+
82108
### Requirements
83109

84110
- Both `--sub-path` and `--workspace-name` must be specified together
@@ -88,14 +114,15 @@ This will:
88114
## Usage
89115

90116
```` shell
91-
socketcli [-h] [--api-token API_TOKEN] [--repo REPO] [--repo-is-public] [--branch BRANCH] [--integration {api,github,gitlab,azure,bitbucket}]
92-
[--owner OWNER] [--pr-number PR_NUMBER] [--commit-message COMMIT_MESSAGE] [--commit-sha COMMIT_SHA] [--committers [COMMITTERS ...]]
117+
socketcli [-h] [--api-token API_TOKEN] [--repo REPO] [--repo-is-public] [--branch BRANCH] [--integration {api,github,gitlab,azure,bitbucket}]
118+
[--owner OWNER] [--pr-number PR_NUMBER] [--commit-message COMMIT_MESSAGE] [--commit-sha COMMIT_SHA] [--committers [COMMITTERS ...]]
93119
[--target-path TARGET_PATH] [--sbom-file SBOM_FILE] [--license-file-name LICENSE_FILE_NAME] [--save-submitted-files-list SAVE_SUBMITTED_FILES_LIST]
94-
[--save-manifest-tar SAVE_MANIFEST_TAR] [--files FILES] [--sub-path SUB_PATH] [--workspace-name WORKSPACE_NAME]
95-
[--excluded-ecosystems EXCLUDED_ECOSYSTEMS] [--default-branch] [--pending-head] [--generate-license] [--enable-debug]
96-
[--enable-json] [--enable-sarif] [--disable-overview] [--exclude-license-details] [--allow-unverified] [--disable-security-issue]
97-
[--ignore-commit-files] [--disable-blocking] [--enable-diff] [--scm SCM] [--timeout TIMEOUT] [--include-module-folders]
98-
[--reach] [--reach-version REACH_VERSION] [--reach-analysis-timeout REACH_ANALYSIS_TIMEOUT]
120+
[--save-manifest-tar SAVE_MANIFEST_TAR] [--files FILES] [--sub-path SUB_PATH] [--workspace-name WORKSPACE_NAME]
121+
[--excluded-ecosystems EXCLUDED_ECOSYSTEMS] [--default-branch] [--pending-head] [--generate-license] [--enable-debug]
122+
[--enable-json] [--enable-sarif] [--enable-gitlab-security] [--gitlab-security-file <path>]
123+
[--disable-overview] [--exclude-license-details] [--allow-unverified] [--disable-security-issue]
124+
[--ignore-commit-files] [--disable-blocking] [--enable-diff] [--scm SCM] [--timeout TIMEOUT] [--include-module-folders]
125+
[--reach] [--reach-version REACH_VERSION] [--reach-analysis-timeout REACH_ANALYSIS_TIMEOUT]
99126
[--reach-analysis-memory-limit REACH_ANALYSIS_MEMORY_LIMIT] [--reach-ecosystems REACH_ECOSYSTEMS] [--reach-exclude-paths REACH_EXCLUDE_PATHS]
100127
[--reach-min-severity {low,medium,high,critical}] [--reach-skip-cache] [--reach-disable-analytics] [--reach-output-file REACH_OUTPUT_FILE]
101128
[--only-facts-file] [--version]
@@ -154,6 +181,8 @@ If you don't want to provide the Socket API Token every time then you can use th
154181
| --enable-debug | False | False | Enable debug logging |
155182
| --enable-json | False | False | Output in JSON format |
156183
| --enable-sarif | False | False | Enable SARIF output of results instead of table or JSON format |
184+
| --enable-gitlab-security | False | False | Enable GitLab Security Dashboard output format (Dependency Scanning report) |
185+
| --gitlab-security-file | False | gl-dependency-scanning-report.json | Output file path for GitLab Security report |
157186
| --disable-overview | False | False | Disable overview output |
158187
| --exclude-license-details | False | False | Exclude license details from the diff report (boosts performance for large repos) |
159188
| --version | False | False | Show program's version number and exit |
@@ -530,9 +559,136 @@ The manifest archive feature is useful for:
530559
531560
### Differential scan skipped on octopus merge
532561
533-
When your repo uses an **octopus merge** (3+ parents), the CLI may not detect all changed files.
562+
When your repo uses an **octopus merge** (3+ parents), the CLI may not detect all changed files.
534563
This is expected Git behavior: the default diff only compares the merge result to the first parent.
535564
565+
## GitLab Security Dashboard Integration
566+
567+
Socket CLI can generate reports compatible with GitLab's Security Dashboard, allowing vulnerability information to be displayed directly in merge requests and security dashboards. This feature complements the existing [Socket GitLab integration](https://docs.socket.dev/docs/gitlab) by providing standardized dependency scanning reports.
568+
569+
### Generating GitLab Security Reports
570+
571+
To generate a GitLab-compatible security report:
572+
573+
```bash
574+
socketcli --enable-gitlab-security --repo owner/repo
575+
```
576+
577+
This creates a `gl-dependency-scanning-report.json` file following GitLab's Dependency Scanning report schema.
578+
579+
### GitLab CI/CD Integration
580+
581+
Add Socket Security scanning to your GitLab CI pipeline to generate Security Dashboard reports:
582+
583+
```yaml
584+
# .gitlab-ci.yml
585+
socket_security_scan:
586+
stage: security
587+
image: python:3.11
588+
before_script:
589+
- pip install socketsecurity
590+
script:
591+
- socketcli
592+
--api-token $SOCKET_API_TOKEN
593+
--repo $CI_PROJECT_PATH
594+
--branch $CI_COMMIT_REF_NAME
595+
--commit-sha $CI_COMMIT_SHA
596+
--enable-gitlab-security
597+
artifacts:
598+
reports:
599+
dependency_scanning: gl-dependency-scanning-report.json
600+
paths:
601+
- gl-dependency-scanning-report.json
602+
expire_in: 1 week
603+
only:
604+
- merge_requests
605+
- main
606+
```
607+
608+
**Note**: This Security Dashboard integration can be used alongside the [Socket GitLab App](https://docs.socket.dev/docs/gitlab) for comprehensive protection:
609+
- **Socket GitLab App**: Real-time PR comments, policy enforcement, and blocking
610+
- **Security Dashboard**: Centralized vulnerability tracking and reporting in GitLab's native interface
611+
612+
### Custom Output Path
613+
614+
Specify a custom output path for the GitLab security report:
615+
616+
```bash
617+
socketcli --enable-gitlab-security --gitlab-security-file custom-path.json
618+
```
619+
620+
### Multiple Output Formats
621+
622+
GitLab security reports can be generated alongside other output formats:
623+
624+
```bash
625+
socketcli --enable-json --enable-gitlab-security --enable-sarif
626+
```
627+
628+
This command will:
629+
- Output JSON format to console
630+
- Save GitLab Security Dashboard report to `gl-dependency-scanning-report.json`
631+
- Save SARIF report (if configured)
632+
633+
### Security Dashboard Features
634+
635+
The GitLab Security Dashboard will display:
636+
- **Vulnerability Severity**: Critical, High, Medium, Low levels
637+
- **Affected Packages**: Package name, version, and ecosystem
638+
- **CVE Identifiers**: Direct links to CVE databases when available
639+
- **Dependency Chains**: Distinction between direct and transitive dependencies
640+
- **Remediation Suggestions**: Fix recommendations from Socket Security
641+
- **Alert Categories**: Supply chain risks, malware, vulnerabilities, and more
642+
643+
### Alert Filtering
644+
645+
The GitLab report includes **actionable security alerts** based on your Socket policy configuration:
646+
647+
**Included Alerts** ✅:
648+
- **Error-level alerts** (`error: true`) - Security policy violations that block merges
649+
- **Warning-level alerts** (`warn: true`) - Important security concerns requiring attention
650+
651+
**Excluded Alerts** ❌:
652+
- **Ignored alerts** (`ignore: true`) - Alerts explicitly ignored in your policy
653+
- **Monitor-only alerts** (`monitor: true` without error/warn) - Tracked but not actionable
654+
655+
**Socket Alert Types Detected**:
656+
- Supply chain risks (malware, typosquatting, suspicious behavior)
657+
- Security vulnerabilities (CVEs, unsafe code patterns)
658+
- Risky permissions (network access, filesystem access, shell access)
659+
- License policy violations
660+
661+
All alert types are included in the GitLab report if they're marked as `error` or `warn` by your Socket Security policy, ensuring the Security Dashboard shows only actionable findings.
662+
663+
### Report Schema
664+
665+
Socket CLI generates reports compliant with [GitLab Dependency Scanning schema version 15.0.0](https://docs.gitlab.com/ee/development/integrations/secure.html). The reports include:
666+
667+
- **Scan metadata**: Analyzer and scanner information
668+
- **Vulnerabilities**: Detailed vulnerability data with:
669+
- Unique deterministic UUIDs for tracking
670+
- Package location and dependency information
671+
- Severity levels mapped from Socket's analysis
672+
- Socket-specific alert types and CVE identifiers
673+
- Links to Socket.dev for detailed analysis
674+
675+
### Requirements
676+
677+
- **GitLab Version**: GitLab 12.0 or later (for Security Dashboard support)
678+
- **Socket API Token**: Set via `$SOCKET_API_TOKEN` environment variable or `--api-token` parameter
679+
- **CI/CD Artifacts**: Reports must be uploaded as `dependency_scanning` artifacts
680+
681+
### Troubleshooting
682+
683+
**Report not appearing in Security Dashboard:**
684+
- Verify the artifact is correctly configured in `.gitlab-ci.yml`
685+
- Check that the job succeeded and artifacts were uploaded
686+
- Ensure the report file follows the correct schema format
687+
688+
**Empty vulnerabilities array:**
689+
- This is normal if no new security issues were detected
690+
- Check Socket.dev dashboard for full analysis details
691+
536692
## Development
537693

538694
This project uses `pyproject.toml` as the primary dependency specification.

socketsecurity/config.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class CliConfig:
4040
allow_unverified: bool = False
4141
enable_json: bool = False
4242
enable_sarif: bool = False
43+
enable_gitlab_security: bool = False
44+
gitlab_security_file: Optional[str] = None
4345
disable_overview: bool = False
4446
disable_security_issue: bool = False
4547
files: str = None
@@ -118,6 +120,8 @@ def from_args(cls, args_list: Optional[List[str]] = None) -> 'CliConfig':
118120
'allow_unverified': args.allow_unverified,
119121
'enable_json': args.enable_json,
120122
'enable_sarif': args.enable_sarif,
123+
'enable_gitlab_security': args.enable_gitlab_security,
124+
'gitlab_security_file': args.gitlab_security_file,
121125
'disable_overview': args.disable_overview,
122126
'disable_security_issue': args.disable_security_issue,
123127
'files': args.files,
@@ -449,6 +453,19 @@ def create_argument_parser() -> argparse.ArgumentParser:
449453
action="store_true",
450454
help="Enable SARIF output of results instead of table or JSON format"
451455
)
456+
output_group.add_argument(
457+
"--enable-gitlab-security",
458+
dest="enable_gitlab_security",
459+
action="store_true",
460+
help="Enable GitLab Security Dashboard output format (Dependency Scanning report)"
461+
)
462+
output_group.add_argument(
463+
"--gitlab-security-file",
464+
dest="gitlab_security_file",
465+
metavar="<path>",
466+
default="gl-dependency-scanning-report.json",
467+
help="Output file path for GitLab Security report (default: gl-dependency-scanning-report.json)"
468+
)
452469
output_group.add_argument(
453470
"--disable-overview",
454471
dest="disable_overview",

0 commit comments

Comments
 (0)