Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request juju#18294 from nvinuesa/juju-6344
juju#18294 Before this patch we weren't able to bootstrap on MAAS when configured for TLS with a self-signed certificate. We now add the posibility to take the `skip-tls-verify` cloud spec field into account and create an insecure TLS http client for the maas controller connection in that case. <!-- The PR title should match: <type>(optional <scope>): <description>. Please also ensure all commits in this PR comply with our conventional commits specification: https://docs.google.com/document/d/1SYUo9G7qZ_jdoVXpUVamS5VCgHmtZ0QA-wZxKoMS-C0 --> <!-- Why this change is needed and what it does. --> ## Checklist <!-- If an item is not applicable, use `~strikethrough~`. --> - [X] Code style: imports ordered, good names, simple structure, etc - [X] Comments saying why design decisions were made - [X] Go unit tests, with comments saying what you're testing - [ ] ~[Integration tests](https://github.com/juju/juju/tree/main/tests), with comments saying what you're testing~ - [ ] ~[doc.go](https://discourse.charmhub.io/t/readme-in-packages/451) added or updated in changed packages~ ## QA steps _Note: you should wait until maas downloads the ubuntu image before bootstrapping, otherwise it won't be able to create a machine._ The steps will include running a local MAAS inside multipass (follow https://maas.io/docs/maas-in-thirty-minutes), and enable TLS with a self signed certificate. Then creating a maas juju cloud with `skip-tls-verify: true`: ``` wget -qO- https://raw.githubusercontent.com/canonical/maas-multipass/main/maas.yml \n | multipass launch --name maas -c4 -m8GB -d32GB --cloud-init - # once the VM is up: multipass shell maas ``` the following steps are run inside the VM: ``` sudo bash -c 'cat <<EOF > ~/san.conf [req] default_bits = 2048 distinguished_name = req_distinguished_name req_extensions = req_ext x509_extensions = v3_req prompt = no [req_distinguished_name] countryName = XX stateOrProvinceName = N/A localityName = N/A organizationName = Self-signed certificate commonName = 120.0.0.1: Self-signed certificate [req_ext] subjectAltName = @alt_names [v3_req] subjectAltName = @alt_names [alt_names] IP.1 = 10.254.213.97 ``` _Note: make sure to replace the last IP with the IP of your maas VM (the first of the two IPs you see when `multipass ls`!_ Then create the cert and move it to `/var/snap/maas/common/cert` (it needs to be accessible to the maas snap): ``` openssl req -x509 -nodes -days 730 -newkey rsa:2048 -keyout key.pem -out cert.pem -config san.cnf sudo mkdir /var/snap/maas/common/cert sudo mv key.pem /var/snap/maas/common/cert sudo mv cert.pem /var/snap/maas/common/cert sudo chown root:root /var/snap/maas/common/cert/* ``` and now you can enable TLS with that cert: ``` sudo maas config-tls enable /var/snap/maas/common/cert/key.pem /var/snap/maas/common/cert/cert.pem ``` also retrieve the apikey needed for the juju credential: ``` sudo maas apikey --username admin euGNK3UyF7H247LdkY:p9nQaDe4xgxZRzXsRZ:rEqtjsjGHCSUWSXERm4qCXfXGrWuXEPx ``` Now you can quit the multipass shell and create the maas cloud for juju with this yaml: ``` maas-multipass: type: maas auth-types: [oauth1] endpoint: https://10.254.213.97:5443/MAAS skip-tls-verify: true ``` and the credential: ``` maas-multipass: foo: auth-type: oauth1 maas-oauth: euGNK3UyF7H247LdkY:p9nQaDe4xgxZRzXsRZ:rEqtjsjGHCSUWSXERm4qCXfXGrWuXEPx ``` Now you can bootstrap and no errors seen: ``` juju bootstrap maas-multipass --debug ``` If you remove the `skip-tls-verify: true` field from the cloud spec, then you should see the error: ``` ... creating MAAS environ: Get "https://10.254.213.97:5443/MAAS/api/2.0/version/": tls: failed to verify certificate: x509: certificate signed by unknown authority ``` ## Links **Launchpad bug:** https://bugs.launchpad.net/juju/+bug/2072653 **Jira card:** JUJU-6344
- Loading branch information