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

mock-build to support --git-url option for scratch build #278

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

rhyw
Copy link
Contributor

@rhyw rhyw commented May 23, 2024

@@ -15,6 +16,16 @@ def options(self):

# this option cannot be used for diff-build tasks
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we need to change the comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure I understand. The changes in this MR doesn't change the behavior of diff-build, I think it's still true that the option cannot be used for diff-build.

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 diff-build would not work with cspodman anyway. It should probably work with version-diff-build though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Latested updates applied both client/hub side validation.

osh/client/commands/cmd_mock_build.py Show resolved Hide resolved
@hanchuntao
Copy link
Collaborator

@rhyw After installing the test rpm, run the command: osh-cli mock-build --config cspodman --hub=https://covscan.lab.eng.brq2.redhat.com/osh/xmlrpc --git-url 'git+https://pkgs.devel.redhat.com/git/containers/amq-broker#d90c3cfb9c69e5fa023be1c08bd8ec98a876dfa3', I got the following error: https://privatebin.corp.redhat.com/?4f46af6856f23901#9sZE8pR8t8bwfBAuxUvLQLguCXCuMcUjRiMyxpixnwd1

@kdudka
Copy link
Contributor

kdudka commented Jun 5, 2024

@hanchuntao Did you also update the hub and worker?

Note that links to the RH internal pastebin instance are not much useful for external community members.

if profile != "cspodman":
print("dist-git URL scan is incompatible with profile:", profile, file=sys.stderr)
return None, 2
return self.analyze(analyzers, dist_git_url, profile, su_user, additional_arguments, **kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

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

Where do we protect dist_git_url against shell command injection? My quick check suggests that nowhere:

osh-cli mock-build --hub https://covscan.lab.eng.brq2.redhat.com/osh/xmlrpc --config=cspodman --git-url "https://example/ --help; ls -l ~/.config/configstore; #hash"

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes, I tested it

[root@chhan-rhel9 ~]# osh-cli mock-build --hub https://covscan.lab.eng.brq2.redhat.com/osh/xmlrpc --config=cspodman --git-url "https://example/ --help; ls -l ~/.config/configstore; #hash"
Task info: https://covscan.lab.eng.brq2.redhat.com/osh/task/467528/
Watching tasks (this may be safely interrupted)...
467528 MockBuild: FREE
--> FREE: 1 [total: 1]
467528 MockBuild: FREE -> OPEN (osh-test-worker-001.osh-001.preprod.iad2.dc.redhat.com)
--> OPEN: 1 [total: 1]
467528 MockBuild: OPEN (osh-test-worker-001.osh-001.preprod.iad2.dc.redhat.com) -> FAILED (osh-test-worker-001.osh-001.preprod.iad2.dc.redhat.com)
--> FAILED: 1 [total: 1]
[root@chhan-rhel9 ~]# 

result in https://covscan.lab.eng.brq2.redhat.com/osh/task/467528/log/stdout.log

total 8
-rw-------. 1 csmock csmock 58 Nov 24  2023 snyk.json
-rw-------. 1 csmock csmock 58 Oct 10  2023 snyk.json.bak
Task did not produce any results

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a dist git URL check here: https://github.com/openscanhub/openscanhub/pull/278/files#diff-26bebd5671ea9c96d9eba3bdf8d8fcdcd3a4f8c594e359d29464c3623ff3aee3R36

But it appears the error was thrown before the validation is even triggerred. I'll see what can be done to throw this error earlier, probably to add some validation in cspodman cli.

Copy link
Contributor

Choose a reason for hiding this comment

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

Validation in osh-cli is not a solution to the security issue because anyone can comment out the validation in their copy of osh-cli or just use the XML-RPC interface directly.

Copy link
Contributor

Choose a reason for hiding this comment

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

... and validation in cspodman would not help either because the shell injection happens in the shell that runs cspodman, not in the implementation of cspodman.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's still helpful from client side because we should always raise/return earlier. I had this commit addressed: 69a902a

I'll see how similar sanitation/validation can be done from hub too. working in progress.

@hanchuntao
Copy link
Collaborator

@hanchuntao Did you also update the hub and worker?

Note that links to the RH internal pastebin instance are not much useful for external community members.

yes, I update osh-client, osh-worker, but forget update osh-hub, after update it, the command run correctly,and get correct result:

[root@chhan-rhel9 ~]# osh-cli mock-build --config cspodman --hub=https://covscan.lab.eng.brq2.redhat.com/osh/xmlrpc --git-url 'git+https://pkgs.devel.redhat.com/git/containers/amq-broker#d90c3cfb9c69e5fa023be1c08bd8ec98a876dfa3'
Task info: https://covscan.lab.eng.brq2.redhat.com/osh/task/467527/
Watching tasks (this may be safely interrupted)...
467527 MockBuild: FREE
--> FREE: 1 [total: 1]
467527 MockBuild: FREE -> OPEN (osh-test-worker-001.osh-001.preprod.iad2.dc.redhat.com)
--> OPEN: 1 [total: 1]
467527 MockBuild: OPEN (osh-test-worker-001.osh-001.preprod.iad2.dc.redhat.com) -> CLOSED (osh-test-worker-001.osh-001.preprod.iad2.dc.redhat.com)
--> CLOSED: 1 [total: 1]
[root@chhan-rhel9 ~]# 

@rhyw rhyw marked this pull request as draft June 12, 2024 10:53
@rhyw rhyw marked this pull request as ready for review June 14, 2024 08:51
@rhyw rhyw self-assigned this Jun 14, 2024
@rhyw
Copy link
Contributor Author

rhyw commented Jun 14, 2024

/packit rebuild-failed

Copy link
Contributor

@kdudka kdudka left a comment

Choose a reason for hiding this comment

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

@rhyw Let's not over-complicate this. The git URL is now checked at multiple places using multiple regular expressions. Manually maintaining a set of disallowed characters is not a way to protect against shell command injection. To protect against shell injection, please use shlex.quote() as we do for other arguments passed to csmock or cspodman. To reject invalid URLs before starting a scan, I would just rewrite the regex that splits the URL parts so that it explicitly lists the set of allowed characters in each part of the URL.

@rhyw
Copy link
Contributor Author

rhyw commented Jun 19, 2024

@kdudka thanks for the suggestion, I have revised the way how validation was done a bit. The existing REs we use in csmock/cspodman are not enough to check the validity of the git URLs, some additional checks are added in latest code.

@kdudka
Copy link
Contributor

kdudka commented Jun 19, 2024

@rhyw Is this ready for review?

The commits seem to be in wrong order with some unnecessary changes back and forth:

  • a41fb53 introduces a call to the parse_git_url() function, which is not yet defined.
  • The parse_git_url() function is defined later in commit ae3c67a.
  • The parse_git_url() function is again removed in commit 0a44958.

@rhyw
Copy link
Contributor Author

rhyw commented Jun 20, 2024

@rhyw Is this ready for review?

The pipeline is failed though I was checking the cause of the failure.

The commits seem to be in wrong order with some unnecessary changes back and forth:

I had some problem rebasing earlier due to merge conflicts.

I'll mark this as Draft first, and mark it as Ready once these issues are fixed. Thanks

@rhyw rhyw marked this pull request as draft June 20, 2024 01:56
rhyw added 6 commits June 21, 2024 10:07
so that it's easier to reuse the code snippets.
cmd construction to a separate function, output_path to be
determined in a separate function. The change split the function
into smaller ones, to make it ealier to partially re-use.
@rhyw rhyw requested review from kdudka and hanchuntao June 21, 2024 07:25
@rhyw rhyw marked this pull request as ready for review June 21, 2024 07:26
@rhyw
Copy link
Contributor Author

rhyw commented Jun 21, 2024

I think the pipeline failure is not relevent. I had some tests on stage, and I think it's working as expected.

Validation is done on both cli/hub side. e.g., on client side with an invalid URL provided:

$ osh-cli mock-build --nowait --hub <hub-xmlrpc-endpoint> --git-url "https://example.com/--help;ls-l ~/.config/configstore;#hash"
Usage: osh-cli mock-build [options] <args>

osh-cli: error: Invalid path in dist-git URL: /--help;ls-l ~/.config/configstore;

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.

None yet

3 participants