<?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 Shatrugna Sadhu on Medium]]></title>
        <description><![CDATA[Stories by Shatrugna Sadhu on Medium]]></description>
        <link>https://medium.com/@vansadhu?source=rss-e1f5605d4a8d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*USbgdPSlWtLl1Ofo.png</url>
            <title>Stories by Shatrugna Sadhu on Medium</title>
            <link>https://medium.com/@vansadhu?source=rss-e1f5605d4a8d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 19:11:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vansadhu/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[Kubernetes API Aggregation Setup — Nuts & Bolts]]></title>
            <link>https://medium.com/@vansadhu/kubernetes-api-aggregation-setup-nuts-bolts-733fef22a504?source=rss-e1f5605d4a8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/733fef22a504</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[aggregation]]></category>
            <category><![CDATA[aggregation-api]]></category>
            <category><![CDATA[delegated-authentication]]></category>
            <dc:creator><![CDATA[Shatrugna Sadhu]]></dc:creator>
            <pubDate>Mon, 20 Aug 2018 00:15:18 GMT</pubDate>
            <atom:updated>2018-08-20T00:15:18.584Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RbiXi_oarNMOixKGL88rTA.jpeg" /></figure><p>This article takes a stab at uncovering some of the details associated with the control flows that occur when one deploys an <a href="https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/apiserver-aggregation/">extension apiserver with the aggregation layer</a>.</p><p>Concepts/Keywords:</p><ul><li><strong>extension-apiserver</strong>: API servers written using the library <a href="https://github.com/kubernetes/apiserver">kube-apiserver</a>. Provides a way of defining custom APIs that are deeply integrated with core Kubernetes API machinery. <a href="https://docs.google.com/document/d/1y16jKL2hMjQO0trYBJJSczPAWj8vAgNFrdTZeCincmI/edit#heading=h.qzaj1hoslggu">Compared</a> to <a href="https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/">CRDs</a>, it offers more features and options for dealing with performance, policy and customization.</li><li><strong>kube-aggregator</strong>: It is the controller associated with apiregistration API and constitutes what we call the aggregation layer. It is responsible for discovering and registering extension apiservers and acting as a <strong>front-proxy</strong> to the individual extension apiservers.</li><li><strong>delegated authN/Z</strong>: The mechanism where-in API calls to the extension-apiserver are authenticated &amp; authorized by the core kubernetes apiserver (kubernetes master)</li></ul><p>For the purposes of demo, I will use the kubernetes <a href="https://github.com/kubernetes/sample-apiserver">sample-apiserver</a> and the various deployment yamls it presents to illustrate the various control flow variables as well.</p><p>Lets say you have built the extension-apiserver <a href="https://github.com/kubernetes/sample-apiserver/tree/release-1.11">sample-apiserver</a>; it comes with the custom resources Flunder &amp; Fischer under the wardle.k8s.io apigroup. You then deploy this alongside a kubernetes master, that has the aggregation layer configured, using the provided <a href="https://github.com/kubernetes/sample-apiserver/tree/master/artifacts/example">example artifacts</a> (kubectl apply -f artifcats/example). And it all just works!</p><p>kubectl get wardle.k8s.io/flunder ; kubectl get wardle.k8s.io/fischer</p><blockquote><em>But, what does having the “aggregation layer” configured mean? What do the “example” artifacts exactly set and enable? And how does the delegated authentication and authorization work?</em></blockquote><p>Exactly what I will look to answer.</p><h4>Primer on Authentication mechanisms</h4><p>Before going further with the control flows associated with an extension-apiserver deployment, its essential to clear some concepts around the three primary authentication mechanisms that make up an extension-apiservers delegated authentication setup:</p><p><strong>Client Certificate Authentication</strong>: In this mechanism, the client sends a certificate signed by a CA that the server trusts for validating the identity of the client.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/1*ApcjnpNoQjom6jwVQ6Fb1A.png" /></figure><p>The server request authentication decorator could read something like the below if it were <a href="https://stackoverflow.com/questions/31751764/get-remote-ssl-certificate-in-golang">written in Go</a>:</p><pre>func renewCert(w http.ResponseWriter, r *http.Request) {<br><br>  if r.TLS != nil &amp;&amp; len(r.TLS.PeerCertificates) &gt; 0 {<br>    cn := strings.ToLower(r.TLS.PeerCertificates[0].Subject.CommonName)<br>    fmt.Println(&quot;CN: %s&quot;, cn)<br>  }<br><br>}</pre><p><strong>Delegated Token Authentication: </strong>In this mechanism, the server extracts the Token present in Authorization: Bearer Token $TOKEN from the HTTP Request and forwards it for a review onto a different server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*dATT8mvsCr2SGealf4oAbA.png" /></figure><p>In case of an extension-apiserver, the Token is sent for a TokenReview to the master Kubernetes API server.</p><p><strong>RequestHeader Client Authentication: </strong>In this mechanism, there is a proxy in play, that is responsible for authenticating an API call before it makes to the apiserver.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*8pC4uzRjN7enOWXb9d0zRg.png" /></figure><p>From the apiserver’s point of view, the requests are coming in from the proxy, but it <strong>trusts</strong> the proxy to masquerade as any other user. This masquerading takes place via HTTP Header set by the proxy (e.g. X-Remote-User).</p><p>Now, lets look at the control flows and configurations associated with deploying an extension-apiserver with the kube-aggregator.</p><h4><strong>Registering an extension-API server</strong></h4><p><a href="https://github.com/kubernetes/sample-apiserver/blob/release-1.11/artifacts/example/apiservice.yaml">APIService</a> resource under the group apiregistraion.k8s.io/v1beta1, serviced by the kube-aggregator controller, is the API used for registering extension apiserver. Following is the spec used for sample-apiserver:</p><pre>apiVersion: apiregistration.k8s.io/v1beta1<br>kind: APIService<br>metadata:<br>  name: v1alpha1.wardle.k8s.io<br>spec:<br>  <strong>insecureSkipTLSVerify: true</strong><br>  group: wardle.k8s.io<br>  groupPriorityMinimum: 1000<br>  versionPriority: 15<br>  service:<br>    name: <a href="https://github.com/kubernetes/sample-apiserver/blob/release-1.11/artifacts/example/service.yaml">api</a><br>    namespace: wardle<br>  version: v1alpha1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/921/1*bWul8y0nbcBLXCQeIaIuwA.png" /></figure><p>When the above APIService resource is created, kube-aggregator, which lives inside of the kube-apiserver, as part of the registration and discovery process, initiates a TLS enabled HTTP2 connection with the sample-apiserver. This HTTP2 transport, going forward, is used for the purposes of <strong>proxying authenticated</strong> user requests onto the sample-apiserver. i.e. the<strong> kube-aggregator </strong>is setup to perform <strong>RequestHeader Client Authentication</strong>.</p><h4>Configuring the Aggregator</h4><p>Lets look at the flags that need to be setup for the kube-aggregator to perform RequestHeader Authentication. This is also what primarily constitutes the <a href="https://kubernetes.io/docs/tasks/access-kubernetes-api/configure-aggregation-layer/">aggregation layer setup</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*qv9ngKdGQcVdEzhY39Y9Dg.png" /></figure><p>proxy-client-cert-file &amp; proxy-client-key-file contain the cert/key pair used by the Aggregator to perform Client Certificate Authentication with an extension-apiserver.</p><blockquote><em>But who/what signs the Client/Aggregator certificate? And how is the extension-apiserver configured to verify with this Client CA?</em></blockquote><p>The Aggregator certificate is signed using the CA file specified in requestheader-client-ca-file .</p><p>requestheader-allowed-names carry a list of identities/names (CN used in the Client Certificate) that are allowed to act as a masquerading front-proxy.</p><p>requestheader-username-headers, requestheader-group-headers &amp; requestheader-extraheaders-prefix carry a list of HTTP headers that will carry the remote user information and more.</p><p>The various requestheader-* variables are shared with the extension-apiserver using the extension-apiserver-authentication configMap. On startup, the extension-apiserver reads the said configMap to obtain the CA file to verify the identity of the Aggregator proxy and process the remote client identity variables.</p><pre>Note: Since, Kubernetes by default is setup with RBAC, the sample-apiserver&#39;s <a href="https://github.com/kubernetes/sample-apiserver/blob/release-1.11/artifacts/example/sa.yaml">ServiceAccount</a> needs to be bound to the extension-apiserver-authentication-reader. <a href="https://github.com/kubernetes/sample-apiserver/blob/release-1.11/artifacts/example/auth-reader.yaml">Here&#39;s</a> the yaml which does it.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*mkaLbGPNL3YBV3fOzGEN7w.png" /></figure><blockquote>What does the extension apiserver do with the remote client info obtained off the various requestheaders?</blockquote><p>Once, the identity is obtained, the extension apiserver uses it perform a delegated authorization on the request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*GOiKAFkCVmflB3zq3K5zTQ.png" /></figure><pre>Note: The following <a href="https://github.com/kubernetes/sample-apiserver/blob/release-1.11/artifacts/example/auth-delegator.yaml">role binding</a> is needed for the extension-apiserver to perform a authN/Z delegation request. </pre><p>And, that, pretty much sums up the Aggregation Layer.</p><h4>Setting the extension-apiserver Cert</h4><p>In the APIService object, insecureSkipTLSVerify is set to true. Meaning, the client (kube-aggregator) will skip verifying the identity of the extension-apiserver. It is recommended that we set this to false and the cabundle field in the spec is set to the base-64 encoded CA cert that was used to sign the extension-apiserver certificate. The kube-aggregator will then use the cabundle to verify the sample-apiserver certificate.</p><pre>Note: Make sure to mount the signed cert/key onto the extension-apiserver <a href="https://github.com/kubernetes/sample-apiserver/blob/release-1.11/artifacts/example/rc.yaml">Pod</a>. The path used for reading the cert/key pair is as set in the argument --cert-dir to the apiserver which currently defaults to `/apiserver.local.config/certificates`. <br>One could also, instead, use the flags --tls-cert-file and --tls-private-key to set the cert/key for the apiserver.</pre><h4><em>References:</em></h4><ol><li><a href="https://kubernetes.io/docs/tasks/access-kubernetes-api/setup-extension-api-server/"><em>https://kubernetes.io/docs/tasks/access-kubernetes-api/setup-extension-api-server/</em></a></li><li><a href="https://kubernetes.io/docs/tasks/access-kubernetes-api/configure-aggregation-layer/"><em>https://kubernetes.io/docs/tasks/access-kubernetes-api/configure-aggregation-layer/</em></a></li><li><a href="https://github.com/kubernetes-incubator/apiserver-builder/blob/master/docs/concepts/auth.md"><em>https://github.com/kubernetes-incubator/apiserver-builder/blob/master/docs/concepts/auth.md</em></a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=733fef22a504" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>