Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mount key values from json/yaml secret files #169

Open
splasharun opened this issue May 4, 2022 · 3 comments
Open

Mount key values from json/yaml secret files #169

splasharun opened this issue May 4, 2022 · 3 comments
Labels

Comments

@splasharun
Copy link

splasharun commented May 4, 2022

Hi, is there any way now where I can directly mount key values from a json/yaml file as individual objects? I guess this will be helpful when mounting values to k8s secrets.

The options that I have right now are

  1. To hold individual values in my gsm secret and consume that.
  2. Mount a whole json file inside the pod and parse the key values using some postStart script.

I was wondering if there was any straightforward way to do this.
In other providers(aws) I've seen them use jmespath to get values from json files, can we do something similar.

- resourceName: "projects/$PROJECT_ID/secrets/secret"
  path: "secret.json"
  keys:
    - keyPath: "key_0.key_1"      //jmespath
      alias: "key1"               //name/path to be mounted

I guess we can extend this for tls certificates and other usecases too.
Also, I'd be happy to contribute to this.
Thanks.

@tam7t
Copy link
Contributor

tam7t commented May 27, 2022

Sorry for delay response. I'm not sure I understand your example yaml there. The path parameter is the relative file path within the mount where you want data to be written.

Considering a secret in secret manager with the contents:

{
  "key_0": {
    "key_1": "my super secret"
  }
}

You're looking to have the result of the SecretProviderClass be a file on disk at <mount path>/key1 with contents my super secret, is that the case?

If so I think we'd want to make the format a bit more like:

- resourceName: "projects/$PROJECT_ID/secrets/secret/versions/latest"
  path: "key1"
  extract:
    jsonpath: ".key_0.key_1"

This would leave open the possibility of different types of extraction methods depending on the format of the secret (i.e. xml values, yaml secret, etc) and match the current semantics of path meaning the location to write data.

A downside with this may be that to extract/map multiple keys from a secret to separate files would involve a lot of repetition.

- resourceName: "projects/$PROJECT_ID/secrets/secret/versions/latest"
  path: "cert.pem"
  extract:
    jsonpath: ".cert"
- resourceName: "projects/$PROJECT_ID/secrets/secret/versions/latest"
  path: "key.pem"
  extract:
    jsonpath: ".key'"

Maybe something with:

- resourceName: "projects/$PROJECT_ID/secrets/secret/versions/latest"
  extract:
  - jsonpath: ".cert"
    path: "cert.pem"
  - jsonpath: "key.pem"
    path: "key.pem"

where the top level path is left empty when an extract is used, and the format of the extract is a tuple of where in the content json to extra data and the file path to write it to, and allow multiple extract operations.

Am I understanding this request correctly?

@tam7t
Copy link
Contributor

tam7t commented May 27, 2022

Thinking about it now, I believe we had some talk in the community call a few weeks ago about splitting out the jsonpath functionality of kubernetes-sigs/secrets-store-csi-driver#820 from the secret syncing. If that was done then it may address this feature request without changes to the provider.

cc @manedurphy

@vitordeap
Copy link

vitordeap commented Jan 3, 2023

Upvote!!
Please, this will be amazing to have

UPDATE:
Just found out about #963

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants