initial commit

This commit is contained in:
W Anders
2024-05-06 17:37:57 -06:00
commit 12bcac933a
35 changed files with 3027 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
PLUGINS = [
'netbox_dns',
]
PLUGINS_CONFIG = {
'netbox_dns': {
'feature_ipam_coupling': True,
'tolerate_underscores_in_hostnames': True,
},
}
+39
View File
@@ -0,0 +1,39 @@
services:
netbox:
image: localhost/netbox-plugin-dns:latest
build:
context: .
dockerfile: ./netbox.Containerfile
depends_on:
- postgres
- redis
- redis-cache
env_file: env/netbox.env
user: 'unit:root'
healthcheck:
start_period: 60s
timeout: 3s
interval: 15s
test: "curl -f http://localhost:8080/api/ || exit 1"
ports:
- "9999:8080"
postgres:
image: docker.io/library/postgres:16
env_file: env/postgres.env
redis:
image: docker.io/library/redis:7
command:
- sh
- -c
- redis-server --appendonly yes --requirepass $$REDIS_PASSWORD
env_file: env/redis.env
redis-cache:
image: docker.io/library/redis:7
command:
- sh
- -c
- redis-server --requirepass $$REDIS_PASSWORD
env_file: env/redis-cache.env
+34
View File
@@ -0,0 +1,34 @@
CORS_ORIGIN_ALLOW_ALL=True
DB_HOST=postgres
DB_NAME=netbox
DB_PASSWORD=J5brHrAXFLQSif0K
DB_USER=netbox
EMAIL_FROM=netbox@bar.com
EMAIL_PASSWORD=
EMAIL_PORT=25
EMAIL_SERVER=localhost
EMAIL_SSL_CERTFILE=
EMAIL_SSL_KEYFILE=
EMAIL_TIMEOUT=5
EMAIL_USERNAME=netbox
# EMAIL_USE_SSL and EMAIL_USE_TLS are mutually exclusive, i.e. they can't both be `true`!
EMAIL_USE_SSL=false
EMAIL_USE_TLS=false
GRAPHQL_ENABLED=true
HOUSEKEEPING_INTERVAL=86400
MEDIA_ROOT=/opt/netbox/netbox/media
METRICS_ENABLED=false
REDIS_CACHE_DATABASE=1
REDIS_CACHE_HOST=redis-cache
REDIS_CACHE_INSECURE_SKIP_TLS_VERIFY=false
REDIS_CACHE_PASSWORD=t4Ph722qJ5QHeQ1qfu36
REDIS_CACHE_SSL=false
REDIS_DATABASE=0
REDIS_HOST=redis
REDIS_INSECURE_SKIP_TLS_VERIFY=false
REDIS_PASSWORD=H733Kdjndks81
REDIS_SSL=false
RELEASE_CHECK_URL=https://api.github.com/repos/netbox-community/netbox/releases
SECRET_KEY='r(m)9nLGnz$(_q3N4z1k(EFsMCjjjzx08x9VhNVcfd%6RF#r!6DE@+V5Zk2X'
WEBHOOKS_ENABLED=true
SUPERUSER_API_TOKEN=w5pgWXPqZVmngLN4w4XwuPvZfUC72ytDxnnHgEmI
+3
View File
@@ -0,0 +1,3 @@
POSTGRES_DB=netbox
POSTGRES_PASSWORD=J5brHrAXFLQSif0K
POSTGRES_USER=netbox
+1
View File
@@ -0,0 +1 @@
REDIS_PASSWORD=t4Ph722qJ5QHeQ1qfu36
+1
View File
@@ -0,0 +1 @@
REDIS_PASSWORD=H733Kdjndks81
+68
View File
@@ -0,0 +1,68 @@
package main
import (
"fmt"
"io"
"log"
"net/http"
"os"
"path/filepath"
"runtime"
)
var (
apiRoot = "http://localhost:9999/api/plugins/netbox-dns"
token = "w5pgWXPqZVmngLN4w4XwuPvZfUC72ytDxnnHgEmI"
execdir string
)
func init() {
_, filename, _, ok := runtime.Caller(0)
if !ok {
panic("unable to get current filename")
}
execdir = filepath.Dir(filename)
}
func post(client *http.Client, path string, filepath string) (string, []byte) {
file, err := os.Open(filepath)
if err != nil {
log.Fatal(err)
}
defer file.Close()
stat, _ := file.Stat()
req, err := http.NewRequest("POST", apiRoot+path, file)
if err != nil {
log.Fatal(err)
}
req.Header.Set("Authorization", fmt.Sprintf("Token %s", token))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json; indent=4")
req.ContentLength = stat.Size()
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
content, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
return resp.Status, content
}
func main() {
nameservers := filepath.Join(execdir, "nameservers.json")
zones := filepath.Join(execdir, "zones.json")
records := filepath.Join(execdir, "records.json")
client := &http.Client{}
nsStatus, nsContent := post(client, "/nameservers/", nameservers)
log.Printf("nameservers: %s\n%s", nsStatus, nsContent)
zoneStatus, zoneContent := post(client, "/zones/", zones)
log.Printf("zones: %s\n%s", zoneStatus, zoneContent)
recordStatus, recordContent := post(client, "/records/", records)
log.Printf("records: %s\n%s", recordStatus, recordContent)
}
+8
View File
@@ -0,0 +1,8 @@
[
{
"name": "dns01.example.com"
},
{
"name": "dns02.example.com"
}
]
+250
View File
@@ -0,0 +1,250 @@
[
{
"zone": {
"name": "example.com"
},
"type": "A",
"name": "dns01",
"value": "10.0.0.10"
},
{
"zone": {
"name": "example.com"
},
"type": "AAAA",
"name": "dns01",
"value": "2001:db8:dead:beef::1:10"
},
{
"zone": {
"name": "example.com"
},
"type": "A",
"name": "dns02",
"value": "10.0.0.11"
},
{
"zone": {
"name": "example.com"
},
"type": "AAAA",
"name": "dns02",
"value": "2001:db8:dead:beef::1:11"
},
{
"zone": {
"name": "example.com"
},
"type": "A",
"name": "aservice",
"value": "10.0.0.12"
},
{
"zone": {
"name": "example.com"
},
"type": "AAAA",
"name": "aservice",
"value": "2001:db8:dead:beef::1:12"
},
{
"zone": {
"name": "example.com"
},
"type": "MX",
"name": "@",
"value": "10 mail.example.com"
},
{
"zone": {
"name": "example.com"
},
"type": "A",
"name": "mail",
"value": "10.0.0.13"
},
{
"zone": {
"name": "example.com"
},
"type": "AAAA",
"name": "mail",
"value": "2001:db8:dead:beef::1:13"
},
{
"zone": {
"name": "example.com"
},
"type": "TXT",
"name": "@",
"value": "v=spf1 ip4:10.0.0.13 ip6:2001:db8:dead:beef::1:13 a -all"
},
{
"zone": {
"name": "example.com"
},
"type": "TXT",
"name": "@",
"value": "v=DMARC1;p=none;sp=quarantine;pct=100;rua=admin@example.com;"
},
{
"zone": {
"name": "example.com"
},
"type": "TXT",
"name": "@",
"value": "\"some value\"\\r\\n\"another value\""
},
{
"zone": {
"name": "example.com"
},
"type": "TXT",
"name": "@",
"value": "\"newline record\"\\n\"second value\""
},
{
"zone": {
"name": "example.com"
},
"type": "TXT",
"name": "@",
"value": "\"my value\" \"second my value\" \"third my value\""
},
{
"zone": {
"name": "example.com"
},
"type": "A",
"name": "puppet-server-a",
"value": "10.0.0.15"
},
{
"zone": {
"name": "example.com"
},
"type": "AAAA",
"name": "puppet-server-a",
"value": "2001:db8:dead:beef::1:15"
},
{
"zone": {
"name": "example.com"
},
"type": "SRV",
"name": "_x-puppet._tcp",
"value": "0 5 8140 puppet-server-a.example.com"
},
{
"zone": {
"name": "example.com"
},
"type": "A",
"name": "puppet-server-b",
"value": "10.0.0.16"
},
{
"zone": {
"name": "example.com"
},
"type": "AAAA",
"name": "puppet-server-b",
"value": "2001:db8:dead:beef::1:16"
},
{
"zone": {
"name": "example.com"
},
"type": "SRV",
"name": "_x-puppet._tcp",
"value": "0 5 8140 puppet-server-b.example.com"
},
{
"zone": {
"name": "example.com"
},
"type": "A",
"name": "web",
"value": "10.0.0.17"
},
{
"zone": {
"name": "example.com"
},
"type": "AAAA",
"name": "web",
"value": "2001:db8:dead:beef::1:17"
},
{
"zone": {
"name": "example.com"
},
"type": "CNAME",
"name": "www",
"value": "web.example.com"
},
{
"zone": {
"name": "example.com"
},
"type": "NS",
"name": "sub",
"value": "dns01.example.com"
},
{
"zone": {
"name": "example.com"
},
"type": "NS",
"name": "sub",
"value": "dns02.example.com"
},
{
"zone": {
"name": "example.com"
},
"type": "NS",
"name": "subtwo",
"value": "dns01.example.com"
},
{
"zone": {
"name": "example.com"
},
"type": "NS",
"name": "subtwo",
"value": "dns02.example.com"
},
{
"zone": {
"name": "sub.example.com"
},
"type": "A",
"name": "myservice",
"value": "10.0.1.10"
},
{
"zone": {
"name": "sub.example.com"
},
"type": "AAAA",
"name": "myservice",
"value": "2001:db8:dead:beef::2:10"
},
{
"zone": {
"name": "subtwo.example.com"
},
"type": "A",
"name": "myotherservice",
"value": "10.0.2.10"
},
{
"zone": {
"name": "subtwo.example.com"
},
"type": "AAAA",
"name": "myotherservice",
"value": "2001:db8:dead:beef::3:10"
}
]
+209
View File
@@ -0,0 +1,209 @@
[
{
"name": "example.com",
"nameservers": [
{
"name": "dns01.example.com"
},
{
"name": "dns02.example.com"
}
],
"default_ttl": 3600,
"soa_expire": 2419200,
"soa_minimum": 3600,
"soa_mname": {
"name": "dns01.example.com"
},
"soa_ttl": 86400,
"soa_refresh": 43200,
"soa_retry": 7200,
"soa_rname": "admin.example.com",
"soa_serial_auto": false,
"soa_serial": 1
},
{
"name": "0.0.10.in-addr.arpa",
"nameservers": [
{
"name": "dns01.example.com"
},
{
"name": "dns02.example.com"
}
],
"default_ttl": 3600,
"soa_expire": 2419200,
"soa_minimum": 3600,
"soa_mname": {
"name": "dns01.example.com"
},
"soa_ttl": 86400,
"soa_refresh": 43200,
"soa_retry": 7200,
"soa_rname": "admin.example.com",
"soa_serial_auto": false,
"soa_serial": 1
},
{
"name": "1.0.0.0.0.0.0.0.0.0.0.0.f.e.e.b.d.a.e.d.8.b.d.0.1.0.0.2.ip6.arpa",
"nameservers": [
{
"name": "dns01.example.com"
},
{
"name": "dns02.example.com"
}
],
"default_ttl": 3600,
"soa_expire": 2419200,
"soa_minimum": 3600,
"soa_mname": {
"name": "dns01.example.com"
},
"soa_ttl": 86400,
"soa_refresh": 43200,
"soa_retry": 7200,
"soa_rname": "admin.example.com",
"soa_serial_auto": false,
"soa_serial": 1
},
{
"name": "sub.example.com",
"nameservers": [
{
"name": "dns01.example.com"
},
{
"name": "dns02.example.com"
}
],
"default_ttl": 3600,
"soa_expire": 2419200,
"soa_minimum": 3600,
"soa_mname": {
"name": "dns01.example.com"
},
"soa_ttl": 86400,
"soa_refresh": 43200,
"soa_retry": 7200,
"soa_rname": "admin.example.com",
"soa_serial_auto": false,
"soa_serial": 1
},
{
"name": "1.0.10.in-addr.arpa",
"nameservers": [
{
"name": "dns01.example.com"
},
{
"name": "dns02.example.com"
}
],
"default_ttl": 3600,
"soa_expire": 2419200,
"soa_minimum": 3600,
"soa_mname": {
"name": "dns01.example.com"
},
"soa_ttl": 86400,
"soa_refresh": 43200,
"soa_retry": 7200,
"soa_rname": "admin.example.com",
"soa_serial_auto": false,
"soa_serial": 1
},
{
"name": "2.0.0.0.0.0.0.0.0.0.0.0.f.e.e.b.d.a.e.d.8.b.d.0.1.0.0.2.ip6.arpa",
"nameservers": [
{
"name": "dns01.example.com"
},
{
"name": "dns02.example.com"
}
],
"default_ttl": 3600,
"soa_expire": 2419200,
"soa_minimum": 3600,
"soa_mname": {
"name": "dns01.example.com"
},
"soa_ttl": 86400,
"soa_refresh": 43200,
"soa_retry": 7200,
"soa_rname": "admin.example.com",
"soa_serial_auto": false,
"soa_serial": 1
},
{
"name": "subtwo.example.com",
"nameservers": [
{
"name": "dns01.example.com"
},
{
"name": "dns02.example.com"
}
],
"default_ttl": 3600,
"soa_expire": 2419200,
"soa_minimum": 3600,
"soa_mname": {
"name": "dns01.example.com"
},
"soa_ttl": 86400,
"soa_refresh": 43200,
"soa_retry": 7200,
"soa_rname": "admin.example.com",
"soa_serial_auto": false,
"soa_serial": 1
},
{
"name": "2.0.10.in-addr.arpa",
"nameservers": [
{
"name": "dns01.example.com"
},
{
"name": "dns02.example.com"
}
],
"default_ttl": 3600,
"soa_expire": 2419200,
"soa_minimum": 3600,
"soa_mname": {
"name": "dns01.example.com"
},
"soa_ttl": 86400,
"soa_refresh": 43200,
"soa_retry": 7200,
"soa_rname": "admin.example.com",
"soa_serial_auto": false,
"soa_serial": 1
},
{
"name": "3.0.0.0.0.0.0.0.0.0.0.0.f.e.e.b.d.a.e.d.8.b.d.0.1.0.0.2.ip6.arpa",
"nameservers": [
{
"name": "dns01.example.com"
},
{
"name": "dns02.example.com"
}
],
"default_ttl": 3600,
"soa_expire": 2419200,
"soa_minimum": 3600,
"soa_mname": {
"name": "dns01.example.com"
},
"soa_ttl": 86400,
"soa_refresh": 43200,
"soa_retry": 7200,
"soa_rname": "admin.example.com",
"soa_serial_auto": false,
"soa_serial": 1
}
]
+13
View File
@@ -0,0 +1,13 @@
FROM docker.io/netboxcommunity/netbox:latest
COPY ./requirements-plugin.txt /opt/netbox/
RUN /opt/netbox/venv/bin/pip install \
--no-warn-script-location \
-r /opt/netbox/requirements-plugin.txt
COPY configuration/plugins.py /etc/netbox/config/plugins.py
RUN SECRET_KEY="dummydummydummydummydummydummydummydummydummydummy" \
/opt/netbox/venv/bin/python \
/opt/netbox/netbox/manage.py \
collectstatic --no-input
+1
View File
@@ -0,0 +1 @@
netbox-plugin-dns >= 0.22.8
+10
View File
@@ -0,0 +1,10 @@
#!/bin/bash
docker compose -p coredns-netbox-plugin-dns -f ./.testing/docker-compose.yml up -d && \
until [[ "`docker inspect -f {{.State.Health.Status}} coredns-netbox-plugin-dns-netbox-1`" == "healthy" ]]; do
echo "Waiting for Netbox to come online..."
sleep 5;
done && \
go run ./.testing/init/init.go
+14
View File
@@ -0,0 +1,14 @@
-----BEGIN CERTIFICATE-----
MIICHDCCAcKgAwIBAgIUKqkR+rk8a0RIfpAdkRRr/jgdhhQwCgYIKoZIzj0EAwIw
bDELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1TYW4gRnJhbmNp
c2NvMRcwFQYDVQQKEw5OZXRib3ggVGVzdGluZzEfMB0GA1UEAxMWTmV0Ym94IFRl
c3RpbmcgUm9vdCBDQTAeFw0yNDA1MDIwMDU1MDBaFw0yOTA1MDEwMDU1MDBaMGwx
CzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNj
bzEXMBUGA1UEChMOTmV0Ym94IFRlc3RpbmcxHzAdBgNVBAMTFk5ldGJveCBUZXN0
aW5nIFJvb3QgQ0EwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAARInLLhQRy22ueR
FMUVzpzhllZkEkuOMQzDR83X9B5oKWWIhbEtjILLYOigf4BstV4O4NoaNbTF9gON
PRtkVL0ao0IwQDAOBgNVHQ8B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