Skip to content

Commit 3defe2e

Browse files
jonathanStrange0Jonathan Muchaclaudedacoburn
authored
Mucha dev gitlab security output (#147)
* 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> * capturing all recent changes * chore: bump version to 2.3.0 for GitLab Security Dashboard feature Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * bumping version * Removing unneeded files --------- Co-authored-by: Jonathan Mucha <jonathan@mucha.local> Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: Douglas Coburn <douglas@dactbc.com>
1 parent 54e6ec7 commit 3defe2e

File tree

7 files changed

+811
-14
lines changed

7 files changed

+811
-14
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 |
@@ -624,9 +653,136 @@ The manifest archive feature is useful for:
624653
625654
### Differential scan skipped on octopus merge
626655
627-
When your repo uses an **octopus merge** (3+ parents), the CLI may not detect all changed files.
656+
When your repo uses an **octopus merge** (3+ parents), the CLI may not detect all changed files.
628657
This is expected Git behavior: the default diff only compares the merge result to the first parent.
629658
659+
## GitLab Security Dashboard Integration
660+
661+
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.
662+
663+
### Generating GitLab Security Reports
664+
665+
To generate a GitLab-compatible security report:
666+
667+
```bash
668+
socketcli --enable-gitlab-security --repo owner/repo
669+
```
670+
671+
This creates a `gl-dependency-scanning-report.json` file following GitLab's Dependency Scanning report schema.
672+
673+
### GitLab CI/CD Integration
674+
675+
Add Socket Security scanning to your GitLab CI pipeline to generate Security Dashboard reports:
676+
677+
```yaml
678+
# .gitlab-ci.yml
679+
socket_security_scan:
680+
stage: security
681+
image: python:3.11
682+
before_script:
683+
- pip install socketsecurity
684+
script:
685+
- socketcli
686+
--api-token $SOCKET_API_TOKEN
687+
--repo $CI_PROJECT_PATH
688+
--branch $CI_COMMIT_REF_NAME
689+
--commit-sha $CI_COMMIT_SHA
690+
--enable-gitlab-security
691+
artifacts:
692+
reports:
693+
dependency_scanning: gl-dependency-scanning-report.json
694+
paths:
695+
- gl-dependency-scanning-report.json
696+
expire_in: 1 week
697+
only:
698+
- merge_requests
699+
- main
700+
```
701+
702+
**Note**: This Security Dashboard integration can be used alongside the [Socket GitLab App](https://docs.socket.dev/docs/gitlab) for comprehensive protection:
703+
- **Socket GitLab App**: Real-time PR comments, policy enforcement, and blocking
704+
- **Security Dashboard**: Centralized vulnerability tracking and reporting in GitLab's native interface
705+
706+
### Custom Output Path
707+
708+
Specify a custom output path for the GitLab security report:
709+
710+
```bash
711+
socketcli --enable-gitlab-security --gitlab-security-file custom-path.json
712+
```
713+
714+
### Multiple Output Formats
715+
716+
GitLab security reports can be generated alongside other output formats:
717+
718+
```bash
719+
socketcli --enable-json --enable-gitlab-security --enable-sarif
720+
```
721+
722+
This command will:
723+
- Output JSON format to console
724+
- Save GitLab Security Dashboard report to `gl-dependency-scanning-report.json`
725+
- Save SARIF report (if configured)
726+
727+
### Security Dashboard Features
728+
729+
The GitLab Security Dashboard will display:
730+
- **Vulnerability Severity**: Critical, High, Medium, Low levels
731+
- **Affected Packages**: Package name, version, and ecosystem
732+
- **CVE Identifiers**: Direct links to CVE databases when available
733+
- **Dependency Chains**: Distinction between direct and transitive dependencies
734+
- **Remediation Suggestions**: Fix recommendations from Socket Security
735+
- **Alert Categories**: Supply chain risks, malware, vulnerabilities, and more
736+
737+
### Alert Filtering
738+
739+
The GitLab report includes **actionable security alerts** based on your Socket policy configuration:
740+
741+
**Included Alerts** ✅:
742+
- **Error-level alerts** (`error: true`) - Security policy violations that block merges
743+
- **Warning-level alerts** (`warn: true`) - Important security concerns requiring attention
744+
745+
**Excluded Alerts** ❌:
746+
- **Ignored alerts** (`ignore: true`) - Alerts explicitly ignored in your policy
747+
- **Monitor-only alerts** (`monitor: true` without error/warn) - Tracked but not actionable
748+
749+
**Socket Alert Types Detected**:
750+
- Supply chain risks (malware, typosquatting, suspicious behavior)
751+
- Security vulnerabilities (CVEs, unsafe code patterns)
752+
- Risky permissions (network access, filesystem access, shell access)
753+
- License policy violations
754+
755+
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.
756+
757+
### Report Schema
758+
759+
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:
760+
761+
- **Scan metadata**: Analyzer and scanner information
762+
- **Vulnerabilities**: Detailed vulnerability data with:
763+
- Unique deterministic UUIDs for tracking
764+
- Package location and dependency information
765+
- Severity levels mapped from Socket's analysis
766+
- Socket-specific alert types and CVE identifiers
767+
- Links to Socket.dev for detailed analysis
768+
769+
### Requirements
770+
771+
- **GitLab Version**: GitLab 12.0 or later (for Security Dashboard support)
772+
- **Socket API Token**: Set via `$SOCKET_API_TOKEN` environment variable or `--api-token` parameter
773+
- **CI/CD Artifacts**: Reports must be uploaded as `dependency_scanning` artifacts
774+
775+
### Troubleshooting
776+
777+
**Report not appearing in Security Dashboard:**
778+
- Verify the artifact is correctly configured in `.gitlab-ci.yml`
779+
- Check that the job succeeded and artifacts were uploaded
780+
- Ensure the report file follows the correct schema format
781+
782+
**Empty vulnerabilities array:**
783+
- This is normal if no new security issues were detected
784+
- Check Socket.dev dashboard for full analysis details
785+
630786
## Development
631787

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

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
66

77
[project]
88
name = "socketsecurity"
9-
version = "2.2.66"
9+
version = "2.2.68"
1010
requires-python = ">= 3.10"
1111
license = {"file" = "LICENSE"}
1212
dependencies = [

socketsecurity/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
__author__ = 'socket.dev'
2-
__version__ = '2.2.66'
2+
__version__ = '2.2.68'
33
USER_AGENT = f'SocketPythonCLI/{__version__}'

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
@@ -119,6 +121,8 @@ def from_args(cls, args_list: Optional[List[str]] = None) -> 'CliConfig':
119121
'allow_unverified': args.allow_unverified,
120122
'enable_json': args.enable_json,
121123
'enable_sarif': args.enable_sarif,
124+
'enable_gitlab_security': args.enable_gitlab_security,
125+
'gitlab_security_file': args.gitlab_security_file,
122126
'disable_overview': args.disable_overview,
123127
'disable_security_issue': args.disable_security_issue,
124128
'files': args.files,
@@ -451,6 +455,19 @@ def create_argument_parser() -> argparse.ArgumentParser:
451455
action="store_true",
452456
help="Enable SARIF output of results instead of table or JSON format"
453457
)
458+
output_group.add_argument(
459+
"--enable-gitlab-security",
460+
dest="enable_gitlab_security",
461+
action="store_true",
462+
help="Enable GitLab Security Dashboard output format (Dependency Scanning report)"
463+
)
464+
output_group.add_argument(
465+
"--gitlab-security-file",
466+
dest="gitlab_security_file",
467+
metavar="<path>",
468+
default="gl-dependency-scanning-report.json",
469+
help="Output file path for GitLab Security report (default: gl-dependency-scanning-report.json)"
470+
)
454471
output_group.add_argument(
455472
"--disable-overview",
456473
dest="disable_overview",

0 commit comments

Comments
 (0)