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

node_exporter "Create textfile collector dir" task - Consistent "change" state #92

Closed
fitz123 opened this issue Apr 26, 2023 · 2 comments · Fixed by #105
Closed

node_exporter "Create textfile collector dir" task - Consistent "change" state #92

fitz123 opened this issue Apr 26, 2023 · 2 comments · Fixed by #105

Comments

@fitz123
Copy link
Contributor

fitz123 commented Apr 26, 2023

Description
The "Create textfile collector dir" task in the node_exporter role for the Prometheus Ansible collection is consistently reporting a "changed" state upon every run. The task in question

Other system services generate their own metrics and place the corresponding metric files in the "{{ node_exporter_textfile_dir }}" directory. These services belong to the "{{ node_exporter_system_group }}" group, enabling them to change the group ownership of created metric files to the desired "{{ node_exporter_system_group }}". The node-exporter can read from these metric files, but the services are unable to change the ownership to the "{{ node_exporter_system_user }}". This results in a "changed" state for the "Create textfile collector dir" task after every run, as long as there are new or updated metric files within the "{{ node_exporter_textfile_dir }}" directory.

Problem
This issue is problematic because I monitor Ansible changes for security reasons and to detect any unexpected changes. Constant changes are undesirable and should not occur under normal circumstances.

Expected Outcome:
When all files and directories within the node_exporter_textfile_dir directory have the correct group set, no Ansible changes should be reported. The role should neither alter the "user" for files nor report any changes regarding this.

Solution Proposal
I have tried to come up with a suitable solution but have been unsuccessful. Unfortunately, there is no associated PR. Possible solutions could include:

  1. Setting recurse: false - This would set the desired ownership for the directory itself, allowing the user to manage and verify that text metric files have the correct group, which node-exporter can read from.
  2. Using changed: false - This option is also not ideal.

I am unsure how to address this issue and welcome any suggestions or proposals for a resolution.

@mikelsid
Copy link

imo the solution with setting recurse: false should work, since, according to the source, collector only scrapes files in this directory, excluding subdirectories and g+rwX,o=rX guarantees, that all files created in the directory will have the desired group

@gardar
Copy link
Member

gardar commented Apr 26, 2023

I suspect that the recursive option was set as a safety precaution to ensure that node_exporter can read the files in the directory.
But as you are experiencing there are different scenarios where node_exporter can very well read the directory contents, without enforcing the user/group/mode that the task sets.

A better solution would be to confirm that the user can read the contents, with the ansible.builtin.stat module and become and then only change the permissions if the node exporter user can't access the files.

But to avoid over complicating the role we can just simply drop the recurse option.

The role isn't installing anything in that directory and if it were, then we would just make sure that those files were installed with the correct permissions.

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 a pull request may close this issue.

3 participants