Skip to content

Comments

Add sprig function library for templating#1542

Merged
alemorcuq merged 1 commit intobitnami-labs:mainfrom
jfly:add-sprig
Jun 10, 2024
Merged

Add sprig function library for templating#1542
alemorcuq merged 1 commit intobitnami-labs:mainfrom
jfly:add-sprig

Conversation

@jfly
Copy link
Contributor

@jfly jfly commented Jun 7, 2024

This fixes #1534 and #1193.

Description of the change

Add sprig function library for templating

Benefits

As described in #1534, this lets people safely generate more types of configuration (such as yaml files) and safely and correctly escape passwords.

Possible drawbacks

I have not removed env, expandenv, and getHostByName, as argocd does. I supposed there's some security concern here? Happy to filter them out if folks like.

Applicable issues

Additional information

Thanks for the consideration!

Copy link
Contributor

@alemorcuq alemorcuq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jfly ! Could you please run go mod tidy? I'm pretty sure sprig should not be an indirect dependency.

@jfly
Copy link
Contributor Author

jfly commented Jun 7, 2024

Oh yikes. Sorry, I am a complete go noob. sprig should definitely not be an indirect dependency. Fixed!

@jfly jfly requested a review from alemorcuq June 7, 2024 15:56
@alemorcuq alemorcuq merged commit 36e6308 into bitnami-labs:main Jun 10, 2024
@alemorcuq
Copy link
Contributor

Thanks @jfly !

@jfly jfly deleted the add-sprig branch June 11, 2024 22:19
alvneiayu pushed a commit that referenced this pull request Mar 27, 2025
…nctions (#1703)

<!--
Before you open the request please review the following guidelines and
tips to help it be more easily integrated:

 - Describe the scope of your change - i.e. what the change does.
 - Describe any known limitations with your change.
- Please run any tests or examples that can exercise your modified code.

Thank you for contributing! We will try to test and integrate the change
as soon as we can, but be aware we have many GitHub repositories to
manage and can't immediately respond to every request. There is no need
to bump or check in on a pull request (it will clutter the discussion of
the request).

Also don't be worried if the request is closed or not integrated
sometimes the priorities of Bitnami might not match the priorities of
the pull request. Don't fret, the open source community thrives on forks
and GitHub makes it easy to keep your changes in a forked repo.
 -->

**Description of the change**

Fixing potential controller environment exposure by removing some sprig
template functions:
- `env`, `expandenv` - controller environment variables exposure (which
can contain sensitive data)
- `getHostByName` - add possibility to resolve dns entries from
templates, which is not secure in some cases

This potential exposure is added by PR #1542 where security risks was
described in "possible drawbacks" section.

Also, sprig func map is now initialized due module initialization and
reusing for rendering, which may improve performance.

In fact is just port of the
[argocd](https://github.com/argoproj/argo-cd/blob/v2.11.3/applicationset/utils/utils.go#L31-L34)
solution, which described in initial PR #1542

**Benefits**

- Fix potential controller sensitive data exposure
- Improve rendering performance

**Possible drawbacks**

No one

**Applicable issues**

<!-- Enter any applicable Issues here (You can reference an issue using
#) -->

**Additional information**

<!-- If there's anything else that's important and relevant to your pull
request, mention that information here.-->

Signed-off-by: Artur Kraev <[email protected]>
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

Successfully merging this pull request may close these issues.

Templating support for escaping JSON/YAML values Sprig support in templates

2 participants