Commit 26e688bf authored by Alan Paruszewski's avatar Alan Paruszewski

Remove Kubernetes IP address from errors returned in Threat Monitoring

This fix resolves problems with leaked Kubernetes IP address in error
messages.
parent e3a57b32
...@@ -23,7 +23,7 @@ module NetworkPolicies ...@@ -23,7 +23,7 @@ module NetworkPolicies
ServiceResponse.success ServiceResponse.success
rescue Kubeclient::HttpError => e rescue Kubeclient::HttpError => e
kubernetes_error_response(e) kubernetes_error_response(e.message)
end end
end end
end end
...@@ -26,7 +26,7 @@ module NetworkPolicies ...@@ -26,7 +26,7 @@ module NetworkPolicies
load_policy_from_resource load_policy_from_resource
ServiceResponse.success(payload: policy) ServiceResponse.success(payload: policy)
rescue Kubeclient::HttpError => e rescue Kubeclient::HttpError => e
kubernetes_error_response(e) kubernetes_error_response(e.message)
end end
private private
......
...@@ -16,7 +16,7 @@ module NetworkPolicies ...@@ -16,7 +16,7 @@ module NetworkPolicies
ServiceResponse.success(payload: get_policy) ServiceResponse.success(payload: get_policy)
rescue Kubeclient::HttpError => e rescue Kubeclient::HttpError => e
kubernetes_error_response(e) kubernetes_error_response(e.message)
end end
private private
......
---
title: Remove Kubernetes IP address from error messages returned in Threat Monitoring
merge_request:
author:
type: security
...@@ -49,8 +49,11 @@ RSpec.describe NetworkPolicies::DeleteResourceService do ...@@ -49,8 +49,11 @@ RSpec.describe NetworkPolicies::DeleteResourceService do
end end
context 'with Kubeclient::HttpError' do context 'with Kubeclient::HttpError' do
let(:request_url) { 'https://kubernetes.local' }
let(:response) { RestClient::Response.create('', {}, RestClient::Request.new(url: request_url, method: :get)) }
before do before do
allow(kubeclient).to receive(:delete_network_policy).and_raise(Kubeclient::HttpError.new(500, 'system failure', nil)) allow(kubeclient).to receive(:delete_network_policy).and_raise(Kubeclient::HttpError.new(500, 'system failure', response))
end end
it 'returns error response' do it 'returns error response' do
...@@ -58,6 +61,10 @@ RSpec.describe NetworkPolicies::DeleteResourceService do ...@@ -58,6 +61,10 @@ RSpec.describe NetworkPolicies::DeleteResourceService do
expect(subject.http_status).to eq(:bad_request) expect(subject.http_status).to eq(:bad_request)
expect(subject.message).not_to be_nil expect(subject.message).not_to be_nil
end end
it 'returns error message without request url' do
expect(subject.message).not_to include(request_url)
end
end end
context 'with CiliumNetworkPolicy' do context 'with CiliumNetworkPolicy' do
......
...@@ -94,8 +94,11 @@ RSpec.describe NetworkPolicies::DeployResourceService do ...@@ -94,8 +94,11 @@ RSpec.describe NetworkPolicies::DeployResourceService do
end end
context 'with Kubeclient::HttpError' do context 'with Kubeclient::HttpError' do
let(:request_url) { 'https://kubernetes.local' }
let(:response) { RestClient::Response.create('', {}, RestClient::Request.new(url: request_url, method: :get)) }
before do before do
allow(kubeclient).to receive(:create_network_policy).and_raise(Kubeclient::HttpError.new(500, 'system failure', nil)) allow(kubeclient).to receive(:create_network_policy).and_raise(Kubeclient::HttpError.new(500, 'system failure', response))
end end
it 'returns error response' do it 'returns error response' do
...@@ -103,6 +106,10 @@ RSpec.describe NetworkPolicies::DeployResourceService do ...@@ -103,6 +106,10 @@ RSpec.describe NetworkPolicies::DeployResourceService do
expect(subject.http_status).to eq(:bad_request) expect(subject.http_status).to eq(:bad_request)
expect(subject.message).not_to be_nil expect(subject.message).not_to be_nil
end end
it 'returns error message without request url' do
expect(subject.message).not_to include(request_url)
end
end end
context 'with cilium network policy' do context 'with cilium network policy' do
......
...@@ -62,8 +62,11 @@ RSpec.describe NetworkPolicies::FindResourceService do ...@@ -62,8 +62,11 @@ RSpec.describe NetworkPolicies::FindResourceService do
end end
context 'with Kubeclient::HttpError' do context 'with Kubeclient::HttpError' do
let(:request_url) { 'https://kubernetes.local' }
let(:response) { RestClient::Response.create('', {}, RestClient::Request.new(url: request_url, method: :get)) }
before do before do
allow(kubeclient).to receive(:get_network_policy).and_raise(Kubeclient::HttpError.new(500, 'system failure', nil)) allow(kubeclient).to receive(:get_network_policy).and_raise(Kubeclient::HttpError.new(500, 'system failure', response))
end end
it 'returns error response' do it 'returns error response' do
...@@ -71,6 +74,10 @@ RSpec.describe NetworkPolicies::FindResourceService do ...@@ -71,6 +74,10 @@ RSpec.describe NetworkPolicies::FindResourceService do
expect(subject.http_status).to eq(:bad_request) expect(subject.http_status).to eq(:bad_request)
expect(subject.message).not_to be_nil expect(subject.message).not_to be_nil
end end
it 'returns error message without request url' do
expect(subject.message).not_to include(request_url)
end
end end
end end
end end
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