Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Split up "pod" images and managed container images #224

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ManageIQ::Providers::Openshift::ContainerManager < ManageIQ::Providers::Ku
require_nested :ContainerTemplate
require_nested :EventCatcher
require_nested :EventParser
require_nested :ManagedContainerImage
require_nested :MetricsCollectorWorker
require_nested :OrchestrationStack
require_nested :RefreshWorker
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,10 @@
class ManageIQ::Providers::Openshift::ContainerManager::ContainerImage < ContainerImage
def annotate_image(annotations)
ext_management_system.annotate(
"image",
digest,
annotations
)
end

def openscap_summary
failed_rules = openscap_rule_results.where(:result => "fail").group(:severity).count
[[['High'], 'Critical', 3],
[['Medium'], 'Important', 2],
[['Low'], 'Medium', 1],
[['Info', 'Unknown'], 'Low', 0]].collect do |severities, label, index|
{
:label => label,
:severityIndex => index,
:data => failed_rules.select { |sev| severities.include?(sev) }.values.sum
}
end
end
ManageIQ::Providers::Kubernetes::ContainerManager::ContainerImage.include(ActsAsStiLeafClass)

def security_quality_annotation(compliant)
{"quality.images.openshift.io/vulnerability.openscap" => {
:name => "ManageIQ",
:timestamp => Time.now.utc.to_i,
:description => "OpenSCAP Score",
:reference => "",
:compliant => compliant,
:summary => openscap_summary
}.to_json}
end
class ManageIQ::Providers::Openshift::ContainerManager::ContainerImage < ManageIQ::Providers::Kubernetes::ContainerManager::ContainerImage
supports_not :capture

def annotate_scan_policy_results(causing_policy, compliant)
annotate_image({
"security.manageiq.org/#{compliant ? "successful" : "failed"}-policy" => causing_policy,
"images.openshift.io/deny-execution" => (!compliant).to_s
}.merge!(security_quality_annotation(compliant)))
def self.disconnect_inv(ids)
_log.info "Disconnecting Images [#{ids}]"
base_class.where(:id => ids).update_all(:container_image_registry_id => nil, :deleted_on => Time.now.utc)
Comment on lines +6 to +8
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO not sure why this is necessary, when the ContainerImage.disconnect_inv method is run from the context of the ManageIQ::Providers::Openshift::ContainerManager::ContainerImage class where isn't picking up on the child classes. Suspect something to do with the ActsAsStiLeafClass but need to investigate more

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is due to ActsAsStiLeafClass using just [sti_class] for the type clause

end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class ManageIQ::Providers::Openshift::ContainerManager::ManagedContainerImage < ManageIQ::Providers::Openshift::ContainerManager::ContainerImage
supports :capture

def annotate_image(annotations)
ext_management_system.annotate(
"image",
digest,
annotations
)
end

def openscap_summary
failed_rules = openscap_rule_results.where(:result => "fail").group(:severity).count
[[['High'], 'Critical', 3],
[['Medium'], 'Important', 2],
[['Low'], 'Medium', 1],
[['Info', 'Unknown'], 'Low', 0]].collect do |severities, label, index|
{
:label => label,
:severityIndex => index,
:data => failed_rules.select { |sev| severities.include?(sev) }.values.sum
}
end
end

def security_quality_annotation(compliant)
{"quality.images.openshift.io/vulnerability.openscap" => {
:name => "ManageIQ",
:timestamp => Time.now.utc.to_i,
:description => "OpenSCAP Score",
:reference => "",
:compliant => compliant,
:summary => openscap_summary
}.to_json}
end

def annotate_scan_policy_results(causing_policy, compliant)
annotate_image({
"security.manageiq.org/#{compliant ? "successful" : "failed"}-policy" => causing_policy,
"images.openshift.io/deny-execution" => (!compliant).to_s
}.merge!(security_quality_annotation(compliant)))
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def parse_openshift_image(openshift_image)
:ref => "#{ContainerImage::DOCKER_PULLABLE_PREFIX}#{id}",
}

new_result[:type] = 'ManageIQ::Providers::Openshift::ContainerManager::ContainerImage'
new_result[:type] = 'ManageIQ::Providers::Openshift::ContainerManager::ManagedContainerImage'

if openshift_image[:dockerImageManifest].present?
begin
Expand Down
2 changes: 2 additions & 0 deletions spec/factories/container_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
factory :openshift_container_image, :class => "ManageIQ::Providers::Openshift::ContainerManager::ContainerImage" do
sequence(:name) { |n| "openshift_container_image_#{seq_padded_for_sorting(n)}" }
end

factory :openshift_managed_container_image, :class => "ManageIQ::Providers::Openshift::ContainerManager::ManagedContainerImage", :parent => :openshift_container_image
end
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
describe ManageIQ::Providers::Openshift::ContainerManager::ContainerImage do
context "#security_quality_annotation" do
let(:openshift_image_type) { "ManageIQ::Providers::Openshift::ContainerManager::ContainerImage" }
let(:container_image) do
FactoryBot.create(:openshift_container_image,
:type => openshift_image_type)
end
let(:blob) do
FactoryBot.create(:binary_blob,
:binary => "blah",
:name => "test_blob")
end
let(:container_image) { FactoryBot.create(:openshift_managed_container_image) }
let(:blob) { FactoryBot.create(:binary_blob, :binary => "blah", :name => "test_blob") }
let(:scan_result) do
FactoryBot.create(:openscap_result_skip_callback,
:binary_blob => blob,
:resource_id => container_image.id,
:resource_type => openshift_image_type,
:container_image_id => container_image.id)
:binary_blob => blob,
:resource_id => container_image.id,
:resource_type => container_image.type,
:container_image_id => container_image.id)
end
let(:successful_rule) do
FactoryBot.create(:openscap_rule_result,
:openscap_result_id => scan_result.id,
:severity => "High",
:result => "success")
:openscap_result_id => scan_result.id,
:severity => "High",
:result => "success")
end
let(:failed_rule) do
FactoryBot.create(:openscap_rule_result,
:openscap_result_id => scan_result.id,
:severity => "Medium",
:result => "fail")
:openscap_result_id => scan_result.id,
:severity => "Medium",
:result => "fail")
end

before :each do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def assert_table_counts
expect(ContainerTemplate.count).to eq(26)
expect(ContainerImage.count).to eq(all_images_count)
expect(ContainerImage.joins(:containers).distinct.count).to eq(pod_images_count)
expect(ManageIQ::Providers::Openshift::ContainerManager::ContainerImage.count).to eq(images_managed_by_openshift_count)
expect(ManageIQ::Providers::Openshift::ContainerManager::ManagedContainerImage.count).to eq(images_managed_by_openshift_count)
end

def assert_ems
Expand Down