feat: support exempt_files to skip source code overwrite detection - #485
Open
hemantkumar-dev wants to merge 1 commit into
Open
Conversation
Honors the exempt_files value sent by the harden-runner action so that configured paths are excluded from source code overwrite detection. Paths are matched by full path or trailing path segment, since the action sends repo-relative paths while file events carry absolute paths. Related to step-security/harden-runner#330.
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.
Summary
Honors a new
exempt_filesconfig value so that specific files can be excluded from source code overwrite detection, while file monitoring stays enabled for everything else.Problem
Source code overwrite detection currently applies to every source file under the working directory. The only way to quiet it for expected writes (for example generated bundles or lock files) is
disable_file_monitoring, which disables monitoring for the whole job. There was no way to exempt individual files.This is the agent side of step-security/harden-runner#330. The action change that surfaces the
exempt-filesinput and sendsexempt_filesin the agent config is in step-security/harden-runner#678.Fix
exempt_filesvalue from the agent config into a list of paths (parseExemptFiles). Splitting on newlines only keeps paths that contain spaces intact.configthroughProcessMonitortoEventHandler.handleFileEvent, skip source code overwrite tracking for a file when it matches an exempt path. Exempt entries are usually repo-relative while events carry absolute paths, so matching is done on the full path or a trailing path segment.When
exempt_filesis empty (the default) behavior is unchanged.Files changed
config.goexempt_filesinto[]stringviaparseExemptFilesprocmon.goExemptFilestoProcessMonitoragent.goExemptFilesfrom config to the monitorprocmon_linux.goExemptFilesinto theEventHandlereventhandler.goisExemptFileand skip overwrite detection for exempt filesTesting
go test ./...— addedTest_parseExemptFiles(newline handling, CRLF, blank lines, spaces in paths) andTestEventHandler_isExemptFile(exact, suffix, space-in-path, and negative matches)gofmtRelated to step-security/harden-runner#330
Companion action PR: step-security/harden-runner#678