Skip to content

Conversation

@MahatiC
Copy link
Member

@MahatiC MahatiC commented Oct 24, 2025

Fragment extraction and validation is a common operation across C-LCOW and C-WCOW. This PR moves that functionality into the SecurityPolicy package, so that gcs and gcs-sidecar can call directly into it.

@MahatiC MahatiC force-pushed the policy-refactor branch 2 times, most recently from 57a463d to 37ea7f4 Compare October 24, 2025 15:35
@KenGordon KenGordon self-assigned this Oct 27, 2025
@KenGordon KenGordon requested review from a team and anmaxvl October 27, 2025 13:49
@KenGordon KenGordon removed their assignment Oct 27, 2025
@KenGordon KenGordon self-requested a review October 27, 2025 13:50
@MahatiC MahatiC marked this pull request as ready for review October 27, 2025 14:59
@MahatiC MahatiC requested a review from a team as a code owner October 27, 2025 14:59
sha.Write(blob)
timestamp := time.Now()
fragmentPath := fmt.Sprintf("fragment-%x-%d.blob", sha.Sum(nil), timestamp.UnixMilli())
_ = os.WriteFile(filepath.Join(os.TempDir(), fragmentPath), blob, 0644)
Copy link
Contributor

Choose a reason for hiding this comment

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

any reason we're ignoring this error?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is just purely for internal debug purposes, so we don't want to throw any errors on failure to write this.

_ = os.WriteFile(filepath.Join(os.TempDir(), fragmentPath), blob, 0644)

unpacked, err := cosesign1.UnpackAndValidateCOSE1CertChain(raw)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

is it expected that we always keep the fragment file in temp directory regardless of the validation result?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, as it is just for debug purpose.

"issuer": issuer, // eg the DID:x509:blah....
"feed": feed,
"cty": unpacked.ContentType,
"chainPem": chainPem,
Copy link
Contributor

Choose a reason for hiding this comment

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

do we want to log chainPem?

Copy link
Member Author

@MahatiC MahatiC Nov 3, 2025

Choose a reason for hiding this comment

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

This is a CA cert pem which contains public certs - used for troubleshooting

// (ie fingerprint of a non leaf cert and the subject matches the leaf cert)
// 3 - Check that this issuer/feed match the requirement of the user provided
// security policy (done in the regoby LoadFragment)
func ExtractAndVerifyFragment(ctx context.Context, fragment *guestresource.LCOWSecurityPolicyFragment) (issuer string, feed string, payloadString string, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

we could also put this into its own file, e.g. pkg/securitypolicy/fragments.go

Copy link
Member Author

Choose a reason for hiding this comment

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

At this point, it's just a helper function, so leaving it here seems appropriate.

Copy link
Member Author

@MahatiC MahatiC Nov 3, 2025

Choose a reason for hiding this comment

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

@anmaxvl Actually, I have an upcoming PR that does move this along with some other common functions into a different file #2544 - (I haven't pushed all my changes into that PR yet)

Move inject and load fragment into the securitypolicy pkg

Signed-off-by: Mahati Chamarthy <[email protected]>
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.

3 participants