Skip to content

Commit eb0eb42

Browse files
committed
CWCOW: Include merged layer hash
Signed-off-by: Mahati Chamarthy <mahati.chamarthy@gmail.com>
1 parent 0e46ce2 commit eb0eb42

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

internal/gcs-sidecar/handlers.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -641,11 +641,7 @@ func (b *Bridge) modifySettings(req *request) (err error) {
641641
log.G(ctx).Debugf("block CIM layer digest %s, path: %s\n", layerHashes[i], physicalDevPath)
642642
}
643643

644-
// skip the merged cim and verify individual layer hashes
645644
hashesToVerify := layerHashes
646-
if len(layerHashes) > 1 {
647-
hashesToVerify = layerHashes[1:]
648-
}
649645

650646
err := b.hostState.securityOptions.PolicyEnforcer.EnforceVerifiedCIMsPolicy(req.ctx, containerID, hashesToVerify)
651647
if err != nil {

pkg/ociwclayer/cim/import.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func WithParentLayers(parentLayers []*cimfs.BlockCIM) BlockCIMLayerImportOpt {
9696
}
9797
}
9898

99-
func writeIntegrityChecksumInfoFile(ctx context.Context, blockPath string) error {
99+
func writeIntegrityChecksumInfoFile(ctx context.Context, blockPath string, pathName string) error {
100100
log.G(ctx).Debugf("writing integrity checksum file for block CIM `%s`", blockPath)
101101
// for convenience write a file that has the hex encoded root digest of the generated verified CIM.
102102
// this same hex string can be used in the confidential policy.
@@ -105,7 +105,7 @@ func writeIntegrityChecksumInfoFile(ctx context.Context, blockPath string) error
105105
return fmt.Errorf("failed to query verified info of the CIM layer: %w", err)
106106
}
107107

108-
digestFile, err := os.Create(filepath.Join(filepath.Dir(blockPath), "integrity_checksum"))
108+
digestFile, err := os.Create(filepath.Join(filepath.Dir(blockPath), pathName))
109109
if err != nil {
110110
return fmt.Errorf("failed to create verification info file: %w", err)
111111
}
@@ -120,6 +120,18 @@ func writeIntegrityChecksumInfoFile(ctx context.Context, blockPath string) error
120120
return nil
121121
}
122122

123+
func GetIntegrityChecksum(ctx context.Context, blockPath string) (string, error) {
124+
log.G(ctx).Debugf("Getting integrity checksum for block CIM `%s`", blockPath)
125+
digest, err := cimfs.GetVerificationInfo(blockPath)
126+
if err != nil {
127+
return "", fmt.Errorf("failed to query verified info of the CIM layer: %w", err)
128+
}
129+
130+
digestStr := hex.EncodeToString(digest)
131+
132+
return digestStr, nil
133+
}
134+
123135
func ImportBlockCIMLayerWithOpts(ctx context.Context, r io.Reader, layer *cimfs.BlockCIM, opts ...BlockCIMLayerImportOpt) (_ int64, err error) {
124136
log.G(ctx).WithField("layer", layer).Debug("Importing block CIM layer from tar")
125137

@@ -164,7 +176,7 @@ func ImportBlockCIMLayerWithOpts(ctx context.Context, r io.Reader, layer *cimfs.
164176
}
165177

166178
if config.dataIntegrity {
167-
if err = writeIntegrityChecksumInfoFile(ctx, layer.BlockPath); err != nil {
179+
if err = writeIntegrityChecksumInfoFile(ctx, layer.BlockPath, "integrity_checksum"); err != nil {
168180
return 0, err
169181
}
170182
}
@@ -358,5 +370,10 @@ func MergeBlockCIMLayersWithOpts(ctx context.Context, sourceCIMs []*cimfs.BlockC
358370
return fmt.Errorf("append VHD footer to block CIM: %w", err)
359371
}
360372
}
373+
if config.dataIntegrity {
374+
if err = writeIntegrityChecksumInfoFile(ctx, mergedCIM.BlockPath, "merged_integrity_checksum"); err != nil {
375+
return err
376+
}
377+
}
361378
return nil
362379
}

0 commit comments

Comments
 (0)