diff options
Diffstat (limited to 'app/services/pod_logs')
-rw-r--r-- | app/services/pod_logs/base_service.rb | 3 | ||||
-rw-r--r-- | app/services/pod_logs/elasticsearch_service.rb | 10 | ||||
-rw-r--r-- | app/services/pod_logs/kubernetes_service.rb | 9 |
3 files changed, 21 insertions, 1 deletions
diff --git a/app/services/pod_logs/base_service.rb b/app/services/pod_logs/base_service.rb index 2451ab8e0ce..8936f9b67a5 100644 --- a/app/services/pod_logs/base_service.rb +++ b/app/services/pod_logs/base_service.rb @@ -58,6 +58,9 @@ module PodLogs result[:pod_name] = params['pod_name'].presence result[:container_name] = params['container_name'].presence + return error(_('Invalid pod_name')) if result[:pod_name] && !result[:pod_name].is_a?(String) + return error(_('Invalid container_name')) if result[:container_name] && !result[:container_name].is_a?(String) + success(result) end diff --git a/app/services/pod_logs/elasticsearch_service.rb b/app/services/pod_logs/elasticsearch_service.rb index aac0fa424ca..f79562c8ab3 100644 --- a/app/services/pod_logs/elasticsearch_service.rb +++ b/app/services/pod_logs/elasticsearch_service.rb @@ -11,6 +11,7 @@ module PodLogs :pod_logs, :filter_return_keys + self.reactive_cache_work_type = :external_dependency self.reactive_cache_worker_finder = ->(id, _cache_key, namespace, params) { new(::Clusters::Cluster.find(id), namespace, params: params) } private @@ -52,12 +53,16 @@ module PodLogs def check_search(result) result[:search] = params['search'] if params.key?('search') + return error(_('Invalid search parameter')) if result[:search] && !result[:search].is_a?(String) + success(result) end def check_cursor(result) result[:cursor] = params['cursor'] if params.key?('cursor') + return error(_('Invalid cursor parameter')) if result[:cursor] && !result[:cursor].is_a?(String) + success(result) end @@ -65,6 +70,8 @@ module PodLogs client = cluster&.application_elastic_stack&.elasticsearch_client return error(_('Unable to connect to Elasticsearch')) unless client + chart_above_v2 = cluster.application_elastic_stack.chart_above_v2? + response = ::Gitlab::Elasticsearch::Logs::Lines.new(client).pod_logs( namespace, pod_name: result[:pod_name], @@ -72,7 +79,8 @@ module PodLogs search: result[:search], start_time: result[:start_time], end_time: result[:end_time], - cursor: result[:cursor] + cursor: result[:cursor], + chart_above_v2: chart_above_v2 ) result.merge!(response) diff --git a/app/services/pod_logs/kubernetes_service.rb b/app/services/pod_logs/kubernetes_service.rb index 0a8072a9037..b573ceae1aa 100644 --- a/app/services/pod_logs/kubernetes_service.rb +++ b/app/services/pod_logs/kubernetes_service.rb @@ -17,6 +17,7 @@ module PodLogs :split_logs, :filter_return_keys + self.reactive_cache_work_type = :external_dependency self.reactive_cache_worker_finder = ->(id, _cache_key, namespace, params) { new(::Clusters::Cluster.find(id), namespace, params: params) } private @@ -46,6 +47,10 @@ module PodLogs ' chars' % { max_length: K8S_NAME_MAX_LENGTH })) end + unless result[:pod_name] =~ Gitlab::Regex.kubernetes_dns_subdomain_regex + return error(_('pod_name can contain only lowercase letters, digits, \'-\', and \'.\' and must start and end with an alphanumeric character')) + end + unless result[:pods].include?(result[:pod_name]) return error(_('Pod does not exist')) end @@ -69,6 +74,10 @@ module PodLogs ' %{max_length} chars' % { max_length: K8S_NAME_MAX_LENGTH })) end + unless result[:container_name] =~ Gitlab::Regex.kubernetes_dns_subdomain_regex + return error(_('container_name can contain only lowercase letters, digits, \'-\', and \'.\' and must start and end with an alphanumeric character')) + end + unless container_names.include?(result[:container_name]) return error(_('Container does not exist')) end |