Skip to content

fix: plumbing security policy fragments#2642

Open
anmaxvl wants to merge 2 commits intomainfrom
plumb-fragment-fix
Open

fix: plumbing security policy fragments#2642
anmaxvl wants to merge 2 commits intomainfrom
plumb-fragment-fix

Conversation

@anmaxvl
Copy link
Contributor

@anmaxvl anmaxvl commented Mar 21, 2026

Fix missing response to shim when injecting SecurityPolicyFragment via
ModifySettings in the GCS sidecar and add unit tests.

Previously, the PolicyFragment handler in `modifySettings` returned the
result of `InjectFragment` directly. On success (`nil` error), no response
was sent to the shim and the request was not forwarded to the inbox GCS,
leaving the shim's bridge RPC blocked waiting for a response that never
arrived. After the 5-minute bridge timeout, the connection would be
killed.

Changes:
 - Send an explicit success response to the shim after `InjectFragment`
   succeeds, matching the pattern used by other sidecar-handled resource
   types (e.g. `ResourceTypeSecurityPolicy`).
 - Add `ResourceTypePolicyFragment` to the unmarshaling switch in
   `unmarshalContainerModifySettings` so the fragment payload is properly
   deserialized before reaching the handler.
 - Fix "invald" -> "invalid" typo in error messages.

Signed-off-by: Maksim An <maksiman@microsoft.com>

Co-authored-by: Mahati Chamarthy <mahati.chamarthy@gmail.com>

@anmaxvl anmaxvl requested a review from a team as a code owner March 21, 2026 15:28
@anmaxvl anmaxvl added the cwcow label Mar 21, 2026
@anmaxvl
Copy link
Contributor Author

anmaxvl commented Mar 21, 2026

@MahatiC , FYI

@msscotb msscotb self-assigned this Mar 23, 2026
Copy link
Contributor

@msscotb msscotb left a comment

Choose a reason for hiding this comment

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

Missing tests which led to this problem. Known issue that unit tests are needed.
Should have a PR description.

Fix missing response to shim when injecting SecurityPolicyFragment via
ModifySettings in the GCS sidecar.

Previously, the PolicyFragment handler in `modifySettings` returned the
result of `InjectFragment` directly. On success (`nil` error), no response
was sent to the shim and the request was not forwarded to the inbox GCS,
leaving the shim's bridge RPC blocked waiting for a response that never
arrived. After the 5-minute bridge timeout, the connection would be
killed.

Changes:
 - Send an explicit success response to the shim after `InjectFragment`
   succeeds, matching the pattern used by other sidecar-handled resource
   types (e.g. `ResourceTypeSecurityPolicy`).
 - Add `ResourceTypePolicyFragment` to the unmarshaling switch in
   `unmarshalContainerModifySettings` so the fragment payload is properly
   deserialized before reaching the handler.
 - Fix "invald" -> "invalid" typo in error messages.

Signed-off-by: Maksim An <maksiman@microsoft.com>

Co-authored-by: Mahati Chamarthy <mahati.chamarthy@gmail.com>
@anmaxvl anmaxvl force-pushed the plumb-fragment-fix branch from 0ea3dc7 to fb2fa5c Compare March 23, 2026 17:06
Add unit tests for the `modifySettings` handler in the GCS sidecar,
covering the `PolicyFragment` response behavior that was fixed in the
previous commit.

Tests added:

 - `TestModifySettings_PolicyFragment_InvalidFragment` - invalid base64
   fragment returns an error.
 - `TestModifySettings_PolicyFragment_SuccessResponse` - regression test
   verifying a success response is sent to sendToShimCh with correct
   message ID and Result=0.
 - `TestModifySettings_SecurityPolicy_SendsResponse` - reference test for
   the SecurityPolicy handler's response pattern.
 - `TestModifySettings_NetworkNamespace_ForwardedToGCS` - non-intercepted
   resource types are forwarded to GCS, not responded to directly.
 - `TestModifySettings_PolicyFragment_ErrorDoesNotSendResponse` - failed
   COSE validation returns error without sending a direct response.
 - `TestModifySettings_PolicyFragment_TypeAssertionFailure` - empty
   fragment returns an error.

Also adds `buildModifySettingsRequest` and `newTestBridge` test helpers
for constructing handler test fixtures.

Signed-off-by: Maksim An <maksiman@microsoft.com>
@anmaxvl anmaxvl force-pushed the plumb-fragment-fix branch from fb2fa5c to dfbcda0 Compare March 23, 2026 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants