Write enhanced fragment loading diagnostics and expose to container in the security context#2830
Open
micromaomao wants to merge 3 commits into
Open
Write enhanced fragment loading diagnostics and expose to container in the security context#2830micromaomao wants to merge 3 commits into
micromaomao wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR enhances security policy fragment injection diagnostics by persisting decoded fragment artifacts (COSE, payload, metadata, and per-request outcome markers) in a predictable guest location, and exposing those diagnostics to the workload container via the existing security-context mechanism (LCOW and WCOW).
Changes:
- Add per-fragment dump directory keyed by fragment SHA, writing
fragment.cose, decodedfragment,metadata.json, and{n}.succeed/{n}.failmarkers. - Introduce guest paths for fragment diagnostics (
/tmp/fragmentsfor LCOW,C:\InjectedFragmentsfor WCOW). - Mount/map the fragments diagnostics directory into the container under
<security-context-dir>/fragments.debugafter policy enforcement.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| pkg/securitypolicy/securitypolicy_options.go | Implements enhanced fragment dump (COSE/payload/metadata) and per-request success/failure markers; creates fragments directory during policy setup. |
| internal/guestpath/paths.go | Adds constants for LCOW/WCOW fragments diagnostics storage locations inside the UVM. |
| internal/guest/runtime/hcsv2/uvm.go | Adds a post-enforcement bind mount to expose fragments diagnostics into the LCOW container’s security-context directory. |
| internal/gcs-sidecar/handlers.go | Adds a post-enforcement mapped directory to expose fragments diagnostics into the WCOW container’s security-context directory. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+77
to
+79
| if err := os.MkdirAll(fragmentsPath(), 0755); err != nil { | ||
| return fmt.Errorf("failed to create injected fragments directory: %w", err) | ||
| } |
Comment on lines
+241
to
+246
| if err := os.MkdirAll(thisFragmentDir, 0755); err != nil { | ||
| return fmt.Errorf("failed to create injected fragment directory: %w", err) | ||
| } | ||
| if err := writeFileIfNotExists(filepath.Join(thisFragmentDir, "fragment.cose"), raw, 0644); err != nil { | ||
| return fmt.Errorf("failed to write fragment.cose: %w", err) | ||
| } |
Comment on lines
+261
to
+263
| if err := writeFileIfNotExists(filepath.Join(thisFragmentDir, "fragment"), unpacked.Payload, 0644); err != nil { | ||
| return fmt.Errorf("failed to write injected fragment payload: %w", err) | ||
| } |
Comment on lines
+41
to
+45
| // Global counter for fragment injection requests, used to create unique | ||
| // error / success marker files even when the same fragment is injected | ||
| // multiple times. | ||
| var FragmentRequestId atomic.Uint64 | ||
|
|
Comment on lines
+748
to
+755
| if securityContextDir != "" { | ||
| settings.OCISpecification.Mounts = append(settings.OCISpecification.Mounts, specs.Mount{ | ||
| Destination: path.Join("/", filepath.Base(securityContextDir), "fragments.debug"), | ||
| Type: "bind", | ||
| Source: guestpath.LCOWFragmentsPath, | ||
| Options: []string{"bind", "ro"}, | ||
| }) | ||
| } |
Comment on lines
+186
to
+192
| if securityContextDir != "" { | ||
| container.MappedDirectories = append(container.MappedDirectories, hcsschema.MappedDirectory{ | ||
| HostPath: guestpath.WCOWFragmentsPath, | ||
| ContainerPath: filepath.Join(`C:\`, filepath.Base(securityContextDir), "fragments.debug"), | ||
| ReadOnly: true, | ||
| }) | ||
| } |
Write the error string or a success marker, the decoded fragment content, and headers, and place them in a findable place on Windows and Linux. Assisted-by: GitHub-Copilot copilot-review Signed-off-by: Tingmao Wang <tingmaowang@microsoft.com>
…\fragments.debug [cherry-pick of 43dcfafab onto main] Assisted-by: GitHub-Copilot copilot-review Signed-off-by: Tingmao Wang <tingmaowang@microsoft.com>
…ragments.debug Assisted-by: GitHub-Copilot copilot-review Signed-off-by: Tingmao Wang <tingmaowang@microsoft.com>
micromaomao
force-pushed
the
fragments-debug-dir
branch
from
July 20, 2026 16:09
988c0c2 to
4600cb1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is useful as a debugging aid and not a security feature.
Enhance the existing fragment dumping code to also write the error string or a success marker, the decoded fragment content, and metadata, and place them in a findable place on Windows and Linux.
Example: