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 #31049 - Introduce server CA file setting #8076

Conversation

kamils-iRonin
Copy link
Member

No description provided.

@theforeman-bot
Copy link
Member

Issues: #31049

@ezr-ondrej
Copy link
Member

Do we have installer PR for this?

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

I'm concerned that this would break registration via Smart Proxies. Should we introduce a different macro for that?

lib/foreman/renderer/scope/macros/base.rb Outdated Show resolved Hide resolved
lib/foreman/renderer/scope/macros/base.rb Outdated Show resolved Hide resolved
@ares
Copy link
Member

ares commented Oct 23, 2020

I think @ekohl is right about breaking the through proxy registration. However with this new setting, the macro should load certificates from both files. That way, we'd make sure the user can use whatever method if they deploy certificates provided by this macro.

The other option is to go with what is proposed here and introduce a second macro to provide the same for proxies and then pick whichever is needed in the template. However the added value of this imho doesn't outbalance the effort. I'd lean towards the existing macro providing certs from both files.

@ekohl
Copy link
Member

ekohl commented Oct 26, 2020

Not needed here, but I also thought about introducing something like /ca-bundle.pem as a route. It would return a bundle to connect to Foreman and the Smart Proxies. This does feel like a good place to suggest it. Thoughts on it are welcome :)

@ares
Copy link
Member

ares commented Oct 26, 2020

introducing something like /ca-bundle.pem

should it be served by the application or rather just apache from /public? Anyway that's not in scope for this PR. Next steps I think are

  1. do we need an installer change for this and if so, is there already some PR for that?
  2. the foreman_server_ca_cert should load content from both settings now, to avoid breaking through proxy registration

@kamils-iRonin please let me know if there are any questions from your side, thanks!

@kamils-iRonin
Copy link
Member Author

2. the foreman_server_ca_cert should load content from both settings now, to avoid breaking through proxy registration

@ares @ekohl we could introduce server_ca_file_enabled and ssl_ca_file_enabled flags (which are true by default), so that you can load exactly the file you want, something like:

def foreman_server_ca_cert(server_ca_file_enabled: true, ssl_ca_file_enabled: true)
  if server_ca_file_enabled && File.exist?(Setting[:server_ca_file])
    File.read(Setting[:server_ca_file])
  elsif ssl_ca_file_enabled && File.exist?(Setting[:ssl_ca_file])
    File.read(Setting[:ssl_ca_file])
  else
    msg = N_("SSL CA file not found, check the 'Server CA file' in Settings > Authentication")
    raise Foreman::Exception.new(msg)
  end
end

@ekohl
Copy link
Member

ekohl commented Oct 27, 2020

From the signature I would expect it concat both when both are true but the implementation only returns one. I think curl is happy to have both CA bundles together and use whatever validates it.

@kamils-iRonin kamils-iRonin force-pushed the 31049-Add-more-reliable-way-to-detect-Foreman-CA-certificate branch 2 times, most recently from c2286ea to c767580 Compare October 29, 2020 16:13
Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

Mostly some readability suggestions. Overall I think it looks good but let me know if you want to apply the suggestions.

lib/foreman/renderer/scope/macros/base.rb Outdated Show resolved Hide resolved
lib/foreman/renderer/scope/macros/base.rb Outdated Show resolved Hide resolved
@kamils-iRonin kamils-iRonin force-pushed the 31049-Add-more-reliable-way-to-detect-Foreman-CA-certificate branch from c767580 to 82673da Compare November 24, 2020 09:30
ekohl
ekohl previously approved these changes Nov 24, 2020
Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

LGTM. @ares want to have a look at latest iteration?

ares
ares previously requested changes Dec 9, 2020
Copy link
Member

@ares ares left a comment

Choose a reason for hiding this comment

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

I'm sorry it took me a while to get back to this. I have one little ask about error handling, otherwise I tested and it works well indeed. Ready to merge after that comments is resolved.

setting_values << Setting[:ssl_ca_file] if ssl_ca_file_enabled
files_content = setting_values.compact.map do |setting_value|
File.read(setting_value)
rescue Errno::ENOENT, Errno::EACCES
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 rescue the File.read for more exceptions, if I specify wrong path (e.g. a directory) it's not catched by this.
I'd recommend wrapping the File.read in begin end block and just rescue instead of trying to list all Errno::* here. Also I'd say we should log something in case of such error, currently we silently ignore this and admin has no way to find out the set file is not accessible. This would deserve a warning in a log I think.

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 added logger and rescue from StandardError

@ares
Copy link
Member

ares commented Dec 9, 2020

Also reiterating a question around the installer PR that ondrej asked. This settings work out of the box so it's not strictly necessary, but I wonder if we should preconfigure this setting from the installer and if someone started working on that already or we need to look into it.

@laugmanuel
Copy link
Member

Also reiterating a question around the installer PR that ondrej asked. This settings work out of the box so it's not strictly necessary, but I wonder if we should preconfigure this setting from the installer and if someone started working on that already or we need to look into it.

I've opened a first draft here: theforeman/puppet-foreman#910
@ares / @ezr-ondrej, let me know if this is what you were asking about. I'm open for comments or other ideas.

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

Small nits, otherwise it looks OK to me.

test/fixtures/settings.yml Outdated Show resolved Hide resolved
@kamils-iRonin kamils-iRonin force-pushed the 31049-Add-more-reliable-way-to-detect-Foreman-CA-certificate branch 2 times, most recently from 1a5f6a5 to 614efad Compare February 9, 2021 15:52
@ares
Copy link
Member

ares commented Mar 24, 2021

my appologies, this now requires a rebase, I think the installer PR is ready so this can get in once rebased

@kamils-iRonin kamils-iRonin force-pushed the 31049-Add-more-reliable-way-to-detect-Foreman-CA-certificate branch from 614efad to 7f1e777 Compare April 12, 2021 22:13
@kamils-iRonin kamils-iRonin force-pushed the 31049-Add-more-reliable-way-to-detect-Foreman-CA-certificate branch from 7f1e777 to de46ba0 Compare April 12, 2021 22:19
Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

CI fails with:

NameError: undefined local variable or method `error' for #<Class:0x000000000e8e98e8>
/home/jenkins/workspace/test_develop_pr_core/database/postgresql/ruby/2.5/slave/fast/test/unit/foreman/renderer/renderers_shared_tests.rb:274:in `block (2 levels) in <module:RenderersSharedTests>'

I'm not sure if it's related, but would you mind taking a look?

@ezr-ondrej
Copy link
Member

[test foreman][test upgrade]

Copy link
Member

@ezr-ondrej ezr-ondrej left a comment

Choose a reason for hiding this comment

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

Just trying to push this forward, I think I found the cause of test failures.

Setting[:server_ca_file] = cert_path
Setting[:ssl_ca_file] = 'not-existing-file'

assert_raise Foreman::Exception do
Copy link
Member

Choose a reason for hiding this comment

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

This could be bit more specific by adding assertion for the message

Suggested change
assert_raise Foreman::Exception do
assert_raise Foreman::Exception, '<expected message>' do

assert_raise Foreman::Exception do
subject
end
end
end

assert_includes error.message, '[Foreman::Exception]: No such file or directory'
Copy link
Member

Choose a reason for hiding this comment

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

This seems to be quite forgotten and I belive that makes the tests to fail.

@kamils-iRonin kamils-iRonin force-pushed the 31049-Add-more-reliable-way-to-detect-Foreman-CA-certificate branch from de46ba0 to 0a023b8 Compare August 4, 2021 13:56
@ezr-ondrej
Copy link
Member

@ares tests seems to be 🍏 now ^_^

Copy link
Member

@ezr-ondrej ezr-ondrej left a comment

Choose a reason for hiding this comment

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

Works for me 👍 Thanks @kamils-iRonin

@ezr-ondrej ezr-ondrej merged commit 0d08d7a into theforeman:develop Aug 11, 2021
@ares
Copy link
Member

ares commented Aug 16, 2021

Thanks @kamils-iRonin and @ezr-ondrej for taking care of the merge.

@ekohl
Copy link
Member

ekohl commented Aug 17, 2021

Note to self: we can introduce some URL to expose this. It would replace Katello's http[s]://$HOSTNAME/pub/katello-server-ca.crt.

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.

6 participants