Skip to content

Allow environment variables via shortcode in hugo #772

@jorgemoralespou

Description

@jorgemoralespou

Is your feature request related to a problem? Please describe.

In classic renderer one could use ENV_ prefix to use environment variables. This is not possible in hugo renderer.

Per the docs:

If using the hugo renderer there is no builtin equivalent for this feature, although you could provide your own shortcode for Hugo to use which implements it if desired.

An easy shortcode env.html can be created with this content:

{{- $name := "" }}
{{- if .IsNamedParams }}
  {{- $name = .Get "name" }}
{{- else }}
  {{- $name = .Get 0 }}
{{- end }}
{{ getenv $name }}

But then in hugo, security feature prevents from reading variables not defined in config.toml. Erroring with something like this:

Error: error building site: render: failed to render pages: render of "/opt/workshop/content/05-configure-vscode.md" failed: "/opt/eduk8s/etc/themes/educates/layouts/_default/single.html:18:13": execute of template failed: template: _default/single.html:18:13: executing "main" at <.Content>: error calling Content: "/opt/workshop/content/05-configure-vscode.md:26:13": failed to render shortcode "env": failed to process shortcode: "/opt/workshop/layouts/shortcodes/env.html:7:3": execute of template failed: template: shortcodes/env.html:7:3: executing "shortcodes/env.html" at <getenv $name>: error calling getenv: access denied: "LITELLM_API_KEY" is not whitelisted in policy "security.funcs.getenv"; the current security configuration is:

[security]
  enableInlineShortcodes = false

  [security.exec]
    allow = ['^(dart-)?sass(-embedded)?$', '^go$', '^git$', '^npx$', '^postcss$', '^tailwindcss$']
    osEnv = ['(?i)^((HTTPS?|NO)_PROXY|PATH(EXT)?|APPDATA|TE?MP|TERM|GO\w+|(XDG_CONFIG_)?HOME|USERPROFILE|SSH_AUTH_SOCK|DISPLAY|LANG|SYSTEMDRIVE)$']

  [security.funcs]
    getenv = ['^HUGO_', '^CI$']

  [security.http]
    methods = ['(?i)GET|POST']
    urls = ['.*']

Describe the solution you'd like

I would like to be able to use environment variables that are defined in the platform to render content, like it was possible in classic renderer.

Describe alternatives you've considered

No response

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    Status

    Untriaged

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions