From 59111ba5e7fe1ed436d28f9bf0d00544219e4fa6 Mon Sep 17 00:00:00 2001 From: choudharypooja Date: Wed, 27 Nov 2024 15:46:43 +0530 Subject: [PATCH] Adding restriction/validation on the allowed domains for LM portal --- README.md | 3 ++- lib/logstash/outputs/lmlogs.rb | 7 +++++++ lib/logstash/outputs/version.rb | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6791a96..16c6111 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,8 @@ output { } ``` You would need either `access_id` and `access_id` both or `bearer_token` for authentication with Logicmonitor. -The portal_domain is the domain of your LM portal. If not set the default is set to `logicmonitor.com`. Eg if your LM portal URL is `https://test.domain.com`, portal_name should be set to `test` and portal_domain to `domain.com` +The portal_domain is the domain of your LM portal. If not set the default is set to `logicmonitor.com`. Eg if your LM portal URL is `https://test.lmgov.us`, portal_name should be set to `test` and portal_domain to `lmgov.us` +The allowed values for portal_domain are ["logicmonitor.com", "lmgov.us", "qa-lmgov.us"] diff --git a/lib/logstash/outputs/lmlogs.rb b/lib/logstash/outputs/lmlogs.rb index 7105709..ea6eef5 100644 --- a/lib/logstash/outputs/lmlogs.rb +++ b/lib/logstash/outputs/lmlogs.rb @@ -115,6 +115,8 @@ class InvalidHTTPConfigError < StandardError; end # For developer debugging. @@CONSOLE_LOGS = false + ALLOWED_DOMAINS = ["logicmonitor.com", "lmgov.us", "qa-lmgov.us"] + public def register @total = 0 @@ -130,6 +132,11 @@ def register @portal_domain = "logicmonitor.com" end + unless ALLOWED_DOMAINS.include?(@portal_domain) + raise LogStash::ConfigurationError, "Invalid portal_domain: #{@portal_domain}. Allowed values are: #{ALLOWED_DOMAINS.join(', ')}" + end + log_debug("Setting LM portal domain ", :portal_domain => portal_domain) + @final_metadata_keys = Hash.new if @include_metadata_keys.any? include_metadata_keys.each do | nested_key | diff --git a/lib/logstash/outputs/version.rb b/lib/logstash/outputs/version.rb index eaa2212..690f3d0 100644 --- a/lib/logstash/outputs/version.rb +++ b/lib/logstash/outputs/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module LmLogsLogstashPlugin - VERSION = '2.0.2' + VERSION = '2.0.3' end