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

Allow overriding passwords generated by extlib #409

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

coreone
Copy link
Contributor

@coreone coreone commented Jun 8, 2023

No description provided.

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.

Apologies for missing this completely while I was on vacation, but I do like this change.

manifests/candlepin.pp Outdated Show resolved Hide resolved
@@ -73,6 +75,7 @@
Boolean $generate = true,
Boolean $regenerate = false,
Boolean $deploy = true,
String[1] $ca_key_password = $certs::params::ca_key_password,
Copy link
Member

Choose a reason for hiding this comment

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

What's the reason for moving this parameter to another line?

I also like the data type, but should we enforce at least X characters? for NSS we use 10 and I think that's a good number.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This wasn't a parameter before. The other line in the diff was where it was defined inside the class. I also increased the string size to 10 per your suggestion.

# Generate and cache the password on the master once
# In multi-puppetmaster setups, the user should specify their own
$ca_key_password = extlib::cache_data('foreman_cache_data', 'ca_key_password', extlib::random_password(24))
$nss_db_password = extlib::cache_data('foreman_cache_data', 'certs-nss-db-password', extlib::random_password(32))
Copy link
Member

Choose a reason for hiding this comment

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

What's the reason to move the NSS DB pass to params.pp? Looks like we can continue using it in certs::ssltools:nssdb. You do need to set it via Hiera, but you don't introduce it as a top level parameter anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was just following a pattern. Most of the other modules I looked at had this kind of thing done in params.pp, so I just did it there as well. I can move it out to the class itself if that makes more sense.

Copy link
Member

Choose a reason for hiding this comment

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

Ideally we would get rid of params.pp. In our installer we use Kafo, which can't deal with function calls in parameters (default parsing breaks). Now I do see that ca_key_password already was doing that in init.pp so now I wonder if that was broken all along.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I missed something in my review: it's in the body now, not the actual class parameter. That's why it's not a problem today.

@coreone coreone force-pushed the passwords branch 2 times, most recently from be4f369 to 7b4234a Compare August 11, 2023 14:25
@coreone
Copy link
Contributor Author

coreone commented Sep 5, 2023

@ekohl anything else needed on this?

# Generate and cache the password on the master once
# In multi-puppetmaster setups, the user should specify their own
$final_keystore_password = pick(
$keystore_password, extlib::cache_data('foreman_cache_data', $keystore_password_file, extlib::random_password(32))
Copy link
Member

Choose a reason for hiding this comment

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

This may be a slight nuance, but in this case I do think the data is generated and cached, even if unused. Would it make sense to use a more traditional approach with if/else here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed these 2 lines into if/else blocks

@@ -73,6 +75,7 @@
Boolean $generate = true,
Boolean $regenerate = false,
Boolean $deploy = true,
String[10] $ca_key_password = $certs::params::ca_key_password,
Copy link
Member

Choose a reason for hiding this comment

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

Can you keep it on the line where it used to be? So between ca_cert_stripped and ca_key_password_file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is new because ca_key_password was not in the parameters for the class previously.

Copy link
Member

Choose a reason for hiding this comment

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

I'm debating having a default or not. Having it means it ends up in our installer's answer files. Not sure if that's a benefit or a downside. @ehelms?

I also wonder what happens if you change the password parameter. I fear it would break since there's no support to change the password.

Copy link
Member

Choose a reason for hiding this comment

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

I'm a bit confused. I do not like having it as a default and showing up in the answers file. This currently already has a default coming from params.pp?

Copy link
Member

Choose a reason for hiding this comment

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

The diff in GH isn't clear (I also failed at that at first). Right now it's in the body of the class. This PR moves it to a class parameter (with indirection via params since Kafo can't deal with calling functions as defaults).

Copy link
Member

Choose a reason for hiding this comment

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

@ehelms can we revisit this? I still think this is a good direction.

I'm still leaning to undef and also support Sensitive. So Variant[Undef, Sensitive[String[10]], String[10]]] $ca_key_password = undef (or Optional[Variant[Sensitive[String[10]], String[10]]] which is equivalent).

Copy link
Member

Choose a reason for hiding this comment

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

If I understand correctly, for an existing setup, if a new ca_key_password is provided this will force a new key to be generated, which forces a new CA to be generated which cascades and forces all smart-proxy / Capsules and clients to need to be updated.

Will the code properly handle that? I think we need a test for it. How do we help users not break their installations accidentally?

Copy link
Member

Choose a reason for hiding this comment

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

One data point that just came up today: if puppet-agent is removed then the cache is wiped. If the ssl-build directory isn't wiped, then there's a mismatch. If we have the value as an explicit parameter, the value is stored in the answer file and there wouldn't be an issue. So an argument against undef as default and in favor of the current code.

@coreone coreone force-pushed the passwords branch 3 times, most recently from d1e4700 to 7a7de26 Compare September 23, 2023 12:04
@ekohl
Copy link
Member

ekohl commented Sep 28, 2023

I did some testing: if you change the password for either the keystore or the truststore it fails to open it:

Error 1: Puppet Truststore_certificate resource '/etc/candlepin/certs/truststore:artemis-client' failed. Logs:
  /Stage[main]/Certs::Candlepin/Truststore_certificate[/etc/candlepin/certs/truststore:artemis-client]
    Adding autorequire relationship with File[/etc/pki/katello/truststore_password-file]
    Adding autorequire relationship with File[/etc/foreman/client_cert.pem]
    Adding autonotify relationship with File[/etc/candlepin/certs/truststore]
    Starting to evaluate the resource (581 of 1413)
    Evaluated in 0.46 seconds
  /Stage[main]/Certs::Candlepin/Truststore_certificate[/etc/candlepin/certs/truststore:artemis-client]/ensure
    change from 'absent' to 'present' failed: Execution of '/bin/keytool -import -v -noprompt -storetype pkcs12 -keystore /etc/candlepin/certs/truststore -alias artemis-client -file /etc/foreman/client_cert.pem -storepass:file /etc/pki/katello/truststore_password-file -J-Dcom.redhat.fips=false' returned 1: keytool error: java.io.IOException: keystore password was incorrect
java.io.IOException: keystore password was incorrect
	at sun.security.pkcs12.PKCS12KeyStore.engineLoad(PKCS12KeyStore.java:2089)
	at java.security.KeyStore.load(KeyStore.java:1445)
	at sun.security.tools.keytool.Main.doCommands(Main.java:839)
	at sun.security.tools.keytool.Main.run(Main.java:380)
	at sun.security.tools.keytool.Main.main(Main.java:373)
Caused by: java.security.UnrecoverableKeyException: failed to decrypt safe contents entry: javax.crypto.BadPaddingException: Given final block not properly padded. Such issues can arise if a bad key is used during decryption.
	... 5 more
Error 2: Puppet Truststore_certificate resource '/etc/candlepin/certs/truststore:candlepin-ca' failed. Logs:
  /Stage[main]/Certs::Candlepin/Truststore_certificate[/etc/candlepin/certs/truststore:candlepin-ca]
    Adding autorequire relationship with File[/etc/pki/katello/truststore_password-file]
    Adding autorequire relationship with File[/etc/candlepin/certs/candlepin-ca.crt]
    Adding autonotify relationship with File[/etc/candlepin/certs/truststore]
    Starting to evaluate the resource (602 of 1413)
    Evaluated in 0.36 seconds
  /Stage[main]/Certs::Candlepin/Truststore_certificate[/etc/candlepin/certs/truststore:candlepin-ca]/ensure
    change from 'absent' to 'present' failed: Execution of '/bin/keytool -import -v -noprompt -storetype pkcs12 -keystore /etc/candlepin/certs/truststore -alias candlepin-ca -file /etc/candlepin/certs/candlepin-ca.crt -storepass:file /etc/pki/katello/truststore_password-file -J-Dcom.redhat.fips=false' returned 1: keytool error: java.io.IOException: keystore password was incorrect
java.io.IOException: keystore password was incorrect
	at sun.security.pkcs12.PKCS12KeyStore.engineLoad(PKCS12KeyStore.java:2089)
	at java.security.KeyStore.load(KeyStore.java:1445)
	at sun.security.tools.keytool.Main.doCommands(Main.java:839)
	at sun.security.tools.keytool.Main.run(Main.java:380)
	at sun.security.tools.keytool.Main.main(Main.java:373)
Caused by: java.security.UnrecoverableKeyException: failed to decrypt safe contents entry: javax.crypto.BadPaddingException: Given final block not properly padded. Such issues can arise if a bad key is used during decryption.
	... 5 more

You can delete the file and it will be recreated, but rotating passwords is not supported. I'm not sure what's the best solution to prevent users from this footgun.

@ehelms any thoughts on changing the keystore & truststore types to catch the password error and recreate the file?

@ehelms
Copy link
Member

ehelms commented Sep 28, 2023

@ehelms any thoughts on changing the keystore & truststore types to catch the password error and recreate the file?

Possible to add I should think -- if password change is detected we need to trigger a delete of the truststore and then let it re-build itself.

@ekohl
Copy link
Member

ekohl commented Sep 28, 2023

I've opened #428 but it doesn't work yet. I'll continue on it tomorrow.

@coreone
Copy link
Contributor Author

coreone commented Dec 20, 2023

@ekohl circling back around to this after I see that the #428 has been merged.

@ehelms
Copy link
Member

ehelms commented May 15, 2024

I think this needs at least two acceptance tests added:

  1. Providing a password on fresh run
  2. Changing the password for an existing setup

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