{"id":62,"date":"2014-06-29T18:23:57","date_gmt":"2014-06-29T18:23:57","guid":{"rendered":"http:\/\/credelius.com\/credelius\/?p=62"},"modified":"2014-06-29T18:39:38","modified_gmt":"2014-06-29T18:39:38","slug":"cloud-hsm-automation-part-2","status":"publish","type":"post","link":"https:\/\/credelius.com\/credelius\/?p=62","title":{"rendered":"Cloud HSM Automation &#8211; Part 2"},"content":{"rendered":"<p><b>Why would you need HA<\/b><\/p>\n<p>While the <a href=\"https:\/\/bitly.com\/1434Q10\" data-blogger-escaped-target=\"_blank\">previous Cloud HSM article<\/a> was mostly covering &#8220;Why Cloud HSM is Important&#8221; topics, this one describes technical details about <b>how<\/b> <a href=\"http:\/\/cloudhsm-safenet-docs.s3.amazonaws.com\/007-011136-002_lunasa_5-1_webhelp_rev-a\/Content\/administration\/ha_with_luna_sa.htm\" data-blogger-escaped-target=\"_blank\">Luna HA (High Availability ) cluster<\/a> can be built in a cloud and provides links to scripts that could help automating and codifying a rather complicated Luna&#8217;s setup process.<\/p>\n<p>It&#8217;s obvious that when you build an HA system with subsystems that rely heavily on cryptographic services built around Luna, you need to put latter to the same HA category. That&#8217;s why a single Luna appliance is not usually sufficient and you need an array (or cluster) of HSM&#8217;s that look and behave as a single one from a client&#8217;s point of view.<\/p>\n<p>The first few chapters of this document cover manual Luna and Luna array configuration topics, while &#8220;Setup Automation&#8221; section describes a command line tool that allows automating the whole process by creating a JSON configuration file and running a Python script. You do need to go through manual setup topics if you didn&#8217;t have a prior experience with configuring Luna, otherwise it could be very difficult to understand how to create the JSON file and troubleshoot possible issues.<\/p>\n<p><b>Provisioning<\/b><\/p>\n<p>Unfortunately, there is no way to deploy a Luna device to a cloud in the same automated manner (e.g. through <a href=\"http:\/\/aws.amazon.com\/cloudformation\/\" data-blogger-escaped-target=\"_blank\">CloudFormation<\/a>) as other pieces of AWS infrastructure. There is a well documented\u00a0 manual process for that, which is not very difficult to follow,\u00a0 but it&#8217;s still manual. The process is described <a href=\"http:\/\/docs.aws.amazon.com\/cloudhsm\/latest\/gsg\/cloud-hsm-prereq.html\" data-blogger-escaped-target=\"_blank\">here<\/a>.<\/p>\n<p>The two important things that are worth mentioning are the facts that you&#8217;ll need a <a href=\"http:\/\/aws.amazon.com\/vpc\/\" data-blogger-escaped-target=\"_blank\">VPC<\/a> to deploy a Luna appliance and that you&#8217;ll need at least two devices to create an HA array.<\/p>\n<p>After the appliances are provisioned to a VPC, you&#8217;ll be given managers passwords that could be used to connect to the devices remotely and perform all necessary configuration jobs.<\/p>\n<p><b>Configuring Luna Servers<\/b><\/p>\n<p>You&#8217;ll need to login to a Luna device using SSH from a client machine to perform a configuration job. I would strongly recommend to enable key based authentication on a Luna device, because most likely you&#8217;ll need to SSH to the device many times before you&#8217;re done with configuration and verification:<\/p>\n<p>scp &lt;public-cert-file-name&gt; manager@&lt;luna-ip&gt;:.<\/p>\n<p>ssh manager@&lt;luna-ip&gt;<\/p>\n<p>sysc ssh pu esysc ssh pu a -f &lt;public-cert-file-name&gt;\u00a0 <b>\u00a0<\/b><\/p>\n<p>where &lt;public-cert-file-name&gt; is a public certificate generated by a &#8216;ssh-keygen&#8217; command on a client machine.<\/p>\n<p>The following high level manual steps are required to configure a Luna server:<\/p>\n<ol>\n<li>&#8216;hsm init&#8217; command to initialize the device<\/li>\n<li>&#8216;sysconf re&#8217; command to regenerate server side certificates<\/li>\n<li>&#8216;ntls bind&#8217; command to restart Luna&#8217;s network interfaces<\/li>\n<li>&#8216;hsm login&#8217; to as admin to Luna<\/li>\n<li>&#8216;par cr &#8230;&#8217; to create a partition<\/li>\n<li>&#8216;c reg &#8230;&#8217; to register client<\/li>\n<li>&#8216;c a &#8230;&#8217; to assign a partition to a client<\/li>\n<\/ol>\n<p>The Luna configuration process is described in details <a href=\"http:\/\/docs.aws.amazon.com\/cloudhsm\/latest\/gsg\/configure-hsm-appliance.html\" data-blogger-escaped-target=\"_blank\">here<\/a>.<\/p>\n<p><b>Configuring Luna Clients<\/b><\/p>\n<p>This one is interesting and requires some re-thinking because of differences introduced by AWS&#8217; auto scaling groups (<a href=\"http:\/\/aws.amazon.com\/autoscaling\/\" data-blogger-escaped-target=\"_blank\">ASG<\/a>). In a traditional &#8216;static&#8217; environment each client would require a unique client certificate and an IP (or client&#8217;s host name) to be registered on a Luna server. Since EC2 instances can randomly go up and down in ASG that approach would be difficult to implement. Fortunately, there is a way around that allows sharing a single client&#8217;s certificate for the whole ASG.<\/p>\n<p>The first step in configuring clients is to download and install Luna&#8217;s client tools and libraries\u00a0 that are available for free:<\/p>\n<ul>\n<li><a href=\"http:\/\/cloudhsm-software.s3.amazonaws.com\/Luna_5.1_Client_Software.tar%7C\" data-blogger-escaped-target=\"_blank\">Luna Client Software<\/a><\/li>\n<li><a href=\"http:\/\/cloudhsm-software.s3.amazonaws.com\/Luna_5.1.1_Client_Patch.tar%7C\" data-blogger-escaped-target=\"_blank\">Client Software Patch<\/a><\/li>\n<\/ul>\n<p>After these two components are installed, &#8216;vtl&#8217; command line tool used for a client&#8217;s setup could be found at the following location on Linux: \/usr\/lunasa\/bin\/vtl. A new client certificate and a private key can be generated by running the following command:<\/p>\n<p>vtl createCert -n &lt;cert_name&gt;<\/p>\n<p>A newly generated certificate will be stored at &#8216;\/usr\/lunasa\/cert\/client\/&lt;cert_name&gt;.pem&#8217; and will need to be transferred to a Luna server for further registration:<\/p>\n<p>scp \/usr\/lunasa\/cert\/client\/&lt;cert_name&gt;.pem manager@&lt;luna_server&gt;:.<\/p>\n<p>A trick that allows registering the whole ASG without binding a registration to an IP is to use &lt;cert-name&gt; as a parameter in &#8216;-hostname&#8217; option and not to use &#8216;-ip&#8217; option at all. It&#8217;s not obvious, but it definitely works. A command on the server will look like this:<\/p>\n<p>c reg -c &lt;client-name&gt; -h &lt;cert-name&gt;<\/p>\n<p>where &lt;client-name&gt; is a logical name that the server will use to refer the new client and &lt;cert-name&#8221; is the same cert that we&#8217;ve just created on the client using &#8216;vtl&#8217; command.<\/p>\n<p>To replicate the generated certificate and private key to other ASG members you&#8217;ll need to place the generated files to \/usr\/lunasa\/cert\/client\/ and to make sure that you have two following entries in &#8216;LunaSA Client&#8217; section of &#8216;\/etc\/Chrystoki.conf&#8217; file:<\/p>\n<p>ClientPrivKeyFile = \/usr\/lunasa\/cert\/client\/&lt;cert-name&gt;Key.pem;<\/p>\n<p>ClientCertFile = \/usr\/lunasa\/cert\/client\/&lt;cert-name&gt;.pem;<\/p>\n<p>You&#8217;ll also need to register a Luna server on the client to be able to connect to that server:<\/p>\n<p>scp manager@&lt;luna-server-host&gt;:server.pem .<\/p>\n<p>vtl addServer -n &lt;luna-server-host&gt; -c server.pem<\/p>\n<p><b>Configuring Luna HA Cluster<\/b><\/p>\n<p>You&#8217;ll need at least two Luna servers configured as described in &#8220;Configuring Luna Servers&#8221; section with the following limitations:<\/p>\n<ol>\n<li>Admin and partition passwords should be the same.<\/li>\n<li>Partition names for partitions participating in HA cluster should be the same<\/li>\n<li>Cloning domain names should be the same<\/li>\n<\/ol>\n<p>If the conditions above are met, registering the cluster should be easy:<\/p>\n<p>vtl haAdmin -newGroup -serialNum &lt;par-ser-nbr1&gt; -label &lt;group-name&gt; -password &lt;par-pwd&gt;<\/p>\n<p>vtl haAdmin -addMember -serialNum &lt;par-ser-nbr2&gt; -group &lt;group-ser-num&gt; -password &lt;par-pwd&gt;<\/p>\n<p>where<\/p>\n<p>&lt;par-ser-nbr1&gt; and &lt;par-ser-nbr1&gt; &#8211; serial numbers of partitions included to the cluster<\/p>\n<p>&lt;group-name&gt; &#8211; is a logical name for the newly created cluster<\/p>\n<p>&lt;par-pwd&gt; &#8211; is a partition password<\/p>\n<p>&lt;group-ser-num&gt; &#8211; a serial number for the newly created group (it will be displayed after the group is created by &#8216;newGroup&#8217; command.<\/p>\n<p>To figure out what &lt;par-ser-nbr1&gt; and &lt;par-ser-nbr1&gt; parameters are, you can run the following command on a client:<\/p>\n<p>vtl verify<\/p>\n<p>The output should look as below:<\/p>\n<p>The following Luna SA Slots\/Partitions were found:<\/p>\n<p>Slot\u00a0\u00a0\u00a0 Serial #\u00a0\u00a0\u00a0 Label<\/p>\n<p>====\u00a0\u00a0\u00a0 ========\u00a0\u00a0\u00a0 =====<\/p>\n<p>1\u00a0\u00a0\u00a0 &lt;par-ser-nbr1&gt; \u00a0\u00a0\u00a0 &lt;par name&gt;<\/p>\n<p>2\u00a0\u00a0\u00a0 &lt;par-ser-nbr1&gt; \u00a0\u00a0\u00a0 &lt;par name&gt;<\/p>\n<p><b>Configuring Java Client<\/b><\/p>\n<p>Luna&#8217;s client includes Java classes that implement traditional <a href=\"http:\/\/docs.oracle.com\/javase\/6\/docs\/technotes\/guides\/security\/crypto\/CryptoSpec.html\" data-blogger-escaped-target=\"_blank\">JCA<\/a> architecture. You&#8217;ll need to include LunaProvider.jar to a classpath and modify java.security file that can be normally found at the following location: &lt;JRE-DIR&gt;\/lib\/security\/java.security. The section that needs to be updated looks as follows:<\/p>\n<p>security.provider.1=sun.security.provider.Sun<\/p>\n<p>security.provider.2=sun.security.rsa.SunRsaSign<\/p>\n<p>security.provider.3=sun.security.ec.SunEC<\/p>\n<p>security.provider.4=com.sun.net.ssl.internal.ssl.Provider<\/p>\n<p>security.provider.5=com.sun.crypto.provider.SunJCE<\/p>\n<p>security.provider.6=sun.security.jgss.SunProvider<\/p>\n<p>security.provider.7=com.sun.security.sasl.Provider<\/p>\n<p>security.provider.8=org.jcp.xml.dsig.internal.dom.XMLDSigRI<\/p>\n<p>security.provider.9=sun.security.smartcardio.SunPCSC<\/p>\n<p>To enable Luna Provider, add the following line to the list:<\/p>\n<p>security.provider.10=com.safenetinc.luna.provider.LunaProvider<\/p>\n<p><b>Testing HA Luna from a Java application<\/b><\/p>\n<p>You can find many Java sample applications under following location: \/usr\/lunasa\/jsp\/samples\/com\/safenetinc\/luna\/sample. Connecting to an HA cluster is not different from connecting to a single Luna device &#8211; you just need to know a correct Slot number that represents the Luna array. &#8216;vtl haAdmin -show&#8217; command can be used to find out what HA slot number is:<\/p>\n<p>[ec2-user@ip-10-0-1-225 lunasa]$ \/usr\/lunasa\/bin\/vtl haAdmin -show<\/p>\n<p>================ HA Group and Member Information ================<\/p>\n<p>HA Group Label:\u00a0 ha_group<\/p>\n<p>HA Group Number:\u00a0 &lt;grp-ser-nbr&gt;<\/p>\n<p>HA Group Slot #:\u00a0 &lt;grp-slot-nbr&gt;<\/p>\n<p>Synchronization:\u00a0 enabled<\/p>\n<p>Group Members:\u00a0 &lt;par-ser-nbr1&gt;, &lt;par-ser-nbr1&gt;<\/p>\n<p>Standby members:\u00a0 &lt;none&gt;<\/p>\n<p>Slot #\u00a0\u00a0\u00a0 Member S\/N\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Member Label\u00a0\u00a0\u00a0 Status<\/p>\n<p>======\u00a0\u00a0\u00a0 ==========\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ============\u00a0\u00a0\u00a0 ======<\/p>\n<p>1\u00a0\u00a0\u00a0\u00a0 &lt;par-ser-nbr1&gt;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;par_name&gt; \u00a0\u00a0\u00a0 alive<\/p>\n<p>2\u00a0\u00a0\u00a0\u00a0 &lt;par-ser-nbr2&gt;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;par_name&gt;\u00a0\u00a0\u00a0\u00a0 alive<\/p>\n<p>The slot number that you&#8217;re looking for is &lt;grp-slot-nbr&gt;.<\/p>\n<p>If you look at\u00a0 Java sample found in the KeyStoreLunaDemo.java file, you&#8217;ll find the following lines :<\/p>\n<p>ByteArrayInputStream is1 = new ByteArrayInputStream((&#8220;slot:1&#8221;)<\/p>\n<p>.getBytes());<\/p>\n<p>&nbsp;<\/p>\n<p>This is the place where you would need to use the slot number displayed by &#8216;vtl haAdmin -show&#8217; command.<\/p>\n<p><b>Setup Automation<\/b><\/p>\n<p>As you&#8217;ve probably noticed already, the Luna HA setup process is rather cumbersome and doesn&#8217;t fit well to a major cloud concept that assumes a great deal of automation. I&#8217;ve tried to address the issue by creating a <a href=\"https:\/\/sourceforge.net\/projects\/lunamech\" data-blogger-escaped-target=\"_blank\">Python package<\/a> that would allow setting up a Luna HA cluster by running a single command:<\/p>\n<p>luna_mech -a -g -r\u00a0 &lt;luna-array-config-file&gt;<\/p>\n<p>or, if you want to configure a single Luna appliance, you can run:<\/p>\n<p>luna_mech -l -g -r\u00a0 &lt;luna-config-file&gt;<\/p>\n<p>An idea here is to put all Luna parameters to a JSON file and make the Luna Mechanizer to parse and interpret it.\u00a0 The next step could be to in integrate the mechanizer with a CloudFormation framework.<\/p>\n<p>The code can be found in a git repo @ sf.net and can be downloaded by usual means:<\/p>\n<p>git clone git clone\u00a0 http:\/\/git.code.sf.net\/p\/lunamech\/code luna_mech<\/p>\n<p>or<\/p>\n<p>git clone\u00a0 git:\/\/git.code.sf.net\/p\/lunamech\/code luna_mech<\/p>\n<p>Check README file for further instructions.<\/p>\n<p><b>Security Considerations<\/b><\/p>\n<p>Since a cloud environment is not commonly considered as trusted,\u00a0 there is still a problem of passing secrets such as an HA partition password and client side private key to ASG members. You definitely don&#8217;t want to &#8220;bake&#8221; secrets like this to an <a href=\"https:\/\/aws.amazon.com\/amis\/\" data-blogger-escaped-target=\"_blank\">AMI<\/a> or even store them in an encrypted <a href=\"http:\/\/aws.amazon.com\/s3\/\" data-blogger-escaped-target=\"_blank\">S3 bucket<\/a>, let alone putting them to unencrypted EC2&#8217;s &#8220;<a href=\"http:\/\/docs.aws.amazon.com\/AWSEC2\/latest\/UserGuide\/AESDG-chapter-instancedata.html\" data-blogger-escaped-target=\"_blank\">user data<\/a>&#8220;.<\/p>\n<p>I&#8217;ll try to explore other AWS specific ways of passing secrets from an internal DC to a cloud in the next blog.<\/p>\n<p>Stay tuned!<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Why would you need HA While the previous Cloud HSM article was mostly covering &#8220;Why Cloud HSM is Important&#8221; topics, this one describes technical details about how Luna HA (High Availability ) cluster can be built in a cloud and provides links to scripts that could help automating and codifying a rather complicated Luna&#8217;s setup [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/credelius.com\/credelius\/index.php?rest_route=\/wp\/v2\/posts\/62"}],"collection":[{"href":"https:\/\/credelius.com\/credelius\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/credelius.com\/credelius\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/credelius.com\/credelius\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/credelius.com\/credelius\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=62"}],"version-history":[{"count":1,"href":"https:\/\/credelius.com\/credelius\/index.php?rest_route=\/wp\/v2\/posts\/62\/revisions"}],"predecessor-version":[{"id":63,"href":"https:\/\/credelius.com\/credelius\/index.php?rest_route=\/wp\/v2\/posts\/62\/revisions\/63"}],"wp:attachment":[{"href":"https:\/\/credelius.com\/credelius\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=62"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/credelius.com\/credelius\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=62"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/credelius.com\/credelius\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=62"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}