From 7be5b1cd199c10070ae406a6b0f1f81efc262200 Mon Sep 17 00:00:00 2001 From: Shivam Sandbhor Date: Fri, 17 Jun 2022 15:30:24 +0530 Subject: [PATCH] Deprecate challenge action; Log on bouncer start Signed-off-by: Shivam Sandbhor --- cloudflare.go | 2 +- cloudflare_test.go | 14 +++++++------- config.go | 10 +++++++++- main.go | 1 + 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/cloudflare.go b/cloudflare.go index 1b911b3..9d110f6 100644 --- a/cloudflare.go +++ b/cloudflare.go @@ -28,7 +28,7 @@ const CallsPerSecondLimit uint32 = 4 var TotalIPListCapacity int = 10000 var CloudflareActionByDecisionType = map[string]string{ - "captcha": "challenge", + "captcha": "managed_challenge", "ban": "block", "js_challenge": "js_challenge", } diff --git a/cloudflare_test.go b/cloudflare_test.go index b287517..18fdf50 100644 --- a/cloudflare_test.go +++ b/cloudflare_test.go @@ -388,7 +388,7 @@ func Test_classifyDecisionsByAction(t *testing.T) { "block": { &decision1, }, - "challenge": { + "managed_challenge": { &decision2, }, }, @@ -397,8 +397,8 @@ func Test_classifyDecisionsByAction(t *testing.T) { name: "with dups, all supported", args: args{decisions: []*models.Decision{&decision2, &decision2dup}}, want: map[string][]*models.Decision{ - "defaulted": {}, - "challenge": {&decision2}, + "defaulted": {}, + "managed_challenge": {&decision2}, }, }, { @@ -419,9 +419,9 @@ func Test_classifyDecisionsByAction(t *testing.T) { decisions: []*models.Decision{&decisionUnsup, &decision1, &decision2}, }, want: map[string][]*models.Decision{ - "defaulted": {}, - "block": {&decision1}, - "challenge": {&decision2}, + "defaulted": {}, + "block": {&decision1}, + "managed_challenge": {&decision2}, }, }, } @@ -836,7 +836,7 @@ func Test_allZonesHaveAction(t *testing.T) { zones: []ZoneConfig{ { ActionSet: map[string]struct{}{ - "challenge": {}, + "managed_challenge": {}, }, }, { diff --git a/config.go b/config.go index 4deb4a5..3fe6fc7 100644 --- a/config.go +++ b/config.go @@ -96,7 +96,7 @@ func NewConfig(configPath string) (*bouncerConfig, error) { if _, ok := validAction[account.DefaultAction]; !ok { return nil, fmt.Errorf("account %s 's default action is invalid. %s ", account.ID, validChoiceMsg) } - + zoneUsingChallenge := make([]string, 0) for j, zone := range account.ZoneConfigs { config.CloudflareConfig.Accounts[i].ZoneConfigs[j].ActionSet = map[string]struct{}{} if len(zone.Actions) == 0 { @@ -106,6 +106,8 @@ func NewConfig(configPath string) (*bouncerConfig, error) { for _, a := range zone.Actions { if _, ok := validAction[a]; !ok { return nil, fmt.Errorf("invalid actions '%s', %s", a, validChoiceMsg) + } else if a == "challenge" { + zoneUsingChallenge = append(zoneUsingChallenge, zone.ID) } if a == account.DefaultAction { defaultActionIsSupported = true @@ -122,6 +124,12 @@ func NewConfig(configPath string) (*bouncerConfig, error) { } zoneIdSet[zone.ID] = true } + if len(zoneUsingChallenge) > 0 { + log.Warningf( + "zones %s uses 'challenge' action which is deprecated in favour of 'managed_challenge'. See migration guide at ", + strings.Join(zoneUsingChallenge, ", "), + ) + } } /*Configure logging*/ if err = types.SetDefaultLoggerConfig(config.LogMode, config.LogDir, config.LogLevel, 0, 0, 0, nil); err != nil { diff --git a/main.go b/main.go index fd34b34..0f558a1 100644 --- a/main.go +++ b/main.go @@ -180,6 +180,7 @@ func main() { } if !*onlySetup && !*delete { + log.Infof("Starting %s %s", name, version.VersionStr()) csLAPI = &csbouncer.StreamBouncer{ APIKey: conf.CrowdSecLAPIKey, APIUrl: conf.CrowdSecLAPIUrl,