Issue - File Permission Error

1,086 views
Skip to first unread message

Luke Baker

unread,
Apr 21, 2021, 7:02:33 AM4/21/21
to NetBox
Hi,

this may be a really simple issue to fix as I am fairly new to using Ubuntu, but whenever I try uploading an image to Netbox I get the error below;

 Server Error

A file permission error was detected while processing this request. Common causes include the following:

 Insufficient write permission to the media root - The configured media root is . Ensure that the user NetBox runs as has access to write files to all locations within this path.

The complete exception is provided below:

<class 'PermissionError'>
[Errno 13] Permission denied: '/opt/netbox/netbox/media/image-attachments/rack_1_P-A_1.jpg' Python version: 3.8.6 NetBox version: 2.11.0

If further assistance is required, please post to the NetBox mailing list.


I am trying to work out where the user netbox should be running, as this looks like it is the error. I have tried giving my main user permission using chown to netbox directories including the media, have tried giving www-data permission to the media directory, but so far it hasn't been solving the issue. Any help greatly appreciated,


Thanks,


Luke

Jeremy Stretch

unread,
Apr 21, 2021, 8:15:28 AM4/21/21
to Luke Baker, NetBox
You just need to make sure that the netbox user has write permission to the /opt/netbox/netbox/media/ path. Try this:

  sudo chown --recursive netbox /opt/netbox/netbox/media/

(This assumes that your NetBox user is named "netbox".)

Jeremy Stretch
Founder
NetVerity, LLC



Emails and any files transmitted with them are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received an email from Benjamin Britten High School in error please notify the School. Please note that any views or opinions presented in Benjamin Britten High School emails are solely those of the author and do not necessarily represent those of Benjamin Britten High School. The recipient should check received emails and any attachments for the presence of viruses.

Benjamin Britten High School accepts no liability for any damage caused by any virus transmitted by this email.

Benjamin Britten High School
Blyford Road
Lowestoft
Suffolk
NR32 4PZ
United Kingdom

01502 582312

--
You received this message because you are subscribed to the Google Groups "NetBox" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netbox-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netbox-discuss/38150bc4-b98a-4d26-b37c-92a555501bc3n%40googlegroups.com.

luism...@gmail.com

unread,
Apr 21, 2021, 9:01:12 AM4/21/21
to NetBox
Hi,

I have a similar problem but when running a report.

I am preparing a report that will scan all the IPs of the prefixes registered in Netbox, if the IP responds to ping but is not registered in Netbox, an alert will be generated.
At the moment I am testing with a constant prefix, if I test it in python it works but not in Netbox.

error-report.PNG
file permissions ( I've given everyone permission and it still doesn't work )perm.PNG

Code:
import sys
sys.path.append("/usr/local/lib/python3.6/site-packages")
#===========================================
#Requirements
#===========================================
#sudo pip install ping3
#sudo yum install python3-tkinter
#sudo pip install ipaddresses
#===========================================
#from ipam.constants import *
#from ipam.choices import *
from extras.reports import Report
from ipam.models import *
import ipaddresses
import ipaddress
from ping3 import ping , verbose_ping
#from netbox import NetBox
###########################################
#PREFIX TO SCAN
###########################################
#The idea is that then the scan will be on all the
#     prefixes registered in the database Then compare the results with the registered IPs
###########################################
PREFIX_LIST = ["10.5.10.0/24"]
class Rep_Network_Scann(Report):
    description = "Network Scann"
    def test_rep_scann_net(self):
        for prefix in PREFIX_LIST:
            for ipaddr in ipaddress.IPv4Network(prefix):
                ipaddr = ipaddress.IPv4Address(ipaddr)+1
                try:
                    #if ((ping('192.168.43.64',timeout=1)) == None):
                    if (ping(str(ipaddress.IPv4Address(ipaddr))) == None):
                        self.log_failure(ipaddr,"IP does not respond to ping")
                        #print("No Responde a Ping la ip " + str(ipaddress.IPv4Address(ipaddr)))
                        #print("Responde a Ping la ip " + str(ipaddress.IPv4Address(ipaddr)))
                    else:
                        #print("No Responde a Ping la ip " + str(ipaddress.IPv4Address(ipaddr)))
                        self.log_success(ipaddr, "IP respond to ping")
                        #print("Responde a Ping la ip " + str(ipaddress.IPv4Address(ipaddr)))
                except IndexError as e:
                    self.log_failure(ipaddr, e)
####################################################################
#References
####################################################################
#https://www.pythonparatodo.com/?p=194
#https://netbox.readthedocs.io/en/stable/additional-features/reports/
#https://docs.python.org/3/library/ipaddress.html
####################################################################

Could they indicate what is happening?

regards,

Luis.

Brian Candler

unread,
Apr 21, 2021, 9:28:54 AM4/21/21
to NetBox
That's because normally you can't open a raw socket for sending ICMP unless you're running as root.

Solutions have been given here.  The reports are run as the same user as netbox itself; running netbox with the cap_net_raw permission is much safer than running netbox as root.

Luke Baker

unread,
Apr 21, 2021, 9:52:09 AM4/21/21
to NetBox
Hi,

thanks for your help

I have added this, I also added it for the user of the Ubuntu installation, in my case I log in as administrator so put;

sudo chown --recursive administrator /opt/netbox/netbox/media

So that I could have access, I have even given permission for my administrator user to access anything within /opt/netbox

The netbox user I created the same as the documentation, but do I need to log into netbox as netbox? In this case do I need to change permissions for every extra user I create?

Logging in with the netbox user is that in netbox/postgresql/other dependency?

Thanks for your help and hopefully will see what is causing the issue

Thanks,

Luke

Brian Candler

unread,
Apr 21, 2021, 10:45:02 AM4/21/21
to NetBox
> sudo chown --recursive administrator /opt/netbox/netbox/media

No.

Here you must put the user which Netbox itself runs as (the gunicorn process), which in the standard installation is "netbox".  In Unix file permissions, a file can only have one owner, and "chown" will remember only the most recent one you applied.

If as an administrator you want direct write access to put files in that directly, then use group permissions or extended ACLs to do this.  Or more easily, just use "sudo" when you want to do this.

> The netbox user I created the same as the documentation, but do I need to log into netbox as netbox? In this case do I need to change permissions for every extra user I create?

The netbox web GUI logins are not related to system users.
Reply all
Reply to author
Forward
0 new messages