Skip to content

feat(tools): add go-dependency-analyzer skill#20247

Open
janisz wants to merge 9 commits into
masterfrom
dependency_skipp
Open

feat(tools): add go-dependency-analyzer skill#20247
janisz wants to merge 9 commits into
masterfrom
dependency_skipp

Conversation

@janisz
Copy link
Copy Markdown
Contributor

@janisz janisz commented Apr 27, 2026

Description

Skill for using go mod ... and goda to learn about dependencies and their usage useful when dealing with CVE reports in dependencies.

User-facing documentation

Testing and quality

  • the change is production ready: the change is GA, or otherwise the functionality is gated by a feature flag
  • CI results are inspected

Automated testing

  • added unit tests
  • added e2e tests
  • added regression tests
  • added compatibility tests
  • modified existing tests

How I validated my change

/go-dependency-analyzer analyze kubevirt.io/containerized-data-importer-api

● Dependency Analysis: kubevirt.io/containerized-data-importer-api (TRANSITIVE)

  Dependency: kubevirt.io/containerized-data-importer-api v1.64.0
  Status: TRANSITIVE ONLY - Not directly imported

  Dependency Chain:
  Our code (StackRox)
      ↓ imports
  kubevirt.io/api v1.8.2 (KubeVirt virtual machine API)
      ↓ depends on
  kubevirt.io/containerized-data-importer-api v1.64.0 (CDI API for persistent storage)

  Why It Exists:
  From go mod why:
  - pkg/virtualmachine imports kubevirt.io/api/core/v1 (KubeVirt core API)
  - KubeVirt API depends on containerized-data-importer-api/pkg/apis/core/v1beta1 for DataVolume specs
  - CDI (Containerized Data Importer) is KubeVirt's persistent storage subsystem for VM disks

  Our Usage of Intermediate Package:
  - We import: kubevirt.io/api (KubeVirt virtual machine APIs)
  - Used in: 5 production files (direct kubevirt.io/api imports)
  - Plus: 7 production files via pkg/virtualmachine wrapper
  - Components: Central (VM pipeline), Sensor (VM monitoring)
  - Files (direct kubevirt.io/api usage):
    - pkg/virtualmachine/api.go - VM type definitions
    - sensor/kubernetes/listener/resources/virtualmachine/dispatcher/*.go - VM event dispatching (4 files)

  What Intermediate Uses It For:
  - KubeVirt API uses CDI API to define DataVolume types for VM persistent storage
  - When VMs reference persistent disks, they use CDI DataVolume specs
  - We monitor VM resources through KubeVirt API, which includes CDI DataVolume references
  - CDI API defines schemas for volume provisioning, cloning, and importing

  Recommended Action:
  - ✅ No direct action needed - transitive dependency
  - ✅ Monitor for security updates (managed by kubevirt.io/api)
  - ✅ Low priority - updated automatically with KubeVirt API

  Team Assignment:
  N/A - Managed via kubevirt.io/api updates
  (If CVE: assign to @sensor-team who owns VM monitoring feature in sensor/kubernetes/listener/resources/virtualmachine)

User request: Create a Go dependency analyzer skill for StackRox codebase
to support CVE triage, security analysis, and dependency impact assessment.

Key features:
- Branching workflow for direct vs transitive dependencies
- Wrapper pattern detection (e.g., zap via pkg/logging)
- Mandatory goda visualization for dependency trees
- Replace directive tracking for StackRox forks
- Team assignment recommendations based on component usage

Tested with pgx, docker, prometheus, zap, protoc-gen-validate, and
kubevirt.io/containerized-data-importer-api dependencies.

Skill designed for team sharing via repository .claude/skills/ directory.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented Apr 27, 2026

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@janisz janisz changed the title feat(tools): add go-dependency-analyzer skill for CVE triage feat(tools): add go-dependency-analyzer skill Apr 27, 2026
janisz and others added 2 commits April 27, 2026 13:01
User feedback: Component-to-team mapping should be based on .github/CODEOWNERS,
remove redundant "Recommended Action" sections, and handle dependencies that can
be both direct and indirect.

Changes:
- Use .github/CODEOWNERS for team assignment instead of hardcoded mapping
- Remove "Recommended Action" checkbox sections from all report templates
- Add nuance for dependencies that can be both direct and indirect
- Update transitive dependency team assignment to target teams using intermediate packages
- Updated all 7 examples to reflect new team assignment approach

Reasoning:
- CODEOWNERS is the source of truth for code ownership
- "Recommended Action" sections were redundant and not actionable
- Dependencies can appear as both direct and transitive simultaneously
- Transitive deps should be assigned to teams that introduced them via intermediate dependencies

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Simplify skill review findings:
- Fix typo: missing space after 'on' in Example 6
- Standardize phrasing: 'From CODEOWNERS' across all examples
- Simplify verbose explanations while keeping essential info
- Improve readability and consistency

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 27, 2026

🚀 Build Images Ready

Images are ready for commit c2b236d. To use with deploy scripts:

export MAIN_IMAGE_TAG=4.11.x-793-gc2b236da67

@janisz janisz marked this pull request as ready for review April 27, 2026 11:10
@janisz janisz requested a review from a team April 27, 2026 11:10
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 49.83%. Comparing base (bf5a0b4) to head (0d4b2d4).
⚠️ Report is 26 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #20247      +/-   ##
==========================================
+ Coverage   49.79%   49.83%   +0.04%     
==========================================
  Files        2770     2773       +3     
  Lines      210223   210736     +513     
==========================================
+ Hits       104673   105018     +345     
- Misses      97829    97957     +128     
- Partials     7721     7761      +40     
Flag Coverage Δ
go-unit-tests 49.83% <ø> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

janisz and others added 2 commits April 27, 2026 13:45
User request: "make this skill compact... to bare minimum to make it work correctly"

Achieved 33.4% reduction (760 → 506 lines) while preserving all critical functionality.

**Removed (254 lines total):**
- Advanced Techniques section (66 lines) - complete duplication of Steps 2-7
- Example 3: yaml.v3 (23 lines) - redundant with test-only pattern
- Example 4: Go deprecation (28 lines) - out of scope for dependency analysis
- Example 7: Transitive dependency (52 lines) - duplicates Step 2A workflow
- Example 3 "Key Findings" section (15 lines) - repeated table data
- CODEOWNERS examples (8 lines) - users can read actual file
- Verbose explanations in Steps 4-5 (62 lines) - consolidated to essentials

**Streamlined:**
- Step 4: Wrapper detection workflow (43 → 14 lines)
- Step 5: Function analysis (35 → 7 lines)
- Removed redundant prose, consolidated bash commands

**Preserved:**
- All critical branching logic (direct vs transitive)
- MANDATORY commands (go mod why, goda graph)
- Wrapper pattern detection workflow
- Both report templates (direct and transitive)
- CODEOWNERS team assignment
- All essential troubleshooting

Skill maintains full functionality, faster to read and understand.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…yzer

User request: add line about how to install goda

Added Prerequisites section before Instructions to make tool requirement
clear upfront, rather than only mentioning it in Troubleshooting.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Comment on lines +43 to +52
```bash
# Check if dependency is in go.mod (direct or indirect)
grep -i "module-name" go.mod

# Check for replace directives (StackRox forks)
grep -i "module-name" go.mod | grep "=>"

# Check if indirect
grep -i "module-name" go.mod | grep "// indirect"
```
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should only the root go.mod be considered, or can the other go.mod files in the repository be relevant here ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point, If we have a CVE to fix then we can fix it everywhere on the other hand tools are fine as we not ship them. I'll add a note on that

- Format: `Our package → Intermediate package → module-name`
- Example: `central/externalbackups → cloud.google.com/go/storage → protoc-gen-validate`

2. **Check if we use the intermediate package:**
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should there be logic to isolate the test-only dependencies and process them differently ?

- No direct maintenance needed
- Updated automatically when [intermediate package] updates
- Monitor for security issues but low priority (transitive)
```
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can it make sense to bump the indirect dependencies anyway to protect the intermediate packages from the possible vulnerabilities in the target dependency ?

go list -m module-name

# MANDATORY: Show why dependency is needed
go mod why -m module-name
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does go mod why provide a comprehensive view of why a dependency is used or would it be better to rely on the dependency graph to have a better coverage of the target dependency usage ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately go mod is limited that's why I used goda

| **zap** | v1.18.2 (fork) | Direct | 7 | pkg/logging, operator | CRITICAL |
```

### Example 6: Wrapper pattern (infrastructure library)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Where are examples 4 and 5 ?

janisz and others added 4 commits May 26, 2026 18:07
User request: "Look at current PR comments and plan how to fix them all"

Addresses all 5 review comments from PR #20247:

1. Line 52: Added multi-module workspace clarification
   - Explains StackRox monorepo uses single root go.mod
   - Documents tool vs production dependency priority for CVEs

2. Line 89: Added test-only transitive dependency guidance
   - Shows how to detect test-only transitive chains
   - Documents lower CVE priority for test infrastructure

3. Line 117: Added indirect dependency bumping strategy
   - Criteria for when to proactively bump transitive deps
   - Trade-offs between direct bumping vs upstream fixes

4. Line 130: Added go mod why vs goda tool comparison
   - Explains go mod why limitation (shows one path)
   - Documents why goda is needed (shows all paths)
   - Provides example scenario demonstrating the gap

5. Line 355: Added missing Examples 4 and 5
   - Example 4: Transitive dependency (test infrastructure)
   - Example 5: Replace directive (StackRox fork)

Total additions: ~155 lines of clarifications and examples.
No changes to existing skill logic or workflow.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Fixes confirmed bugs from code review that would cause incorrect dependency
analysis or confusing output:

CRITICAL fixes:
- Remove /... suffix from goda reach() patterns (lines 88, 160, 198)
  - Pattern fails for modules without subpackages (e.g., gopkg.in/yaml.v2)
  - Returns empty results instead of showing dependency usage

HIGH priority fixes:
- Remove -i flag from grep commands on module paths (lines 45, 48, 51)
  - Go module paths are case-sensitive
  - Case-insensitive matching causes wrong module identification in CVE triage

MEDIUM priority fixes:
- Add --exclude-dir=test to production grep commands (lines 100, 201, 205)
  - Test fixture files in /test/ directories were counted as production code
  - Inflates CVE priority for test-only dependencies

- Add handling for "does not need" from go mod why (after line 183)
  - Occurs when dependency in go.mod but not actually used
  - Provides guidance for stale entries and build-tag-excluded imports

- Add go.mod existence validation (before line 42)
  - Pre-flight check prevents confusing errors when run from wrong directory

LOW priority fixes:
- Add "Action:" section to Example 4 (line 447)
  - Template showed Action section but example omitted it
  - Ensures template/example consistency

Total changes: 33 insertions, 13 deletions
Impact: Fixes command syntax errors and adds missing edge case handling

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…yzer

After implementing command fixes in commit 8786da1, second code review found
5 documentation sections still showing old incorrect patterns. Main workflow
commands were correctly fixed, but explanatory text, troubleshooting sections,
and examples weren't updated to match.

Documentation fixes:
- Line 179: Remove /... from goda pattern in "Why Both Tools Are Needed"
  - Was: `goda graph "reach(./..., module-name/...)"`
  - Now: `goda graph "reach(./..., module-name)"`

- Line 601: Remove -i flag from troubleshooting grep guidance
  - Was: `grep -i "pgx"` (case-insensitive)
  - Now: `grep "pgx"` (case-sensitive) + clarifying note
  - Matches fix: Go module paths are case-sensitive

- Line 634: Remove /... from troubleshooting goda example
  - Was: `goda list "reach(./central/..., pgx/...)"`
  - Now: `goda list "reach(./central/..., pgx)"`

- Lines 535, 537: Add standard exclusion flags to Example 6
  - Added --exclude-dir=vendor and --exclude-dir=test
  - Matches methodology in Step 4

- Line 338: Add --exclude-dir=test to Example 1
  - Now matches production code search pattern

Total changes: 6 lines modified (6 insertions, 6 deletions)
Impact: Ensures all documentation teaches same correct patterns

Resolves inconsistency where users reading examples/troubleshooting would
learn old incorrect approaches that were fixed in main workflow.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…lyzer

Problem:
- Skill wasn't being invoked for dependency questions like "why do we need X?"
- Trigger conditions were only in frontmatter description (easy to miss)
- No prominent guidance on when to use the skill

Solution:
- Added "When to Use This Skill" section immediately after title
- Listed common question patterns that should trigger skill invocation
- Made it explicit: "ALWAYS use this skill when user asks ANY question about Go dependencies"
- Includes examples: "Why do we need X?", "What uses X?", "Is X used in production?"

This ensures AI agents invoke the skill for all dependency-related questions,
preventing manual analysis when a structured workflow exists.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented May 26, 2026

@janisz: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/gke-qa-e2e-tests c2b236d link false /test gke-qa-e2e-tests
ci/prow/gke-nongroovy-e2e-tests c2b236d link true /test gke-nongroovy-e2e-tests
ci/prow/gke-ui-e2e-tests c2b236d link true /test gke-ui-e2e-tests
ci/prow/ocp-4-12-nongroovy-e2e-tests c2b236d link false /test ocp-4-12-nongroovy-e2e-tests
ci/prow/ocp-4-21-nongroovy-e2e-tests c2b236d link false /test ocp-4-21-nongroovy-e2e-tests

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

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.

2 participants