Skip to content

Commit

Permalink
Ignore layer files that have security capability attrs
Browse files Browse the repository at this point in the history
If a file in a layer has had setcap used on it, it will show up in
the layer, but be unchanged. However, there will be a PAX record
that shows the extended attrs. For now, preflight will ignore these
files, unless/until we find a situation where we should be more robust
in this check and possibly fail it.

Fixes redhat-openshift-ecosystem#969

Signed-off-by: Brad P. Crochet <brad@redhat.com>
  • Loading branch information
bcrochet authored and acornett21 committed May 1, 2023
1 parent eb765b5 commit bbef218
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions internal/policy/container/has_modified_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (p *HasModifiedFilesCheck) gatherDataToValidate(ctx context.Context, imgRef

layerIDs = append(layerIDs, layerID)

files, err := generateChangesFor(layer)
files, err := generateChangesFor(ctx, layer)
if err != nil {
return nil, nil, "", err
}
Expand Down Expand Up @@ -375,7 +375,8 @@ func installedFileMapWithExclusions(ctx context.Context, pkglist []*rpmdb.Packag
}

// generateChangesFor will check layer for file changes, and will return a list of those.
func generateChangesFor(layer v1.Layer) ([]string, error) {
func generateChangesFor(ctx context.Context, layer v1.Layer) ([]string, error) {
logger := logr.FromContextOrDiscard(ctx)
layerReader, err := layer.Uncompressed()
if err != nil {
return nil, fmt.Errorf("reading layer contents: %w", err)
Expand Down Expand Up @@ -408,6 +409,13 @@ func generateChangesFor(layer v1.Layer) ([]string, error) {
if tombstone {
basename = basename[len(whiteoutPrefix):]
}

// If there is a capability entry, ignore the file
if _, found := header.PAXRecords["SCHILY.xattr.security.capability"]; found {
logger.V(log.TRC).Info("security capabilities found in layer tar, ignoring file", "file", header.Name)
continue
}

switch {
case (header.Typeflag == tar.TypeDir && tombstone) || header.Typeflag == tar.TypeReg:
filelist[strings.TrimPrefix(filepath.Join(dirname, basename), "/")] = struct{}{}
Expand Down

0 comments on commit bbef218

Please sign in to comment.