crutonjohn / external-dns-opnsense-webhook

ExternalDNS webhook to manage OPNsense Unbound DNS records
Apache License 2.0
5 stars 2 forks source link

DNS Records are created then deleted automatically #19

Open chkpwd opened 1 week ago

chkpwd commented 1 week ago

On startup, the webhook container initializes a connection with the provider, checks for existing records, creates the ingress/service record, then does a final POST with an empty payload (not sure why). In the end, it seems the record does get created but gets deleted.

The expectation would be to for the webhook provider to list all existing records, ensure the record does not exist, and then create the record.

Not sure if the final POST being empty is an issue but thought I'd mention it.

Configuration:

fullnameOverride: external-dns-opnsense
logLevel: debug
podSecurityContext:
  fsGroup: 65534
securityContext:
  runAsNonRoot: true
  runAsUser: 65534
  readOnlyRootFilesystem: true
  capabilities:
    drop: ["ALL"]
provider:
  name: webhook
  webhook:
    image:
      repository: ghcr.io/crutonjohn/external-dns-opnsense-webhook
      tag: v0.1.0
    env:
      - name: OPNSENSE_API_SECRET
        valueFrom:
          secretKeyRef:
            name: external-dns-opnsense-secret
            key: api_secret
      - name: OPNSENSE_API_KEY
        valueFrom:
          secretKeyRef:
            name: external-dns-opnsense-secret
            key: api_key
      - name: OPNSENSE_HOST
        value: http://172.16.16.1
      - name: OPNSENSE_SKIP_TLS_VERIFY
        value: "true"
      - name: LOG_LEVEL
        value: debug
    livenessProbe:
      httpGet:
        path: /healthz
        port: http-wh-metrics
      initialDelaySeconds: 10
      timeoutSeconds: 5
    readinessProbe:
      httpGet:
        path: /readyz
        port: http-wh-metrics
      initialDelaySeconds: 10
      timeoutSeconds: 5
extraArgs:
  - --events
  - --ingress-class=int-ingress
  - --ignore-ingress-tls-spec
  - --annotation-filter=external-dns.alpha.kubernetes.io/exclude notin (true)
policy: sync
sources: ["ingress", "service"]
registry: noop
domainFilters: ["local.chkpwd.com"]
resources:
  requests:
    cpu: 10m
    memory: 100Mi
  limits:
    memory: 250Mi

As noted above (i.e. empty payload):

{"level":"debug","msg":"create: created record: {Host:{Uuid: Enabled: Hostname: Domain: Rr: Server: Description: Mx: MxPrio:}}","time":"2024-06-19T20:11:50Z"}

Full logs of one record:

external-dns-opnsense-8fb8bf775-98wkc webhook external-dns-provider-opnsense
external-dns-opnsense-8fb8bf775-98wkc webhook version: v0.1.0 (4af0e0a7b06c5ba31dc2b82c39e2abb370727ab9)
external-dns-opnsense-8fb8bf775-98wkc webhook
external-dns-opnsense-8fb8bf775-98wkc webhook {"level":"info","msg":"creating opnsense provider with no kind of domain filters","time":"2024-06-19T20:11:49Z"}
external-dns-opnsense-8fb8bf775-98wkc webhook {"level":"debug","msg":"doRequest: making GET request to http://172.16.16.1/api/unbound/service/status","time":"2024-06-19T20:11:49Z"}
external-dns-opnsense-8fb8bf775-98wkc webhook {"level":"debug","msg":"headers: Requesting http://172.16.16.1/api/unbound/service/status","time":"2024-06-19T20:11:49Z"}
external-dns-opnsense-8fb8bf775-98wkc webhook {"level":"debug","msg":"doRequest: response code from GET request to http://172.16.16.1/api/unbound/service/status: 200","time":"2024-06-19T20:11:49Z"}
external-dns-opnsense-8fb8bf775-98wkc webhook {"level":"info","msg":"starting server on addr: 'localhost:8888' ","time":"2024-06-19T20:11:49Z"}
external-dns-opnsense-8fb8bf775-98wkc webhook {"level":"info","msg":"starting health server on addr: '0.0.0.0:8080' ","time":"2024-06-19T20:11:49Z"}
external-dns-opnsense-8fb8bf775-98wkc webhook {"level":"debug","msg":"requesting records","requestMethod":"GET","requestPath":"/records","time":"2024-06-19T20:11:50Z"}
external-dns-opnsense-8fb8bf775-98wkc webhook {"level":"debug","msg":"records: retrieving records from opnsense","time":"2024-06-19T20:11:50Z"}
external-dns-opnsense-8fb8bf775-98wkc webhook {"level":"debug","msg":"doRequest: making GET request to http://172.16.16.1/api/unbound/settings/searchHostOverride","time":"2024-06-19T20:11:50Z"}
external-dns-opnsense-8fb8bf775-98wkc webhook {"level":"debug","msg":"headers: Requesting http://172.16.16.1/api/unbound/settings/searchHostOverride","time":"2024-06-19T20:11:50Z"}
external-dns-opnsense-8fb8bf775-98wkc webhook {"level":"debug","msg":"doRequest: response code from GET request to http://172.16.16.1/api/unbound/settings/searchHostOverride: 200","time":"2024-06-19T20:11:50Z"}
external-dns-opnsense-8fb8bf775-98wkc webhook {"level":"debug","msg":"gethost: retrieved records: []","time":"2024-06-19T20:11:50Z"}
external-dns-opnsense-8fb8bf775-98wkc webhook {"level":"debug","msg":"records: retrieved: []","time":"2024-06-19T20:11:50Z"}
external-dns-opnsense-8fb8bf775-98wkc webhook {"level":"debug","msg":"returning records count: 0","requestMethod":"GET","requestPath":"/records","time":"2024-06-19T20:11:50Z"}
external-dns-opnsense-8fb8bf775-98wkc webhook {"level":"debug","msg":"requesting adjust endpoints count: 18","time":"2024-06-19T20:11:50Z"}
external-dns-opnsense-8fb8bf775-98wkc webhook {"level":"debug","msg":"return adjust endpoints response, resultEndpointCount: 18","time":"2024-06-19T20:11:50Z"}
external-dns-opnsense-8fb8bf775-98wkc webhook {"level":"debug","msg":"requesting apply changes, create: 18 , updateOld: 0, updateNew: 0, delete: 0","requestMethod":"POST","requestPath":"/records","time":"2024-06-19T20:11:50Z"}
external-dns-opnsense-8fb8bf775-98wkc webhook {"level":"debug","msg":"create: Try pulling pre-existing Unbound CNAME record: prowlarr.local.chkpwd.com","time":"2024-06-19T20:11:50Z"}
external-dns-opnsense-8fb8bf775-98wkc webhook {"level":"debug","msg":"doRequest: making GET request to http://172.16.16.1/api/unbound/settings/searchHostOverride","time":"2024-06-19T20:11:50Z"}
external-dns-opnsense-8fb8bf775-98wkc webhook {"level":"debug","msg":"headers: Requesting http://172.16.16.1/api/unbound/settings/searchHostOverride","time":"2024-06-19T20:11:50Z"}
external-dns-opnsense-8fb8bf775-98wkc webhook {"level":"debug","msg":"doRequest: response code from GET request to http://172.16.16.1/api/unbound/settings/searchHostOverride: 200","time":"2024-06-19T20:11:50Z"}
external-dns-opnsense-8fb8bf775-98wkc webhook {"level":"debug","msg":"gethost: retrieved records: []","time":"2024-06-19T20:11:50Z"}
external-dns-opnsense-8fb8bf775-98wkc webhook {"level":"debug","msg":"lookup: Splitting FQDN","time":"2024-06-19T20:11:50Z"}
external-dns-opnsense-8fb8bf775-98wkc webhook {"level":"debug","msg":"lookup: No matching record found for Host=prowlarr, Domain=local.chkpwd.com, Type=CNAME","time":"2024-06-19T20:11:50Z"}
external-dns-opnsense-8fb8bf775-98wkc webhook {"level":"debug","msg":"create: POST: {\"host\":{\"uuid\":\"\",\"enabled\":\"1\",\"hostname\":\"prowlarr\",\"domain\":\"local.chkpwd.com\",\"rr\":\"CNAME\",\"server\":\"local.chkpwd.com\"}}","time":"2024-06-19T20:11:50Z"}
external-dns-opnsense-8fb8bf775-98wkc webhook {"level":"debug","msg":"doRequest: making POST request to http://172.16.16.1/api/unbound/settings/addHostOverride","time":"2024-06-19T20:11:50Z"}
external-dns-opnsense-8fb8bf775-98wkc webhook {"level":"debug","msg":"headers: Requesting http://172.16.16.1/api/unbound/settings/addHostOverride","time":"2024-06-19T20:11:50Z"}
external-dns-opnsense-8fb8bf775-98wkc webhook {"level":"debug","msg":"doRequest: response code from POST request to http://172.16.16.1/api/unbound/settings/addHostOverride: 200","time":"2024-06-19T20:11:50Z"}
external-dns-opnsense-8fb8bf775-98wkc webhook {"level":"debug","msg":"create: created record: {Host:{Uuid: Enabled: Hostname: Domain: Rr: Server: Description: Mx: MxPrio:}}","time":"2024-06-19T20:11:50Z"}

History from Opnsense UI: image