Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Accept short profile IDs #107

Merged
merged 4 commits into from
Aug 1, 2017
Merged

Conversation

jan-cerny
Copy link
Member

Recently we implemented short profile IDs in OpenSCAP. However
oscapd-evaluate checks if the given profile ID is present
in SCAP Security Guide Datastream. We need to apply
suffix matching on the list of SSG profiles. Otherwise
we will get an error that the profile was not found.

@jan-cerny jan-cerny added this to the 0.1.7 milestone Jul 3, 2017
@mpreisler
Copy link
Member

This definitely needs a comment. Looking at the line and not being familiar with the short ID feature there is no way you can figure out what it is doing...

@mpreisler
Copy link
Member

Doesn't this break the rest of the API? Like creating and defining tasks and all that? Short profile ID won't work when generating HTML guides.

I am leaning NACK on this.

@jan-cerny
Copy link
Member Author

This is in "oscapd-evalaute", not in "oscapd-cli".

This condition checks if the ID provided by user is a suffix of some profile ID in SSG for the target platform. I depends on underlying tool eg. oscap or oscap-ssh if it can process the short ID.

The case that I solve by this patch is: I have oscap that supports shortened IDs installed, so I want to use shortened IDs in oscapd-evaluate scan as well, but I can't, because oscapd-evaluate scan parses SSG datastream, it can't find that exact ID there, so it terminates.

@mpreisler Could you explain connection of this with creating and defining tasks, please?
Do we need a more complex solution for some reason?

@mpreisler
Copy link
Member

IMO if we add some paradigm to one part of the API we should add it everywhere. Profile ID meaning different things in different parts of the API leads to confusion. Furthermore, both oscapd-cli and oscapd-evaluate use EvaluationSpec, so I don't see why this should be limited to oscapd-evaluate.

@jan-cerny
Copy link
Member Author

@mpreisler OK, that sounds reasonable. So I think I will rework the fix so that it completes the shortened ID to the full ID by longest suffix match, preferably before EvaluationSpec is created. That way the shortened ID won't be stored in EvaluationSpec, so it won't introduce any paradigm in any API.

@jan-cerny
Copy link
Member Author

I have reworked it so that it doesn't work with short profile IDs in the API, it completes them instead.

@mpreisler
Copy link
Member

mpreisler commented Jul 13, 2017 via email

@jan-cerny
Copy link
Member Author

jan-cerny commented Jul 14, 2017

@mpreisler Then, please could you explain how do you imagine short IDs in oscapd-evaluate? I don't understand at all what do you want.

I still think it would be beneficial to support short IDs in oscapd-evaluate, because that will enable short IDs in atomic scan, which will improve user experience of atomic scan, because users will not have to remember and type looong IDs.

If it isn't possible to enable short IDs in oscapd-evaluate, please feel free to close this pull request.

@jan-cerny
Copy link
Member Author

@mpreisler Any idea?

@mpreisler
Copy link
Member

mpreisler commented Jul 25, 2017

@mpreisler Any idea?

As I said, if it were me I would do this in a way that adds short profile IDs to both oscapd-evaluate (all subcommands) and oscapd-cli (all subcommands). Perhaps others can chime in.

@jan-cerny
Copy link
Member Author

We discussed this yesterday. I will look into this problem again. I will try to find a solution that works across whole Deamon in all use-cases. It could be done in EvalauationSpec, maybe as a new method of EvaluationSpec.

@jan-cerny
Copy link
Member Author

I looked into this again today. I think that EvaulationSpec doesn't care if the ID is short or long. Only subcommand in oscapd-cli that I found that takes the profile ID is "task-create -i", which is interactive, so user just presses a number, and doesn't type the ID by hand. In oscapd-evaluate, the only subcommand is "oscapd-evaluate scan", which was solved in this PR. I think we I just need the code to evaluation_spec module.

@jan-cerny
Copy link
Member Author

I have created a method in EvaluationSpec and moved the code there.

@@ -349,6 +349,21 @@ def get_cpe_ids(self, config):

return cpe_ids

def match_ssg_profile_id(self, ssg_sds, profile):
Copy link
Member

@mpreisler mpreisler Jul 27, 2017

Choose a reason for hiding this comment

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

suggested name "select_profile_by_suffix". and please change "profile" variable to "profile_suffix".

@jan-cerny
Copy link
Member Author

I have renamed the method to "select_profile_by_suffix" and changed "profile" variable to "profile_suffix".

break
else:
raise RuntimeError(
"Profile with id='%s' doesn't exist on target '%s'. "
Copy link
Member

Choose a reason for hiding this comment

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

this error is wrong if we are selecting by suffix

Copy link
Member Author

Choose a reason for hiding this comment

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

Should it be something like Profile with ID matching suffix '%s' doesn't ?

Copy link
Member

Choose a reason for hiding this comment

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

The whole thing doesn't make sense in the method in EvaluationSpec, I suggest to make it throw an exception and then you can make a nice message in oscapd-evaluate.

Copy link
Member Author

Choose a reason for hiding this comment

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

Can I catch the exception?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, throw in EvaluationSpec, then catch it in oscapd-evaluate to make a nice specific message.

Copy link
Member Author

Choose a reason for hiding this comment

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

Awesome

Recently we implemented short profile IDs in OpenSCAP. However
oscapd-evaluate checks if the given profile ID is present
in SCAP Security Guide Datastream. We need to apply
suffix matching on the list of SSG profiles. Otherwise
we will get an error that the profile was not found.
@jan-cerny
Copy link
Member Author

I have improved this patch . The method select_profile_by_suffix throws an exception. This exception is caught in oscapd-evaluate where an error message is produced.

@jan-cerny
Copy link
Member Author

@openscap-ci test this please

for p in profiles:
if p.endswith(profile_suffix):
self.profile_id = p
break
Copy link
Member

Choose a reason for hiding this comment

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

We should handle multiple matches of the suffix too.

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 think that we don't have multiple profiles with same ID in SSG. But it still makes sense to check for multiple matches. Thanks for suggestion. It will handle if user types some very short suffix, maybe a single character. I'll do that.

@@ -349,6 +349,16 @@ def get_cpe_ids(self, config):

return cpe_ids

def select_profile_by_suffix(self, ssg_sds, profile_suffix):
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't take ssg_sds. Instead it should use whatever content is already set in the EvaluationSpec. If there is no content set yet it should throw an exception.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I wouldn't expect that. I'll try to handle it.

self.profile_id = p
break
else:
raise RuntimeError("No profile with suffix %s" % profile_suffix)
Copy link
Member

Choose a reason for hiding this comment

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

make this a typed exception if you plan to catch it.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK 👍

% (es.profile_id, target, target)
try:
args.profile = es.select_profile_by_suffix(ssg_sds, args.profile)
except RuntimeError:
Copy link
Member

Choose a reason for hiding this comment

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

this is quite dangerous, a lot of things can throw RuntimeError, please make this exception typed

Copy link
Member Author

Choose a reason for hiding this comment

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

OK 👍 👍

An exception will be raised if multiple matches occur.
Instead of providing the SCAP Security Guide source datastream
directly to the method select_profile_by_suffix, we will make
the datastream available in EvaluationSpec and then we will
obtain the datastream filepath from the EvaluationSpec.
This commit creates a new class of exception "ProfileSuffixMatchError",
that is thrown by select_profile_by_suffix method in situations
when a profile ID could not be matched. Then this exception is
caught and then an error message is issued.
@jan-cerny
Copy link
Member Author

I have done requested changes.

@yuumasato
Copy link
Member

LGTM.
I think @mpreisler would like to review before merging.

@jan-cerny
Copy link
Member Author

@yuumasato thank you

@mpreisler
Copy link
Member

mpreisler commented Aug 1, 2017

I trust you @yuumasato ! :D

@mpreisler mpreisler merged commit aeb6325 into OpenSCAP:master Aug 1, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants