When syncing a folder with files the worker process doesn't have permissions for, the DataSource will be stuck in "Syncing" status. #7817

Closed
opened 2025-12-29 20:28:36 +01:00 by adam · 1 comment
Owner

Originally created by @kkthxbye-code on GitHub (Mar 30, 2023).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.5.0

Python version

3.8

Steps to Reproduce

  1. Create a DataSource
  2. Set the type to local and the path to /etc/
  3. Save and initiate a sync

Expected Behavior

The sync job will ignore files with no permissions or alternatively gracefully fail.

Observed Behavior

The background task fails with an exception like this:

Traceback (most recent call last):
File "/opt/netbox/venv/lib/python3.10/site-packages/rq/worker.py", line 1359, in perform_job
rv = job.perform()
File "/opt/netbox/venv/lib/python3.10/site-packages/rq/job.py", line 1178, in perform
self._result = self._execute()
File "/opt/netbox/venv/lib/python3.10/site-packages/rq/job.py", line 1215, in _execute
result = self.func(*self.args, **self.kwargs)
File "/opt/netbox/netbox/core/jobs.py", line 20, in sync_datasource
datasource.sync()
File "/opt/netbox/netbox/core/models/data.py", line 184, in sync
datafile.refresh_from_disk(source_root=local_path)
File "/opt/netbox/netbox/core/models/data.py", line 304, in refresh_from_disk
file_hash = sha256_hash(file_path).hexdigest()
File "/opt/netbox/netbox/utilities/files.py", line 8, in sha256_hash
with open(filepath, 'rb') as f:
PermissionError: [Errno 13] Permission denied: '/etc/ufw/before6.rules'

The DataSource will be permanently stuck in the "Syncing" status, which will grey out the sync button.

This is similar to this issue: https://github.com/netbox-community/netbox/issues/11660

Any exception thrown in the background task should fail the sync. We might also want to consider the security implications of the DataSource feature, maybe add some settings to control whether file sync in enabled and maybe an option to control which path local file syncing is allowed in. The documentation should be clear that it can be a dangerous feature to allow users to use.

Originally created by @kkthxbye-code on GitHub (Mar 30, 2023). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.5.0 ### Python version 3.8 ### Steps to Reproduce 1. Create a DataSource 2. Set the type to local and the path to `/etc/` 3. Save and initiate a sync ### Expected Behavior The sync job will ignore files with no permissions or alternatively gracefully fail. ### Observed Behavior The background task fails with an exception like this: Traceback (most recent call last): File "/opt/netbox/venv/lib/python3.10/site-packages/rq/worker.py", line 1359, in perform_job rv = job.perform() File "/opt/netbox/venv/lib/python3.10/site-packages/rq/job.py", line 1178, in perform self._result = self._execute() File "/opt/netbox/venv/lib/python3.10/site-packages/rq/job.py", line 1215, in _execute result = self.func(*self.args, **self.kwargs) File "/opt/netbox/netbox/core/jobs.py", line 20, in sync_datasource datasource.sync() File "/opt/netbox/netbox/core/models/data.py", line 184, in sync datafile.refresh_from_disk(source_root=local_path) File "/opt/netbox/netbox/core/models/data.py", line 304, in refresh_from_disk file_hash = sha256_hash(file_path).hexdigest() File "/opt/netbox/netbox/utilities/files.py", line 8, in sha256_hash with open(filepath, 'rb') as f: PermissionError: [Errno 13] Permission denied: '/etc/ufw/before6.rules' The DataSource will be permanently stuck in the "Syncing" status, which will grey out the sync button. This is similar to this issue: https://github.com/netbox-community/netbox/issues/11660 Any exception thrown in the background task should fail the sync. We might also want to consider the security implications of the DataSource feature, maybe add some settings to control whether file sync in enabled and maybe an option to control which path local file syncing is allowed in. The documentation should be clear that it can be a dangerous feature to allow users to use.
adam added the type: bugstatus: acceptedbeta labels 2025-12-29 20:28:36 +01:00
adam closed this issue 2025-12-29 20:28:36 +01:00
Author
Owner

@jeremystretch commented on GitHub (Mar 31, 2023):

We might also want to consider the security implications of the DataSource feature, maybe add some settings to control whether file sync in enabled and maybe an option to control which path local file syncing is allowed in.

Could you open a feature request for that please?

The documentation should be clear that it can be a dangerous feature to allow users to use.

I'll point out that the background worker runs as the same system user under which custom scripts are already being executed. Ultimately, the onus is on the administrator to understand and consider the trade-offs of enabling advanced functionality.

@jeremystretch commented on GitHub (Mar 31, 2023): > We might also want to consider the security implications of the DataSource feature, maybe add some settings to control whether file sync in enabled and maybe an option to control which path local file syncing is allowed in. Could you open a feature request for that please? > The documentation should be clear that it can be a dangerous feature to allow users to use. I'll point out that the background worker runs as the same system user under which custom scripts are already being executed. Ultimately, the onus is on the administrator to understand and consider the trade-offs of enabling advanced functionality.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7817