Skip to content

Conversation

@michaelawyu
Copy link
Collaborator

Description of your changes

This PR blocks cluster-scoped resources from being wrapped in an envelope to address a security concern.

I have:

  • Run make reviewable to ensure this PR is ready for review.

How has this code been tested

  • Unit tests

Special notes for your reviewer

Signed-off-by: michaelawyu <chenyu1@microsoft.com>
@michaelawyu michaelawyu force-pushed the fix/block-wrapped-cluster-scoped-resources branch from 8c6c173 to 84de5b6 Compare April 25, 2025 01:35
Signed-off-by: michaelawyu <chenyu1@microsoft.com>
@michaelawyu michaelawyu force-pushed the fix/block-wrapped-cluster-scoped-resources branch from 457a462 to 788c33b Compare April 25, 2025 02:22
@codecov
Copy link

codecov bot commented Apr 25, 2025

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment

Thanks for integrating Codecov - We've got you covered ☂️

Signed-off-by: michaelawyu <chenyu1@microsoft.com>
Signed-off-by: michaelawyu <chenyu1@microsoft.com>
@ryanzhang-oss ryanzhang-oss requested a review from Copilot April 25, 2025 19:53
Copy link
Contributor

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 prevents cluster‐scoped resources from being wrapped in an envelope to address a security concern and updates related tests and manifests accordingly.

  • Removed the webhook configuration block from the test envelope configmap and updated related tests.
  • Changed test helper calls and expectations (e.g. using checkEnvelopQuotaPlacement and expecting errors when cluster‐scoped resources are wrapped) to align with the new validation.
  • Updated manifests and integration tests to use ResourceQuota instead of the removed webhook configuration.

Reviewed Changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/e2e/resources/test-envelop-configmap.yaml Removed the webhook configuration block from the envelope.
test/e2e/join_and_leave_test.go Updated CRP status check parameter from false to true and renamed helper calls.
test/e2e/enveloped_object_placement_test.go Adjusted test expectations and helper function call names.
pkg/controllers/workgenerator/suite_test.go Removed references to the webhook manifest and added new manifest for resourcequota2.
pkg/controllers/workgenerator/manifests/* Updated the envelope configmap manifest and added a new ResourceQuota manifest.
pkg/controllers/workgenerator/controller_test.go Changed test expectation—now expecting failure for an envelope with cluster‐scoped resources.
pkg/controllers/workgenerator/controller_integration_test.go Updated integration test to use resourcequota2 manifest instead of webhook manifest.
pkg/controllers/workgenerator/controller.go Added validation to block wrapping cluster‐scoped resources with a clear error message.
Files not reviewed (1)
  • pkg/controllers/workgenerator/manifests/test-envelop-configmap.yaml: Language not supported
Comments suppressed due to low confidence (2)

test/e2e/join_and_leave_test.go:102

  • The parameter change from 'false' to 'true' in customizedCRPStatusUpdatedActual likely reflects new validation behavior. It may be beneficial to update the inline comment to clarify why the expectation has changed and to ensure the test aligns with the intended security concern.
crpStatusUpdatedActual := customizedCRPStatusUpdatedActual(crpName, wantSelectedResources, allMemberClusterNames, nil, "0", true)

pkg/controllers/workgenerator/controller_test.go:246

  • The expected outcome for this test case has been updated to fail when a cluster-scoped resource is wrapped in an envelope. Verify that the test description and expected behavior clearly convey this new policy.
"config map with cluster and namespace scoped data in the correct namespace should fail": {

klog.ErrorS(unMarshallErr, "manifest has invalid content", "manifestKey", key, "envelopeResource", klog.KObj(uConfigMap))
return nil, fmt.Errorf("the object with manifest key `%s` in envelope config `%s` is malformatted, err: %w", key, klog.KObj(uConfigMap), unMarshallErr)
}
if len(uManifest.GetNamespace()) == 0 {
Copy link

Copilot AI Apr 25, 2025

Choose a reason for hiding this comment

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

The new check preventing wrapping of cluster-scoped resources is correctly implemented with a clear error message. Consider adding a dedicated unit test case to explicitly verify that cluster-scoped objects are blocked.

Copilot uses AI. Check for mistakes.
// Block cluster-scoped resources.
return nil, fmt.Errorf("cannot wrap cluster-scoped resource %s in the envelope %s", uManifest.GetName(), klog.KObj(uConfigMap))
}
if len(uManifest.GetNamespace()) != 0 && uManifest.GetNamespace() != configMap.Namespace {
Copy link
Contributor

Choose a reason for hiding this comment

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

with the new condition added, this is just

Suggested change
if len(uManifest.GetNamespace()) != 0 && uManifest.GetNamespace() != configMap.Namespace {
if uManifest.GetNamespace() != configMap.Namespace {

@ryanzhang-oss ryanzhang-oss merged commit 8ab0edb into kubefleet-dev:main Apr 28, 2025
17 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.

2 participants