<p>Updating my CSI Secrets Store Driver as it is outlined here:</p>
<p><a href="https://learn.microsoft.com/en-us/azure/aks/csi-secrets-store-driver" rel="nofollow noreferrer">https://learn.microsoft.com/en-us/azure/aks/csi-secrets-store-driver</a></p>
<p>I had it previously working by usign <code>secretObjects</code> which I accomplished with:</p>
<pre><code>apiVersion: secrets-store.csi.x-k8s.io/v1
kind: SecretProviderClass
metadata:
  name: aks-akv-secret-provider
spec:
  provider: azure
  secretObjects:
  - secretName: myapp-prod-secrets
    type: Opaque
    data:
    - objectName: SENDGRID-API-KEY
      key: SENDGRID_API_KEY
  parameters:
    usePodIdentity: &quot;true&quot;                                        
    keyvaultName: myappakvprod
    cloudName: &quot;&quot;                               
    objects: |
      array:
        - |
            objectName: SENDGRID-API-KEY             
            objectType: secret                 
            objectVersion: &quot;&quot;  
    tenantId: $tenantId
</code></pre>
<p>In the manifest for the API for example I would:</p>
<pre><code>...
  env:
    - name: SENDGRID_API_KEY
      valueFrom:
        secretKeyRef:
          name: myapp-prod-secrets
          key: SENDGRID_API_KEY
  volumeMounts:
    - name: secrets-store01-inline
      mountPath: /mnt/secrets-store
      readOnly: true
volumes:
  - name: secrets-store01-inline
    csi: 
      driver: secrets-store.csi.k8s.io
      readOnly: true
      volumeAttributes:
        secretProviderClass: aks-akv-secret-provider
...
</code></pre>
<p>And then in the code I would just do something like and it would work:</p>
<pre><code>EMAIL_KEY = os.environ['SENDGRID_API_KEY']
</code></pre>
<p>Basically, it is mounting the AKV secrets to the Pod and then creating Kubernetes secret environmental variables.</p>
<p>However, this method in the documentation seems like an after thought (&quot;You might sometimes...&quot; as opposed to &quot;you must&quot;):</p>
<p><a href="https://learn.microsoft.com/en-us/azure/aks/csi-secrets-store-driver#sync-mounted-content-with-a-kubernetes-secret" rel="nofollow noreferrer">https://learn.microsoft.com/en-us/azure/aks/csi-secrets-store-driver#sync-mounted-content-with-a-kubernetes-secret</a></p>
<p>I interpret this as indicating that simply mounting the secrets to the Pod is sufficient and that creating Kubernetes secrets of them is extraneous.</p>
<p>My question is this:</p>
<p><strong>If you are just mounting the secrets to the Pod, how should you access them from the application code if they aren't environmental variables?</strong></p>
<p>They can be accessed with:</p>
<pre><code>kubectl exec busybox-secrets-store-inline -- cat /mnt/secrets-store/ExampleSecret
</code></pre>
<p>So I'd imagine in Python, JavaScript, etc. you could do what ever the analogous command is to read in the secret instead of <code>os.environ['ExampleSecret']</code>. But if you aren't mounting secrets the same way in local development, there's disparity in the code base.</p>
<p>Just looking for clarification on this.</p>

cjones
<p>If you just mount the secrets to the pod, the secrets will be available as files on the mount location</p>
<ul>
<li><strong>The filename</strong> will be the name of the secret (or an alias you specify in the secret provider class)</li>
<li><strong>The content</strong> of the file will be the secret value.</li>
</ul>
<p>To access and use the secrets in your code you would need to read the files to retrieve the secret values. Many frameworks have built in functionality for mapping such structures into configuration objects, for example in .NET there is the <a href="https://learn.microsoft.com/en-us/dotnet/core/extensions/configuration-providers#key-per-file-configuration-provider" rel="nofollow noreferrer">Key-per-file configuration provider</a></p>
<blockquote>
<p>But if you aren't mounting secrets the same way in local development, there's disparity in the code base.</p>
</blockquote>
<p>Yes that is correct, and would be true for anything you do different in development and production. If you want to avoid disparities, use the same mechanism for providing secret values to the application in both development and production, either through environment variables or through files.</p>
