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 #32257 - use trusted hosts to authorize clients #80

Merged
merged 1 commit into from Apr 19, 2021

Conversation

lzap
Copy link
Member

@lzap lzap commented Apr 6, 2021

An improper authorization handling flaw was found in Foreman. The OpenSCAP plugin for the smart-proxy allows foreman clients to execute actions that should be limited to the Foreman Server. This flaw allows an authenticated local attacker to access and delete limited resources and also causes a denial of service on the Foreman server. The highest threat from this vulnerability is to integrity and system availability.

https://access.redhat.com/security/cve/CVE-2021-20290

@lzap
Copy link
Member Author

lzap commented Apr 6, 2021

@ares
Copy link
Member

ares commented Apr 7, 2021

Wait, isn't this effectlively allowing all of the endpoints defined in here to be only accessible by Foreman? note that managed hosts upload their reports post "/arf/:policy", downloads policy xmls get "/policies/:policy_id/content/:digest"" and tailoring files get "/policies/:policy_id/tailoring/:digest"

These still needs to be accessible by anyone with valid certificate (issued by trusted CA)

@xprazak2
Copy link
Contributor

xprazak2 commented Apr 8, 2021

Yes, exactly what @ares said:

[root@oscap-host ~]# foreman_scap_client 2
DEBUG: running: oscap xccdf eval  --profile xccdf_org.ssgproject.content_profile_stig  --results-arf /tmp/d20210408-19625-1czznht/results.xml /var/lib/openscap/content/654f841b9386f771d3999f855f28bfed01e2be4036774103e822950c1e4230aa.xml

DEBUG: running: /usr/bin/env bzip2 /tmp/d20210408-19625-1czznht/results.xml
Uploading results to https://foreman.example.com:9090/compliance/arf/2
Untrusted client a7b1cf7e-6dae-4f71-9717-143ee3afa1ea attempted to access /arf/2. Check :trusted_hosts: in settings.yml
Upload failed: 403 "Forbidden "

Either the verification with trusted hosts needs to ignore the endpoints for client or we could move the endpoints for a client into a separate file.

@lzap
Copy link
Member Author

lzap commented Apr 14, 2021

isn't this effectlively allowing all of the endpoints

Yes, I was hoping that @xprazak2 can guide me on which endpoints need to be authorized like that.

Is there some key I can use? Perhaps I can lookup all calls that OpenSCAP plugin does and add trusted hosts:

https://github.com/theforeman/foreman_openscap/tree/master/app/lib/proxy_api

I hope there are no endpoints shared by both clients and Foreman.

@lzap
Copy link
Member Author

lzap commented Apr 14, 2021

After spending some time, I think that client nodes only use post "/arf/:policy". Then I could split the classes, amended the change.

I am unable to run tests locally for some reason, a weird error appears and I am not sure what rake is trying to tell me:

$ be rake test
/home/lzap/.rbenv/versions/2.7.2/bin/ruby -w -I"lib:.:lib:test" -I"/home/lzap/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rake-12.1.0/lib" "/home/lzap/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rake-12.1.0/lib/rake/rake_test_loader.rb" "test/fetch_scap_api_test.rb" "test/fetch_tailoring_api_test.rb" "test/get_report_xml_html_test.rb" "test/post_report_api_test.rb" "test/scap_content_parser_api_test.rb" "test/script_class_test.rb" "test/spool_forwarder_test.rb"
/home/lzap/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/test-unit-3.2.6/lib/test/unit/attribute.rb:203: warning: Capturing the given block using Proc.new is deprecated; use `&block` instead
/home/lzap/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/test-unit-3.2.6/lib/test/unit/attribute.rb:203: warning: Capturing the given block using Proc.new is deprecated; use `&block` instead
/home/lzap/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/test-unit-3.2.6/lib/test/unit/attribute.rb:203: warning: Capturing the given block using Proc.new is deprecated; use `&block` instead
/home/lzap/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/test-unit-3.2.6/lib/test/unit/attribute.rb:203: warning: Capturing the given block using Proc.new is deprecated; use `&block` instead
/home/lzap/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/test-unit-3.2.6/lib/test/unit/autorunner.rb:36: warning: Capturing the given block using Proc.new is deprecated; use `&block` instead
/home/lzap/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/test-unit-3.2.6/lib/test/unit/autorunner.rb:36: warning: Capturing the given block using Proc.new is deprecated; use `&block` instead
/home/lzap/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/test-unit-3.2.6/lib/test/unit/autorunner.rb:36: warning: Capturing the given block using Proc.new is deprecated; use `&block` instead
/home/lzap/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/test-unit-3.2.6/lib/test/unit/autorunner.rb:36: warning: Capturing the given block using Proc.new is deprecated; use `&block` instead
/home/lzap/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/test-unit-3.2.6/lib/test/unit/autorunner.rb:18: warning: Capturing the given block using Proc.new is deprecated; use `&block` instead
/home/lzap/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/test-unit-3.2.6/lib/test/unit/autorunner.rb:49: warning: Capturing the given block using Proc.new is deprecated; use `&block` instead
/home/lzap/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/test-unit-3.2.6/lib/test/unit/autorunner.rb:18: warning: Capturing the given block using Proc.new is deprecated; use `&block` instead
/home/lzap/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/test-unit-3.2.6/lib/test/unit/autorunner.rb:18: warning: Capturing the given block using Proc.new is deprecated; use `&block` instead
/home/lzap/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/test-unit-3.2.6/lib/test/unit/autorunner.rb:49: warning: Capturing the given block using Proc.new is deprecated; use `&block` instead
/home/lzap/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/addressable-2.5.2/lib/addressable/idna/pure.rb:154: warning: assigned but unused variable - startercc
/home/lzap/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/webmock-3.0.1/lib/webmock/util/json.rb:27: warning: assigned but unused variable - pos
/home/lzap/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/hashdiff-0.3.6/lib/hashdiff/lcs.rb:25: warning: `elsif' at the end of line without an expression
/home/lzap/work/smart_proxy_openscap/lib/smart_proxy_openscap/fetch_file.rb:56: warning: method redefined; discarding old clean_store_folder
/home/lzap/work/smart_proxy_openscap/lib/smart_proxy_openscap/fetch_file.rb:23: warning: previous definition of clean_store_folder was here
/home/lzap/work/smart_proxy_openscap/lib/smart_proxy_openscap/content_parser.rb:18: warning: assigned but unused variable - e
/home/lzap/work/smart_proxy_openscap/lib/smart_proxy_openscap/profiles_parser.rb:25: warning: assigned but unused variable - result

File does not exist:

rake aborted!
Command failed with status (1): [ruby -w -I"lib:.:lib:test" -I"/home/lzap/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rake-12.1.0/lib" "/home/lzap/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rake-12.1.0/lib/rake/rake_test_loader.rb" "test/fetch_scap_api_test.rb" "test/fetch_tailoring_api_test.rb" "test/get_report_xml_html_test.rb" "test/post_report_api_test.rb" "test/scap_content_parser_api_test.rb" "test/script_class_test.rb" "test/spool_forwarder_test.rb" ]
/home/lzap/.rbenv/versions/2.7.2/bin/bundle:23:in `load'
/home/lzap/.rbenv/versions/2.7.2/bin/bundle:23:in `<main>'
Tasks: TOP => test
(See full trace by running task with --trace)

@lzap lzap force-pushed the cve-trusted-hosts-32257 branch 2 times, most recently from d9063d0 to 00db9e3 Compare April 14, 2021 12:38
@lzap
Copy link
Member Author

lzap commented Apr 14, 2021

Its very unfortunate but Rack does not allow mapping via regular expression and since /arg path three is used both for Foreman and clients, so I actually need to create a bit ugly before block with a regular expression. Amended.

@@ -25,6 +25,13 @@ class Api < ::Sinatra::Base
include ::Proxy::Log
helpers ::Proxy::Helpers
authorize_with_ssl_client
CLIENT_PATHS = Rexexp.compile(%r{/arf/\d+})
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it be Regexp?

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 cannot get tests running locally :-(

Copy link
Contributor

Choose a reason for hiding this comment

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

I had:

rake test
/usr/local/rvm/rubies/ruby-2.7.2/bin/ruby -w -I"lib:.:lib:test" /usr/local/rvm/gems/ruby-2.7.2/gems/rake-13.0.3/lib/rake/rake_test_loader.rb "test/fetch_scap_api_test.rb" "test/fetch_tailoring_api_test.rb" "test/get_report_xml_html_test.rb" "test/post_report_api_test.rb" "test/scap_content_parser_api_test.rb" "test/script_class_test.rb" "test/spool_forwarder_test.rb" 
/root/smart_proxy_openscap/lib/smart_proxy_openscap/fetch_file.rb:56: warning: method redefined; discarding old clean_store_folder
/root/smart_proxy_openscap/lib/smart_proxy_openscap/fetch_file.rb:23: warning: previous definition of clean_store_folder was here
/root/smart_proxy_openscap/lib/smart_proxy_openscap/content_parser.rb:18: warning: assigned but unused variable - e
/root/smart_proxy_openscap/lib/smart_proxy_openscap/profiles_parser.rb:25: warning: assigned but unused variable - result
Traceback (most recent call last):
	14: from /usr/local/rvm/gems/ruby-2.7.2/gems/rake-13.0.3/lib/rake/rake_test_loader.rb:5:in `<main>'
	13: from /usr/local/rvm/gems/ruby-2.7.2/gems/rake-13.0.3/lib/rake/rake_test_loader.rb:5:in `select'
	12: from /usr/local/rvm/gems/ruby-2.7.2/gems/rake-13.0.3/lib/rake/rake_test_loader.rb:17:in `block in <main>'
	11: from /usr/local/rvm/gems/ruby-2.7.2/gems/rake-13.0.3/lib/rake/rake_test_loader.rb:17:in `require'
	10: from /root/smart_proxy_openscap/test/script_class_test.rb:2:in `<top (required)>'
	 9: from /root/smart_proxy_openscap/test/script_class_test.rb:2:in `require'
	 8: from /root/smart_proxy_openscap/lib/smart_proxy_openscap/arf_html.rb:1:in `<top (required)>'
	 7: from /root/smart_proxy_openscap/lib/smart_proxy_openscap/arf_html.rb:1:in `require'
	 6: from /usr/local/rvm/gems/ruby-2.7.2/gems/openscap-0.4.9/lib/openscap.rb:3:in `<top (required)>'
	 5: from /usr/local/rvm/gems/ruby-2.7.2/gems/openscap-0.4.9/lib/openscap.rb:3:in `require'
	 4: from /usr/local/rvm/gems/ruby-2.7.2/gems/openscap-0.4.9/lib/openscap/openscap.rb:5:in `<top (required)>'
	 3: from /usr/local/rvm/gems/ruby-2.7.2/gems/openscap-0.4.9/lib/openscap/openscap.rb:7:in `<module:OpenSCAP>'
	 2: from /usr/local/rvm/gems/ruby-2.7.2/gems/ffi-1.15.0/lib/ffi/library.rb:99:in `ffi_lib'
	 1: from /usr/local/rvm/gems/ruby-2.7.2/gems/ffi-1.15.0/lib/ffi/library.rb:99:in `map'
/usr/local/rvm/gems/ruby-2.7.2/gems/ffi-1.15.0/lib/ffi/library.rb:145:in `block in ffi_lib': Could not open library 'libopenscap.so.8': libopenscap.so.8: cannot open shared object file: No such file or directory. (LoadError)
Could not open library 'libopenscap.so.25': libopenscap.so.25: cannot open shared object file: No such file or directory.
Could not open library 'openscap': openscap: cannot open shared object file: No such file or directory.
Could not open library 'libopenscap.so': libopenscap.so: cannot open shared object file: No such file or directory
rake aborted!
Command failed with status (1): [ruby -w -I"lib:.:lib:test" /usr/local/rvm/gems/ruby-2.7.2/gems/rake-13.0.3/lib/rake/rake_test_loader.rb "test/fetch_scap_api_test.rb" "test/fetch_tailoring_api_test.rb" "test/get_report_xml_html_test.rb" "test/post_report_api_test.rb" "test/scap_content_parser_api_test.rb" "test/script_class_test.rb" "test/spool_forwarder_test.rb" ]
/usr/local/rvm/gems/ruby-2.7.2/gems/rake-13.0.3/exe/rake:27:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.7.2/bin/ruby_executable_hooks:24:in `eval'
/usr/local/rvm/gems/ruby-2.7.2/bin/ruby_executable_hooks:24:in `<main>'
Tasks: TOP => test
(See full trace by running task with --trace)

yum install openscap helped.

@xprazak2
Copy link
Contributor

Additional endpoints that client needs to access are the ones for downloading content file and tailoring file.

@xprazak2 xprazak2 merged commit a36f687 into theforeman:master Apr 19, 2021
@xprazak2
Copy link
Contributor

Thanks!

@lzap lzap deleted the cve-trusted-hosts-32257 branch April 23, 2021 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants