<?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 Chopanovv on Medium]]></title>
        <description><![CDATA[Stories by Chopanovv on Medium]]></description>
        <link>https://medium.com/@chopanovv?source=rss-698d17fb9fed------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*X2HhE1AOwl8orn2a</url>
            <title>Stories by Chopanovv on Medium</title>
            <link>https://medium.com/@chopanovv?source=rss-698d17fb9fed------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 01:18:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chopanovv/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[Vault : encrypted password]]></title>
            <link>https://medium.com/@chopanovv/vault-encrypted-password-195bf125144f?source=rss-698d17fb9fed------2</link>
            <guid isPermaLink="false">https://medium.com/p/195bf125144f</guid>
            <category><![CDATA[vault]]></category>
            <category><![CDATA[kubernetes-security]]></category>
            <category><![CDATA[hashicorp-vault]]></category>
            <dc:creator><![CDATA[Chopanovv]]></dc:creator>
            <pubDate>Fri, 21 Oct 2022 07:10:44 GMT</pubDate>
            <atom:updated>2022-10-21T07:10:44.377Z</atom:updated>
            <content:encoded><![CDATA[<h3>Vault : encrypted password</h3><h3><strong>Integration between external Vault and K8 cluster with vault agent injector</strong></h3><p>In this blog post we will walk through an example of delivering database credentials from External Vault to a Kubernetes pod using the Vault Agent. We store our secrets and passwords in K8s secret! It’s not best solution! We came to a conclusion to store our secrets, env values and password in Hashicorp Vault! How i configure Vault server “I will write in the next few days” For <strong>backend storage i </strong>used <strong>Hashicorp Consul!</strong> In this guide i made <strong>Integraration between EXTERNAL VAULT SERVER </strong>and Kubernetes Cluster! Because i didn’ t find any guide for integration between EXTERNAL VAULT server most of guides written integration between Vault in Kubernetes cluster not in <strong>external server!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1007/1*onrtp0uGRf2jPZL_6rTn-w.png" /></figure><h3>Create a service account</h3><ol><li>In Kubernetes, a <strong>service account</strong> provides an identity for processes that run in a Pod so that the processes can contact the API server. Open the provided vault-auth-service-account.yaml file in your preferred text editor and examine its content for the service account definition to be used for this tutorial</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*sjNz6OKz7qPYvcIV5egILQ.png" /><figcaption>vault-auth-service-account.yaml</figcaption></figure><p>2. Create the vault-auth service account.</p><pre>kubectl apply --filename vault-auth-service-account.yaml</pre><h3>Kubernetes 1.24+ only</h3><p>The service account generated a secret that is required for configuration automatically in Kubernetes 1.23. In Kubernetes 1.24+, you need to create the secret explicitly</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*J0ReD-HEaIra5u2kC3D_nQ.png" /><figcaption>vault-auth-secret.yaml</figcaption></figure><p>Create a vault-auth-secret secret.</p><pre>kubectl apply --filename vault-auth-secret.yaml</pre><h3>Configure Kubernetes auth method in <strong>Vault server!</strong></h3><p>3. Create a read-only policy, secret-kv-ro in Vault.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*FJS7yyH1F1pk_R2nvu9mmg.png" /></figure><p>4. Create some test data at the secret/myapp path.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*d5Xt5GOTwMl71Ym0LwbHHg.png" /></figure><figure><img alt="Output:" src="https://cdn-images-1.medium.com/max/394/1*mCCDNmNs4jQGLK2DBzul9A.png" /><figcaption>Output:</figcaption></figure><p>5. Set the environment variables to point to the running K8s custer environment in Vault Server</p><p><strong>Set the SA_SECRET_NAME environment variable value to the vault-auth service account secret.</strong></p><pre><strong>export SA_SECRET_NAME=$(kubectl get secrets --output=json \     | jq -r &#39;.items[].metadata | select(.name|startswith(&quot;vault-auth-&quot;)).name&#39;)</strong></pre><p><strong>Set the SA_JWT_TOKEN environment variable value to the service account JWT used to access the TokenReview API</strong></p><pre><strong>export SA_JWT_TOKEN=$(kubectl get secret $SA_SECRET_NAME \<br>    --output &#39;go-template={{ .data.token }}&#39; | base64 --decode)</strong></pre><p><strong>Set the SA_CA_CRT environment variable value to the PEM encoded CA cert used to talk to Kubernetes API.</strong></p><pre><strong>export SA_CA_CRT=$(kubectl config view --raw --minify --flatten \     --output &#39;jsonpath={.clusters[].cluster.certificate-authority-data}&#39; | base64 --decode)</strong></pre><p>Set the K8S_HOST environment variable value to K8s cluster IP address.</p><pre><strong>export K8S_HOST=$(kubectl config view --raw --minify --flatten \     --output &#39;jsonpath={.clusters[].cluster.server}&#39;)</strong></pre><h3>Now, enable and configure the Kubernetes auth method in external Vault server</h3><p>Enable the Kubernetes auth method at the default path (“auth/kubernetes”).</p><pre><strong>vault auth enable kubernetes</strong></pre><p>Tell Vault how to communicate with the Kubernetes cluster.</p><pre><strong>vault write auth/kubernetes/config \ <br>     token_reviewer_jwt=&quot;$SA_JWT_TOKEN&quot; \     <br>     kubernetes_host=&quot;$K8S_HOST&quot; \      <br>     kubernetes_ca_cert=&quot;$SA_CA_CRT&quot;</strong></pre><p><strong>Output:</strong></p><p>Success! Data written to: auth/kubernetes/config</p><p>Create a role named, example, that maps the Kubernetes Service Account to Vault policies and default token TTL.</p><pre><strong>vault write auth/kubernetes/role/example \ <br>     bound_service_account_names=vault-auth \  <br>     bound_service_account_namespaces=default \      <br>     policies=myapp-kv-ro \  <br>     ttl=24h</strong></pre><p><strong>Output:</strong></p><p>Success! Data written to: auth/kubernetes/role/example</p><h3>Start Vault Agent with Auto-Auth</h3><p>Now that you have verified that the Kubernetes auth method has been configured on the Vault server, it is time to spin up a client Pod which leverages Vault Agent to automatically authenticate with Vault and retrieve a client token.</p><ol><li>First, open the provided configmap.yaml file in your preferred text editor and review its content</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/657/1*3jIyflmyRjBs5tk-ZloG9A.png" /><figcaption>configmap.yaml</figcaption></figure><p>This creates a Vault Agent configuration file, vault-agent-config.hcl. Notice that the Vault Agent Auto-Auth (<strong>auto_auth</strong> block) is configured to use the kubernetes auth method enabled at the auth/kubernetes path on the external Vault <strong>server</strong>. The Vault Agent will use the example role which you created in up!</p><p>The sink block specifies the location on disk where to write tokens. Vault Agent Auto-Auth sink can be configured multiple times if you want Vault Agent to place the token into multiple locations. In this example, the sink is set to [/home/vault/.vault-token]</p><p>Finally, the <strong>template</strong> block creates a templated file which retrieves username and password values at the secret/data/myapp/config path.</p><ol><li>Create a ConfigMap containing a Vault Agent configuration.</li></ol><pre><strong>kubectl create --filename configmap.yaml</strong></pre><p>2. View the created ConfigMap.</p><pre><strong>kubectl get configmap example-vault-agent-config --output yaml</strong></pre><p>3. An example Pod spec file is provided. Review the provided example Pod spec file, example-k8s-spec.yaml</p><figure><img alt="example-k8s-spec.yamlexample-k8s-spec.yaml" src="https://cdn-images-1.medium.com/max/646/1*FDA0pvA350OoCK2NQY2LmA.png" /></figure><p>The example Pod spec (example-k8s-spec.yaml) spins up two containers in vault-agent-example pod. A <a href="https://hub.docker.com/_/vault/">vault</a> container which runs Vault Agent as an <a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/">Init Container</a>. And an nginx container exposing port 80.</p><h3>Check username and password is correctly recieved!</h3><p>Execute pod shell</p><pre>kubectl exec -it vault-agent-example --container nginx-container -- cat /usr/share/nginx/html/index.html</pre><p>💡 Output</p><pre>&lt;html&gt;<br>&lt;body&gt;<br>&lt;p&gt;Some secrets:&lt;/p&gt;<br>&lt;ul&gt;<br>&lt;li&gt;&lt;pre&gt;username: appuser&lt;/pre&gt;&lt;/li&gt;<br>&lt;li&gt;&lt;pre&gt;password: suP3rsec(et!&lt;/pre&gt;&lt;/li&gt;<br>&lt;/ul&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>For more information: <a href="https://learn.hashicorp.com/tutorials/vault/agent-kubernetes?in=vault/vault-agent">https://learn.hashicorp.com/tutorials/vault/agent-kubernetes?in=vault/vault-agent</a></p><p>You can use this guide for <strong>PRODUCTION </strong>we tested already and using this method for keeping our password!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=195bf125144f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>