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

Better error handling with templates #90

Open
vickicello opened this issue May 30, 2023 · 0 comments
Open

Better error handling with templates #90

vickicello opened this issue May 30, 2023 · 0 comments

Comments

@vickicello
Copy link
Contributor

The Issue

Currently, if you try to template an individual secret object by parsing it out of a JSON file returned by all-secrets kind, and that individual secret doesn't exist in the JSON, AKVA will panic and fail. For example:

    resources:
      - kind: all-secrets
        vaultBaseURL: https://my-testing.vault.azure.net/
    sinks:
      - path: secrets.json
        template: "{{ index .Secrets | toValues | toJson }}"
      - path: testcert.pem
        template: '{{ index .Secrets "testcert" | fullChain }}' # testcert.pem does not exist in secrets.json

...

AKVA logs show the following:

{"_timestamp":"2023-05-25T13:16:21-04:00","level":"fatal","msg":"Caught Panic In Worker: Error executing template: {{ in
dex .Secrets \"testcert\" | fullChain }} Error: template: template:1:43: executing \"template\" at 'ful
lChain': error calling fullChain: runtime error: invalid memory address or nil pointer dereference"}

Proposed Solution

We should update this code to loop through the resource sinks twice. The first pass will render all of the templates, and if a template fails, AKVA should bail out (but not crash). If all templated items render correctly in the first loop, then AKVA should write them all in the second loop.

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

No branches or pull requests

1 participant