Sign inSign up

zultron/freeipa-cloud-prov

By zultron

•Updated about 9 years ago

CoreOS and FreeIPA provisioning on DigitalOcean

Image
0

683

zultron/freeipa-cloud-prov repository overview

⁠FreeIPA in Kubernetes on CoreOS on DigitalOcean with Ansible

This project uses Ansible to automate bootstrapping a Kubernetes cluster around FreeIPA infrastructure, with cluster nodes running CoreOS Container Linux on DigitalOcean droplets. It also installs a number of basic containerized services, including email and web.

FreeIPA provides core services essential to clusters, such as DNS, user/host authentication/authorization, and SSL certificate authorities. A Kubernetes cluster built on this infrastructure orchestrates various containerized services, including FreeIPA itself, simplifying service management across the cluster. Kubernetes runs in CoreOS Container Linux, a minimal OS that might be seen as a cluster node appliance requiring minimal maintenance. And the OS runs on DigitalOcean droplets for inexpensive, automated provisioning on the cloud. Provisioning and configuration management is automated at all levels with Ansible, and a full cluster may be bootstrapped and running within an hour by issuing a few simple commands.

This project means to automate setup of a basic Internet site with self-hosted email, web and phone system. Service is redundant where possible to increase reliability. The components are chosen to scale up, but the down-scaled, three-node bootstrap configuration is complete, and meant to be ready for production.

⁠Current status

Although the goal is production readiness, this is unfinished and experimental work. It is not represented to be fit for any purpose. Readers are strongly advised to contemplate the risks before using this work in any critical scenario.

At present, the Ansible playbooks can complete the following tasks for a 3-node cluster with no manual intervention. The end result is a running Kubernetes cluster, still with a few minor known issues.

  • Provision DigitalOcean cloud servers
    • Configure CoreOS image with ignition
    • Add and configure block storage for filesystems and swap
    • Other basic OS configuration
  • Install FreeIPA cluster
    • Add and configure block storage for IPA data
    • Configure and run FreeIPA server install
    • Configure and run FreeIPA replica installs
    • Harden publicly exposed services
    • Basic DNS and other configuration
  • Configure Docker TLS
    • IPA: Create CA and install monitored service certificates
    • Configure Docker TLS port with client cert authentication
    • Create client cert
    • Restart docker service with TLS configuration
  • Configure and start etcd
    • IPA: Create CA and install monitored service certificates
    • Set up cluster DNS SRV records
    • Start etcd service with TLS and client cert authentication
    • Configure etcdctl client on nodes
  • Configure and start flannel networking
    • Configure etcd TLS endpoints and etcd network configuration
    • Start flanneld service
  • Configure and start kubernetes
    • IPA: Create CA and install monitored service certificates
    • Template kube-system pod manifests, kubelet service, kube configuration, etc. for API server and other nodes, with inter-node TLS and etcd TLS endpoints
    • Start kubelet service, wait for API availability, and check for pod creation
    • Install and configure kubectl client with TLS client certs
    • Install and configure the k8s dns and dashboard add-ons

⁠Installing the cluster

  • Initial site setup (only run once):

      # Copy `hosts.yaml` template and edit
      cp hosts.yaml.example hosts.yaml
      # You will certainly want to edit:
      # - domain_name and kerberos_realm
      # - network_prefix:  each host, first 2 octets MUST BE unique
      # You might want to edit:
      # - host names:  host1 etc.
      # - additional hosts:  minimum 3 hosts
      # - defaults:  size_id (default 1gb), region_id (nyc1)
      $EDITOR hosts.yaml
    
      # Optionally build container if not pulling from docker hub
      ./container -b
    
      # Start shell in container; the following `ansible-*` commands
      # should all be run in the container
      ./container
    
      # Set up password vault once; will prompt for FreeIPA admin
      # and directory passwords
      ansible-playbook playbooks/init-site.yaml
    
  • Install whole cluster in one command:

      ansible-playbook playbooks/site.yaml
    
  • Delete a node or the whole cluster

      # Destroy host1
      ansible-playbook playbooks/destroy.yaml -e confirm=host -l host1
    
      # Destroy whole cluster
      ansible-playbook playbooks/destroy.yaml -e confirm=all
    

⁠Commands for development

  • Misc commands:

      # Re-collect facts about host
      ansible host1 -m setup \
          -e ansible_python_interpreter=/home/core/bin/python \
          -e ansible_ssh_user=core
    
      # List all variables for a host
      ansible host1 -m debug -a "var=hostvars[inventory_hostname]"
      # Also vars, environment, group_names, groups
    
  • Ansible ipa_* tests:

    • Testing against live IPA server
        env \
          PYTHONPATH=$(pwd)/lib \
          IPA_HOST=host1.example.com \
          IPA_USER=admin \
          IPA_PASS=mysecretpw \
          IPA_DOMAIN=example.com \
          IPA_NSRECORD=host1.example.com. \
          nosetests -v test/units/modules/identity/ipa/
    
  • Run nosetests in ansible repo

    • PYTHONPATH=$(pwd)/lib nosetests -v test/units/modules/identity/ipa/

Run etcdctl with SSL:

cd /media/state/etcd
etcdctl --endpoint=https://127.0.0.1:2380 \
    --ca-file=ca.pem --cert-file=client.pem --key-file=client-key.pem \
    cluster-health

Run shell in running container:

ssh -t core@$HOST0 docker exec -it ipa bash

FreeIPA information commands

    # List all servers and replicas
    ipa-replica-manage list
    # List agreements for a server
    ipa-replica-manage list host1.example.com

Querying LDAP needs SASL auth mech explicitly defined

    docker exec -it ipa ldapsearch -H ldaps://host1.example.com -Y GSSAPI

Run shell in ipaclient container, ready to run emacs

    docker exec -it --detach-keys ctrl-^ ipaclient env TERM=screen bash

Misc. kubernetes commands

kubectl config *
kubectl cluster-info
kubectl get cs
kubectl --namespace=kube-system get pods
kubectl --namespace=kube-system describe pods kube-dns-v20-d7crm
kubectl --namespace=kube-system logs kube-dns-v20-d7crm kubedns
kubectl --namespace=kube-system replace --force -f var/k8s/dns-addon.yaml
kubectl --namespace=kube-system delete pods kube-dns-v20-d7crm
kubectl --namespace=kube-system port-forward kubernetes-dashboard-v1.6.0-xcgh7 9090
kubectl --namespace=kube-system exec kube-dns-v20-jh9sb -c kubedns -- nslookup host1
kubectl --namespace=kube-system describe pods kube-dns-v20-jh9sb

⁠Documentation used to develop this system

⁠Ansible⁠

Ansible automates the bootstrapping before anything else.

At this time, Ansible has an enormous number of modules that handle 90% of our needs. The missing 10% primarily handle FreeIPA object classes that the roles in this repo use extensively, such as the SSL-related objects CA, CA ACL, certificate and service, and also DNS zones and records. There is also a parted module copied from upstream with bugfixes.

It also turned out to simplify playbooks to write a number of filter plugins, some for specific purposes and some general.

⁠DigitalOcean⁠

First step is to provision DigitalOcean droplets with CoreOS image.

⁠FreeIPA⁠:

Next step is to install and configure FreeIPA in a Docker container.

⁠CoreOS⁠

CoreOS Container Linux must be configured for clustering with etcd3 and Kubernetes. This depends on FreeIPA being bootstrapped.

The initial node will be bootstrapped with a static cluster configuration and no TLS. TLS will be introduced after FreeIPA is running and DNS and the CA are available.

The etcd cluster will be bootstrapped from DNS with the --discovery-srv flag.

All communication will be over TLS with certs generated from FreeIPA (in a dedicated sub-CA) and monitored with certmonger.

⁠Flannel

Kubernetes depends on Flannel networking.

⁠Kubernetes

Install Kubernetes after the Container Linux cluster is configured.

⁠HAProxy⁠

HAProxy for load balancing, but really for reverse-proxying multiple web services on a single IP.


⁠TODO

⁠IPA configuration

These should be added to automation

  • Connect replica servers to eliminate host1 as SPOF

      ipa-replica-manage connect host2.example.com host3.example.com
    
  • Create ipa sidekick /etc/resolv.conf service to install FreeIPA/Google DNS servers at start/stop

⁠Public SSL Certs
⁠Cheaper VPSs

DO isn't the cheapest anymore, and Dogtag struggles in a $10/month 1gb droplet.

  • Scaleway⁠: For 30% less money, get 300% more CPU and RAM and 150% more disk, and 300% more disk for the same money. Apparently no Ansible modules, but there is an API and a (read-only?) Python module.
⁠Logging

Possibilities:

⁠Schedule pods on k8s apiserver
  • Security recommendations say don't schedule pods on k8s master
  • However, this is possible; see master isolation docs⁠
⁠Memory
  • The FreeIPA Dogtag CA and kubernetes API servers take an enormous amount of RAM; 1GB is insufficient for both, even with 2GB swap
  • How can these pieces be distributed to ensure redundancy but minimize RAM requirements?
⁠DNS service
  • DNS service exposed at public IP won't recurse
  • DNS service exposed at internal IPs will recurse, but not routable across nodes and thus no DNS redundancy
  • Probably the IPA servers need to be moved into Kubernetes so that internal service can be routed
⁠CoreOS SSSD
  • Enrol CoreOS in IPA
⁠Adding later nodes
  • This probably won't work at all right now.

Tag summary

Content type

Image

Digest

Size

51.9 MB

Last updated

about 9 years ago

docker pull zultron/freeipa-cloud-prov:dnsmasq