Skip to content

[BUG] Inventree fiddles with files directly rather than using Django Storage api #2585

Closed

Description

@nwns

Describe the bug
Django provides an abstract storage api that should be used for all file accesses so that the server can be run from places that do not have a local filesystem and/or shared filesystem to store the media files.

Steps to Reproduce

Steps to reproduce the behavior:
Run Inventree API server on a node with a readonly filesystem and you will crash out in label/app.py because it cannot create the folders, no matter what the DEFAULT_STORAGE_CLASS is set to.

Expected behavior
I expect that inventree should honour the DEFAULT_STORAGE_CLASS for writing and reading its media files.

Deployment Method

  • Docker
  • Kubernetes
  • Bare Metal

Version Information
Application fails to start up. This using the master branch of the main Inventree repository.

Activity

  1. added
    bug
    question
    on Feb 1, 2022
  2. added
    enhancement
    and removed
    bug
    on Feb 1, 2022
  3. matmair commented on Feb 1, 2022

    @matmair
    Member

    @nwns this is a known side effect of the current implementation of file access.
    The storage API can help with this but introduces a number of possible bugs/security issues with different storage providers as some of them (boto for example) do not respect the originally intended access rights.
    We have to rewrite at least 30 code blocks, possible more, to get full compliance with the API and introduce extra security measures so that users do not just expose all their part files, photos, test results and reports to the world. Especially with cloud deployments like Kubernetes in mind.

    So this is a rather sensitive task - contributions are very welcome. I would love to get to this but I am slammed with work rn.
    When implementing this we should also document and test a few possible storage classes and recommended settings for those. Especially block storage services like Amazon S3 can be dangerous as they enable fast misconfiguration and could lead to circumvention of our privileges system.

  4. nwns commented on Feb 1, 2022

    @nwns
    ContributorAuthor

    The changes for running in k8s will come with at least one example of a S3 like API for testing.

    More importantly, we need to stop adding new code that directly fiddles with the filesystem and uses the Storages api, even if the only production supported storage is local files for now.

  5. added this to the 0.7.0 milestone on Feb 2, 2022
  6. matmair commented on Feb 3, 2022

    @matmair
    Member

    @nwns I will have to disagree here. Current standard in the codebase is to use pythons built-in file-APIs (fiddle as you call it). Using 2 different APIs for the same thing sounds like a great source for strange, hard to reproduce, special case bugs.
    If we switch to Django's storage API this needs to be for the whole codebase and not a bit-per-bit situation as there need to be docs etc. connected to it. The storage API can behave strange with symlinks on windows, some user might have to change their storage setups after the switch.

  7. nwns commented on Feb 3, 2022

    @nwns
    ContributorAuthor

    @matmair

    Using 2 different APIs for the same thing sounds like a great source for strange, hard to reproduce, special case bugs.

    Agreed. However, I will also note, from what I can tell, Inventree hardcodes the default file storage so until that can be changed, it should be fine. Unless, someone is maintaining their own settings.py (which I used to do, I would not recommend), but if they are, they are also advanced enough to know how this works.

    Who is using symlinks? How are they using symlinks? For the media files? I searched the code and the only symlink stuff I can find is in various libraries, all of which should know if what they are trying to do will not work on windows and do a copy. In particular django itself can use symlinks for collect static, but this is about media files.

    To be clear, I am not suggesting that Inventree should change the default location for media files or the default behaviour, they are both fine when Inventree is run on a single machine with a persistent writable disk.

  8. matmair commented on Feb 3, 2022

    @matmair
    Member

    @nwns symlinks are often used in big MSFT environments when deploying with IIS. I would never recommend using that but some enterprises have strict rules on what can be deployed so they have to use IIS.
    Overriding the settings is done a lot from what I hear. One of the reasons a lot of ppl. keep using old releases for a long time.
    I find it a bad idea to use 2 APIs, feel free to submit PRs how you like. There are no concrete coding styles for this org.

  9. modified the milestones: 0.7.0, 0.8.0 on Apr 21, 2022
  10. self-assigned this
    on Apr 24, 2022
  11. matmair commented on Apr 24, 2022

    @matmair
    Member

    @SchrodingersGat I look at this while handling #2861 and my suggestion would be to move:

    • plugins.txt
    • config.yaml
    • locale_stats.json

    to the root media folder

  12. added a commit that references this issue on Apr 24, 2022
    089b25c
  13. 7 remaining items

  14. added this to the 0.9.0 milestone on Jun 6, 2022
  15. modified the milestones: 0.9.0, 1.0.0 on Oct 16, 2022
  16. added
    roadmap
    and removed
    question
    on Oct 16, 2022
  17. modified the milestones: 1.0.0, horizon on Jun 7, 2023
  18. modified the milestones: horizon, 0.15.0 on Feb 9, 2024
  19. matmair commented on Feb 27, 2024

    @matmair
    Member

    Partly addressed by 1199291

  20. added a commit that references this issue on Feb 28, 2024
    1199291
  21. added a commit that references this issue on Mar 24, 2024
    cfe00aa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementroadmap

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions