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

Add URI checks from trusted repo for gpg key download #459

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 11 additions & 1 deletion inbm/dispatcher-agent/dispatcher/source/source_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
from dispatcher.source.source_manager_factory import create_os_source_manager
from dispatcher.source.source_manager_factory import create_application_source_manager
from inbm_lib.xmlhandler import XmlException, XmlHandler
from dispatcher.packagemanager.package_manager import verify_source
from dispatcher.dispatcher_broker import DispatcherBroker
from inbm_common_lib.utility import CanonicalUri
from dispatcher.dispatcher_exception import DispatcherException

logger = logging.getLogger(__name__)

Expand All @@ -41,11 +45,17 @@ def do_source_command(parsed_head: XmlHandler, os_type: OsType) -> Result:

try:
app_action = parsed_head.get_children("applicationSource")
url = parsed_head.get_children("applicationSource/add/gpg")["uri"]
Copy link
Contributor

Choose a reason for hiding this comment

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

@tsirlapu Was just looking over this PR and noticed this code. The actual execution of the command (including any checks) should not go in do_source_command. do_source_command's responsibility is to detect whether we are running an appliaction or os source command and pass it on to the _handle_app_source_command or _handle_os_source_command methods. This code should probably go in the Ubuntu/Debian specific source application add method, or should go in the abstract base class as a concrete method and then be called from each OS that needs it (currently just Ubuntu).

if not isinstance(url, CanonicalUri):
return Result(status=400, message="Internal error: url improperly passed to download function")
source = uri.value[:-(len(url.value.split('/')[-1]) + 1)]
verify_source(source=source, dispatcher_broker=dispatcher_broker)
if app_action:
return _handle_app_source_command(parsed_head, os_type, app_action)
except XmlException as e:
return Result(status=400, message=f"unable to handle source command XML: {e}")

except DispatcherException as err:
return Result(status=400, message="Source URI verification check failed")
return Result(status=400, message="unknown source command")


Expand Down