mirror of
https://github.com/netbox-community/netbox-docker.git
synced 2026-01-28 13:43:13 +00:00
Compare commits
8 commits
3ef6dce571
...
e6799ba214
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e6799ba214 | ||
|
|
fd6a75ac96 | ||
|
|
94dd752652 | ||
|
|
20cccc3869 | ||
|
|
269cf83362 | ||
|
|
da0784992e | ||
|
|
c0ead010ec | ||
|
|
ebba20d02b |
2
.flake8
2
.flake8
|
|
@ -4,4 +4,4 @@ extend-ignore = E203, W503
|
|||
per-file-ignores =
|
||||
configuration/*:E131,E251,E266,E302,E305,E501,E722
|
||||
startup_scripts/startup_script_utils/__init__.py:F401
|
||||
docker/*:E266,E722
|
||||
docker/*:E266,E722,E501
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ COPY docker/configuration.docker.py /opt/netbox/netbox/netbox/configuration.py
|
|||
COPY docker/ldap_config.docker.py /opt/netbox/netbox/netbox/ldap_config.py
|
||||
COPY docker/docker-entrypoint.sh /opt/netbox/docker-entrypoint.sh
|
||||
COPY docker/launch-netbox.sh /opt/netbox/launch-netbox.sh
|
||||
COPY docker/super_user.py /opt/netbox/super_user.py
|
||||
COPY configuration/ /etc/netbox/config/
|
||||
COPY docker/granian.py /opt/netbox/netbox/netbox/granian.py
|
||||
COPY VERSION /opt/netbox/VERSION
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ services:
|
|||
retries: 5
|
||||
env_file: env/postgres.env
|
||||
volumes:
|
||||
- netbox-postgres-data:/var/lib/postgresql/data
|
||||
- netbox-postgres:/var/lib/postgresql
|
||||
|
||||
# redis
|
||||
redis:
|
||||
|
|
@ -75,7 +75,7 @@ services:
|
|||
volumes:
|
||||
netbox-media-files:
|
||||
driver: local
|
||||
netbox-postgres-data:
|
||||
netbox-postgres:
|
||||
driver: local
|
||||
netbox-redis-cache-data:
|
||||
driver: local
|
||||
|
|
|
|||
|
|
@ -54,42 +54,9 @@ fi
|
|||
if [ "$SKIP_SUPERUSER" == "true" ]; then
|
||||
echo "↩️ Skip creating the superuser"
|
||||
else
|
||||
if [ -z ${SUPERUSER_NAME+x} ]; then
|
||||
SUPERUSER_NAME='admin'
|
||||
./manage.py shell --no-startup --no-imports --interface python \
|
||||
</opt/netbox/super_user.py
|
||||
fi
|
||||
if [ -z ${SUPERUSER_EMAIL+x} ]; then
|
||||
SUPERUSER_EMAIL='admin@example.com'
|
||||
fi
|
||||
if [ -f "/run/secrets/superuser_password" ]; then
|
||||
SUPERUSER_PASSWORD="$(</run/secrets/superuser_password)"
|
||||
elif [ -z ${SUPERUSER_PASSWORD+x} ]; then
|
||||
SUPERUSER_PASSWORD='admin'
|
||||
fi
|
||||
if [ -f "/run/secrets/superuser_api_token" ]; then
|
||||
SUPERUSER_API_TOKEN="$(</run/secrets/superuser_api_token)"
|
||||
elif [ -z ${SUPERUSER_API_TOKEN+x} ]; then
|
||||
SUPERUSER_API_TOKEN='0123456789abcdef0123456789abcdef01234567'
|
||||
fi
|
||||
|
||||
./manage.py shell --interface python <<END
|
||||
from users.models import Token, User
|
||||
if not User.objects.filter(username='${SUPERUSER_NAME}'):
|
||||
u = User.objects.create_superuser('${SUPERUSER_NAME}', '${SUPERUSER_EMAIL}', '${SUPERUSER_PASSWORD}')
|
||||
Token.objects.create(user=u, key='${SUPERUSER_API_TOKEN}')
|
||||
END
|
||||
|
||||
echo "💡 Superuser Username: ${SUPERUSER_NAME}, E-Mail: ${SUPERUSER_EMAIL}"
|
||||
fi
|
||||
|
||||
./manage.py shell --interface python <<END
|
||||
from users.models import Token
|
||||
try:
|
||||
old_default_token = Token.objects.get(key="0123456789abcdef0123456789abcdef01234567")
|
||||
if old_default_token:
|
||||
print("⚠️ Warning: You have the old default admin API token in your database. This token is widely known; please remove it. Log in as your superuser and check API Tokens in your user menu.")
|
||||
except Token.DoesNotExist:
|
||||
pass
|
||||
END
|
||||
|
||||
echo "✅ Initialisation is done."
|
||||
|
||||
|
|
|
|||
36
docker/super_user.py
Normal file
36
docker/super_user.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
from os import environ
|
||||
|
||||
from django.conf import settings
|
||||
from users.choices import TokenVersionChoices
|
||||
from users.models import Token, User
|
||||
|
||||
|
||||
# Read secret from file
|
||||
def _read_secret(secret_name: str, default: str | None = None) -> str | None:
|
||||
try:
|
||||
f = open("/run/secrets/" + secret_name, "r", encoding="utf-8")
|
||||
except EnvironmentError:
|
||||
return default
|
||||
else:
|
||||
with f:
|
||||
return f.readline().strip()
|
||||
|
||||
|
||||
su_name = environ.get("SUPERUSER_NAME", "admin")
|
||||
su_email = environ.get("SUPERUSER_EMAIL", "admin@example.com")
|
||||
su_password = _read_secret("superuser_password", environ.get("SUPERUSER_PASSWORD", "admin"))
|
||||
su_api_token = _read_secret(
|
||||
"superuser_api_token",
|
||||
environ.get("SUPERUSER_API_TOKEN", "0123456789abcdef0123456789abcdef01234567"),
|
||||
)
|
||||
|
||||
if not User.objects.filter(username=su_name):
|
||||
u = User.objects.create_superuser(su_name, su_email, su_password)
|
||||
msg = ""
|
||||
if not settings.API_TOKEN_PEPPERS:
|
||||
print("⚠️ No API token will be created as API_TOKEN_PEPPERS is not set")
|
||||
msg = f"💡 Superuser Username: {su_name}, E-Mail: {su_email}"
|
||||
else:
|
||||
t = Token.objects.create(user=u, token=su_api_token, version=TokenVersionChoices.V2)
|
||||
msg = f"💡 Superuser Username: {su_name}, E-Mail: {su_email}, API Token: {t} (use with '{t.get_auth_header_prefix()}<Your token>')"
|
||||
print(msg)
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
django-auth-ldap==5.3.0
|
||||
dulwich==0.25.0
|
||||
granian[uvloop]==2.6.0
|
||||
granian[uvloop]==2.6.1
|
||||
python3-saml==1.16.0
|
||||
--no-binary lxml
|
||||
--no-binary xmlsec
|
||||
sentry-sdk[django]==2.48.0
|
||||
sentry-sdk[django]==2.49.0
|
||||
|
|
|
|||
Loading…
Reference in a new issue