<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Julien on Medium]]></title>
        <description><![CDATA[Stories by Julien on Medium]]></description>
        <link>https://medium.com/@julien_sqooba?source=rss-c81ac418358c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*AqVrGfarmZHaUX_7DjihfQ.jpeg</url>
            <title>Stories by Julien on Medium</title>
            <link>https://medium.com/@julien_sqooba?source=rss-c81ac418358c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 05:03:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@julien_sqooba/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Securing a single-page app through OpenID Connect SSO using an explicit flow with Play2 and Pac4J]]></title>
            <link>https://medium.com/sqooba/securing-a-single-page-app-through-openid-connect-sso-using-an-explicit-flow-with-play2-and-pac4j-7f6c4f46e31a?source=rss-c81ac418358c------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f6c4f46e31a</guid>
            <category><![CDATA[keycloak]]></category>
            <category><![CDATA[play-framework]]></category>
            <category><![CDATA[pac4j]]></category>
            <category><![CDATA[single-sign-on]]></category>
            <category><![CDATA[openid-connect]]></category>
            <dc:creator><![CDATA[Julien]]></dc:creator>
            <pubDate>Wed, 13 Feb 2019 15:57:03 GMT</pubDate>
            <atom:updated>2019-02-17T15:28:15.549Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Explicit Flow</em> is a slight misnomer: we are actually talking about the <em>Authorization Code Flow</em>, but Google pushed us to update our wording slightly: searching for <em>Single Page App OpenID explicit flow</em> (as opposed to <em>implicit</em>) was, interestingly, yielding this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*HWCo04dkqGReGH7Dtc3F0g.png" /><figcaption>Nope, Google does not want you to search for the <em>other flow…</em></figcaption></figure><p>The above illustrates the little struggles we went through, facing an interesting conundrum:</p><ul><li>OAuth2 and OpenId standards recommend <em>against </em>using the implicit flow, and suggest using the Authorization Code flow instead. See <a href="https://medium.com/oauth-2/why-you-should-stop-using-the-oauth-implicit-grant-2436ced1c926">here</a> and <a href="https://tools.ietf.org/id/draft-parecki-oauth-browser-based-apps-02.txt">there</a></li><li>Most guides and tutorials out there that explain how to integrate single sign-on with a single page app <em>will tell you to use the implicit flow </em>and not to bother too much about the workarounds to refresh the short-lived token.</li></ul><p>This article explains how we went on to do the correct thing in a (relatively) simple manner: using the authorization code flow to secure a React single page app with an OpenId-Connect SSO server.</p><p>To avoid any misplaced hope, let us describe our setup:</p><ul><li>A React Single Page App (hereafter SPA): it is served from a public end-point from our web-server and it accesses protected APIs.</li><li>A <a href="https://www.playframework.com/">Play2</a> server</li><li>Pac4J to handle the security plumbing (using <a href="https://github.com/pac4j/play-pac4j">play-pac4j</a>)</li><li>We use <a href="https://www.keycloak.org/">Keycloak</a> as our SSO server, but this should work with any other implementation as well.</li></ul><p>We assume that you have already set up everything so that hitting <a href="https://yourappdomain/secure-api/">https://yourappdomain/secure-api/</a> in your browser will redirect to your SSO provider and work correctly once you have authenticated successfully.</p><h4>Authorization Code Flow in a Nutshell</h4><p>With play2/pac4j, it looks like this:</p><ul><li>Request something on /api/secured without being authenticated</li><li>Get redirected to sso.somewhere/auth/realms/MyApp/protocol/openid-connect/auth where you fill and submit the login form</li><li>Get redirected to /auth/callback with the authorization code being contained in the callback url</li><li>Behind the scene, the API server makes a request to sso.somewhere to validate the supplied code and fetch relevant user metadata</li><li>Your session with the API server is now authenticated, and your call to api/secured should succeed</li></ul><p>Full details can be found on the <a href="https://tools.ietf.org/html/rfc6749#page-24">OAuth 2.0 Authorization Framework RFC</a>.</p><h3>The Pain Point</h3><p>At this point, if you are familiar with the authorization code flow you should be wondering <em>but why is it even an issue?!</em></p><p>Easy! In our setup, the server (here driven by Pac4J) will do a 302 redirect to the SSO provider in order to start the authentication process, whenever a protected endpoint is hit by an un-authenticated request.</p><p>That’s <em>fine</em> when you query the endpoints directly, but is <em>slightly</em> problematic when your SPA is doing this under the hood.</p><h4>Why?</h4><ul><li>You need to redirect the whole browser window to the SSO server</li><li>A 302 redirect is <em>opaque</em> to the javascript environment that runs your SPA, meaning there is no way you can extract the Location header from the request to redirect the entire browser.</li></ul><h4>Long Story Short</h4><p>As some more arcane tutorials and guides note, you somehow need to:</p><ul><li>Tell your API server that the request was made through an AJAX call (as this is generally <em>not</em> obvious to the server <em>at all</em>)</li><li>Tell your security module to send a 401 instead of a 302 , in which case you will have full access to the response’s headers</li></ul><p>At this point you’ll be able to read the Location header and send your user on her way to the SSO server with a simple window.location.href = &lt;location-header-content&gt; .</p><p>The second point may seem hard to handle at first, but if you search a bit, you’ll discover that pac4j offers you a few options to do so, if you look at its <a href="https://github.com/pac4j/pac4j/blob/master/pac4j-core/src/main/java/org/pac4j/core/http/ajax/DefaultAjaxRequestResolver.java">DefaultAjaxRequestResolver.java</a>:</p><ul><li>The is_ajax_request=true parameter that can be added to the request</li><li>Setting the X-Requested-With header to XMLHttpRequest</li></ul><p>Both of which are actually extremely easy to do from your SPA , and will always cause pac4j to send you a 401 instead of a 302 response, with all the headers unchanged.</p><h4>What About My Dev Proxy?</h4><p>If you are developing a React app, chances are you are also relying on the local development proxy: mixing this with SSO introduces a few complications that will be covered in another post.</p><p>But for starters, you’ll need to tell your proxy to let certain calls go through to the API server no matter what, and this can be done with a file named setupProxy.js that sits at the root of your src folder, containing the following:</p><pre>const proxy = require(&#39;http-proxy-middleware&#39;);</pre><pre>const apiUrl =  &#39;<a href="http://localhost:9000/&#39;">http://localhost:9000/&#39;</a></pre><pre>module.exports = function(app) {<br>    app.use(proxy(&#39;/api&#39;, { target: apiUrl}));<br>    app.use(proxy(&#39;/auth/callback&#39;, { target: apiUrl }));<br>};</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yHihcjcivMbuCyZdIltzgg.jpeg" /><figcaption>Image courtesy <a href="https://pixabay.com/en/users/michaelgaida-652234/">MichaelGaida</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f6c4f46e31a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sqooba/securing-a-single-page-app-through-openid-connect-sso-using-an-explicit-flow-with-play2-and-pac4j-7f6c4f46e31a">Securing a single-page app through OpenID Connect SSO using an explicit flow with Play2 and Pac4J</a> was originally published in <a href="https://medium.com/sqooba">Sqooba</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A close look at a kerberos handshake –authenticate to a Hadoop Namenode via HRPC]]></title>
            <link>https://medium.com/sqooba/a-close-look-at-a-kerberos-handshake-authenticate-to-a-hadoop-namenode-via-hrpc-c56746ddb290?source=rss-c81ac418358c------2</link>
            <guid isPermaLink="false">https://medium.com/p/c56746ddb290</guid>
            <category><![CDATA[kerberos]]></category>
            <category><![CDATA[hdfs]]></category>
            <category><![CDATA[gssapi]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[hadoop]]></category>
            <dc:creator><![CDATA[Julien]]></dc:creator>
            <pubDate>Fri, 25 May 2018 12:55:26 GMT</pubDate>
            <atom:updated>2018-05-25T12:55:26.003Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YKDRD5H5gPpRVVqbsJCIaw.jpeg" /></figure><p>This is a follow-up of our <a href="https://medium.com/sqooba/making-hdfs-a-hundred-times-faster-ac75b8b5e0b4">making HDFS a hundred times faster</a> story and provides a deeper view of the authentication exchange taking place upon connection to a Hadoop Namenode secured with Kerberos.</p><p>This post goes back over the details of a <strong>Hadoop RPC SASL</strong> handshake using <strong>Kerberos</strong> and aims at providing a real world, step-by-step, example of how Kerberos can be used.</p><p>As part of our work to make <a href="https://github.com/colinmarc/hdfs">go-hdfs</a> compatible with a kerberized Hadoop HDFS cluster, we had to look at exactly what is sent during authentication. As an extra difficulty layer, we were not using any bindings to GSSApi.</p><p>Instead, we wanted a pure Go solution: we were relying on a young Go library that, while actively maintained and developed, still missed a few things. Hence, we had only little usage for all the tutorials out there mentioning</p><blockquote>[…] just call GSSApi.xxx() with the received bytes and send back what it returns.</blockquote><p>We wish we had stumbled upon such a walk-through when we began. Given that the Kerberos RFC’s are relatively voluminous and that the way Hadoop RPC integrates Kerberos does not seem to be thoroughly documented, we hope that this post will shed some light on these subjects.</p><p>Note that we will only look at the exact bytes of the kerberos related data. For the rest we will refer to the protocol buffer structs.</p><h3>Opening the socket</h3><blockquote>Upon socket opening, these bytes shall be uttered:</blockquote><pre>// Connection header, to be written when the socket is open<br>rpcHeader := []<strong>byte</strong>{<br>  0x68, 0x72, 0x70, 0x63, // &quot;hrpc&quot;<br>  rpcVersion,             // go-hdfs works with version 9<br>  serviceClass,           // 0. No idea why<br>  authProtocol,           // 223 (0xDF) for SASL, 0 for None<br>}</pre><p>Once this connection header has been written, we are ready to write the first message of the negotiation handshake, namely, the negotiation request.</p><h4>Negotiation request</h4><p>The RPC packets are always composed of a message header, containing various things like the client id and request method, and the request body. What makeRPCPacket does below is just marshalling each passed struct to bytes and appending them.</p><pre>// Initial request state<br>protoState := hadoop.RpcSaslProto_NEGOTIATE</pre><pre>// Build the complete request packet<br>pkt, _ := makeRPCPacket(<br>    newSASLMessageHeader(c.clientId),<br>    &amp;hadoop.RpcSaslProto{<br>        State: &amp;protoState,<br>    })</pre><p>pkt can then be written to the socket. The RpcSaslProto struct and sub-struct look like this:</p><pre>type <strong>RpcSaslProto</strong> struct {<br>  <strong>Version</strong>        <strong>*uint32</strong>                  // protocol version<br>  <strong>State</strong>          <strong>*RpcSaslProto_SaslState</strong>  // Current protocol state<br>  <strong>Token</strong>          []<strong>byte</strong>                   // Token data<br>  // A list of supported auth mechanisms<br>  <strong>Auths</strong>          <strong>[]*RpcSaslProto_SaslAuth</strong> <br>  <strong>XXX_unrecognized</strong> []<strong>byte</strong>                 // Unrecognized bytes<br>}</pre><pre>// Some of these fields are optional<br>type <strong>RpcSaslProto_SaslAuth</strong> struct {<br>  <strong>Method</strong>           <strong>*string</strong><br>  <strong>Mechanism</strong>        <strong>*string</strong><br>  <strong>Protocol</strong>         <strong>*string</strong><br>  <strong>ServerId</strong>         <strong>*string</strong><br>  <strong>Challenge</strong>        []<strong>byte<br>  XXX_unrecognized</strong> []<strong>byte<br></strong>}</pre><h4>First server reply</h4><p>The server should then reply with a SASL response, the body of which contains the following:</p><pre>state:NEGOTIATE<br>auths:<br>  - method:&quot;TOKEN&quot;<br>    mechanism:&quot;DIGEST-MD5&quot;<br>    protocol:&quot;&quot;<br>    serverId:&quot;default&quot;<br>    challenge:&quot;<br>      realm=\&quot;<strong>default</strong>\&quot;,<br>      nonce=\&quot;RSRMhaQdSoMpYJWFTexUObsZ8QMvEUqoAbpFh+ys\&quot;,<br>      qop=\&quot;auth\&quot;,<br>      charset=utf-8,<br>      algorithm=md5-sess&quot;<br>  - method:&quot;KERBEROS&quot;<br>    mechanism:&quot;GSSAPI&quot;<br>    protocol:&quot;nn&quot;<br>    serverId:&quot;mynamenode.example.com&quot;</pre><p>In the above, we can see that the server would support a password authentication through DIGEST-MD5, and that is also supports KERBEROS using GSSAPI. At this point we can only guess that the nn protocol refers to NameNode and refers to the steps that we had to figure out.</p><h4>Sending the Kerberos token</h4><p>If we are satisfied with the server’s reply, we may send out the next message, which contains the Kerberos token with which we will initiate a kerberos handshake.</p><pre>token, sessionKey := getAPR(<br>  c.kerberosClient,<br>  c.servicePrincipalName,<br>  // Get rid of the potential port contained in the address string<br>  strings.Split(c.host.address, &quot;:&quot;)[0])</pre><pre>protoState := hadoop.RpcSaslProto_INITIATE</pre><pre>pkt, err := makeRPCPacket(<br>  newSASLMessageHeader(c.clientId), // Header<br>  &amp;hadoop.RpcSaslProto{<br>      <strong>State</strong>: &amp;protoState,           // Current state<br>      // The token, composed of the service ticket <br>      // and an assorted authenticator<br>      <strong>Token</strong>: token.MechToken,<br>      // The kerberos mechanism received earlier <br>      <strong>Auths</strong>: []*hadoop.RpcSaslProto_SaslAuth{mechanism},  <br>    })</pre><p>getAPR() does the following (for which we won’t go into the details), using a <a href="https://github.com/jcmturner/gokrb5">gokrb5</a> kerberos client:</p><ul><li>fetch a TGT</li><li>fetch a service ticket</li><li>build an authenticator</li><li>marshall everything into a conforming kerberos token</li></ul><p>It also returns the session key that is to be used to authenticate and encrypt bytes with the service.</p><h4>Token Structure</h4><p>The token is composed of the following:</p><pre>type <strong>APReq</strong> struct {<br>  <strong>PVNO</strong>          <strong>int</strong>  // IANA protocol version number: 5<br>  <strong>MsgType</strong>       <strong>int</strong>  // KRB_AP_REQ(14): appl. request to server<br>  <strong>APOptions</strong>     <strong>asn1.BitString</strong>  // Options. Details in RFC 4120<br>  <strong>Ticket</strong>        <strong>Ticket</strong>  // The ticket as returned by the TGS<br>  // The authenticator,<br>  // encrypted using the key specified in the ticket<br>  <strong>Authenticator</strong> <strong>types.EncryptedData</strong> <br>}</pre><pre>// Unencrypted authenticator structure:</pre><pre>type Authenticator struct {<br>  <strong>AVNO</strong>              <strong>int</strong> // Version for the authenticator format (5)<br>  <strong>CRealm</strong>            <strong>string</strong> // Same as the one in the ticket<br>  <strong>CName</strong>             <strong>PrincipalName</strong> // Same as the one in the ticket<br>  // Checksum of the application data<br>  // that might be sent along the request. Not used here.<br>  <strong>Cksum</strong>             <strong>Checksum</strong>  <br>  // Microsecond part of the client&#39;s timestamp.<br>  <strong>Cusec</strong>             <strong>int</strong><br>  <strong>CTime</strong>             <strong>time.Time</strong> // Current time on the client&#39;s host<br>  // Optional key that can be used in place <br>  // of the session-key specified by the TGS<br>  <strong>SubKey</strong>            <strong>EncryptionKey</strong> <br>  // Optionally specify the initial sequence number, <br>  // when kerberos is used for providing message <br>  // confidentiality or  integrity<br>  <strong>SeqNumber</strong>         <strong>int</strong><br>  <strong>AuthorizationData</strong> <strong>AuthorizationData</strong> // Not used here</pre><pre>}</pre><p>The APReq is then marshalled to bytes using ASN.1.†</p><h4>Second server reply</h4><p>Up to here, things are completely standard. They become more hadoop specific when we examine the reply of the namenode:</p><pre>state: CHALLENGE<br>token: 0x050401ff000c000000000000575e85d601010000853b728d5268525a1386c19f</pre><p>We now receive a challenge from the server, and from here things get a bit tricky to the non-initiated. What is sent back is actually a GSS_Wrap token (full detail in <a href="https://tools.ietf.org/html/rfc4121#section-4.2.6.2">RFC-4121</a>). The breakdown of our received token is as follows:</p><pre><strong>0504</strong>           : Identification field. All wrap tokens start with this.<br><strong>01</strong>             : Flags. 01 means the token was sent from the context acceptor (here, the server)<br><strong>ff</strong>             : Filler byte. Should always be ff.<br><strong>000c</strong>           : EC for &quot;Extra Count&quot; field. The byte length of the authentication checksum.<br><strong>0000</strong>           : RRC for &quot;Right Rotation Count&quot;. See RFC 4121 for more details. For our purpose this can be kept to 0 at all times<br><strong>00000000575e85d6</strong> : Sender&#39;s sequence number.<br><strong>01010000</strong>       : Payload<br><strong>853b728d5268525a1386c19f</strong> : 12 bytes of authentication checksum, as specified by the EC field</pre><p>The first thing that must be done with this token is to verify its authenticity. To compute the checksum of such a token, HMAC the bytes obtained by appending the header to the body above, while setting the EC and RRC fields to 0. The header is composed of the identification field, flags, fille byte, EC and RRC fields.</p><pre>checksum = <br>    HMAC({ body | header[EC/RRC=0] }, <br>         K[GSSAPI_ACCEPTOR_SEAL])</pre><p>In our example, we have:</p><ul><li>header: 0x050401ff000c000000000000575e85d6</li><li>body: 0x01010000853b728d5268525a1386c19f</li></ul><p>With K[GSSAPI_ACCEPTOR_SEAL] being a key derived from the session key and an usage indicator (here, GSSAPI_ACCEPTOR_SEAL) reflecting the fact that the key was used by the context acceptor (the server) to authenticate a message. More details about the key derivation can be found in the code and in <a href="https://tools.ietf.org/html/rfc3961">RFC 3961</a>.</p><h4>Sending back a signed reply token</h4><p>If the computed checksum matches the one contained in the received token, we may proceed and reply with our own signed token. It needs to contain the payload sent in the server’s token:</p><pre><strong>0504</strong>         : ID header, constant as before<br><strong>00</strong>           : Flags. This time the sent by acceptor bit is set to 0<br><strong>ff</strong>           : Filler byte<strong><br>000c</strong>         : EC as before<br><strong>0000</strong>         : RRC as before<br><strong>00000000000000000</strong>  : sequence number set to 0. As we only do an authentication and won&#39;t be sending opther MIC or WRAP tokens, this is of no importance.<br><strong>1010000</strong>      : Original payload<br><strong>79a033510b6f127212242b97</strong> : checksum of the reply</pre><p>The checksum of the reply is obtained as before, except that the key is now derived using the GSSAPI_INITIATOR_SEAL usage number (24).</p><p>We can now send back this response to the server:</p><pre>protoState := hadoop.RpcSaslProto_RESPONSE</pre><pre>pkt, _ := makeRPCPacket(<br>    newSASLMessageHeader(c.clientId),<br>    &amp;hadoop.RpcSaslProto{ <br>        State: &amp;protoState,<br>        Token: replyToken,<br>    })</pre><h4>Final server reply</h4><p>Once pkt was sent, if all goes well, the server will send back a response containing only:</p><pre>state: SUCCESS</pre><p>At this point you may proceed with sending a connection context followed by your usual Hadoop RPC commands.</p><p>This may look easy enough, but it takes some time to figure it out on your own by scrawling through source code, various RFC’s and random Kerberos related blog posts.</p><p>We hope it will prove helpful to some readers. If there are any questions or remarks, please feel free to get in touch with us.</p><h4>Footnotes and References</h4><ul><li>† : For more details, please consult gokrb5’s source code at <a href="https://github.com/jcmturner/gokrb5/tree/master/gssapi">https://github.com/jcmturner/gokrb5/</a>. Look at the messages.NewAPReq() function specifically</li><li><a href="https://tools.ietf.org/html/rfc4120">https://tools.ietf.org/html/rfc4120</a></li><li><a href="https://tools.ietf.org/html/rfc4121">https://tools.ietf.org/html/rfc4121</a></li><li><a href="https://tools.ietf.org/html/rfc2744">https://tools.ietf.org/html/rfc2744</a></li><li><a href="https://tools.ietf.org/html/rfc3961">https://tools.ietf.org/html/rfc3961</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c56746ddb290" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sqooba/a-close-look-at-a-kerberos-handshake-authenticate-to-a-hadoop-namenode-via-hrpc-c56746ddb290">A close look at a kerberos handshake –authenticate to a Hadoop Namenode via HRPC</a> was originally published in <a href="https://medium.com/sqooba">Sqooba</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Making HDFS a hundred times faster*]]></title>
            <link>https://medium.com/sqooba/making-hdfs-a-hundred-times-faster-ac75b8b5e0b4?source=rss-c81ac418358c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac75b8b5e0b4</guid>
            <category><![CDATA[hadoop]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[kerberos]]></category>
            <category><![CDATA[hdfs]]></category>
            <dc:creator><![CDATA[Julien]]></dc:creator>
            <pubDate>Mon, 29 Jan 2018 16:51:17 GMT</pubDate>
            <atom:updated>2018-08-03T06:38:09.824Z</atom:updated>
            <content:encoded><![CDATA[<p>Okay, the title is a bit clickbaitish. Let us be more specific: are you stuck with native java based HDFS clients because the few alternatives don’t fit your needs or, specifically, because they don’t support Kerberos?</p><p>We were too, but with a little engineering we found a solution!</p><p><em>Update: our PR was merged! The </em><a href="https://github.com/colinmarc/hdfs#using-the-commandline-client-with-kerberos-authentication"><em>go HDFS client</em></a><em> now supports Kerberos out of the box!</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AjwURZxtwpw9zkI4OL-z3g.png" /><figcaption>Before: the usual duration, enough to think about 100 other things…</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SBPVJRozpiJG3oBumKcVUQ.png" /><figcaption>After: and here are your two orders of magnitude of improvement</figcaption></figure><p>Want to have such response times on your kerberized HDFS? Then read on.</p><p>The Hadoop ecosystem is wonderful. But when you quickly want to interact with, say, HDFS, for a few mundane queries (“<em>what’s the path to this file already?</em>”, “<em>did I move this to the correct place?</em>”, “<em>did my script screw up again?</em>“,…) each individual command loads up a JVM instance. This quickly leads to frustration and rising blood pressure; seconds for a simple ls? Come on this is the 21st century!</p><p>If you issue more than one HDFS command a day you will, most likely, already have looked at potential alternatives:</p><ul><li><strong>libhdfs3</strong>: everyone refers to this library, it is well maintained and supports Kerberos. However it is just that: a library. You’ll need to wrap it in your code, or look for a client that already does¹.</li></ul><p>If you want or need C/C++, the above is the way to go. Otherwise, this leaves you with a couple of other options:</p><ul><li><strong>snakebite</strong>: wonderful, written in python (though only compatible with 2.7) and easy to install anywhere!</li><li><strong>go-hdfs</strong>: easy to install and use.</li></ul><p>These two are excellent but… If you are using Kerberos for client authentication: neither <em>snakebite</em> nor <em>go-hdfs</em> currently support it. Turn off authentication? Hey! Did we already mention this is the 21st century?</p><p>At this point in our search we wondered “<em>but surely someone did write an easy to use hdfs clients that supports kerberos</em>”. Turns out we did not find any.</p><h4>Cutting a long story short</h4><p>The situation of the kerberized HDFS client landscape led us to wonder if we could improve it easily. Furthermore, we really wanted to use a Go based tool: it’s so easy to build wherever you want or to cross compile to any destination architecture. Ideal for our environment! (docker containers with a s**tload of options for our customers) as well as workstations across heterogeneous environments. A solution written in go would be a perfect addition to our arsenal.</p><p>And behold! Thanks to the power of open source, all we needed to do was combine two existing tools:</p><ul><li>A good, pure Go, hdfs clients: <a href="https://github.com/colinmarc/hdfs">go-hfds</a>, that only lacked kerberos support</li><li>A nice, actively maintained, pure Go kerberos library: <a href="https://github.com/jcmturner/gokrb5">gokrb5</a></li></ul><p>So the plan seemed easy: just integrate one into the other!</p><p>As usual with software, nothing is ever as straightforward as it seems: we were not 100% familiar with the kerberos internals and Hadoop’s RPC protocol. So it took some time to dig through RFC’s and Java source code to understand exactly what needs to be sent when to a Namenode. (Because it turns out that most of the Kerberos guides out there generally end in “<em>just do a call to GSS_Init_sec_context() or GSS_Wrap() with the bytes and send the return value</em>”, leaving you not a bit wiser).</p><p>But we made it! (The details will be published in another blog post).</p><p>You can find the working code here: <a href="https://github.com/Sqooba/hdfs">https://github.com/Sqooba/hdfs</a></p><h4>Quick start</h4><p>As the code has not been merged back to the original go-hdfs yet, you will need to jump through a few hoops. Prerequisite: docker.</p><pre># Create folder where go binary will be built<br>mkdir go-bin</pre><pre># Inside the golang container<br>docker run -it -v $PWD/go-bin:/go/bin:rw golang bash</pre><pre># Get initial project<br>go get <a href="http://github.com/colinmarc/hdfs">github.com/colinmarc/hdfs</a></pre><pre># Replace colinmarc/hdfs with Sqooba’s<br>cd $GOPATH/src/<a href="http://github.com/colinmarc/hdfs/">github.com/colinmarc/hdfs/</a><br>git remote add sqooba <a href="https://github.com/Sqooba/hdfs.git">https://github.com/Sqooba/hdfs.git</a><br>git fetch sqooba<br>git checkout -b sqooba-master sqooba/master</pre><pre># Get all the (new) dependencies<br>go get -u <a href="http://github.com/colinmarc/hdfs">github.com/colinmarc/hdfs</a></pre><pre># Build<br>go install ./…</pre><pre># hdfs binary has been built and deployed, so you can run it<br>ls -l $GOPATH/bin<br>$GOPATH/bin/hdfs</pre><pre># Outside of the container, $PWD/go-bin/hdfs is also available.</pre><p>The hdfs binary at$GOPATH/bin/hdfs will check the default locations for your kerberos and hadoop configurations. These can be overridden via environment variables HADOOP_KRB_CONF, HADOOP_CONF_DIR.</p><p>You will need either a kinit’ed credential cache, which is expected to live at /tmp/krb5cc_$(id -u $(whoami)) — override via HADOOP_CCACHE — or a keytab specified through HADOOP_KEYTAB.</p><p>If you come from the JVM client world, you will see improvements of up to 100 times. Enough to really enjoy go-hdfs’ autocomplete feature and to stop making your cardiologist worry too much.</p><p>Next steps: merge these improvements back into the go-hdfs client, after some thorough testing.</p><p>Thanks for reading!</p><p>Update: we published a little story having <a href="https://medium.com/sqooba/a-close-look-at-a-kerberos-handshake-authenticate-to-a-hadoop-namenode-via-hrpc-c56746ddb290">a deeper look at what goes into the Kerberos handshake</a> between the client and the Namenode.</p><p>[1]: There is a C/C++ client as part of <a href="http://hawq.incubator.apache.org/">Apache HAWQ</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac75b8b5e0b4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sqooba/making-hdfs-a-hundred-times-faster-ac75b8b5e0b4">Making HDFS a hundred times faster*</a> was originally published in <a href="https://medium.com/sqooba">Sqooba</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>