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

fix(config_ini): added quotes to regex tabs pattern #208

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nunesvn
Copy link

@nunesvn nunesvn commented May 22, 2023

PR progress checklist (to be filled in by reviewers)

  • Changes to documentation are appropriate (or tick if not required)
  • Changes to tests are appropriate (or tick if not required)
  • Reviews completed

What type of PR is this?

Primary type

  • [build] Changes related to the build system
  • [chore] Changes to the build process or auxiliary tools and libraries such as documentation generation
  • [ci] Changes to the continuous integration configuration
  • [feat] A new feature
  • [fix] A bug fix
  • [perf] A code change that improves performance
  • [refactor] A code change that neither fixes a bug nor adds a feature
  • [revert] A change used to revert a previous commit
  • [style] Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc.)

Secondary type

  • [docs] Documentation changes
  • [test] Adding missing or correcting existing tests

Does this PR introduce a BREAKING CHANGE?

No.

Related issues and/or pull requests

Describe the changes you're proposing

With Salt-Master 3005.1 and Salt-Minion on 3006.1, both on Debian 11, the unquoted tab was being parsed as part of the yaml structure and throwing the following error:

local:
    Data failed to compile:
----------
    Rendering SLS 'base:openssh.config_ini' failed: Illegal tab character; line 8

---
[...]
include:
  - openssh sshd_config-with-ini:
  file.replace:
    - name: /etc/ssh/sshd_config
    - pattern: ^(\w+)	+(\w)    <======================
    - repl: '\1 \2'
    - show_changes: True
    - require_in:
      - ini: sshd_config-with-ini

[...]
---

Pillar / config required to test the proposed changes

Pillar:

sshd_config:
    Banner: /etc/issue.net
    PermitRootLogin: "no"
    PasswordAuthentication: "yes"
    PermitEmptyPasswords: "no"
    HostbasedAuthentication: "no"
    MaxSessions: 10
    MaxStartups: "10:30:60"

Testing checklist

  • Included in Kitchen (i.e. under state_top).
  • Covered by new/existing tests (e.g. InSpec, Serverspec, etc.).
  • Updated the relevant test pillar.

Additional context

With Salt-Master 3005.1 and Salt-Minion on 3006.1, both on Debian 11, the unquoted tab was being parsed as part of the yaml structure and throwing the following error:


local:
    Data failed to compile:
----------
    Rendering SLS 'base:openssh.config_ini' failed: Illegal tab character; line 8

---
[...]
include:
  - openssh
sshd_config-with-ini:
  file.replace:
    - name: /etc/ssh/sshd_config
    - pattern: ^(\w+)	+(\w)    <======================
    - repl: '\1 \2'
    - show_changes: True
    - require_in:
      - ini: sshd_config-with-ini

[...]
---
@alxwr alxwr self-requested a review February 8, 2024 23:04
@@ -13,7 +13,7 @@ sshd_config-with-ini:
{%- if salt['file.contains_regex'](openssh.sshd_config, regex_search_for_tabs) %}
file.replace:
- name: {{ openssh.sshd_config }}
- pattern: {{ regex_search_for_tabs }}
- pattern: '{{ regex_search_for_tabs }}'
Copy link
Member

Choose a reason for hiding this comment

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

Good catch! But this implementation does not account for single quotes in the regular expression.

Suggested change
- pattern: '{{ regex_search_for_tabs }}'
- pattern: {{ regex_search_for_tabs | yaml_dquote }}

As documented in https://docs.saltproject.io/en/latest/topics/jinja/index.html#yaml-dquote.

Does this work for you? If it does, please update this PR. I'll merge it then.

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.

2 participants