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 permissions for config files used in tests #42914

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

Conversation

AndersonQ
Copy link
Member

@AndersonQ AndersonQ commented Feb 26, 2025

Proposed commit message

fix permissions for config files used in tests

The tests which rely on reading config from disk did not correctly set the 
permissions. The beats require the config files must be writable only by the 
owner, now the tests explicitly set the permissions accordingly.

A new `testcfg` package provides `NewFileWith644Perm` and
`CopyDirectoryWithOwnerWriteOnly` as helper functions for tests to create 
a temporary copy of the files committed to the repo to use in the test.

The test framework was also adjusted to save the config file with the correct 
permission.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation
  • [ ] I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

Disruptive User Impact

  • N/A

How to test this PR locally

tl;dr: no unit/system test should fail due to a configuration file with the wrong permissions.

  • set the system umask to 002
  • run the tests with the new test framework:
cd filebeat/testing/integration
go test -v -tags integration -run TestFilebeat
  • it should succeed, before it'd fail with:
[...]
        Exiting: error loading config file: config file ("/tmp/TestFilebeatFilebeat_starts_and_ingests_filesplain_text_files1677938519/002/filebeat.yml") can only be writable by the owner but the permissions are "-rwxrwxr-x" (to fix the permissions use: 'chmod go-w /tmp/TestFilebeatFilebeat_starts_and_ingests_filesplain_text_files1677938519/002/filebeat.yml')
[...]
  • try some of the other unit tests, but first ensure the configuration files have the wrong permissions
cd metricbeat/mb/testdata
chmod -R go+w ./
go test -run TestProcessorsForMetricSet_FromSource ./
  • it should succeed. Before it's fail with:
❯ go test -run TestProcessorsForMetricSet_FromSource ./              
--- FAIL: TestProcessorsForMetricSet_FromSource (0.00s)
    registry_test.go:245: 
        	Error Trace:	/home/ainsoph/devel/github.com/elastic/beats/metricbeat/mb/registry_test.go:245
        	Error:      	Received unexpected error:
        	            	reading processors for metricset 'withprocessors' in module 'unpack': loading light module 'unpack' definition: loading module configuration from 'testdata/lightmodules/unpack/module.yml': config file ("testdata/lightmodules/unpack/module.yml") can only be writable by the owner but the permissions are "-rw-rw-r--" (to fix the permissions use: 'chmod go-w /home/ainsoph/devel/github.com/elastic/beats/metricbeat/mb/testdata/lightmodules/unpack/module.yml')
        	Test:       	TestProcessorsForMetricSet_FromSource
FAIL
FAIL	github.com/elastic/beats/v7/metricbeat/mb	0.082s
FAIL

Related issues

@AndersonQ AndersonQ self-assigned this Feb 26, 2025
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Feb 26, 2025
Copy link
Contributor

mergify bot commented Feb 26, 2025

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @AndersonQ? 🙏.
For such, you'll need to label your PR with:

  • The upcoming major version of the Elastic Stack
  • The upcoming minor version of the Elastic Stack (if you're not pushing a breaking change)

To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-8./d is the label to automatically backport to the 8./d branch. /d is the digit
  • backport-active-all is the label that automatically backports to all active branches.
  • backport-active-8 is the label that automatically backports to all active minor branches for the 8 major.
  • backport-active-9 is the label that automatically backports to all active minor branches for the 9 major.

@AndersonQ AndersonQ added Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team backport-8.x Automated backport to the 8.x branch with mergify labels Feb 27, 2025
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Feb 27, 2025
The tests which rely on reading config from disk did not correctly set the 
permissions. The beats require the config files must be writable only by the 
owner, now the tests explicitly set the permissions accordingly.

A new `testcfg` package provides `NewFileWith644Perm` and
`CopyDirectoryWithOwnerWriteOnly` as helper functions for tests to create 
a temporary copy of the files committed to the repo to use in the test.

The test framework was also adjusted to save the config file with the correct 
permission.
@AndersonQ AndersonQ force-pushed the 42779-fix-test-config-creation branch from 0151d2e to dc61260 Compare February 27, 2025 08:03
@AndersonQ AndersonQ marked this pull request as ready for review February 27, 2025 08:03
@AndersonQ AndersonQ requested a review from a team as a code owner February 27, 2025 08:03
@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

@AndersonQ AndersonQ changed the title [WIP] Fix permissions for config files used in tests Fix permissions for config files used in tests Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-8.x Automated backport to the 8.x branch with mergify Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test framework incorrectly creates beat config file
2 participants