nautobot / nautobot-app-golden-config

Golden Configuration App for Nautobot.
https://docs.nautobot.com/projects/golden-config/en/latest/
Other
100 stars 57 forks source link

Considerations/Issues with file paths in Backups/Intended/Templates #778

Open bile0026 opened 4 months ago

bile0026 commented 4 months ago

Environment

Expected Behavior

Backups should be able to be saved to the filesystem and saved to Git

Observed Behavior

Received an error BACKUP CONFIG failed: Subtask: SAVE BACKUP CONFIGURATION TO FILE (failed). This appeared to be due to having a leading / in my backup config path in Golden Config Settings, which I'm assuming was referencing the root of the filesystem. Since Nautobot doesn't run as root it doesn't have access to / in the filesystem.

# correct (references current working directory)
{{obj.location.name}}/{{obj.name | upper}}.cfg

# invalid (references the root of the host/container filesystem)
/{{obj.location.name}}/{{obj.name | upper}}.cfg

Steps to Reproduce

  1. Use a leading / in the path for backup, intended, or template settings in Golden Config settings for a given device.
  2. Run Backup/Intended job for device

Proposed solutions

  1. Pop up a warning if a leading / is detected in the settings page or when the settings are created/updated. i.e. "You have a leading / in your configuration, is this expected?"
  2. Have a more descriptive error thrown if the above backup error occurs (not tested but I believe this would happen with intended as well).
  3. Strip any leading / when the settings are created/updated. This could limit some customer implementations if they are actually storing backups in a root directory that Nautobot does have access to.
itdependsnetworks commented 4 months ago

Would add a check here: https://github.com/nautobot/nautobot-app-golden-config/blob/5451c7d856399153a84c480357460110b964462a/nautobot_golden_config/models.py#L586

gsnider2195 commented 1 week ago

That's unexpected. This is due to this behavior in os.path.join: Help on function join in module posixpath:

join(a, *p)
    Join two or more pathname components, inserting '/' as needed.
    If any component is an absolute path, all previous path components
    will be discarded.  An empty last part will result in a path that
    ends with a separator.