NetBox

From NixOS Wiki
Revision as of 05:55, 9 November 2022 by imported>Vater (→‎basic configuration)

NetBox (wikipedia:en:NetBox) is available as a module.

configuration examples

minimal configuration

mkdir -p /var/lib/netbox/
$EDITOR /var/lib/netbox/passwordFile
cat /var/lib/netbox/passwordFile
this-is-an-initial-password-for-netbox

basic configuration

# system.stateVersion = "22.05";

# networking.hostName = "netbox";
# networking.domain = "domain.tld";

  services.netbox.enable = true;
  services.netbox.secretKeyFile = "/var/lib/netbox/passwordFile";

  services.nginx.enable = true;
# services.nginx.recommendedOptimisation = true;
#  services.nginx.recommendedGzipSettings = true;

# services.nginx.recommendedProxySettings = true;
  services.nginx.virtualHosts."${config.networking.fqdn}" = {
    locations = {
      "/" = {
#        extraConfig = ''
##          proxy_pass http://127.0.0.1:8001;
#          proxy_pass http://[::1]:8001;
#          proxy_set_header X-Forwarded-Host $http_host;
#          proxy_set_header X-Real-IP $remote_addr;
#          proxy_set_header X-Forwarded-Proto $scheme;
#        '';
#        proxyPass = "http://127.0.0.1:8001";
        proxyPass = "http://[::1]:8001";
####        proxyPass = "http://${config.services.netbox.listenAddress}:${config.services.netbox.port}";
      };
      "/static/" = {
#        extraConfig = ''
#          alias /var/lib/netbox/static/;
#        '';
#        alias = "/var/lib/netbox/static/";
        alias = "${config.services.netbox.dataDir}/static/";
      };
    };
    forceSSL = true;
    enableACME = true;
  };
  services.nginx.clientMaxBodySize = "25m";
  services.nginx.user = "netbox";
# services.nginx.recommendedTlsSettings = true;
  security.acme.defaults.email = "acme@${config.networking.domain}";
  security.acme.acceptTerms = true;

#  networking.firewall.allowedTCPPorts = [ 80 443 8001 ];
  networking.firewall.allowedTCPPorts = [ 80 443 ];

https://netbox.domain.tld


login

no (initial) account is create by default

tl;dr: No login is possible after installing and running NetBox. No account is created. You have to #create an initial account.

reenact that there is no initial account created by default

su postgres

psql


postgres=#

\l
                                  List of databases                                                                                                                                                                                           
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges                                                                                                                                                            
-----------+----------+----------+-------------+-------------+-----------------------                                                                                                                                                         
 netbox    | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc/postgres         +                                                                                                                                                         
           |          |          |             |             | postgres=CTc/postgres+                                                                                                                                                         
           |          |          |             |             | netbox=CTc/postgres                                                                                                                                                            
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |                                                         
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +                                  
           |          |          |             |             | postgres=CTc/postgres                                   
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +                                  
           |          |          |             |             | postgres=CTc/postgres                                   
(4 rows)

postgres=#

\c netbox
You are now connected to database "netbox" as user "postgres".

netbox=#

\dt

netbox=#

SELECT * FROM auth_user;
 id | password | last_login | is_superuser | username | first_name | last_name | email | is_staff | is_active | date_joined                                                                                                                   
----+----------+------------+--------------+----------+------------+-----------+-------+----------+-----------+-------------                                                                                                                  
(0 rows)

netbox=#

\q


exit

create an initial account

(first you have to) create an initial account (on the cli)

this initial account will get highest privileges
netbox-manage createsuperuser
Username (leave blank to use 'netbox'):
Email address: 
Password: 
Password (again):
Superuser created successfully.

first login

https://netbox.domain.tld/login/

Login
netbox
Password
Sign In