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

Fixes #38164 - Update on bulk-upload from scap security guide #590

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ofedoren
Copy link
Member

No description provided.

@@ -48,12 +48,16 @@ def upload_from_files(files_array, from_scap_guide = false)
next
end

file = File.open(datastream, 'rb').read
file = File.read(datastream, mode: 'rb')
digest = Digest::SHA2.hexdigest(datastream)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we still keep calculating the digest from the filename?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've left it just so we don't change behavior for non-standard content files.

For updates, it will be regenerated https://github.com/theforeman/foreman_openscap/blob/master/app/models/concerns/foreman_openscap/scap_file_content.rb#L11 based of file contents. I think we could change it to be generated based on contents right away on the first upload.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we could change it to be generated based on contents right away on the first upload.

That would make sense.

Copy link
Member Author

@ofedoren ofedoren Jan 30, 2025

Choose a reason for hiding this comment

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

Now I'm thinking that it will change behavior for both cases (upload from custom files and scap guide): currently, on first upload it will generate digest from fullpath, stores it and then searches for existing db entry based on title and digest and if an entry is found it does nothing. By changing digest generation we will throw errors like "title already exists" on re-uploads (digests won't match for existing contents) .

Should we then just make it simple for all the cases: generate digest on upload in before_validation if it doesn't already exist (so we don't generate it twice on re-upload) and make already existing content updatable (as we want with scap guide) if titles match?

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we then just make it simple for all the cases: generate digest on upload in before_validation if it doesn't already exist (so we don't generate it twice on re-upload) and make already existing content updatable (as we want with scap guide) if titles match?

That sounds like the best approach to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants