Skip to content

(v1alpha1) Validate source/target upstream package names on PackageRevision upgrade - #1343

Merged
liamfallon merged 10 commits into
kptdev:mainfrom
Nordix:fix-upgrade-package-reference-validation
Nov 18, 2026
Merged

liamfallon merged 10 commits into
kptdev:mainfrom
Nordix:fix-upgrade-package-reference-validation

Conversation

@JamesMcDermott

@JamesMcDermott JamesMcDermott commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Description

  • What changed:
    • Added server-side validation to the v1alpha1 upgrade task mutation
      • oldUpstream/newUpstream references supplied in an upgrade request are now checked against the package the local revision was actually derived from
      • for whole-package upgrades, validateUpstreamPackages resolves the local revision's real upstream and validates that:
        • the request's current upstream matches the local revision's actual upstream, and
        • the target upstream belongs to the same package as that upstream
      • for subpackage upgrades, validateSubpackageUpstreamPackages reads the subpackage's Kptfile upstream to determine its origin package and applies the equivalent current/target consistency checks.
    • Added --force flag to porchctl rpkg upgrade to skip validation and force upgrade
  • Why it’s needed:
    • porchctl computes and validates the upstream refs on the user's behalf, but a raw API call can supply mismatched or incorrect oldUpstream/newUpstream references. Without server-side validation, an upgrade could be applied against the wrong upstream package, producing an incorrect merge. This adds the guard so the server does not trust client-supplied refs.
  • How it works:
    • During upgradePackageMutation.apply, before performing the merge, the mutation resolves the relevant package-revision keys and compares the request's upstream references to the local revision's genuine origin, returning a descriptive error if they are inconsistent
    • If --force is present or forceUpgrade is set to true, the validation short-circuits and allows the upgrade

Related Issue(s)


Type of Change

  • Bug fix
  • New feature
  • Enhancement
  • Refactor
  • Documentation
  • Tests
  • Other: ________

Checklist

  • Code follows project style guidelines
  • Self-reviewed changes
  • Tests added/updated
  • Documentation added/updated
  • All tests and gating checks pass

Testing Instructions (Optional)

  1. Run unit tests: make test — covers the new upgrade validation cases in upgrade_test.go and generictaskhandler_test.go.
  2. Run the e2e tests against a fresh Porch cluster: make setup-dev-env run-in-kind-db-cache test-e2e (see additions in test/e2e/api/rpkg_clone_test.go).
  3. Manually:
  4. attempt an upgrade via a raw v1alpha1 API call whose oldUpstream/
    newUpstream refer to a different package than the local revision's origin
  5. confirm the request is rejected with an "invalid upstream package reference" error

Additional Notes (Optional)

  • Further improvements:
    • Counterpart validation in controllers/v1alpha2 to be covered in a separate PR

AI Disclosure

  • I have used AI in the creation of this PR.

If so, please describe how:

  • Kiro to:
    • review initial efforts and highlight small issues hidden in copied code
    • draft changes to respond to Copilot comments
    • generate new unit and e2e tests
    • analyse changes and draft this pull request description.

@JamesMcDermott
JamesMcDermott requested review from a team and a balanced review from Copilot November 2, 2026 11:16
@netlify

netlify Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for kpt-porch canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit 62e911f
🔍 Latest deploy log https://app.netlify.com/projects/kpt-porch/deploys/6afd89a995d7011a0972f2b9

Copilot AI left a comment

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.

🟡 Changes recommended

Upgrade validation still permits unrelated packages or incorrect merge bases through wildcard and incomplete origin checks, and rejects valid edited revisions when source history is missing despite a surviving upstream lock.

3 open issues
What changed in this PR

Adds server-side upstream validation to v1alpha1 PackageRevision upgrades, addressing the raw API validation gap described in #1308. The v1alpha2 counterpart remains out of scope.

Changes:

  • Validates whole-package upgrade references against the local revision’s origin.
  • Adds subpackage validation using Kptfile upstream metadata.
  • Extends unit and end-to-end coverage for mismatched references and valid upgrades.
File Description
test/​e2e/​api/​rpkg_clone_test.go Tests rejection of mismatched upstream packages and acceptance of a valid upgrade.
pkg/​task/​upgrade.go Adds origin resolution and upstream validation before merging.
pkg/​task/​upgrade_test.go Adds mismatch and nested-subpackage tests; updates fixtures.
pkg/​task/​generictaskhandler_test.go Adds upstream metadata to successful subpackage-upgrade fixtures.

Review effort: Balanced

Comment thread pkg/task/upgrade.go Resolved
Comment thread pkg/task/upgrade.go Resolved
Comment thread pkg/task/upgrade.go Resolved

Copilot AI left a comment

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.

Comment thread pkg/task/upgrade.go Resolved
Comment thread pkg/task/upgrade.go Resolved
Comment thread pkg/task/upgrade.go Resolved
@liamfallon

liamfallon commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

You'll need to raise a separate PR for the API change. There's a choreography to go through:

  1. Raise and merge a PR for the API change
  2. Release a prerelease of the Porch API
  3. Rebase this PR.

This will avoid checking in a replace in the go.mod.

If there's an API change on v1alpha2 for a force flag it might be best to include that in the same API PR and do the API changes for v1alpha1 and v1alpha2 in one go.

JamesMcDermott added a commit to Nordix/porch that referenced this pull request Nov 11, 2026
- flag to skip upgrade package name validation introduced in kptdev#1343

Signed-off-by: James McDermott <james.j.mcdermott@ericsson.com>
@JamesMcDermott

Copy link
Copy Markdown
Contributor Author

You'll need to raise a separate PR for the API change. There's a choreography to go through:

1. Raise and merge a PR for the API change

2. Release a prerelease of the Porch API

3. Rebase this PR.

This will avoid checking in a replace in the go.mod.

If there's an API change on v1alpha2 for a force flag it might be best to include that in the same API PR and do the API changes for v1alpha1 and v1alpha2 in one go.

OK - have done. It's up at #1366 and ready for review now - once we've got that in, I'll rebase this one and push again to de-check-in the replace.

efiacor pushed a commit that referenced this pull request Nov 12, 2026
* Add `ForceUpgrade` flag to `PackageUpgradeTaskSpec`

- flag to skip upgrade package name validation introduced in #1343

Signed-off-by: James McDermott <james.j.mcdermott@ericsson.com>

* Regenerate further API files to include `forceUpgrade`

Signed-off-by: James McDermott <james.j.mcdermott@ericsson.com>

---------

Signed-off-by: James McDermott <james.j.mcdermott@ericsson.com>
Comment thread test/e2e/api/rpkg_clone_test.go Resolved
@JamesMcDermott

Copy link
Copy Markdown
Contributor Author

You'll need to raise a separate PR for the API change. There's a choreography to go through:

1. Raise and merge a PR for the API change

2. Release a prerelease of the Porch API

3. Rebase this PR.

This will avoid checking in a replace in the go.mod.
If there's an API change on v1alpha2 for a force flag it might be best to include that in the same API PR and do the API changes for v1alpha1 and v1alpha2 in one go.

OK - have done. It's up at #1366 and ready for review now - once we've got that in, I'll rebase this one and push again to de-check-in the replace.

Commented out the replace again there.

Signed-off-by: James McDermott <james.j.mcdermott@ericsson.com>
- fix duplicate import that set off linter
- change package upstream comparison to key identity rather than (looser)
  Matches() method
- add fallback route via UpstreamLock to resolve upstream of package revision
  with edit origin
- resolve subpackage upstream more comprehensively by comparing all Git
  details from upstream in Kptfile

Signed-off-by: James McDermott <james.j.mcdermott@ericsson.com>
Signed-off-by: James McDermott <james.j.mcdermott@ericsson.com>
…evision-based edit origin matching

Signed-off-by: James McDermott <james.j.mcdermott@ericsson.com>
…de validation

- due to API change, uncomment go.mod replace directive
- fix generate-api-reference-md.sh path in docs Makefile

Signed-off-by: James McDermott <james.j.mcdermott@ericsson.com>
Signed-off-by: James McDermott <james.j.mcdermott@ericsson.com>
Signed-off-by: James McDermott <james.j.mcdermott@ericsson.com>
- resolve merge conflict

Signed-off-by: James McDermott <james.j.mcdermott@ericsson.com>
@JamesMcDermott
JamesMcDermott force-pushed the fix-upgrade-package-reference-validation branch from ff4f44a to 0a8ffe6 Compare November 18, 2026 11:01
@sonarqubecloud

Copy link
Copy Markdown

@liamfallon
liamfallon merged commit 807c492 into kptdev:main Nov 18, 2026
28 checks passed
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.

On Upgrade API calls, Porch does not validate the package references in the upgrade request

4 participants