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

vault template stanza exec object appears to not parse correctly #16230

Closed
johnalotoski opened this issue Jul 6, 2022 · 4 comments · Fixed by #16231
Closed

vault template stanza exec object appears to not parse correctly #16230

johnalotoski opened this issue Jul 6, 2022 · 4 comments · Fixed by #16231
Labels
agent bug Used to indicate a potential bug

Comments

@johnalotoski
Copy link

johnalotoski commented Jul 6, 2022

The vault documentation for a template stanza describes the exec declaration as:

[exec](https://www.vaultproject.io/docs/agent/template#exec) (object: optional) - 
The exec block executes a command when the template is rendered and the output has changed. 
The block parameters are command (string slice: required) and timeout (string: optional, defaults to 30s).

For vault v1.11.0 with consul-template 0.29.0, the consul template config docs show the exec hcl block example as:

template {

  # ...

  # This is the optional exec block to give a command to be run when the template 
  # is rendered. The command will only run if the resulting template changes. 
  # The command must return within 30s (configurable), and it must have a 
  # successful exit code.
  # See the Exec section below and the Commands section in the README for more.
  exec {
      command = ["restart", "service", "foo"]
      timeout = "30s"
  }
}

The JSON equivalent (what we are using for config submission to vault-agent) for the exec block should be:

      ...
      "exec": [
        {
          "command": [
            "restart",
            "service",
            "foo"
          ],
          "timeout": "30s"
        }
      ],
      ...

However, this JSON produces the error:

Error loading configuration from $FILE.json: error parsing 'template': 1 error(s) decoding:

* 'exec' expected a map, got 'slice'

I cannot seem to change the JSON in any manner to get the exec declaration to parse correctly.
Another user independently reported the same issue in the hashicorp discussion channel here.

For now, falling back to use of the deprecated command (string) is a workaround.

Environment:
Vault v1.11.0 (ea296cc), built 2022-06-17T15:48:44Z
NixOS, x86_64-linux

@heatherezell heatherezell added agent bug Used to indicate a potential bug labels Jul 6, 2022
@jasonodonnell
Copy link
Contributor

jasonodonnell commented Jul 6, 2022

@johnalotoski Can you try this format for exec?

  "Templates": [
    {
      "Destination": "/path/on/disk/where/template/will/render.txt",
      "Exec": {
        "Command": [
          "test"
        ],
      },
      "Source": "/path/on/disk/to/template.ctmpl"
    }
  ]

@johnalotoski
Copy link
Author

Hi @jasonodonnell, thanks for the fast response!

Testing with that verbatim (and removing the extra comma after the command list in the exec object), I receive:

[ERROR] runtime error encountered: error="template server failed to create: template: must specify exactly one of 'source' or 'contents'"

However, "Source" is definitely included, as shown above.

It seems, though, that I should be using singular "Template" which if I only change Templates to Template from the above (with the removal of the extra comma) then I receive the same error as reported:

* 'exec' expected a map, got 'slice'

If I modify both the Templates to singular, and revert to the deprecated command declaration instead of exec, it parses properly:

  "Template": [
    {
      "Destination": "/path/on/disk/where/template/will/render.txt",
      "Command": "test",
      "Source": "/path/on/disk/to/template.ctmpl"
    }
  ]

@jasonodonnell
Copy link
Contributor

@johnalotoski This turned out to be a bug, so I opened a PR to fix it. Thanks and hope this helps!

@johnalotoski
Copy link
Author

Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent bug Used to indicate a potential bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants