Skip to content

Conversation

sozercan
Copy link
Member

@sozercan sozercan commented Jun 4, 2025

Signed-off-by: Sertac Ozercan sozercan@gmail.com
Part of #147

Hold merge after current release

Describe the changes in this pull request using active verbs such as Add, Remove, Replace ...

Adds experimental app-level patching support with Python language manager

This PR introduces scaffolding for experimental support for patching application-level dependencies (libraries/packages) in addition to OS packages, with initial Python support.

Key Features

🔬 Experimental Feature

  • Requires COPA_EXPERIMENTAL=1 environment variable
  • Subject to breaking changes in future releases

📦 Package Type Filtering

  • New --pkg-types flag with values: os, library, os,library
  • Defaults to os (maintains backward compatibility)
  • Enables separate patching policies for OS vs application dependencies

🎯 Patch Level Control

  • New --library-patch-level flag with values: patch, minor, major
  • Defaults to patch for conservative updates
  • Implements preference ordering: patch > minor > major for safest upgrades

🐍 Python Support

  • Support for pip-managed Python packages. Other package managers are not considered for this initial PR.
  • Special handling for certifi (always latest version)

Example Usage

export COPA_EXPERIMENTAL=1
export IMAGE=mcr.microsoft.com/azure-cli:2.50.0 

# Scan for package vulnerabilities
trivy image --vuln-type os,library --ignore-unfixed -f json -o scan.json $IMAGE

# Patch only libraries with patch level updates only
copa patch -i $IMAGE -r scan.json --pkg-types library --library-patch-level patch

# Mixed OS and library patching with major level updates allowed
copa patch -i $IMAGE -r scan.json --pkg-types os,library --library-patch-level major

sozercan added 14 commits June 3, 2025 23:03
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Copy link

codecov bot commented Jun 5, 2025

Codecov Report

❌ Patch coverage is 50.41021% with 544 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.45%. Comparing base (3974d9c) to head (b5bceba).

Files with missing lines Patch % Lines
pkg/langmgr/python.go 36.01% 180 Missing and 3 partials ⚠️
pkg/patch/single.go 23.52% 77 Missing and 1 partial ⚠️
pkg/patch/manifest.go 0.00% 67 Missing ⚠️
pkg/patch/core.go 0.00% 65 Missing ⚠️
pkg/report/trivy.go 78.21% 42 Missing and 14 partials ⚠️
pkg/patch/cmd.go 15.78% 46 Missing and 2 partials ⚠️
pkg/utils/utils.go 53.84% 12 Missing ⚠️
pkg/langmgr/langmgr.go 88.77% 8 Missing and 3 partials ⚠️
pkg/patch/patch.go 25.00% 7 Missing and 2 partials ⚠️
pkg/types/v1alpha2/convert.go 89.28% 4 Missing and 2 partials ⚠️
... and 5 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1091      +/-   ##
==========================================
+ Coverage   48.80%   49.45%   +0.64%     
==========================================
  Files          35       38       +3     
  Lines        4143     5136     +993     
==========================================
+ Hits         2022     2540     +518     
- Misses       1985     2433     +448     
- Partials      136      163      +27     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

sozercan added 12 commits June 5, 2025 04:18
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
robert-cronin and others added 5 commits August 6, 2025 02:22
Signed-off-by: robert-cronin <robert.owen.cronin@gmail.com>
…trieval functionality

Signed-off-by: robert-cronin <robert.owen.cronin@gmail.com>
…und for buildx v0.25.0 bug

Signed-off-by: robert-cronin <robert.owen.cronin@gmail.com>
…nutes

Signed-off-by: robert-cronin <robert.owen.cronin@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
@sozercan sozercan marked this pull request as ready for review August 6, 2025 19:29
Copy link
Contributor

@Copilot 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

This PR introduces experimental app-level patching support for Python packages, extending Copa's patching capabilities beyond OS packages to include application-level dependencies. The feature is gated behind the COPA_EXPERIMENTAL=1 environment variable and introduces new flags for package type filtering and library patch level control.

  • Adds scaffolding for experimental app-level patching with initial Python support
  • Introduces package type filtering (--pkg-types) to separate OS and library patching
  • Implements patch level control (--library-patch-level) for conservative version upgrades

Reviewed Changes

Copilot reviewed 38 out of 39 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
website/sidebars.js Adds navigation entry for app-level patching documentation
website/docs/app-level-patching.md Comprehensive documentation for the new app-level patching feature
pkg/types/unversioned/types.go Updates manifest structure to separate OS and language updates
pkg/report/trivy.go Implements version selection logic and Python package parsing
pkg/langmgr/python.go Core Python package manager implementation
pkg/patch/cmd.go Adds experimental CLI flags for package types and patch levels
pkg/patch/core.go Integrates language managers into the core patching workflow

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Sertaç Özercan <852750+sozercan@users.noreply.github.com>
@@ -0,0 +1,176 @@
---
Copy link
Contributor

Choose a reason for hiding this comment

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

should we also update website/docs/scanner-plugins.md since the interface UpdatedManifest will change?

Copy link
Member Author

Choose a reason for hiding this comment

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

i missed this, good point! introduced v1alpha2 to support app patching flow, kept v1alpha1 for now

version := strings.TrimSpace(parts[1])
installedPkgs[pkgName] = version
} else {
// Handle other formats that might be encountered in pip freeze output
Copy link
Contributor

Choose a reason for hiding this comment

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

is this a TODO or will this be a limitation of the python library patching?

Copy link
Member Author

Choose a reason for hiding this comment

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

@robert-cronin let's do a follow up on this when/if we encounter any that's not ==

type UpdateMap map[string]*UpdatePackageInfo

func GetValidatedUpdatesMap(
updates unversioned.LangUpdatePackages,
Copy link
Contributor

Choose a reason for hiding this comment

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

since the functionality for validating updates and version comparing is similar with what we do for pkgmgr, maybe we could combine this into a helper folder to share the code?

Copy link
Member Author

Choose a reason for hiding this comment

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

can we do a follow up for this one

Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Comment on lines +8 to +9
OSUpdates UpdatePackages `json:"osupdates"`
LangUpdates LangUpdatePackages `json:"langupdates"`
Copy link
Contributor

Choose a reason for hiding this comment

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

can both OSUpdates and LangUpdates be of type UpdatePackages?

Copy link
Member Author

Choose a reason for hiding this comment

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

I wanted to keep these separately so we can define a boundary between OS and Lang updates

idxBytes, desc, err := resolver.Combine(ctx, srcRefs, annotations, false)
if err != nil {
return fmt.Errorf("failed to combine sources into manifest list: %w", err)
}

// Workaround for buildx v0.25.0 bug: manually inject index-level annotations into manifest bytes
// TODO: fixed in buildx v0.26.0+ so remove after upgrading
Copy link
Contributor

Choose a reason for hiding this comment

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

I think were close to solving this TODO, just flagging it here

Copy link
Member Author

Choose a reason for hiding this comment

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

can we open a new pr for this

Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🏗 In progress
Development

Successfully merging this pull request may close these issues.

[REQ] support for app-level patching
3 participants