Commit 04a60057 authored by Jan Provaznik's avatar Jan Provaznik

Merge branch 'files_blocklist' into 'master'

Rename internal file used to deny pushes for certain files

See merge request gitlab-org/gitlab!33666
parents b65821c5 f818d961
...@@ -98,12 +98,12 @@ GitLab uses [RE2 syntax](https://github.com/google/re2/wiki/Syntax) for regular ...@@ -98,12 +98,12 @@ GitLab uses [RE2 syntax](https://github.com/google/re2/wiki/Syntax) for regular
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/385) in [GitLab Starter](https://about.gitlab.com/pricing/) 8.12. > [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/385) in [GitLab Starter](https://about.gitlab.com/pricing/) 8.12.
Secrets such as credential files, SSH private keys, and other files containing secrets should never be committed to source control. Secrets such as credential files, SSH private keys, and other files containing secrets should never be committed to source control.
GitLab allows you to turn on a predefined blacklist of files which won't be allowed to be GitLab allows you to turn on a predefined denylist of files which won't be allowed to be
pushed to a repository, stopping those commits from reaching the remote repository. pushed to a repository, stopping those commits from reaching the remote repository.
By selecting the checkbox *Prevent committing secrets to Git*, GitLab prevents By selecting the checkbox *Prevent committing secrets to Git*, GitLab prevents
pushes to the repository when a file matches a regular expression as read from pushes to the repository when a file matches a regular expression as read from
[`files_blacklist.yml`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/gitlab/checks/files_blacklist.yml) (make sure you are at the right branch [`files_denylist.yml`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/gitlab/checks/files_denylist.yml) (make sure you are at the right branch
as your GitLab version when viewing this file). as your GitLab version when viewing this file).
NOTE: **Note:** NOTE: **Note:**
......
...@@ -26,7 +26,7 @@ class PushRule < ApplicationRecord ...@@ -26,7 +26,7 @@ class PushRule < ApplicationRecord
before_update :convert_to_re2 before_update :convert_to_re2
FILES_BLACKLIST = YAML.load_file(Rails.root.join('ee/lib/gitlab/checks/files_blacklist.yml')) FILES_DENYLIST = YAML.load_file(Rails.root.join('ee/lib/gitlab/checks/files_denylist.yml'))
SETTINGS_WITH_GLOBAL_DEFAULT = %i[ SETTINGS_WITH_GLOBAL_DEFAULT = %i[
reject_unsigned_commits reject_unsigned_commits
commit_committer_check commit_committer_check
...@@ -78,9 +78,9 @@ class PushRule < ApplicationRecord ...@@ -78,9 +78,9 @@ class PushRule < ApplicationRecord
data_match?(email, author_email_regex) data_match?(email, author_email_regex)
end end
def filename_blacklisted?(file_path) def filename_denylisted?(file_path)
regex_list = [] regex_list = []
regex_list.concat(FILES_BLACKLIST) if prevent_secrets regex_list.concat(FILES_DENYLIST) if prevent_secrets
regex_list << file_name_regex if file_name_regex regex_list << file_name_regex if file_name_regex
regex_list.find { |regex| data_match?(file_path, regex) } regex_list.find { |regex| data_match?(file_path, regex) }
......
...@@ -82,7 +82,7 @@ module EE ...@@ -82,7 +82,7 @@ module EE
def file_name_validation def file_name_validation
lambda do |diff| lambda do |diff|
if (diff.renamed_file || diff.new_file) && blacklisted_regex = push_rule.filename_blacklisted?(diff.new_path) if (diff.renamed_file || diff.new_file) && blacklisted_regex = push_rule.filename_denylisted?(diff.new_path)
return unless blacklisted_regex.present? return unless blacklisted_regex.present?
"File name #{diff.new_path} was blacklisted by the pattern #{blacklisted_regex}." "File name #{diff.new_path} was blacklisted by the pattern #{blacklisted_regex}."
......
...@@ -132,7 +132,7 @@ describe PushRule do ...@@ -132,7 +132,7 @@ describe PushRule do
commit_message_blocked?: :commit_message_negative_regex, commit_message_blocked?: :commit_message_negative_regex,
branch_name_allowed?: :branch_name_regex, branch_name_allowed?: :branch_name_regex,
author_email_allowed?: :author_email_regex, author_email_allowed?: :author_email_regex,
filename_blacklisted?: :file_name_regex filename_denylisted?: :file_name_regex
} }
methods_and_regexes.each do |method_name, regex_attr| methods_and_regexes.each do |method_name, regex_attr|
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment