You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Inventree fiddles with files directly rather than using Django Storage api #2585
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.
@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.
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.
@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.
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.
@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.
Activity
matmair commentedon Feb 1, 2022
@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.
nwns commentedon Feb 1, 2022
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.
matmair commentedon Feb 3, 2022
@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.
nwns commentedon Feb 3, 2022
@matmair
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.
matmair commentedon Feb 3, 2022
@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.
matmair commentedon Apr 24, 2022
@SchrodingersGat I look at this while handling #2861 and my suggestion would be to move:
to the root media folder
[BUG] Inventree fiddles with files directly rather than using Django …
7 remaining items
matmair commentedon Feb 27, 2024
Partly addressed by 1199291
Refactor label/report template copying (inventree#6582)
Move media operations to storages backend (inventree#6478)