apiVersion: v1
kind: ConfigMap
metadata:
  name: netbox-configmap
  namespace: netbox-community
data:
  # NetBox environment variables
  # More configuration can be added via: https://netbox.readthedocs.io/en/stable/configuration/optional-settings/
  #changeme
  ALLOWED_HOSTS: '*'
  CHANGELOG_RETENTION: "90"
  DB_HOST: netbox-community-postgresql
  DB_NAME: netbox
  DB_USER: netbox
  EMAIL_FROM: netbox@bar.com
  EMAIL_PORT: "25"
  EMAIL_SERVER: localhost
  EMAIL_TIMEOUT: "10"
  EMAIL_USERNAME: foo
  EXEMPT_VIEW_PERMISSIONS: ''
  LOGIN_REQUIRED: "true"
  METRICS_ENABLED: "true"
  NETBOX_USERNAME: guest
  REDIS_HOST: netbox-community-redis-master
  REDIS_PORT: "6379"
  REDIS_CACHE_PORT: "6379"
  REDIS_DATABASE: "0"
  REDIS_CACHE_DATABASE: "1"
  SUPERUSER_EMAIL: admin@example.com
  SUPERUSER_NAME: admin

  # ngin.conf
  # client_max_body_size used to increase limit on attachement sizes
  nginx.conf: |
    worker_processes 1;
    events {
        worker_connections  1024;
    }
    http {
        include       /etc/nginx/mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        tcp_nopush     on;
        keepalive_timeout  65;
        gzip  on;
        server_tokens off;
        server {
            client_max_body_size 10M;
            listen 80;
            server_name 127.0.0.1;
            access_log off;
            location /static/ {
                expires 30d;
                alias /opt/netbox/netbox/static/;
            }
            location / {
                proxy_pass http://127.0.0.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;
                add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
            }
        }
    }

  # LDAP configuration against Microsoft Acive Directory
  # For more information around LDAP, see https://netbox.readthedocs.io/en/stable/installation/4-ldap/
  ldap_config.py: |
    import ldap
    from django_auth_ldap.config import LDAPSearch, NestedGroupOfNamesType

    # Read secret from file
    def read_secret(secret_name):
        try:
            f = open('/run/secrets/' + secret_name, 'r', encoding='utf-8')
        except EnvironmentError:
            return ''
        else:
            with f:
                return f.readline().strip()

    AUTH_LDAP_SERVER_URI = "<LDAP_server_URI" #changeme
    AUTH_LDAP_CONNECTION_OPTIONS = {
      ldap.OPT_REFERRALS: 0
    }
    AUTH_LDAP_START_TLS = True

    # Service user credentials. This accout will be making all the queries when users attempt to log in
    AUTH_LDAP_BIND_DN = "<LDAP_bind_DN>" #changeme
    AUTH_LDAP_BIND_PASSWORD = read_secret('auth_ldap_bind_password')
    LDAP_IGNORE_CERT_ERRORS = True

    # Where to look for users
    AUTH_LDAP_USER_SEARCH = LDAPSearch("<LDAP_user_search>") #changeme

    AUTH_LDAP_USER_DN_TEMPLATE = None

    # Map user attributes to Django attributes
    AUTH_LDAP_USER_ATTR_MAP = {
        "first_name": "givenName",
        "last_name": "sn",
        "email": "mail"
    }

    AUTH_LDAP_GROUP_SEARCH = LDAPSearch("<LDAP_group_search>") #changeme

    AUTH_LDAP_GROUP_TYPE = NestedGroupOfNamesType()

    AUTH_LDAP_USER_FLAGS_BY_GROUP = {
      "is_active": ["<LDAP_group>"], #changeme
      "is_staff": ["<LDAP_group>"], #changeme
      "is_superuser": ["<LDAP_group>"], #changeme
    }

    AUTH_LDAP_MIRROR_GROUPS = {"<LDAP_groups_to_mirror>"} #changeme

    AUTH_LDAP_FIND_GROUP_PERMS = True
    AUTH_LDAP_CACHE_GROUPS = False
    AUTH_LDAP_GROUP_CACHE_TIMEOUT = 3600
