From b18692e87f0f6b86d9292be832619fad16dc9588 Mon Sep 17 00:00:00 2001 From: rskntroot Date: Thu, 13 Feb 2025 20:48:44 -0700 Subject: [PATCH] add coding sect --- README.md | 2 +- mkdocs/docs/coding/r53-ddns.md | 103 ++++++++++++++++++ .../docs/{projects/rust.md => coding/test.md} | 19 ++-- 3 files changed, 115 insertions(+), 9 deletions(-) create mode 100644 mkdocs/docs/coding/r53-ddns.md rename mkdocs/docs/{projects/rust.md => coding/test.md} (94%) diff --git a/README.md b/README.md index ae278fd..c9eb245 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # rskio -## brief +## Brief a mkdocs site for rskio.com diff --git a/mkdocs/docs/coding/r53-ddns.md b/mkdocs/docs/coding/r53-ddns.md new file mode 100644 index 0000000..1834055 --- /dev/null +++ b/mkdocs/docs/coding/r53-ddns.md @@ -0,0 +1,103 @@ +# r53-ddns + +[https://github.com/rskntroot/r53-ddns](https://github.com/rskntroot/r53-ddns) + +Route53 Dynamic DNS + +## Brief + +Submits a Route53 `ChangeRequest` for updating `A` or `AAAA` records when PublicIP drift is detected. + +Drift detection is determined by comparing http request to `icanhazip.com` and a DNS lookup to `cloudflare`. + +This is intended to be installed on a public-facing loadbalancer. + +## Assumptions + +1. Your ISP randomly changes your PublicIP and that pisses you off. +1. You just want something that will curl `ipv4.icanhazip.com`, check 3rd-party dns, and update Route53. +1. Your Name records only contain a single IP. (future update maybe). + +If so, this is for you. + +## Setup + +1. setup `Route53AllowRecordUpdate.policy` + ```zsh + DNS_ZONE_ID=YOURZONEIDHERE \ + envsubst < aws.policy > Route53AllowRecordUpdate.policy + ``` +1. in aws, create IAM user, attach policy, generate access keys for automated service +1. log into aws cli with the account you created above + ``` + aws configure + ``` +1. setup link in `/usr/bin` + ``` zsh + ln -sf ~/r53-ddns/target/release/r53-ddns /usr/bin/r53-ddns + ``` +1. setup systemd service and then install as normal + ```zsh + DNS_ZONE_ID=YOURZONEIDHERE \ + DOMAIN_NAME=your.domain.com. \ + envsubst < r53-ddns.service | sudo tee -a /etc/systemd/system/r53-ddns.service + ``` + +## CLI Usage + +``` +$ r53-ddns -h +A CLI tool for correcting drift between your PublicIP and Route53 DNS A RECORD + +Usage: r53-ddns --dns-zone-id --domain-name + +Options: + -z, --dns-zone-id DNS ZONE ID (see AWS Console Route53) + -d, --domain-name DOMAIN NAME (ex. 'docs.rskio.com.') + -h, --help Print help +``` + +### Service + +``` zsh +export DNS_ZONE_ID=YOUR-DNS-ZONE-ID +export DOMAIN_NAME=YOUR-DOMAIN-NAME +export USER=$(whoami) +``` + +``` zsh +envsubst < r53-ddns.service | sudo tee -a /etc/systemd/system/r53-ddns.service +sudo systemctl daemon-reload +sudo systemctl start r53-ddns.service +sudo systemctl status r53-ddns.service +``` + +``` +$ systemctl status r53-ddns.service +● r53-ddns.service - Route53 Dynamic DNS Service + Loaded: loaded (/etc/systemd/system/r53-ddns.service; enabled; vendor preset: enabled) + Active: active (running) since Mon 2024-07-29 09:03:40 UTC; 7min ago + Main PID: 215630 (r53-ddns) + Tasks: 6 (limit: 18886) + Memory: 3.6M + CPU: 389ms + CGroup: /system.slice/r53-ddns.service + └─215630 /usr/bin/r53-ddns -z [##TRUNCATED##] -d rskio.com. + +Jul 29 09:03:40 hostname systemd[1]: Started Route53 Dynamic DNS Service. +Jul 29 09:03:40 hostname r53-ddns[215630]: [2024-07-29T09:03:40Z INFO r53_ddns] starting with options: -z [##TRUNCATED##] -d rskio.com. +Jul 29 09:09:41 hostname r53-ddns[215630]: [2024-07-29T09:09:41Z INFO r53_ddns::dns] dynamic ip drift detected: 10.0.0.1 -> 71.211.88.219 +Jul 29 09:09:41 hostname r53-ddns[215630]: [2024-07-29T09:09:41Z INFO r53_ddns::route53] requesting update to route53 record for A rskio.com. -> 71.211.88.219 +Jul 29 09:09:41 hostname r53-ddns[215630]: [2024-07-29T09:09:41Z INFO r53_ddns::route53] change_id: /change/C02168177BNS6R50C32Q has status: Pending +Jul 29 09:10:41 hostname r53-ddns[215630]: [2024-07-29T09:09:41Z INFO r53_ddns::route53] change_id: /change/C02168177BNS6R50C32Q has status: Insync +``` + +## Q&A + +> Why did you do create this monster in rust? + +To be able to handle errors in the future. + +> wen IPv6? + +It should work with IPv6. diff --git a/mkdocs/docs/projects/rust.md b/mkdocs/docs/coding/test.md similarity index 94% rename from mkdocs/docs/projects/rust.md rename to mkdocs/docs/coding/test.md index 0de0ace..ed49076 100644 --- a/mkdocs/docs/projects/rust.md +++ b/mkdocs/docs/coding/test.md @@ -1,13 +1,14 @@ -# Rust +# IPADDR -## Env::args() +## Brief -### Brief +A naive attempt at optimizing an ipv4 address with only std::env -A naive attempt at optimizing a simple ipv4 address checker using env::args() +Note, using `strace` to judge efficacy not a valid approach. + I ended up trying a couple different tests, but need to work on better methodology. -#### Assumptions +## Assumptions === "Cargo.tml" @@ -21,7 +22,9 @@ A naive attempt at optimizing a simple ipv4 address checker using env::args() panic = "abort" ``` -#### Unoptimized +## Code + +### Unoptimized - Stores args as an immutable (imut) string vector - Stores `ip_addr` as imut string then shadows as imut string slice vector @@ -87,7 +90,7 @@ A naive attempt at optimizing a simple ipv4 address checker using env::args() ``` -#### Optimized +### Optimized - Needs some cleanup - Needs break for args after index 1 @@ -148,4 +151,4 @@ A naive attempt at optimizing a simple ipv4 address checker using env::args() 0.00 0.000000 0 1 execve ------ ----------- ----------- --------- --------- ------------------ 100.00 0.000698 10 65 2 total - ``` \ No newline at end of file + ```