From 26f737af5508f1ba906779b989bc6e335a9204a7 Mon Sep 17 00:00:00 2001 From: Paul Okstad Date: Thu, 19 Dec 2019 11:51:52 -0800 Subject: [PATCH 1/3] Protect against improper feature flags --- .../metadata/featureflag/feature_flags.go | 41 +++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/internal/metadata/featureflag/feature_flags.go b/internal/metadata/featureflag/feature_flags.go index ea26ca3c168..2d730c17586 100644 --- a/internal/metadata/featureflag/feature_flags.go +++ b/internal/metadata/featureflag/feature_flags.go @@ -1,20 +1,37 @@ package featureflag -const ( - // UploadPackFilter enables partial clones by sending uploadpack.allowFilter and uploadpack.allowAnySHA1InWant - // to upload-pack - UploadPackFilter = "upload_pack_filter" - // LinguistFileCountStats will invoke an additional git-linguist command to get the number of files per language - LinguistFileCountStats = "linguist_file_count_stats" - // HooksRPC will invoke update, pre receive, and post receive hooks by using RPCs - HooksRPC = "hooks_rpc" - // CacheInvalidator controls the tracking of repo state via gRPC - // annotations (i.e. accessor and mutator RPC's). This enables cache - // invalidation by changing state when the repo is modified. - CacheInvalidator = "cache-invalidator" +import ( + "fmt" + "regexp" +) + +// UploadPackFilter enables partial clones by sending uploadpack.allowFilter and uploadpack.allowAnySHA1InWant +// to upload-pack +// +// LinguistFileCountStats will invoke an additional git-linguist command to get the number of files per language +// +// HooksRPC will invoke update, pre receive, and post receive hooks by using RPCs +// +// CacheInvalidator controls the tracking of repo state via gRPC +// annotations (i.e. accessor and mutator RPC's). This enables cache +// invalidation by changing state when the repo is modified. +var ( + UploadPackFilter = mustValidateFF("upload_pack_filter") + LinguistFileCountStats = mustValidateFF("linguist_file_count_stats") + HooksRPC = mustValidateFF("hooks_rpc") + CacheInvalidator = mustValidateFF("cache-invalidator") ) const ( // HooksRPCEnvVar is the name of the environment variable we use to pass the feature flag down into gitaly-hooks HooksRPCEnvVar = "GITALY_HOOK_RPCS_ENABLED" ) + +var ffRegex = regexp.MustCompile(`^[[:alpha:]_]+$`) + +func mustValidateFF(ff string) string { + if !ffRegex.MatchString(ff) { + panic(fmt.Sprintf("invalid chars found in feature flag: %q", ff)) + } + return ff +} -- GitLab From 9fa214be98b3ef158ba7b78f5072f2fe1321b126 Mon Sep 17 00:00:00 2001 From: Paul Okstad Date: Thu, 19 Dec 2019 11:56:15 -0800 Subject: [PATCH 2/3] Fix cache invalidator feature flag --- internal/metadata/featureflag/feature_flags.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/metadata/featureflag/feature_flags.go b/internal/metadata/featureflag/feature_flags.go index 2d730c17586..97e5c6cf035 100644 --- a/internal/metadata/featureflag/feature_flags.go +++ b/internal/metadata/featureflag/feature_flags.go @@ -19,7 +19,7 @@ var ( UploadPackFilter = mustValidateFF("upload_pack_filter") LinguistFileCountStats = mustValidateFF("linguist_file_count_stats") HooksRPC = mustValidateFF("hooks_rpc") - CacheInvalidator = mustValidateFF("cache-invalidator") + CacheInvalidator = mustValidateFF("cache_invalidator") ) const ( -- GitLab From f49f0d69cc14d6ae275066b55e35cd6d74b792d7 Mon Sep 17 00:00:00 2001 From: Paul Okstad Date: Thu, 19 Dec 2019 11:59:37 -0800 Subject: [PATCH 3/3] Changelog for MR 1714 --- changelogs/unreleased/po-fix-cache-invalidator-ff.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelogs/unreleased/po-fix-cache-invalidator-ff.yml diff --git a/changelogs/unreleased/po-fix-cache-invalidator-ff.yml b/changelogs/unreleased/po-fix-cache-invalidator-ff.yml new file mode 100644 index 00000000000..6c9bbced27a --- /dev/null +++ b/changelogs/unreleased/po-fix-cache-invalidator-ff.yml @@ -0,0 +1,5 @@ +--- +title: Fix cache invalidator feature flag +merge_request: 1714 +author: +type: fixed -- GitLab