secure-zones.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/bash
  2. APITOKEN=`pdns_control current-config | awk -F= -v key="api-key" '$1==key {print $2}'`
  3. cd /root/cronhook
  4. # Iterate over new zones (created with type NATIVE and without DNSSEC)
  5. for ZONE in `echo "SELECT name FROM domains WHERE type = 'NATIVE' && id NOT IN(SELECT domain_id FROM cryptokeys WHERE active = 1);" | mysql --defaults-file=my.cnf -N`; do
  6. set -ex
  7. PARENT=${ZONE#*.}
  8. SALT=`head -c32 /dev/urandom | sha256sum | cut -b 1-16`
  9. # Set up DNSSEC, switch zone type to MASTER, and increase serial for notify
  10. pdnsutil secure-zone -- "$ZONE" \
  11. && pdnsutil set-nsec3 -- "$ZONE" "1 0 300 $SALT" \
  12. && pdnsutil set-kind -- "$ZONE" MASTER \
  13. && pdnsutil increase-serial -- "$ZONE"
  14. # Take care of delegations
  15. if [ "$PARENT" == "dedyn.io" ]; then
  16. SUBNAME=${ZONE%%.*}
  17. set +x # don't write commands with sensitive information to the screen
  18. echo "Getting DS records for $ZONE and put them in parent zone"
  19. DATA='{"subname": "'"$SUBNAME"'", "type": "DS", "ttl": 60, "records": '
  20. DATA+=`curl -sS -X GET -H "X-API-Key: $APITOKEN" "http://nslord:8081/api/v1/servers/localhost/zones/$ZONE/cryptokeys" \
  21. | jq -c '[.[] | select(.active == true) | .ds[]?]'`
  22. DATA+=' }'
  23. curl -sS -X POST --data "$DATA" -H "Content-Type: application/json" http://api:8080/api/v1/domains/$PARENT/rrsets/
  24. fi
  25. done