Commit Graph

226 Commits

Author SHA1 Message Date
Brian Cunnie
8c256c773c 🐞 Golang modules: use proper module name
fixes:
```
main.go:7:2: module github.com/cunnie/sslip.io@latest found (v0.0.0-20201126193932-8400f99e37d2), but does not contain package github.com/cunnie/sslip.io/src/xip
```
2020-11-26 15:12:29 -08:00
Brian Cunnie
f2e8c6246f src/bosh-release/src
...so that the packaging script will work.

I made a symbolic link for convenience.
2020-11-26 15:11:25 -08:00
Brian Cunnie
8400f99e37 BOSH release: .gitignore eliminates unhappy commits
I especially don't want to commit the `config/private.yml`, which has my
GCS credentials.
2020-11-26 11:39:32 -08:00
Brian Cunnie
b640f0b89e BOSH release: vendor the Golang package
I'll need Golang to compile the DNS server during the compilation phase.

<https://github.com/bosh-packages/golang-release>
2020-11-26 11:38:22 -08:00
Brian Cunnie
2d30e75f7e BOSH release: use GCS to store the BOSH blobs
...and the bucket's name is <drumroll> ... sslip-io-release! How's that
for the principle of least surprise?
2020-11-26 11:37:35 -08:00
Brian Cunnie
47adbd1706 BOSH Release for DNS server: job sslip.io-dns-server
This is a bittersweet moment—it's likely the last BOSH release I'll ever
write, and in some ways is closing a chapter of my life that I found
incredibly fun, exciting, and educational.

Why write a BOSH Release? Because the sslip.io infrastructure, or at
least three of the four nameservers, are BOSH-deployed.

Why write a DNS server? Why not continue with the existing PowerDNS
server + BASH backend? Because I'm stuck at the 4.2.2 PowerDNS release,
and I was unable to get 4.3+ to compile in the BOSH way. Let's be
honest: converting an application to a BOSH package is like doing a
port, a difficult port, and it was easier to write my own DNS server
than port PowerDNS 4.3+ to BOSH.

There's only one job in this commit (`sslip.io-dns-server`), which is
clearly named to avoid confusing with the at least 3 other DNS servers
(BOSH's DNS, BIND, and PowerDNS) that have BOSH releases. The BOSH
package will be in an upcoming commit.
2020-11-25 15:05:07 -08:00
Brian Cunnie
d728bb2a0e Experimental server uses Golang modules
...because I want to learn how to use Go modules.

(also I now ignore macOS dingleberries, `.DS_Store`)
2020-11-22 03:52:15 -08:00
Brian Cunnie
4ce0fa323c Document the experimental Golang DNS server
This is mostly for me because I forget how I wrote it (e.g. what happens
when you query a `TXT` record).
2020-11-22 03:47:40 -08:00
Brian Cunnie
15a9cd41e5 Logging is finished
I used a shorthand logging which extracts the info I'm interested in:
- IP of the asker (e.g. 10.0.9.30)
- Port of the asker (e.g. 59036)
- Type of the question (e.g. TypeA)
- Name of the question (e.g. 127.0.0.1.nono.io)
- Question mark (a delimiter)
- one of the following
  - answer (e.g. 127.0.0.1, MX, NS, SOA)
  - or no answer, but an authority section (e.g. nil, SOA)
2020-10-04 13:33:44 -04:00
Brian Cunnie
558a71d0c0 processQuestion() uses name result parameters, too
<https://golang.org/doc/effective_go.html#named-results>
2020-10-04 12:23:50 -04:00
Brian Cunnie
31a0723fd5 QueryResponse() uses named return values
It's more of an experiment than anything else, but I like how it
documents the purpose of the return value.
2020-10-04 12:23:18 -04:00
Brian Cunnie
dc341d1ef7 Scaffolding for log messages
We want to log queries (mostly because I'd like some metric of how many
queries people are making, what those queries are, and what my answers
are).

I also put a guard against one of the error conditions (I had assumed
only one type of error would ever be returned; I believe that assumption
is naïve)
2020-10-04 10:48:49 -04:00
Brian Cunnie
5b1e9986c0 Return remaining records (answers: 0, authorities: 1)
- We return the remaining records (e.g. SRV, HINFO). The behavior is the
  same for an A/AAAA record that is not found, i.e. no answers, 1
  authority.
2020-10-02 11:48:11 -04:00
Brian Cunnie
c3f96b8890 DNS "ANY" Type returns "Not implemented"
Blog post for rationale: https://blog.cloudflare.com/rfc8482-saying-goodbye-to-any/

I am following the behavior of 1.1.1.1, but I may switch to the behavior
of 8.8.8.8 (Google), which returns all records.
2020-10-01 15:02:44 -04:00
Brian Cunnie
4194986d77 NS records are properly returned
- Unlike MX and SOA records, NS records are an array.
- Moved the variables into a block `var ( ... )`, reads more easily.
- `processQuestion()` answers MX & SOA records (and of course NS
records)
2020-09-30 10:35:20 -07:00
Brian Cunnie
15900f4c51 Tidy up: no panic()s
- user better variable naming
- sort functions somewhat alphabetically
2020-09-27 17:44:57 -07:00
Brian Cunnie
41b171fe8d Extracted method processQuestion()
...because `QueryResponse()` was becoming much too big.
2020-09-27 14:47:15 -07:00
Brian Cunnie
2ad70a028a SOAResource(), MXResource() have unit tests
Sure, they have unit tests, but the methods are so simple I'm not sure
they're worth testing.

I changed the hostmaster to `yoyo@nono.io` because I felt more
comfortable having the email on ProtonMail in lieu of Gmail.
2020-09-27 14:27:02 -07:00
Brian Cunnie
93748f8be2 xip: lookup IPv6 (AAAA) records, too
- Refactored the tests, but they're still hard to follow

Todo:

- break out the case statement to a separate method in `QueryResponse()`
- add NS, MX records
2020-09-23 15:35:35 -07:00
Brian Cunnie
c4e5dfb0ca Use dnsmessage's Parser() and Builder()`
- Change Ginkgo's `To(Not(` to use the shorter `ToNot(`
- did fewer initializations in the `vars` block and moved them to the
  `BeforeEach()` blocks.

The `QueryResponse()` test is too long & convoluted; even I have a hard
time understanding them, and I wrote them! The tests & code should be
re-written, but that's for another day.
2020-09-20 16:39:04 -07:00
Brian Cunnie
67acbb7f47 Golang: use dnsmessage.Builder
- It automatically populates the header for us, which would have been a
  big headache to do manually.
- Switched `ENOTFOUND` to `ErrNotFound`, and updated the error message
  as well. As sad as it was to make this switch, I must acknowledge that
  I'm coding in Go, not C, and I should follow its conventions.
- TWO OF THE TESTS ARE BROKEN. I know, I'll fix them soon. I should have
  fixed the tests first, then the code, but I was overeager.
2020-09-16 20:04:25 -07:00
Brian Cunnie
7b3fdd9c04 🏆 Success! It resolves 1 query
- it resolves `127.0.0.1.sslip.io`
- it ranges through all the questions in query, even though, IIRC, only
  the first one is ever populated.
- ran both `gofmt` and `goimports`
2020-09-06 16:03:33 -07:00
Brian Cunnie
e9ef1536cf SOAResource() provides SOA information
- currently hard-coded. And I didn't think too hard about how I could
  make it more flexible in the future.
- various times stolen from the domain `google.com`, with the exception
  of `minTTL`, which I bumped from 60 to 300.
- I called variable names that are arrays "...Array" because they're so
  rare--slices are much more common.
- fixed a bug in main.go where the error-logic was inverted.
2020-09-04 14:53:41 -07:00
Brian Cunnie
6cb1a1902e 🐞 can't have break when not in a loop 2020-09-04 12:50:22 -07:00
Brian Cunnie
c189897bed Document xip package, functions
Because I love documenting, and the act of documenting clarifies my
thinking.
2020-09-04 12:23:40 -07:00
Brian Cunnie
293cc3c7f2 Handle DNS query's processing in a separate thread
...because I can. And because it gives me a reason to use `go func()`
2020-09-04 12:20:10 -07:00
Brian Cunnie
d672bbff70 ResponseHeader(), a convenience function
Returns the DNS header, pre-populated. So simple probably not worth
testing.
2020-08-29 15:09:26 -07:00
Brian Cunnie
00d27ea093 QueryResponse() returns syntactically correct
It doesn't provide any answers yet, but the response is correctly
formatted.
2020-08-29 14:28:16 -07:00
Brian Cunnie
4bd039bc57 QueryResponse() is the centerpiece of the library
`QueryResponse()` takes a byte array and returns a byte array. It's a
black box that `main.go` can use to input the DNS query and get back the
DNS response. This enables us to have a very lean `main.go`, which means
we can put much of the processing into the library, and which means we
can unit-test the components.

- A better-late-than-never `gofmt -w .` included cosmetic changes.
2020-08-29 11:59:07 -07:00
Brian Cunnie
2bd50a2241 sslip.io: lean main.go
Moved much of the processing of DNS messages into the library. Testing a
library is easier than testing `main`, so I like to keep a lean
`main`.
2020-08-22 16:13:56 -07:00
Brian Cunnie
06daa8ab29 NameToAAAA() converts IPv6 addresses
IPv6 only works on dashes, not dots. Mostly because the double-colon:
`--1` → `::1`. The double-colon, in dot-notation, would be `..`, which
is invalid in DNS.
2020-08-19 11:41:27 -07:00
Brian Cunnie
0badb9238b NameToA() has better coverage
I couldn't resist—every network I used in my examples is special.
2020-08-17 08:51:17 -07:00
Brian Cunnie
5031bd0ca6 Remove deprecated sslip.go, was renamed to xip.go 2020-08-17 07:53:02 -07:00
Brian Cunnie
65bb857041 NameToA() accommodates hyphens ("-") in hostnames 2020-08-16 19:02:02 -07:00
Brian Cunnie
5af7186566 Golang package xip resolves IPv4 addresses
- tested with ginkgo
- The primary method, `NameToA`, returns a resource and an error.
  The error can be one value, "ENOTFOUND". I was not sure about the
  returning the error—maybe I could return nil (not possible) when
  I can't find the IP, or maybe return a 0.0.0.0 IP, but 0.0.0.0 is a
  valid IP, so I use the error as out-of-band signaling.
2020-08-16 18:43:58 -07:00
Brian Cunnie
8bb2953367 Git must ignore JetBrains's dingleberries
`.idea/` should not be checked in.
2020-08-16 18:43:58 -07:00
Brian Cunnie
70aa45585e Nameservers: remove ns-vultr.nono.io, not always up
ns-vultr.nono.io is a bad nameserver because it's shut down for ~8 days
each month (when the unbelievable Singapore hunger for  NTP uses up my
monthly allowance of 3TB)

Besides, three nameservers is enough.
2020-07-25 16:56:36 -07:00
Brian Cunnie
244ad48bb1 Revert "+foundry.fun"
This reverts commit b8a327b128.

PowerDNS's bind backend doesn't appear to handle wildcards consistently
as secondaries, so I'm reverting this change and instead using a pair of
FreeBSD+bind servers (ns-he + ns-digitalocean) to provide the DNS.
2020-07-25 16:45:14 -07:00
Brian Cunnie
b8a327b128 +foundry.fun 2020-07-24 18:48:05 -07:00
Brian Cunnie
44f3a1cf95 🐞 PowerDNS 4.2.2 pdns.conf: no "first", "second"
fixes:
```
Jul 21 01:07:03 Caught an exception instantiating a backend: launch= suffixes are not supported on the bindbackend
```
```
Jul 21 01:08:47 Fatal error: Trying to set unknown parameter 'bind-first-config'
```
```
Jul 21 01:08:57 Fatal error: Trying to set unknown parameter 'pipe-second-command'
```
2020-07-20 18:32:33 -07:00
Brian Cunnie
ce7ae97e1e k8s: sslip.io nginx: deployment
readiness probes, memory limits—the works!
2020-07-05 17:04:12 -07:00
Brian Cunnie
46468f9f2c k8s: sslip.io DNS: add readiness & liveness probes
Also fix memory requirements: it's 32Mi not 32Gi
2020-07-05 16:51:44 -07:00
Brian Cunnie
bcb4536502 ks8: sslip.io DNS: deployment does not include nginx 2020-07-05 16:41:58 -07:00
Brian Cunnie
3565c5ab99 k8s sslip.io DNS: only request 32Mi
...because the 2 current pods only use 15Mi, 9Mi respectively.
2020-07-05 16:39:47 -07:00
Brian Cunnie
4164af4e9c k8s: introduce nginx Dockerfile
We now introduce a second Dockerfile, `Dockerfile-nginx`, to be used for
the web assets for sslip.io.

It does not run TLS; we assume that the load balancer will take care of
that.

We also gussied-up the PowerDNS Dockerfile with minor changes.
2020-07-05 15:49:42 -07:00
Brian Cunnie
ae1012f483 document_root/ is under k8s/
fixes `Forbidden path outside the build context` when building the
forthcoming `Dockerfile-nginx`
2020-07-05 11:32:27 -07:00
Brian Cunnie
3c7a883709 k8s: Distinguish Dockerfile with -pdns
...to differentiate from the nginx Dockerfile, which is forthcoming.
2020-07-05 09:08:58 -07:00
Brian Cunnie
50e17b3d7f k8s: deployment & nodePort service
- nodePort service is merely a proof-of-concept; this won't be the final
  form the service takes. The port needs to be 53, not 32767.
- the deployment doesn't include the nginx webserver, merely the DNS
  server. Also, I had trouble connecting both UDP & TCP to port 53,
  so I chose UDP.
2020-07-05 08:27:53 -07:00
Brian Cunnie
c89ff9cdd8 sslip.io needs ps, nc, lsof, ifconfig
Requires +19MB: 494 MB → 513 MB
2020-06-06 11:20:03 -07:00
Brian Cunnie
720e2a71b1 DNS: secondaries for diarizer.com
We are now secondaries for diarizer.com because it needs to share the
same webserver as *.cf.nono.io, and needs SSL certs, and needs to be
able to participate in the DNS challenge.
2020-05-24 17:47:22 -07:00