diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e4f5c2f..150b3bf 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,15 +1,50 @@ -name: build release archives +name: release on: + push: + tags: ['v*'] workflow_dispatch: inputs: version: - description: Version to embed, such as v0.1.0 or v0.1.0-rc.1 + description: Version with release notes, such as v0.1.0 required: true type: string permissions: contents: read +concurrency: + group: release-${{ github.ref }} + cancel-in-progress: false jobs: + prepare: + runs-on: ubuntu-latest + timeout-minutes: 5 + outputs: + version: ${{ steps.version.outputs.version }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: Validate release version and notes + id: version + env: + VERSION_INPUT: ${{ inputs.version }} + shell: bash + run: | + if [[ "$GITHUB_EVENT_NAME" == push ]]; then + version="$GITHUB_REF_NAME" + else + version="$VERSION_INPUT" + fi + if [[ ! "$version" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z]+([.-][0-9A-Za-z]+)*)?$ ]]; then + echo 'Expected vMAJOR.MINOR.PATCH[-PRERELEASE]' >&2 + exit 1 + fi + test -s "docs/releases/$version.md" + echo "version=$version" >> "$GITHUB_OUTPUT" + verify: + needs: prepare + uses: ./.github/workflows/test.yml build: + needs: [prepare, verify] runs-on: ubuntu-latest timeout-minutes: 15 steps: @@ -21,13 +56,41 @@ jobs: go-version: "1.26.x" check-latest: true cache: true - - name: Build archives + - name: Build and verify archives env: - RELEASE_VERSION: ${{ inputs.version }} - run: bash scripts/release.sh "$RELEASE_VERSION" + RELEASE_VERSION: ${{ needs.prepare.outputs.version }} + run: | + bash scripts/release.sh "$RELEASE_VERSION" + bash scripts/verify-release.sh "$RELEASE_VERSION" - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: - name: ask53-release-archives - path: dist/ + name: ask53-release-${{ needs.prepare.outputs.version }} + path: dist/${{ needs.prepare.outputs.version }}/ if-no-files-found: error retention-days: 14 + draft: + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') + needs: [prepare, build] + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + contents: write + actions: read + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: Download verified archives and create draft + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + RELEASE_VERSION: ${{ needs.prepare.outputs.version }} + shell: bash + run: | + gh run download "$GITHUB_RUN_ID" --name "ask53-release-$RELEASE_VERSION" --dir "dist/$RELEASE_VERSION" + (cd "dist/$RELEASE_VERSION" && sha256sum -c SHA256SUMS) + flags=(--draft --verify-tag --title "Ask53 $RELEASE_VERSION" --notes-file "docs/releases/$RELEASE_VERSION.md") + if [[ "$RELEASE_VERSION" == *-* ]]; then + flags+=(--prerelease) + fi + gh release create "$RELEASE_VERSION" "${flags[@]}" "dist/$RELEASE_VERSION/"*.tar.gz "dist/$RELEASE_VERSION/SHA256SUMS" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1d4cc33..70571f9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,8 +1,10 @@ name: test on: push: + branches: ['**'] pull_request: workflow_dispatch: + workflow_call: permissions: contents: read concurrency: @@ -44,4 +46,6 @@ jobs: run: go test ./internal/dnsserver -run='^$' -fuzz=FuzzTXTWire -fuzztime=10s -parallel=2 - name: Verify release packaging if: runner.os == 'Linux' - run: make release VERSION=v0.0.0-ci + run: | + make release VERSION=v0.0.0-ci + bash scripts/test-release.sh v0.0.0-ci diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e702b3..7832e97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,12 @@ ## Unreleased -Initial implementation: +No changes yet. + +## v0.1.0 + +First release. See [release notes](docs/releases/v0.1.0.md) for installation and +deployment limitations. - Direct IN/TXT question interface with case normalization and optional namespace. - OpenAI-compatible completion client with configurable endpoint/model/token cap. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 29921f6..6954ff0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -46,7 +46,6 @@ license; third-party code must retain its own license notices. - Questions, answers, provider credentials, and client addresses stay out of logs. - No recursive resolution, DNS forwarding, tools, or unconfigured AI endpoints. -The module is currently a command-only project with local module name `ask53`. -Clone and build it from the checkout. A canonical remote module path can be set -once the repository URL is chosen; do not add a `go install ...@latest` example -with an invented URL. +The module path is `github.com/MeghdadFadaee/ask-53`. Application packages live +under `internal/`; this repository provides commands rather than a public Go +library. Build versioned release binaries with the Makefile to embed the version. diff --git a/Dockerfile b/Dockerfile index 37441e2..23da3e6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,11 @@ FROM golang:1.26-alpine AS build +ARG VERSION=dev WORKDIR /src COPY go.mod go.sum ./ RUN go mod download COPY cmd/ask53 ./cmd/ask53 COPY internal ./internal -RUN CGO_ENABLED=0 go build -trimpath -ldflags='-s -w' -o /ask53 ./cmd/ask53 +RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w -X main.version=${VERSION}" -o /ask53 ./cmd/ask53 FROM alpine:3.23 RUN apk add --no-cache ca-certificates && addgroup -g 10001 ask53 && adduser -D -H -u 10001 -G ask53 ask53 && mkdir -p /var/lib/ask53 && chown ask53:ask53 /var/lib/ask53 diff --git a/Makefile b/Makefile index c30a6b2..5cc2d24 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ VERSION ?= dev ARCH ?= amd64 -.PHONY: build test check linux mock release clean +.PHONY: build test check linux mock release verify-release clean build: go build -trimpath -ldflags='-X main.version=$(VERSION)' -o bin/ask53 ./cmd/ask53 mock: @@ -14,5 +14,7 @@ linux: CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH) go build -trimpath -ldflags='-s -w -X main.version=$(VERSION)' -o bin/ask53-linux-$(ARCH) ./cmd/ask53 release: bash scripts/release.sh '$(VERSION)' +verify-release: + bash scripts/verify-release.sh '$(VERSION)' clean: rm -rf bin coverage.out diff --git a/PUBLISHING.md b/PUBLISHING.md index 79af24b..b9a0ea4 100644 --- a/PUBLISHING.md +++ b/PUBLISHING.md @@ -1,98 +1,116 @@ -# Publishing Ask53 +# Releasing Ask53 -This checkout is prepared for a public source repository. It does not contain a -remote URL, GitHub repository, published release, or registry credentials. +The public source repository is +[MeghdadFadaee/ask-53](https://github.com/MeghdadFadaee/ask-53). The first planned +release is **v0.1.0**. Preparing files or running a local build does not publish it. -## Publish the source repository +## Prepare a release commit -1. Review the source and [MIT license](LICENSE). Actual credentials and private - client networks must stay in ignored local files or outside this checkout. -2. Create an empty public repository on your preferred host. On GitHub, avoid - precreating a README/license because this checkout already provides them. -3. If this checkout has no commits yet, create the initial commit first: +1. Update `CHANGELOG.md` and create `docs/releases/VERSION.md`, including + installation instructions, changes, and known limitations. v0.1.0 is prepared + in [its release notes](docs/releases/v0.1.0.md). Keep an `Unreleased` section for + subsequent work. This project follows 0.x versioning; interfaces may change. +2. Use a supported Go 1.26+ patch release and run: ```sh - git diff --cached --check - git commit -m 'Initial public-ready Ask53 implementation' + go mod verify + make check + make test + make release VERSION=v0.1.0 + make verify-release VERSION=v0.1.0 + bash scripts/test-release.sh v0.1.0 ``` - If your Git configuration requires a signature, make the configured signing - key available locally before committing. The preparation process does not - disable signing or handle private-key passphrases. + Output is `dist/v0.1.0/`: four Linux/macOS amd64/arm64 `.tar.gz` archives and + `SHA256SUMS`. Verification checks all hashes, exact package contents, and the + native binary's version/configuration. Output directories cannot be overwritten; + use `ASK53_RELEASE_DIR=/absolute/new/path` for a fresh candidate build. Generated + files stay ignored and must not be committed. +3. Review and commit the release preparation, preserving configured commit + signing. Push the commit to `main` through the normal review process and wait + for both Linux and macOS test checks to pass. Tag the exact reviewed commit. - Add the repository's actual URL and push the initial branch: +Optional: run the **release** workflow manually on that commit's branch/ref with +`version=v0.1.0`. It runs the same checks and uploads archives as a workflow +artifact, without creating a GitHub release. Release notes must exist for that +version. Inspect/download the artifact from the Actions run. - ```sh - git remote add origin YOUR_REPOSITORY_URL - git push -u origin main - ``` +## Create the draft from a tag -4. On GitHub, wait for both Linux and macOS test jobs to pass. Protect `main`, - require review and the test checks, enable private vulnerability reporting, - and enable secret scanning/push protection where available. The configuration - files here cannot enable host-side settings before a remote exists. -5. Add a repository description, for example: “Ask concise AI questions through - DNS TXT records, with bounded spending, caching, and TCP safeguards.” Suggested - topics: `dns`, `go`, `ai`, `txt-records`, `openai-compatible`. - -The current Go module is intentionally `ask53`, with only internal packages and -commands. Users can clone and build it using `make build`. If you want remote -`go install` support, first choose the final host/owner/repository URL, change -`module ask53` and the internal import prefixes to that canonical path, and -rerun the tests. Do not advertise an unconfigured install URL. - -## Prepare a binary release - -Use a supported Go patch release. Choose the release version, review the -changelog, and run: +After the preparation commit is on `main` and CI is green: ```sh -make check -make test -make release VERSION=v0.1.0 -``` - -The output directory is `dist/v0.1.0/`, containing four `.tar.gz` archives and -`SHA256SUMS`. Each archive contains `ask53`, the MIT license, dependency notices, -README, and example configurations/deployment files. Archives contain no API -keys, runtime budgets, IDE files, or private configuration. The local mock -provider remains a source-checkout development tool, not a release daemon. - -Extract and verify the binary appropriate for your current OS/architecture: - -```sh -cd dist/v0.1.0 -# Linux: -sha256sum -c SHA256SUMS -# macOS alternative: -# shasum -a 256 -c SHA256SUMS -tar -xzf ask53-v0.1.0-linux-amd64.tar.gz -./ask53-v0.1.0-linux-amd64/ask53 -version -``` - -Select the `darwin` archive when testing on macOS. Retain checksum and license -files when redistributing. Do not package your working-directory secrets into a -handmade archive of the entire checkout. - -The **build release archives** GitHub Actions workflow can be started manually -with a version string. It uploads a downloadable workflow artifact under -read-only repository permissions; it does not create tags, GitHub releases, or -container registry pushes. The regular test workflow also checks packaging on -Linux with an unpublished CI version. - -Once the exact release commit's CI is green and its archives are verified: - -```sh -git tag -a v0.1.0 -m 'Ask53 v0.1.0' +git switch main +git pull --ff-only +git tag -s v0.1.0 -m 'Ask53 v0.1.0' git push origin v0.1.0 ``` -Create a release on the repository host from that tag and attach only the four -archives and `SHA256SUMS`. Use the build artifacts from that same commit and -version, not an older local build. Publish the tested limitations from -[TESTING.md](TESTING.md); do not claim an untested live provider or deployment. +Use your configured signing key; do not disable signing to get around a locked +key. Check the target commit before tagging. If you cannot sign tags, follow your +repository's maintainer policy rather than silently publishing an unsigned tag. -Before an actual production release, run the systemd/container installation on -a target Linux host, verify both TCP and UDP port 53 with the intended firewall -and allowlist, and exercise the selected real provider with a deliberately small -budget. Keep existing quota state through upgrades. +Pushing a `v*` tag starts the **release** workflow. It validates the version/notes, +reuses the full Linux/macOS test workflow at the tagged commit, builds and verifies +all four archives, and uploads a workflow artifact. Only then does a separate job +with `contents: write` create a **draft** GitHub release containing the four +archives and `SHA256SUMS`. Build/test jobs retain read-only repository access. +Prerelease versions such as `v0.2.0-rc.1` are marked as prereleases. + +The CLI uses [`--draft` and `--verify-tag`](https://cli.github.com/manual/gh_release_create) +to keep publication manual and require an existing remote tag. No API keys or +repository secrets are required beyond the workflow's scoped `GITHUB_TOKEN`. +Tag creation should use your normal Git credentials; tags pushed by another +workflow using its `GITHUB_TOKEN` generally do not trigger this workflow. + +If checks fail, no draft is created. Fix the problem and use a new version if the +tag was already distributed. Re-run failed jobs for transient errors. If draft +creation partially succeeds, inspect its assets before repairing it; the workflow +intentionally does not overwrite an existing release or replace published assets. + +## Review and publish + +1. Open the draft in GitHub Releases. Confirm its tag/commit, notes, four archives, + and checksum manifest. Download and extract the archive for your machine: + + ```sh + # If all four archives were downloaded: + shasum -a 256 -c SHA256SUMS + # If only one archive was downloaded: + # shasum -a 256 --ignore-missing -c SHA256SUMS + tar -xzf ask53-v0.1.0-darwin-arm64.tar.gz + ./ask53-v0.1.0-darwin-arm64/ask53 -version + ``` + + On Linux use `sha256sum` and the matching `linux` archive. Missing files are + deliberately ignored only in the single-archive example; verify the selected + archive actually reports `OK`. Checksums detect corruption, not independent + publisher authenticity. +2. Review [TESTING.md](TESTING.md). Linux/macOS automated CI is required. A real + provider, container runtime, and systemd installation still need validation on + the intended deployment before calling that deployment production-tested. + Verify TCP/UDP port 53, firewall/allowlist, and a small provider budget there. +3. Click **Publish release** after this review. Keep existing budget state during + upgrades; release archives must never contain credentials or quota state. + +For manual recovery, download the verified artifact from the tagged run, then: + +```sh +gh release create v0.1.0 --draft --verify-tag --title 'Ask53 v0.1.0' \ + --notes-file docs/releases/v0.1.0.md \ + dist/v0.1.0/*.tar.gz dist/v0.1.0/SHA256SUMS +``` + +Only use files produced at that exact tag/version. + +## Repository settings + +Maintainers should protect `main`, require review and Linux/macOS checks, restrict +release-tag creation, and enable private vulnerability reporting and secret +scanning/push protection where available. See [SECURITY.md](SECURITY.md). These +host-side settings are managed separately from the source checkout. + +The Go module is `github.com/MeghdadFadaee/ask-53`; packages are internal and only +commands are distributed. Prefer release binaries or `make build VERSION=v0.1.0` +from the tagged source to obtain an embedded release version. Plain `go install` +uses the development version unless linker flags are supplied. diff --git a/README.md b/README.md index d1a2358..55b524e 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,13 @@ This is a **direct-query application endpoint**, not a recursive resolver or a c Install Go 1.26 or newer and `dig` (`dnsutils` on Debian/Ubuntu, `bind-utils` on many RPM systems; macOS includes it). +Clone the source before running the commands below: + +```sh +git clone https://github.com/MeghdadFadaee/ask-53.git +cd ask-53 +``` + In terminal one, start the deterministic fake provider: ```sh @@ -258,7 +265,7 @@ go test -race -coverprofile=coverage.out ./... go tool cover -func=coverage.out ``` -Tests never use a real AI key. They cover normalized cache keys, real `dig` TCP fallback, simultaneous UDP/TCP queries, 64-way request coalescing, canceled waiters, LRU eviction/expiry, failure suppression, provider HTTP/JSON/body/text errors, redirect rejection, token and byte limits, timeouts, circuit recovery and Retry-After races, daily quota races/persistence/clock rollover, corrupt/missing budget fields, storage failure, IPv6 source grouping, bounded client/connection/waiter tables, TXT wire escaping and UTF-8 boundaries, 512/1232-byte UDP limits, malformed packets and compression loops, EDNS errors, unsupported types/opcodes/classes, allowlists, active shutdown draining, idle connection shutdown, port rebinding, offline config validation, and real process SIGTERM/restart with persistent budget. Fuzzing checks name interpretation and lossless TXT encoding. CI runs these checks on Linux. +Tests never use a real AI key. They cover normalized cache keys, real `dig` TCP fallback, simultaneous UDP/TCP queries, 64-way request coalescing, canceled waiters, LRU eviction/expiry, failure suppression, provider HTTP/JSON/body/text errors, redirect rejection, token and byte limits, timeouts, circuit recovery and Retry-After races, daily quota races/persistence/clock rollover, corrupt/missing budget fields, storage failure, IPv6 source grouping, bounded client/connection/waiter tables, TXT wire escaping and UTF-8 boundaries, 512/1232-byte UDP limits, malformed packets and compression loops, EDNS errors, unsupported types/opcodes/classes, allowlists, active shutdown draining, idle connection shutdown, port rebinding, offline config validation, and real process SIGTERM/restart with persistent budget. Fuzzing checks name interpretation and lossless TXT encoding. CI runs these checks on Linux and macOS. - `cmd/ask53`: configuration, signals, startup, and shutdown. - `cmd/mock-provider`: deterministic, loopback-only test provider. @@ -267,6 +274,8 @@ Tests never use a real AI key. They cover normalized cache keys, real `dig` TCP - `internal/service`: rate gates, durable budget, bounded LRU, request coalescing, circuit breaker. - `internal/dnsserver`: DNS validation, transport policy, bounded listeners, operational HTTP. - `deploy`: systemd unit and production configuration example. +- `scripts`: release packaging, archive verification, and packaging regression tests. +- `docs/releases`: version-specific release notes. ## Protocol and API references @@ -281,9 +290,19 @@ It refuses to overwrite an existing release directory and does not publish. `ask53 -version` reports the embedded version. Regular `make build` defaults to `dev`; `make build VERSION=v0.1.0` embeds an explicit version. -The manual GitHub Actions workflow builds downloadable archives without creating -a release or pushing anything. For maintainer publication steps and the -remaining repository settings, see [PUBLISHING.md](PUBLISHING.md). +Run `make verify-release VERSION=v0.1.0` to check all archive hashes and contents +and exercise the native binary's version/configuration. Docker builds accept +`--build-arg VERSION=v0.1.0` to embed the same version in a locally built image. + +The first release is prepared as **v0.1.0**; see its +[release notes](docs/releases/v0.1.0.md). After publication, download the matching +OS/architecture archive and `SHA256SUMS` from +[GitHub Releases](https://github.com/MeghdadFadaee/ask-53/releases). Verify the +checksum before extraction, then use the bundled deployment instructions. + +Pushing a version tag runs Linux/macOS checks, builds the archives, and creates a +draft GitHub release for maintainer review. Manual workflow runs produce only +downloadable artifacts. For publication steps, see [PUBLISHING.md](PUBLISHING.md). Ask53 is distributed under the [MIT license](LICENSE). Dependencies retain their own licenses, listed in [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md). diff --git a/TESTING.md b/TESTING.md index 01b25fb..b71b2f2 100644 --- a/TESTING.md +++ b/TESTING.md @@ -22,7 +22,7 @@ Verified on 2026-10-01 using Go 1.26.5 on macOS arm64. No paid provider was call Tests exercise malformed DNS packets (including compression loops), unsupported classes/types/opcodes, EDNS version errors, maximum name lengths, TXT byte boundaries and escaping, UDP message ceilings, bounded TCP connections and DNS waiters, 64-way request coalescing, client/IPv6 rate accounting, failed-result caching, provider timeouts/auth/rate/server/JSON/size errors, credential redirect rejection, circuit probing and concurrent Retry-After handling, concurrent durable reservations, corrupt quota state, storage failures, date rollover/rollback, canceled callers, and shutdown/restart behavior. See the test files for reproducible scenarios. -Docker was not available here. Container execution and systemd unit startup were not performed; use the supplied deployment instructions on the target Linux host. The Linux binaries were cross-compiled, not executed locally. CI is configured to execute the automated suite on Linux but was not dispatched during this local task. A live provider's model availability, authentication, latency, and token-field compatibility require an operator-supplied endpoint/model/key and have not been exercised. +Docker was not available here. Container execution and systemd unit startup were not performed; use the supplied deployment instructions on the target Linux host. The Linux binaries were cross-compiled, not executed locally. CI executes the automated suite on Linux and macOS. A live provider's model availability, authentication, latency, and token-field compatibility require an operator-supplied endpoint/model/key and have not been exercised. ## Public repository preparation @@ -30,7 +30,8 @@ The repository preparation checks also passed on 2026-10-01: - MIT license and copied dependency/runtime notices are present. - Both GitHub workflows pass `actionlint`; action references are pinned to - verified upstream commit hashes and use read-only repository permissions. + verified upstream commit hashes. Build/test jobs use read-only repository + permissions; only the tag-triggered draft release job can write releases. - `make check`, `make test`, and all four Linux/macOS release builds pass. - Packaged binaries include the requested version; archives have valid SHA-256 checksums, dependency notices, normalized ownership, and no macOS resource @@ -39,6 +40,24 @@ The repository preparation checks also passed on 2026-10-01: personal absolute paths. Local binaries, release archives, and test output are ignored. Relative documentation links resolve. -No remote repository, public release, or image-registry publication was created -by these preparation checks. Host-side branch protections, private reporting, -and secret scanning must be enabled after the remote repository is created. +No public release or image-registry publication was created by these checks. +Host-side branch protections, private reporting, and secret scanning are managed +separately from the source checkout. + +## v0.1.0 release preparation + +Local checks on 2026-10-01 passed after migrating to the canonical +`github.com/MeghdadFadaee/ask-53` module path: module checksum verification, static +analysis, and the full race/integration suite. All four v0.1.0 archives were built +and verified for checksums and exact package membership. The macOS arm64 release +binary reported `v0.1.0` and validated its bundled local configuration offline. + +Release validation tests also reject invalid versions, overwrites, missing or +corrupt archives, incomplete checksum manifests, extra private files, symlinks, +and an incorrect native binary version. CI runs these packaging regressions on +Linux using an unpublished version. + +The existing `main` commit `cf6ae40` passed hosted Linux/macOS CI before these +preparation changes. The new tag/draft workflow passed local static validation; +its hosted execution requires committing/pushing the prepared changes and tag. +Live provider, Docker, and systemd validation remain outside this local record. diff --git a/cmd/ask53/main.go b/cmd/ask53/main.go index 39e8786..a0b5726 100644 --- a/cmd/ask53/main.go +++ b/cmd/ask53/main.go @@ -9,10 +9,10 @@ import ( "os/signal" "syscall" - "ask53/internal/ai" - "ask53/internal/config" - "ask53/internal/dnsserver" - "ask53/internal/service" + "github.com/MeghdadFadaee/ask-53/internal/ai" + "github.com/MeghdadFadaee/ask-53/internal/config" + "github.com/MeghdadFadaee/ask-53/internal/dnsserver" + "github.com/MeghdadFadaee/ask-53/internal/service" ) var version = "dev" diff --git a/cmd/ask53/main_test.go b/cmd/ask53/main_test.go index 38bac6b..ec6e6b7 100644 --- a/cmd/ask53/main_test.go +++ b/cmd/ask53/main_test.go @@ -17,7 +17,7 @@ import ( "testing" "time" - "ask53/internal/config" + "github.com/MeghdadFadaee/ask-53/internal/config" "github.com/miekg/dns" ) diff --git a/docs/releases/v0.1.0.md b/docs/releases/v0.1.0.md new file mode 100644 index 0000000..7644f65 --- /dev/null +++ b/docs/releases/v0.1.0.md @@ -0,0 +1,56 @@ +# Ask53 v0.1.0 + +First release of Ask53: a small Go service for asking concise AI questions through +direct DNS TXT queries. + +## Included + +- Configurable OpenAI-compatible Chat Completions integration with strict answer + size and token limits. +- Bounded caching, identical-request coalescing, rate limits, a durable daily + attempt budget, and provider failure suppression/circuit breaking. +- UDP and TCP DNS handling; Internet-facing UDP requests require TCP fallback + before AI work or answer delivery. +- Graceful shutdown, private health/statistics endpoints, a deterministic local + provider, and systemd/container deployment examples. +- Static Linux and macOS binaries for amd64 and arm64, MIT licensing, dependency + notices, and SHA-256 checksums. + +## Install + +Download the archive for your OS/architecture and `SHA256SUMS` from this release. +For Linux amd64: + +```sh +sha256sum --ignore-missing -c SHA256SUMS +tar -xzf ask53-v0.1.0-linux-amd64.tar.gz +cd ask53-v0.1.0-linux-amd64 +./ask53 -version +``` + +On macOS, use the appropriate `darwin` archive and +`shasum -a 256 --ignore-missing -c SHA256SUMS` before extraction. These checks +detect damaged downloads; obtain the manifest from the same trusted release. + +Read the bundled README before configuring a provider. Defaults bind to loopback. +For local trials, clone the repository and run `make mock` with the bundled local +configuration; the mock provider is not included in binary archives. + +## Deployment and limitations + +This is a direct-query application, not a recursive resolver or an authoritative +zone server. Public deployments require both TCP and UDP port 53, an appropriate +source allowlist/firewall, and retained budget state. DNS traffic is plaintext; +TCP verifies reachability, not identity. AI output may be inaccurate. + +The daily budget limits attempts, not monetary cost. Set provider-side spending +limits and select a model/token cap suitable for short answers. Remote provider +compatibility and latency depend on the selected provider. + +Automated race, protocol, provider-failure, caching, concurrency, fuzz, and process +restart tests use fake providers. Live paid providers, Docker execution, and +systemd installation have not been validated locally. See the bundled +`TESTING.md` and README for the verification record and deployment steps. + +This is an initial 0.x release; configuration and interfaces may change in future +versions. Keep quota state through upgrades and review release notes first. diff --git a/go.mod b/go.mod index ec930a6..859935c 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module ask53 +module github.com/MeghdadFadaee/ask-53 go 1.26.0 diff --git a/internal/ai/client.go b/internal/ai/client.go index a82ef83..a82d1ef 100644 --- a/internal/ai/client.go +++ b/internal/ai/client.go @@ -15,7 +15,7 @@ import ( "unicode" "unicode/utf8" - "ask53/internal/config" + "github.com/MeghdadFadaee/ask-53/internal/config" ) type Error struct { diff --git a/internal/ai/client_test.go b/internal/ai/client_test.go index 723bd65..6941a44 100644 --- a/internal/ai/client_test.go +++ b/internal/ai/client_test.go @@ -11,7 +11,7 @@ import ( "testing" "time" - "ask53/internal/config" + "github.com/MeghdadFadaee/ask-53/internal/config" ) func clientFor(t *testing.T, h http.HandlerFunc) *Client { diff --git a/internal/dnsserver/handler.go b/internal/dnsserver/handler.go index 08c81c1..927c0af 100644 --- a/internal/dnsserver/handler.go +++ b/internal/dnsserver/handler.go @@ -8,8 +8,8 @@ import ( "time" "unicode/utf8" - "ask53/internal/config" - "ask53/internal/service" + "github.com/MeghdadFadaee/ask-53/internal/config" + "github.com/MeghdadFadaee/ask-53/internal/service" "github.com/miekg/dns" ) diff --git a/internal/dnsserver/server.go b/internal/dnsserver/server.go index 076f993..460f6c2 100644 --- a/internal/dnsserver/server.go +++ b/internal/dnsserver/server.go @@ -11,8 +11,8 @@ import ( "sync/atomic" "time" - "ask53/internal/config" - "ask53/internal/service" + "github.com/MeghdadFadaee/ask-53/internal/config" + "github.com/MeghdadFadaee/ask-53/internal/service" "github.com/miekg/dns" ) diff --git a/internal/dnsserver/server_test.go b/internal/dnsserver/server_test.go index 84f4f1d..2a8f64b 100644 --- a/internal/dnsserver/server_test.go +++ b/internal/dnsserver/server_test.go @@ -19,9 +19,9 @@ import ( "time" "unicode/utf8" - "ask53/internal/ai" - "ask53/internal/config" - "ask53/internal/service" + "github.com/MeghdadFadaee/ask-53/internal/ai" + "github.com/MeghdadFadaee/ask-53/internal/config" + "github.com/MeghdadFadaee/ask-53/internal/service" "github.com/miekg/dns" ) diff --git a/internal/service/engine.go b/internal/service/engine.go index d601d2d..561ab09 100644 --- a/internal/service/engine.go +++ b/internal/service/engine.go @@ -10,8 +10,8 @@ import ( "sync/atomic" "time" - "ask53/internal/ai" - "ask53/internal/config" + "github.com/MeghdadFadaee/ask-53/internal/ai" + "github.com/MeghdadFadaee/ask-53/internal/config" ) var ( diff --git a/internal/service/limits.go b/internal/service/limits.go index 63fe8ac..d44d38e 100644 --- a/internal/service/limits.go +++ b/internal/service/limits.go @@ -6,7 +6,7 @@ import ( "sync" "time" - "ask53/internal/config" + "github.com/MeghdadFadaee/ask-53/internal/config" ) type bucket struct { diff --git a/internal/service/service_test.go b/internal/service/service_test.go index 7160d3d..8c07271 100644 --- a/internal/service/service_test.go +++ b/internal/service/service_test.go @@ -13,8 +13,8 @@ import ( "testing" "time" - "ask53/internal/ai" - "ask53/internal/config" + "github.com/MeghdadFadaee/ask-53/internal/ai" + "github.com/MeghdadFadaee/ask-53/internal/config" ) type providerFunc func(context.Context, string) (string, error) diff --git a/scripts/release.sh b/scripts/release.sh index 6133bb9..7037b77 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -38,7 +38,11 @@ for target in linux/amd64 linux/arm64 darwin/amd64 darwin/arm64; do go build -trimpath -buildvcs=false \ -ldflags="-s -w -X main.version=$version" \ -o "$package_dir/ask53" ./cmd/ask53 - cp LICENSE README.md THIRD_PARTY_NOTICES.md config.local.json "$package_dir/" + cp LICENSE README.md CHANGELOG.md TESTING.md CONTRIBUTING.md SECURITY.md PUBLISHING.md THIRD_PARTY_NOTICES.md config.local.json "$package_dir/" + if [[ -f "docs/releases/$version.md" ]]; then + mkdir -p "$package_dir/docs/releases" + cp "docs/releases/$version.md" "$package_dir/docs/releases/" + fi cp -R third_party deploy "$package_dir/" COPYFILE_DISABLE=1 tar "${tar_flags[@]}" -czf "$output_dir/$name.tar.gz" -C "$staging" "$name" done diff --git a/scripts/test-release.sh b/scripts/test-release.sh new file mode 100755 index 0000000..0f4e0ba --- /dev/null +++ b/scripts/test-release.sh @@ -0,0 +1,86 @@ +#!/usr/bin/env bash +# Exercise release validation against real build artifacts; never publish. +set -euo pipefail +version=${1:-} +repo_root=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd) +output_dir=${2:-${ASK53_RELEASE_DIR:-"$repo_root/dist/$version"}} +output_dir=$(cd -- "$output_dir" && pwd) +staging=$(mktemp -d) +trap 'rm -rf -- "$staging"' EXIT + +reject() { + if "$@" > "$staging/rejection.log" 2>&1; then + echo "Expected release validation to reject: $*" >&2 + exit 1 + fi +} +reset_candidate() { + rm -rf -- "$staging/candidate" "$staging/extracted" + mkdir "$staging/candidate" + cp "$output_dir/"*.tar.gz "$output_dir/SHA256SUMS" "$staging/candidate/" +} +rehash() { + if command -v sha256sum >/dev/null 2>&1; then + (cd "$staging/candidate" && sha256sum ./*.tar.gz > SHA256SUMS) + else + (cd "$staging/candidate" && shasum -a 256 ./*.tar.gz > SHA256SUMS) + fi +} + +bash "$repo_root/scripts/verify-release.sh" "$version" "$output_dir" +for invalid in '' v1.2 '../invalid' 'v1.2.3;echo invalid'; do + reject bash "$repo_root/scripts/verify-release.sh" "$invalid" "$output_dir" + reject env ASK53_RELEASE_DIR="$staging/invalid" bash "$repo_root/scripts/release.sh" "$invalid" +done +reject env ASK53_RELEASE_DIR="$output_dir" bash "$repo_root/scripts/release.sh" "$version" + +archive="ask53-$version-linux-amd64.tar.gz" +reset_candidate +rm "$staging/candidate/$archive" +reject bash "$repo_root/scripts/verify-release.sh" "$version" "$staging/candidate" + +reset_candidate +printf 'corruption' >> "$staging/candidate/$archive" +reject bash "$repo_root/scripts/verify-release.sh" "$version" "$staging/candidate" + +reset_candidate +head -n 3 "$output_dir/SHA256SUMS" > "$staging/candidate/SHA256SUMS" +reject bash "$repo_root/scripts/verify-release.sh" "$version" "$staging/candidate" + +# A checksum-correct archive must still reject extra private files. +reset_candidate +mkdir "$staging/extracted" +tar -xzf "$staging/candidate/$archive" -C "$staging/extracted" +printf 'fake-secret\n' > "$staging/extracted/${archive%.tar.gz}/api-key" +COPYFILE_DISABLE=1 tar -czf "$staging/candidate/$archive" -C "$staging/extracted" "${archive%.tar.gz}" +rehash +reject bash "$repo_root/scripts/verify-release.sh" "$version" "$staging/candidate" + +# Even a permitted member name cannot be a symlink. +reset_candidate +mkdir "$staging/extracted" +tar -xzf "$staging/candidate/$archive" -C "$staging/extracted" +rm "$staging/extracted/${archive%.tar.gz}/config.local.json" +ln -s /dev/null "$staging/extracted/${archive%.tar.gz}/config.local.json" +COPYFILE_DISABLE=1 tar -czf "$staging/candidate/$archive" -C "$staging/extracted" "${archive%.tar.gz}" +rehash +reject bash "$repo_root/scripts/verify-release.sh" "$version" "$staging/candidate" + +# A checksum-correct native archive must report the requested embedded version. +case "$(uname -s)/$(uname -m)" in + Linux/x86_64) native=linux-amd64 ;; + Linux/aarch64|Linux/arm64) native=linux-arm64 ;; + Darwin/x86_64) native=darwin-amd64 ;; + Darwin/arm64) native=darwin-arm64 ;; + *) echo 'Native version test requires Linux/macOS amd64/arm64' >&2; exit 1 ;; +esac +reset_candidate +archive="ask53-$version-$native.tar.gz" +mkdir "$staging/extracted" +tar -xzf "$staging/candidate/$archive" -C "$staging/extracted" +printf '#!/bin/sh\nprintf "wrong-version\\n"\n' > "$staging/extracted/${archive%.tar.gz}/ask53" +COPYFILE_DISABLE=1 tar -czf "$staging/candidate/$archive" -C "$staging/extracted" "${archive%.tar.gz}" +rehash +reject bash "$repo_root/scripts/verify-release.sh" "$version" "$staging/candidate" + +printf 'Release validation failure cases passed for %s\n' "$version" diff --git a/scripts/verify-release.sh b/scripts/verify-release.sh new file mode 100755 index 0000000..ec2eb87 --- /dev/null +++ b/scripts/verify-release.sh @@ -0,0 +1,80 @@ +#!/usr/bin/env bash +# Verify locally built release packages, including the native binary when present. +set -euo pipefail + +version=${1:-} +if [[ ! "$version" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z]+([.-][0-9A-Za-z]+)*)?$ ]]; then + echo 'Usage: scripts/verify-release.sh vMAJOR.MINOR.PATCH[-PRERELEASE] [DIRECTORY]' >&2 + exit 2 +fi +repo_root=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd) +output_dir=${2:-${ASK53_RELEASE_DIR:-"$repo_root/dist/$version"}} +output_dir=$(cd -- "$output_dir" && pwd) +staging=$(mktemp -d) +trap 'rm -rf -- "$staging"' EXIT + +cd -- "$output_dir" +test "$(wc -l < SHA256SUMS | tr -d ' ')" = 4 +for target in linux/amd64 linux/arm64 darwin/amd64 darwin/arm64; do + archive="ask53-$version-${target%/*}-${target#*/}.tar.gz" + test -s "$archive" + # Every expected archive must occur exactly once in the manifest. + test "$(awk -v file="./$archive" '$2 == file {count++} END {print count+0}' SHA256SUMS)" = 1 +done +if command -v sha256sum >/dev/null 2>&1; then + sha256sum -c SHA256SUMS +else + shasum -a 256 -c SHA256SUMS +fi + +case "$(uname -s)/$(uname -m)" in + Linux/x86_64) native=linux/amd64 ;; + Linux/aarch64|Linux/arm64) native=linux/arm64 ;; + Darwin/x86_64) native=darwin/amd64 ;; + Darwin/arm64) native=darwin/arm64 ;; + *) native= ;; +esac + +for target in linux/amd64 linux/arm64 darwin/amd64 darwin/arm64; do + name="ask53-$version-${target%/*}-${target#*/}" + # Exact membership excludes credentials, quota state, IDE files and tar metadata. + cat > "$staging/members" <<'EOF' + +ask53 +LICENSE +README.md +CHANGELOG.md +TESTING.md +CONTRIBUTING.md +SECURITY.md +PUBLISHING.md +THIRD_PARTY_NOTICES.md +config.local.json +deploy/ +deploy/ask53.service +deploy/config.example.json +third_party/ +third_party/go.LICENSE +third_party/go.PATENTS +third_party/miekg-dns.LICENSE +third_party/x-net.LICENSE +third_party/x-net.PATENTS +third_party/x-sys.LICENSE +third_party/x-sys.PATENTS +EOF + if [[ -f "$repo_root/docs/releases/$version.md" ]]; then + printf 'docs/\ndocs/releases/\ndocs/releases/%s.md\n' "$version" >> "$staging/members" + fi + LC_ALL=C sed "s|^|$name/|" "$staging/members" | LC_ALL=C sort > "$staging/expected" + tar -tzf "$name.tar.gz" | LC_ALL=C sort > "$staging/actual" + diff -u "$staging/expected" "$staging/actual" + # Release packages consist solely of regular files and directories. + tar -tvzf "$name.tar.gz" | awk 'substr($0,1,1) != "-" && substr($0,1,1) != "d" {bad=1} END {exit bad}' + tar -xzf "$name.tar.gz" -C "$staging" + test -x "$staging/$name/ask53" + if [[ "$target" == "$native" ]]; then + test "$("$staging/$name/ask53" -version)" = "$version" + "$staging/$name/ask53" -config "$staging/$name/config.local.json" -check-config + fi +done +printf 'Verified four release archives for %s\n' "$version"