Skip to content

Unescape Jinja block tags in credential type injectors - #249

Open
blaipr wants to merge 1 commit into
ctrliq:mainfrom
blaipr:fix-injectors-jinja-block-escaping
Open

Unescape Jinja block tags in credential type injectors#249
blaipr wants to merge 1 commit into
ctrliq:mainfrom
blaipr:fix-injectors-jinja-block-escaping

Conversation

@blaipr

@blaipr blaipr commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Summary

An author writes { { in an injector so the expression survives the role's own templating, and the role turns it back into {{ before the call. There was no matching rule for { %, so a credential type using {% if %} or {% for %} in an injector was created with the literal spaced form and the block never ran on the controller.

  | regex_replace('{  {', '{_~~remove~~_{')
+ | regex_replace('{  %', '{_~~remove~~_%')
  | regex_replace('_~~remove~~_', '')

Note on #242

#242 rewrites this same expression, to stop the omit placeholder reaching the module. The two touch the same line and will conflict textually; whichever lands first, the other is a one line rebase. They are separate bugs, so they are separate pull requests.

Upstream applied this only to injectors, and I kept to that. notification_templates.messages carries the same { { rule and no { % rule, but a notification message body is not a place a block tag is expected, so extending it there would be a change on our own account rather than a port.

Upstream

Matches 4e861af5 in redhat-cop/infra.aap_configuration (their #1341), the repository this role derives from.

Type of Change

  • Bug fix
  • New feature or enhancement
  • Breaking change
  • Documentation / tooling

Component

The credential_types role, injectors.

Checklist

  • Sanity tests pass (ansible-test sanity) — not run, this changes a role only, no plugin or module code
  • Linting passes (ansible-lint production profile, yamllint, antsibull-changelog lint)
  • Changelog fragment added (if user-facing change)
  • Documentation updated (if applicable)

An author writes {  { in an injector so the expression survives the
role's own templating, and the role turns it back into {{ before the
call. There was no matching rule for {  %, so a credential type using
{% if %} or {% for %} in an injector was created with the literal spaced
form and the block never ran on the controller.

Add the same treatment for {  %.

This matches the fix upstream in redhat-cop/infra.aap_configuration,
commit 4e861af5, which this role derives from.
@ciq-it-service-account

ciq-it-service-account commented Aug 26, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@cigamit cigamit self-assigned this Aug 27, 2026
@cigamit cigamit added bug Something isn't working needs triage Needs some work labels Aug 27, 2026
@cigamit
cigamit requested a lite review from Copilot August 27, 2026 03:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes credential type injectors preprocessing so authors can escape Jinja block tags ({% ... %}) using the spaced form ({ %) to survive role templating, and have it correctly restored before sending to the controller (matching upstream behavior).

Changes:

  • Add an unescape rule for { %{% alongside the existing { {{{ rule in the credential_types role injector handling.
  • Add a changelog fragment documenting the bugfix and its impact.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
roles/credential_types/tasks/main.yml Adds { % unescape via regex_replace so block tags in injectors are restored before the module call.
changelogs/fragments/fix-injectors-jinja-block-escaping.yml Documents the bugfix in the changelog fragment format.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working needs triage Needs some work

Development

Successfully merging this pull request may close these issues.

4 participants