update-apex-ips

command module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 15 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

update-apex-ips

Keeps a zone apex A record in step with a subdomain. A zone apex can't be a CNAME, so when www.example.com points at a load balancer, the apex example.com needs the same IPs as plain A records.

update-apex-ips -name www.example.com           # plan only
update-apex-ips -name www.example.com -apply    # update Route53
  1. Resolves -name (IPv4) with the system resolver.
  2. Looks up the apex (derived with the public suffix list) the same way. If it already matches, stops.
  3. Otherwise finds the public Route53 hosted zone (or use -zone-id), reads the apex A record, and prints the difference. With -apply, UPSERTs the apex to the source's IPs.

Exit codes: 0 in sync or applied, 1 error, 2 drift found in plan-only mode.

An existing record keeps its TTL; a new record gets 300 s. It refuses to run when the name is already the apex, when the source has no IPv4 addresses, or when the apex record is an alias or a weighted, latency or failover set.

AWS access

Standard AWS SDK credential chain. The principal needs route53:ListHostedZones (account-wide), and route53:ListResourceRecordSets and route53:ChangeResourceRecordSets (scopeable to one zone).

Running in a pod

The program uses the standard AWS credential chain, so the pod only needs a credentials file. Use short-lived STS credentials from the OpenBao/Vault AWS secrets engine (credential_type=assumed_role); they work immediately, with no IAM propagation delay. Two ways to deliver them:

Delivery Manifests Use when
External Secrets Operator (VaultDynamicSecret) deploy/eso/ ESO is already installed
Vault agent injector deploy/injector/ the injector is installed

The Dockerfile builds a small nonroot image and cross-compiles, so build for the cluster's architecture with docker buildx build --platform linux/amd64 -t REGISTRY/update-apex-ips:TAG ..

One-time setup (both options)

AWS (an administrator; the policy documents are in deploy/iam/, with placeholders):

  1. Create the IAM user ENGINE_USER with engine-user-policy.json (it may only sts:AssumeRole the role below, and create, list and delete its own access keys so OpenBao can run bao write -f aws/config/rotate-root). Create no access key until the OpenBao engine is ready to receive it.
  2. Create the role update-apex-ips with trust policy trust-policy.json and permissions permissions-policy.json. The permissions allow only UPSERT of A records, only on the apex names, in the listed zones; the default 1 h maximum session is enough.
  3. Later, create one access key for ENGINE_USER and write it straight into OpenBao as the engine's root (bao write aws/config/root). Keep it out of shell history, logs, and chat.

OpenBao/Vault (keep keys out of shell history):

bao secrets enable aws
bao write aws/config/root region=us-east-1 access_key=... secret_key=...
bao write aws/roles/update-apex-ips \
    credential_type=assumed_role \
    role_arns=arn:aws:iam::ACCOUNT_ID:role/update-apex-ips \
    default_sts_ttl=1h max_sts_ttl=1h
bao policy write update-apex-ips - <<'POLICY'
path "aws/creds/update-apex-ips" { capabilities = ["read"] }
POLICY
bao write auth/AUTH_MOUNT/role/update-apex-ips \
    bound_service_account_names=update-apex-ips-eso \
    bound_service_account_namespaces=NAMESPACE \
    policies=update-apex-ips ttl=15m

OpenBao does not bundle the AWS secrets engine in its core binary. If bao secrets enable aws reports an unknown plugin, declare the secrets-aws plugin from openbao-plugins in the server configuration (plugin "secret" "aws" { ... } with its image, version and sha256sum) and restart the servers.

Cluster

Apply deploy/eso/credentials.yaml and deploy/eso/cronjob.yaml after replacing the placeholders. For the injector, apply deploy/injector/cronjob.yaml instead (its init-only mode, vault.hashicorp.com/agent-pre-populate-only, lets the Job finish).

Start plan-only: leave -apply off, so a drift exits 2 and the Job shows as failed, which is a useful alert while you watch the first runs. Trigger one run by hand to prove the credential chain: kubectl -n NAMESPACE create job --from=cronjob/update-apex-ips first-run.

Notes:

  • The credentials template reads security_token. Check the field names with bao read aws/creds/update-apex-ips.
  • The public-DNS check goes through the cluster DNS (CoreDNS). A rewrite or split-horizon rule for the name inside the cluster can hide drift.

Caveats

  • The public check uses the system resolver, so a stale cache can hide drift or report a false mismatch.
  • Copying IPs only makes sense if the source's A records are stable. A source that rotates IPs or CNAMEs to a CDN will make the apex chase it.

Build

go build -o update-apex-ips .
go test ./...

License

MIT; see LICENSE.

Documentation

Overview

update-apex-ips keeps a zone apex A record in step with a subdomain.

Given a source name such as www.mailstrom.co, it resolves the source's IPv4 addresses and compares them with the apex (mailstrom.co) in public DNS. If they match, it stops. Otherwise it compares with the apex A record in Route53 and, with -apply, updates it. (A zone apex cannot be a CNAME, so the apex gets the source's IPs as plain A records.)

Default is plan-only: it prints the difference and exits 2 if the apex is out of date. Exit codes: 0 in sync (or applied), 1 error, 2 drift found in plan-only mode.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL