-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
Report bugs to unifi deploy hook #3359
Comments
just curious tho this might not be related purely to the unifi deploy hook (first time using acmesh, used certbot before) but i couldn't find something on that matter: does the cronjob that comes with acme is also deploying the certs? |
@blackjack4494 yes, acme.sh saves your deploy-hook settings, and re-deploys with those same settings after a successful cron certificate renewal. (This applies to all deploy hooks, not just unifi.) |
I'm just replacing an Ubuntu 16.04 VM running Unifi with a new VM running 22.04. When trying to use the unifi hook (which worked great on 16.04), I get
I can run
and see 1 existing certificate in the keystore (either providing no password or the default one in the script). I wonder if this relates to it as it mentions Ubuntu Jammy (which is v22) but I'm unsure if I can add the -legacy parameter in the script and if, so where. |
I realised the topkcs routine called in unifi.sh lives in the main acme.sh file, so I added -legacy to the first call in that (line 1427 on my system). That line now reads:
And the import now works. |
@SupersixEvo thanks for tracking this down. @Neilpang this affects |
@medmunds add one more parameter to the in the deploy hook, invoke it with value |
also, you should check if current openssl supports "-legacy" option first. |
Can confirm that this works, though my openssl does not accept -legacy directly? |
I had a problem with a CloudKey G2+. The deploy script seemed to think it was a Gen1, so deployment failed.
The script was looking for /etc/ssl/private/cloudkey.key to identify it as a G1, and that file did exist but was > 2 years old. I wonder if it used to use nginx before it upgraded itself to use Unifi OS. and then the deploy ran fine.
|
Just to add a +1 to robinalden's comment above. My CloudKey2 was upgraded from UnifiOS 1 --> 2.x --> 3.x and I had exactly the same issue with the deploy hook until I renamed /etc/ssl/private. Perhaps there is a better way to detect the OS version? |
from unifi-utilities case "$(ubnt-device-info firmware || true)" in |
Not strictly a deploy issue, but ECC certs borked unifi-core on my CloudKey Gen2 Plus running firmware v3.1.13. Blew away the ECC certs, reissued RSA certs, and redeployed to fix. |
There should be a status check var. You're assuming we're (FreeBSD) using systemd. The same for the other systectl usage. |
I found I had trouble deploying my certs on my UDR running Unifi OS (3.1.16). It seems I'd fall foul of this line as for some reason I had a keystore file at
From a bit of searching around it seems that the guest hotspot portal (which I have enabled) may use the I ended up hacking the deploy hook to avoid running the |
Trying this on a Unifi Express ... wish me luck! == will delete this comment if no issues No keytool (line 103) on Unifi Express. Wonder what they use? Asked in the community over there, see if I get a response. https://community.ui.com/questions/Keytool-alternative-on-UniFi-Express/5154559a-b064-4f41-a183-a106b9e690dc |
We need a check for keytool and if it does not exist use openssl. |
Running a Unifi Dream Machine with the same poblem. I'm not sure openssl can create a Java keystore. You'll notice that the java binaries are also removed. I got my response from Ubiquiti support yesterday, told me SSL isn't their problem. Hacky fix is just to reinstall keytool: apt update && apt install openjdk-11-jre-headless -y puts it in place with a few other packages that seem harmless enough. YMMV with support on that, and likely need to re-run after an update. openjdk-17 is newer, but loads a lot more packages. There's also a minor problem with the UDM running hotspot portal. I need to redeploy a few times to see what's going on, but I think the keystore shouldn't have the CA as well. Error in the log is that "2 certificates were found, only 1 expected." Manually creating the keystore fixes it. |
Once the keytool problem is sorted and the certificates correctly converted to a JKS keystore, the next problem is that the default Unifi console uses weak ciphers that aren't compatible with the default RSA certificates from letsencrypt. The system configuration needs to be updated for hotspot portal (and potentially other services to work.) |
I recently updated my CloudKey G2 to After getting the certs issued and running this hook, I could see /data/unifi-core/config/unifi-core.key and unifi-core.crt update at first, but when the unifi service restarted, both files were replaced with self-signed RSA certs. I noticed that the certs getting wiped out were ECC, which seemed new with this version of acme.sh. After fiddling with some different options, issuing with |
Openssl can create a java compatible keystore. If fact you should be using it instead of keytool these days for acme.sh. The instructions are here https://docs.oracle.com/cd/E19509-01/820-3503/ggfhb/index.html Modern java implementations are moving away from the old proprietry keystore format to the new pkcs12 format which is the type openssl can create. Example below. The alias should be the same as the one it uses now for the current certificate and key in the keystore. You cannot use this to update a keystore, only create it. Please note a password is mandatory for it to be a java compatible keystore. $ cat mykey.pem.txt mycertificate.pem.txt>mykeycertificate.pem.txt
$ openssl pkcs12 -export -in mykeycertificate.pem.txt -out mykeystore.pkcs12
-name myAlias -noiter -nomaciter |
It looks like you're correct. Every implementation of this Unifi certificate installation was converting to PKCS12 and then importing that to JKS. All the historical documents I could find from Unifi have that as the process as well. I just re-deployed, skipping the JKS import, and it handles the pkcs12 just fine. |
Fantastic! Does that mean we have solved the problem? That would be a great outcome! Can you send me links to the historical documents? I am itching to use this on my UX. Happy to drop in a patched unifi deploy hook to test for here then I can write it up. You guys have a wiki or a pages site for this place? |
Potentially. Tested on a UDM (not the UDM Pro), and don't have any other devices to test with. Welcome to take a look at my updates: Here's where I am with it: I also had to change the logic for service restart. If unifi is running while unifi-core restarts, it throws an error: This seems to break both wifiman and the hotspot portal, but I don't use wifiman. The hotspot portal now works, but you have to turn encryption off and back on after deploying a new cert for some reason. That's not a new bug though. |
Hey all: I no longer own a working CloudKey, so can't really provide support for the unifi deploy hook. (Also, I didn't create it—I just fixed a bug and opened this issue.) If something's broken and you're able to fix it, please open a PR. And mention #3359 in your PR comments so it shows up here. Neilpang (the acme.sh creator/maintainer) has been really responsive about merging fixes while maintaining high project quality. (Especially considering the huge number of PRs this project gets.) But Neil also doesn't run Unifi, so the folks here that are using it will need to make sure proposed fixes work for all the versions of CloudKey and self-hosted Unifi Controller the unifi deploy hook supports. If anyone is able to help with unifi deploy hook maintenance and wants to be on the "assignees" list for this issue, let Neilpang know. (I've removed myself as the assignee.) Also, if the unifi deploy hook doesn't meet your needs, there are a couple of alternatives depending on your setup:
|
Found a patch to unifi.sh tested on UnifiOS 4.0.7 on Cloud Gateway Ultra. Here it is. https://gist.github.com/mry/61125fba7b474c0c61cccc4100dd6e02 |
Kinda punted on this, moved @Dadeos concerns into DEPLOY environment variables. I did remove the explicit calls to systemctl. Probably safe to assume the service is running if the files/directories exist. I just don't have any way to test it outside my UDM. |
On UnifiOS 4.0.18 with a CloudKey Gen 2 the Unifi deploy hook fails with the following error:
Commenting out https://github.com/acmesh-official/acme.sh/blob/master/deploy/unifi.sh#L186-L189 and run
|
I’m getting this odd error on a Cloudkey gen1:
But the file exists
so I’m not sure what the problem is. |
Per the comment above that error it's doing a comparison to the keystore that's replaced. Since they're different, you get that error, which isn't really accurate. I don't have a cloudkey to test or check how things should be configure, but if I'm reading that comment right, then as a workaround you can create a symlink and try re-deploying:
(If you've changed your DEPLOY_UNIFI_KEYSTORE variable in the environment or script, you want the symlink pointing to that.) |
Thanks, that got around the error but the Unifi service refused to start. In the end I used —install-cert instead, with the —reloadcmd as:
|
That's basically the same command that the script runs to generate the keystore that you tried to link to. I'd just copy it into place if the symlink doesn't work, rather than generate a whole new one. Wouldn't surprise me if Ubiquiti stopped allowing symlinks or something though. |
I have a gen1 too.
Basically: yep. Your deploy-script (with default SAVED_DEPLOY_UNIFI_KEYSTORE='/usr/lib/unifi/data/keystore)
His script:
Status before using deploy-hook:
After deploy-hook
So the symbolic-link is moved away Next time starting deploy the compare fails. After putting |
Ok, so Gen1 Cloudkey still has keytool, which is good to know. It's probably not necessary to bother keeping the logic, since openssl pkcs12 works either way, but it currently seems to work.
Then I misread @medmunds comment, the symlink goes the other way.
I'd prefer to use symlinks to keep the filesystem clean, but just copying seems reliable. Since I don't have a Cloudkey to test, I'm not terribly comfortable doing a pull request, but I did update my own repository with an attempted fix if anyone wants to test it. It's pretty ham-fisted. Moves any existing /etc/ssl/private/unifi.keystore.jks out of the way and copies the store from DEPLOY_UNIFI_KEYSTORE. |
Hi all, I checked the keystore and the /data/unifi-core/config/ .crt & .key. UnifiOS ver is 4.1.9 and Network App is on 8.6.9. |
I've seen Unifi replace the SSL certs with the defaults if there's a problem with whatever is in place. Not always though, I think the unifi service breaks with a bad keystore while unifi-core is able to recover with the defaults. (Or maybe vice-versa). I never did find anything in the logs to prove it though. I don't have a cloudkey, but if you run in debug mode, you can post logs, might offer some clues. Also see above for my changes in my own repo. If you test that version successfully, I can do a pull request on it. |
I re-executed the deploy with --debug, here is the output:
|
I swapped the unifi.sh for the one in your repo and reran the command. |
There's your problem. Default LE certificates are ECC, unifi won't use them. Re-issue the certificate, using "-k 2048" and it'll pull a non-ecc cert. |
Interesting. I reissued a cert with the option you supplied, and then deployed again, this time it worked. Can we put a warning in this section (https://github.com/acmesh-official/acme.sh/wiki/deployhooks#23-deploy-the-cert-on-a-unifi-controller-or-cloud-key) to inform about this ECC issue? |
We stumbled upon file permission issues for the keystore. opnsense/plugins#4417 lists a possible solution by adding a chown to the RELOAD variable. A cleaner way would be to have env variables containing the desired owner and do the chown in the deploy script if run as root. Would you be open to this kind of addition? Then I would propose a PR with the required changes. |
Gen1 Appliance here (unifi os 4.1.9), updated to acme.sh v3.1.0 , cert renew didn't work first time to fix....
|
I've been running into trouble lately with this deploy script on my Cloud Key Gen2+ running Unifi OS 4.1.9, Network 8.6.9. The cert/key I'm trying to deploy are 2048-bit RSA. Output of
|
There's a potential fix for this in my fork, but since I don't have a Cloud Key, I can't test it, and I don't want to pull an untested fix upstream. You're welcome to give it a shot and I can pull request if it works. |
Your branch of the deploy script worked. There were some errors reported in the output:
But as you see, it ultimately reported success and the cert was deployed. |
This is exactly why I don't want to merge without testing. The original code tars the certificates. I'm not sure if it's for backup or because the cloudkey needs it. One of the variables wasn't referenced correctly. My fork should be fixed now, if anyone with a CloudKey wants to test it. |
Works for me with a Cloud Key gen 2!
|
Hi all, trying to get a cert on my self-hosted system running on Debian 12. Have tried everything in this thread, last resort was the generate the key (letsencrypt) using the -k 2048 option. My keystone is in the correct location for a standard install:
Have tried editing the unifi.sh to point at both, same result every time. Here is the debug output.... I'm out of ideas that this point, if someone can help, please. |
You are setting DEPLOY_UNIFI_KEYSTORE to an invalid location. It either doesn't exist, is not a file (a directory or maybe symlink?) or else you don't have permission to it. |
Thanks for the push in the right direction. I changed the permissions to 777 for the keystore and the directory and that did the trick. The reason I hesitated do that was the impression that the script did not want one to make all those changes. |
It assumes you're running the script as root, in which case the permissions shouldn't matter. 777 is bad, especially for something like a keystore. The file needs to be readable by whatever user the unifi services are running under, and writable by whatever user you're running acme.sh as. |
I tried rolling back (it's installed in a VM) and installing it as root yesterday. However there was another issue that I didn't write down when I ran the script to create the certificate. It works for now, I will adjust the permissions. Thanks again |
This is the place to report bugs in the unifi deploy hook.
If you experience a bug with
--deploy-hook unifi
, please report it in this issue. (Please include the--debug
output to assist in diagnosing any problems.)Thanks!
The text was updated successfully, but these errors were encountered: