Certmanager Configuration for Deep Thought
I’m working from the official docs for cert-manager
Installing
Here’s the basic install from the web site:
# Install the CustomResourceDefinition resources separately
kubectl apply --validate=false -f https://raw.githubusercontent.com/jetstack/cert-manager/release-0.11/deploy/manifests/00-crds.yaml
# Create the namespace for cert-manager
kubectl create namespace cert-manager
# Add the Jetstack Helm repository
helm repo add jetstack https://charts.jetstack.io
# Update your local Helm chart repository cache
helm repo update
# Install the cert-manager Helm chart
helm upgrade \
--install cert-manager \
--namespace cert-manager \
--version v0.12.0 \
jetstack/cert-manager
Looks good:
denebeim@frankiemouse:~/kubernetes$ kubectl get pods --namespace cert-manager
NAME READY STATUS RESTARTS AGE
cert-manager-55fff7f85f-r8q4s 1/1 Running 0 3m27s
cert-manager-cainjector-54c4796c5d-85cq9 1/1 Running 0 3m27s
cert-manager-webhook-77ccf5c8b4-m2v99 1/1 Running 1 3m27s
And let’s try a basic self signed cert:
# Create a ClusterIssuer to test the webhook works okay
cat <<EOF > test-resources.yaml
apiVersion: v1
kind: Namespace
metadata:
name: cert-manager-test
---
apiVersion: cert-manager.io/v1alpha2
kind: Issuer
metadata:
name: test-selfsigned
namespace: cert-manager-test
spec:
selfSigned: {}
---
apiVersion: cert-manager.io/v1alpha2
kind: Certificate
metadata:
name: selfsigned-cert
namespace: cert-manager-test
spec:
commonName: example.com
secretName: selfsigned-cert-tls
issuerRef:
name: test-selfsigned
EOF
# Create the test resources
kubectl apply -f test-resources.yaml
# Check the status of the newly created certificate
# You may need to wait a few seconds before cert-manager processes the
# certificate request
kubectl describe certificate -n cert-manager-test
...
Spec:
Common Name: example.com
Issuer Ref:
Name: test-selfsigned
Secret Name: selfsigned-cert-tls
Status:
Conditions:
Last Transition Time: 2019-01-29T17:34:30Z
Message: Certificate is up to date and has not expired
Reason: Ready
Status: True
Type: Ready
Not After: 2019-04-29T17:34:29Z
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal CertIssued 4s cert-manager Certificate issued successfully
# Clean up the test resources
kubectl delete -f test-resources.yaml
I love it when things just work.
Configuring for Deepthot
I’m wanting to set this up to generate let’s encrypt for deepthot.org domains and it’s own CA for deepthot.aa domains. Since I don’t have a hole through the firewall to the internet yet for http we’ll do the local CA first
deepthot.aa CA signed certs
First step is to create a CA pair.
ssh over to the ipa server and retrieve the ipa server’s signing keys.
sudo grep "internal=" /var/lib/pki/pki-tomcat/conf/password.conf | awk -F= '{print $2}' >pass.txtsudo pki-server ca-clone-prepare --pkcs12-file ca-certs.p12 --pkcs12-password-file pass.txtpki pkcs12-cert-find --pkcs12-file ca-certs.p12 --pkcs12-password-file pass.txtopenssl pkcs12 -in ca-certs.p12 -out keys.txt -password file:pass.txtopenssl rsa -in ca-enc.key -out ca.key -passin file:pass.txt
This is not quite right sadly. As far as I can tell you still can’t get the key trivially. You can get the cert after step 3 by typing sudo pki pkcs12-cert-export "caSigningCert cert-pki-ca" --pkcs12-file ca-certs.p12 --pkcs12-password $(cat pass.txt) --cert-file ca.crt But I haven’t found a key that way. Instead you have to edit the keys.txt file from step 4 and find the CA cert and key. Save those in ca.crt and ca-enc.key respectively. Finally you use step 5 to decode the key.
About that step 4, it will ask you for a password for each key twice. I just catted out pass.txt and pasted it in over, and over, and…
Once you have the ca crt and key you need to import that into the key that cert manager wants. Switch from the ipa machine back to something with kubectl installed and:
kubectl create secret tls ca-key-pair --cert=ca.crt --key=ca.key --namespace=cert-manager
Creating an ingress controller. This is an issuer:
apiVersion: cert-manager.io/v1alpha2
kind: ClusterIssuer
metadata:
name: ca-issuer
spec:
ca:
secretName: ca-key-pair
Which you apply with kubectl apply -f ca-issuer.yaml
To use it you need to specify cert-manager.io/cluster-issuer : "ca-issuer" in your ingress definition, like this:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: kuard
annotations:
kubernetes.io/ingress.class: "nginx"
cert-manager.io/cluster-issuer : "ca-issuer"
spec:
tls:
- hosts:
- example.deepthot.aa
secretName: quickstart-example-tls
rules:
- host: example.deepthot.aa
http:
paths:
- path: /
backend:
serviceName: kuard
servicePort: 80
lets encrypt
First step is to open ports to the ingress box. ssh into the router and type the following commands. If it acts funky type ‘^V’ to disable the autocomplete.
/ip firewall nat add chain=dstnat action=dst-nat to-addresses=192.168.42.64 to-ports=80 protocol=tcp dst-address=174.70.12.249 in-interface=wan dst-port=80
/ip firewall nat add chain=dstnat action=dst-nat to-addresses=192.168.42.64 to-ports=443 protocol=tcp dst-address=174.70.12.249 in-interface=wan dst-port=443
So… my gitlab fucked up the repository. I can’t delete it either. Very annoying. Not sure what to do about it. Well, onward. Setting up let’s encrypt.
OK, here’s the deal, the problem, and it is an old friend, is that trying to route to my external IP doesn’t really work. I’ve always had issues with this, it has to do with the kernel being unable to send a modified packet back to the same interface it came in on. Or something like that. Regardless, the easiest way to fix that is, since I own my dns server, make it authoritative for deepthot.org and give deepthot.org the address of where my ingress is.
ipa dnszone-add --skip-overlap-check deepthot.org
ipa dnsrecord-add --a-ip-address=192.168.42.64 deepthot.org @
sudo systemd-resolve --flush-caches
That last bit was for good measure.
We’ve defined two let’s encrypt cert managers, one for staging and another for production. There’s two servers out there, the production one is very limited bandwidth wise, you can only do like 5 a week for a given address, if you exceed that you’re screwed. So when you’re trying to debug it you very much want to use the staging one.
First the staging:
apiVersion: cert-manager.io/v1alpha2
kind: Issuer
metadata:
name: letsencrypt-staging
spec:
acme:
# The ACME server URL
server: https://acme-staging-v02.api.letsencrypt.org/directory
# Email address used for ACME registration
email: denebeim@gmail.com
# Name of a secret used to store the ACME account private key
privateKeySecretRef:
name: letsencrypt-staging
# Enable the HTTP-01 challenge provider
solvers:
- http01:
ingress:
class: nginx
And now the production:
apiVersion: cert-manager.io/v1alpha2
kind: Issuer
metadata:
name: letsencrypt-prod
spec:
acme:
# The ACME server URL
server: https://acme-v02.api.letsencrypt.org/directory
# Email address used for ACME registration
email: denebeim@gmail.com
# Name of a secret used to store the ACME account private key
privateKeySecretRef:
name: letsencrypt-prod
# Enable the HTTP-01 challenge provider
solvers:
- http01:
ingress:
class: nginx
No comments:
Post a Comment