{"id":43,"date":"2018-09-22T14:38:36","date_gmt":"2018-09-22T12:38:36","guid":{"rendered":"http:\/\/www.keinzweifel.ch\/?p=43"},"modified":"2018-09-27T16:27:18","modified_gmt":"2018-09-27T14:27:18","slug":"pykmip-as-vcenter-ksm-server","status":"publish","type":"post","link":"http:\/\/www.keinzweifel.ch\/?p=43","title":{"rendered":"PyKMIP as vcenter KSM server"},"content":{"rendered":"<p>There are multiple reasons why somebody would like to have a KSM server.<br \/>\nThis article explains how to set up such a server with persistent database storage, so that an encrypted vm survives a complete (vcenter\/esxi) reboot.<br \/>\nAlthough it works, it is certainly not recommended to do it this way in large environments.<br \/>\nBut nevertheless, it&#8217;s a cheap way to get a vtpm.<br \/>\nRemark: After a reboot of vcenter, the trust seems still intact, but does not work anymore! In that case, just remove the KMS cluster-definition and re-add and trust it. After that you should be able to unlock encrypted VMs again.<\/p>\n<p>I did this with an minimal Ubuntu server 18.04.1 64bit install. The service runs as the admin user (sudoer, not root). You might want to change that to even a less privileges user and probably setup iptables or other means to protect the TPM data! It is an sqlite db, so anybody with file-access could steal and read it! This tutorial also uses a self-signed certificate. If you have a PKI, it would certainly be better to use properly signed and managed ssl certs&#8230;<br \/>\nYou have been warned! \ud83d\ude09<\/p>\n<p>&lt;$username&gt; should get replaced with the actual username.<br \/>\nCommands in <span style=\"color: #339966;\">green<\/span> should be executed as user.<br \/>\nCommands in <span style=\"color: #ff0000;\">red<\/span> should get executed as root.<br \/>\nThe switch between the two are the sudo and exit commands.<\/p>\n<p>Login as user to the ubuntu machine.<br \/>\n<span style=\"color: #339966;\">sudo -i<\/span><br \/>\n<span style=\"color: #ff0000;\">apt-get update<\/span><br \/>\n<span style=\"color: #ff0000;\">apt-get upgrade<\/span><br \/>\n<span style=\"color: #ff0000;\">mkdir \/usr\/local\/PyKMIP<\/span><br \/>\n<span style=\"color: #ff0000;\">mkdir \/etc\/pykmip<\/span><br \/>\n<span style=\"color: #ff0000;\">mkdir \/var\/log\/pykmip<\/span><br \/>\n<span style=\"color: #ff0000;\">chown &lt;$username&gt;: -R \/usr\/local\/PyKMIP<\/span><br \/>\n<span style=\"color: #ff0000;\">chown &lt;$username&gt;: -R \/etc\/pykmip<\/span><br \/>\n<span style=\"color: #ff0000;\"> chown &lt;$username&gt;: -R \/var\/log\/pykmip<\/span><br \/>\n<span style=\"color: #ff0000;\"> apt -get installpython-dev libffi-dev libssl-dev libsqlite3-dev python-setuptools python-requests<\/span><br \/>\n<span style=\"color: #ff0000;\"> openssl req -x509 -nodes -days 9999 -newkey rsa:2048 -keyout \/etc\/ssl\/private\/selfsigned.key -out \/etc\/ssl\/certs\/selfsigned.crt<\/span><\/p>\n<p>Fill out the form&#8230;<br \/>\n<span style=\"color: #ff0000;\"><br \/>\nchown &lt;$username&gt;: -R \/etc\/ssl\/private<\/span><br \/>\n<span style=\"color: #ff0000;\">chown &lt;$username&gt;: \/etc\/ssl\/certs\/selfsigned.crt<\/span><br \/>\n<span style=\"color: #ff0000;\"> exit<\/span><br \/>\n<span style=\"color: #339966;\">cd \/usr\/local<\/span><\/p>\n<p>If you need to use a proxy, then replace X.X.X.X with the ip of the proxy and PORT with the port your proxy server is available. You might also add &#8220;yourproxyusername:yourproxypassword@&#8221; directly in front of the ip, if your proxy requires authentication. We will need this one more time later on, so keep them in mind.<br \/>\nIf you don&#8217;t need any proxy, the you can leave the following two commands out.<\/p>\n<p><span style=\"color: #339966;\">export https_proxy=http:\/\/X.X.X.X:PORT<\/span><br \/>\n<span style=\"color: #339966;\">export http_proxy=http:\/\/X.X.X.X:PORT<\/span><\/p>\n<p><span style=\"color: #339966;\">cd \/usr\/local<\/span><br \/>\n<span style=\"color: #339966;\">git clone https:\/\/github.com\/OpenKMIP\/PyKMIP<\/span><\/p>\n<p><span style=\"color: #339966;\">sudo -i<\/span><\/p>\n<p>Again, the Proxy, but this time as root.<\/p>\n<p><span style=\"color: #ff0000;\">export https_proxy=http:\/\/X.X.X.X:PORT<\/span><br \/>\n<span style=\"color: #ff0000;\">export http_proxy=http:\/\/X.X.X.X:PORT<\/span><\/p>\n<p><span style=\"color: #ff0000;\">cd \/usr\/local\/PyKMIP<\/span><br \/>\n<span style=\"color: #ff0000;\"> python setup.py install<\/span><br \/>\n<span style=\"color: #ff0000;\">exit<\/span><br \/>\n<span style=\"color: #339966;\">nano \/etc\/pykmip\/server.conf<\/span><\/p>\n<p>Enter these following lines between the &#8212; signs (but without them) in the nano editor.<br \/>\nReplace hostname=10.X.X.X with the servers IP.<br \/>\nQuit with ctrl-x followed by y and enter<\/p>\n<p>&#8212;<br \/>\n[server]<br \/>\ndatabase_path=\/etc\/pykmip\/pykmip.database<br \/>\nhostname=10.X.X.X<br \/>\nport=5696<br \/>\ncertificate_path=\/etc\/ssl\/certs\/selfsigned.crt<br \/>\nkey_path=\/etc\/ssl\/private\/selfsigned.key<br \/>\nca_path=\/etc\/ssl\/certs\/selfsigned.crt<br \/>\nauth_suite=TLS1.2<br \/>\npolicy_path=\/usr\/local\/PyKMIP\/examples\/<br \/>\nenable_tls_client_auth=False<br \/>\ntls_cipher_suites=<br \/>\nTLS_RSA_WITH_AES_128_CBC_SHA256<br \/>\nTLS_RSA_WITH_AES_256_CBC_SHA256<br \/>\nTLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384<br \/>\nlogging_level=DEBUG<br \/>\n&#8212;<\/p>\n<p>We should now be ready to start the service!<\/p>\n<p><span style=\"color: #339966;\">cd \/usr\/local\/PyKMIP<\/span><br \/>\n<span style=\"color: #339966;\"> python bin\/run_server.py<\/span><\/p>\n<p>Now you should be able to add the host as KSM server in vcenter with the ip and port 5696.<\/p>\n<p>To make the connection complete, you need to press the &#8220;Make KMS trust vcenter&#8221; button.<br \/>\nChoose &#8220;KMS certificate and private key&#8221;<br \/>\nOpen a new shell to the ubuntu server<br \/>\n<span style=\"color: #339966;\">cat \/etc\/ssl\/certs\/selfsigned.crt<\/span><br \/>\ncopy the whole output inclusive the &#8212;begin and end &#8212; messages and paste it to the first field &#8220;KMS Certificate&#8221; in vcenter<br \/>\n<span style=\"color: #339966;\">cat \/etc\/ssl\/private\/selfsigned.key<\/span><br \/>\ncopy the whole output inclusive the &#8212;begin and end &#8212; messages and paste it to the second field &#8220;KMS Private Key&#8221; in vcenter<\/p>\n<p>Press the &#8220;Establish Trust&#8221; button.<\/p>\n<p>To let the service start on every boot, you can add it to the crontab.<\/p>\n<p><span style=\"color: #339966;\">crontab -e<\/span><\/p>\n<p>Add the following line. and save the file.<\/p>\n<p>@reboot ( sleep 30s; python \/usr\/local\/PyKMIP\/bin\/run_server &amp; )<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are multiple reasons why somebody would like to have a KSM server. This article explains how to set up such a server with persistent database storage, so that an encrypted vm survives a complete (vcenter\/esxi) reboot. Although it works, &hellip; <a href=\"http:\/\/www.keinzweifel.ch\/?p=43\">Weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1,3],"tags":[],"_links":{"self":[{"href":"http:\/\/www.keinzweifel.ch\/index.php?rest_route=\/wp\/v2\/posts\/43"}],"collection":[{"href":"http:\/\/www.keinzweifel.ch\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.keinzweifel.ch\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.keinzweifel.ch\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.keinzweifel.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=43"}],"version-history":[{"count":10,"href":"http:\/\/www.keinzweifel.ch\/index.php?rest_route=\/wp\/v2\/posts\/43\/revisions"}],"predecessor-version":[{"id":53,"href":"http:\/\/www.keinzweifel.ch\/index.php?rest_route=\/wp\/v2\/posts\/43\/revisions\/53"}],"wp:attachment":[{"href":"http:\/\/www.keinzweifel.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=43"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.keinzweifel.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=43"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.keinzweifel.ch\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=43"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}