···11-# tangled contributing guide
22-33-## commit guidelines
44-55-We follow a commit style similar to the Go project. Please keep commits:
66-77-* **atomic**: each commit should represent one logical change
88-* **descriptive**: the commit message should clearly describe what the
99-change does and why it's needed
1010-1111-### message format
1212-1313-```
1414-<service/top-level directory>/<affected package/directory>: <short summary of change>
1515-1616-1717-Optional longer description can go here, if necessary. Explain what the
1818-change does and why, especially if not obvious. Reference relevant
1919-issues or PRs when applicable. These can be links for now since we don't
2020-auto-link issues/PRs yet.
2121-```
2222-2323-Here are some examples:
2424-2525-```
2626-appview/state: fix token expiry check in middleware
2727-2828-The previous check did not account for clock drift, leading to premature
2929-token invalidation.
3030-```
3131-3232-```
3333-knotserver/git/service: improve error checking in upload-pack
3434-```
3535-3636-3737-### general notes
3838-3939-- PRs get merged "as-is" (fast-forward) -- like applying a patch-series
4040-using `git am`. At present, there is no squashing -- so please author
4141-your commits as they would appear on `master`, following the above
4242-guidelines.
4343-- If there is a lot of nesting, for example "appview:
4444-pages/templates/repo/fragments: ...", these can be truncated down to
4545-just "appview: repo/fragments: ...". If the change affects a lot of
4646-subdirectories, you may abbreviate to just the top-level names, e.g.
4747-"appview: ..." or "knotserver: ...".
4848-- Keep commits lowercased with no trailing period.
4949-- Use the imperative mood in the summary line (e.g., "fix bug" not
5050-"fixed bug" or "fixes bug").
5151-- Try to keep the summary line under 72 characters, but we aren't too
5252-fussed about this.
5353-- Follow the same formatting for PR titles if filled manually.
5454-- Don't include unrelated changes in the same commit.
5555-- Avoid noisy commit messages like "wip" or "final fix"—rewrite history
5656-before submitting if necessary.
5757-5858-## code formatting
5959-6060-We use a variety of tools to format our code, and multiplex them with
6161-[`treefmt`](https://treefmt.com): all you need to do to format your changes
6262-is run `nix run .#fmt` (or just `treefmt` if you're in the devshell).
6363-6464-## proposals for bigger changes
6565-6666-Small fixes like typos, minor bugs, or trivial refactors can be
6767-submitted directly as PRs.
6868-6969-For larger changes—especially those introducing new features, significant
7070-refactoring, or altering system behavior—please open a proposal first. This
7171-helps us evaluate the scope, design, and potential impact before implementation.
7272-7373-### proposal format
7474-7575-Create a new issue titled:
7676-7777-```
7878-proposal: <affected scope>: <summary of change>
7979-```
8080-8181-In the description, explain:
8282-8383-- What the change is
8484-- Why it's needed
8585-- How you plan to implement it (roughly)
8686-- Any open questions or tradeoffs
8787-8888-We'll use the issue thread to discuss and refine the idea before moving
8989-forward.
9090-9191-## developer certificate of origin (DCO)
9292-9393-We require all contributors to certify that they have the right to
9494-submit the code they're contributing. To do this, we follow the
9595-[Developer Certificate of Origin
9696-(DCO)](https://developercertificate.org/).
9797-9898-By signing your commits, you're stating that the contribution is your
9999-own work, or that you have the right to submit it under the project's
100100-license. This helps us keep things clean and legally sound.
101101-102102-To sign your commit, just add the `-s` flag when committing:
103103-104104-```sh
105105-git commit -s -m "your commit message"
106106-```
107107-108108-This appends a line like:
109109-110110-```
111111-Signed-off-by: Your Name <your.email@example.com>
112112-```
113113-114114-We won't merge commits if they aren't signed off. If you forget, you can
115115-amend the last commit like this:
116116-117117-```sh
118118-git commit --amend -s
119119-```
120120-121121-If you're submitting a PR with multiple commits, make sure each one is
122122-signed.
123123-124124-For [jj](https://jj-vcs.github.io/jj/latest/) users, you can run the following command
125125-to make it sign off commits in the tangled repo:
126126-127127-```shell
128128-# Safety check, should say "No matching config key..."
129129-jj config list templates.commit_trailers
130130-# The command below may need to be adjusted if the command above returned something.
131131-jj config set --repo templates.commit_trailers "format_signed_off_by_trailer(self)"
132132-```
133133-134134-Refer to the [jj
135135-documentation](https://jj-vcs.github.io/jj/latest/config/#commit-trailers)
136136-for more information.
-172
docs/hacking.md
···11-# hacking on tangled
22-33-We highly recommend [installing
44-nix](https://nixos.org/download/) (the package manager)
55-before working on the codebase. The nix flake provides a lot
66-of helpers to get started and most importantly, builds and
77-dev shells are entirely deterministic.
88-99-To set up your dev environment:
1010-1111-```bash
1212-nix develop
1313-```
1414-1515-Non-nix users can look at the `devShell` attribute in the
1616-`flake.nix` file to determine necessary dependencies.
1717-1818-## running the appview
1919-2020-The nix flake also exposes a few `app` attributes (run `nix
2121-flake show` to see a full list of what the flake provides),
2222-one of the apps runs the appview with the `air`
2323-live-reloader:
2424-2525-```bash
2626-TANGLED_DEV=true nix run .#watch-appview
2727-2828-# TANGLED_DB_PATH might be of interest to point to
2929-# different sqlite DBs
3030-3131-# in a separate shell, you can live-reload tailwind
3232-nix run .#watch-tailwind
3333-```
3434-3535-To authenticate with the appview, you will need redis and
3636-OAUTH JWKs to be setup:
3737-3838-```
3939-# oauth jwks should already be setup by the nix devshell:
4040-echo $TANGLED_OAUTH_CLIENT_SECRET
4141-z42ty4RT1ovnTopY8B8ekz9NuziF2CuMkZ7rbRFpAR9jBqMc
4242-4343-echo $TANGLED_OAUTH_CLIENT_KID
4444-1761667908
4545-4646-# if not, you can set it up yourself:
4747-goat key generate -t P-256
4848-Key Type: P-256 / secp256r1 / ES256 private key
4949-Secret Key (Multibase Syntax): save this securely (eg, add to password manager)
5050- z42tuPDKRfM2mz2Kv953ARen2jmrPA8S9LX9tRq4RVcUMwwL
5151-Public Key (DID Key Syntax): share or publish this (eg, in DID document)
5252- did:key:zDnaeUBxtG6Xuv3ATJE4GaWeyXM3jyamJsZw3bSPpxx4bNXDR
5353-5454-# the secret key from above
5555-export TANGLED_OAUTH_CLIENT_SECRET="z42tuP..."
5656-5757-# run redis in at a new shell to store oauth sessions
5858-redis-server
5959-```
6060-6161-## running knots and spindles
6262-6363-An end-to-end knot setup requires setting up a machine with
6464-`sshd`, `AuthorizedKeysCommand`, and git user, which is
6565-quite cumbersome. So the nix flake provides a
6666-`nixosConfiguration` to do so.
6767-6868-<details>
6969- <summary><strong>MacOS users will have to setup a Nix Builder first</strong></summary>
7070-7171- In order to build Tangled's dev VM on macOS, you will
7272- first need to set up a Linux Nix builder. The recommended
7373- way to do so is to run a [`darwin.linux-builder`
7474- VM](https://nixos.org/manual/nixpkgs/unstable/#sec-darwin-builder)
7575- and to register it in `nix.conf` as a builder for Linux
7676- with the same architecture as your Mac (`linux-aarch64` if
7777- you are using Apple Silicon).
7878-7979- > IMPORTANT: You must build `darwin.linux-builder` somewhere other than inside
8080- > the tangled repo so that it doesn't conflict with the other VM. For example,
8181- > you can do
8282- >
8383- > ```shell
8484- > cd $(mktemp -d buildervm.XXXXX) && nix run nixpkgs#darwin.linux-builder
8585- > ```
8686- >
8787- > to store the builder VM in a temporary dir.
8888- >
8989- > You should read and follow [all the other intructions][darwin builder vm] to
9090- > avoid subtle problems.
9191-9292- Alternatively, you can use any other method to set up a
9393- Linux machine with `nix` installed that you can `sudo ssh`
9494- into (in other words, root user on your Mac has to be able
9595- to ssh into the Linux machine without entering a password)
9696- and that has the same architecture as your Mac. See
9797- [remote builder
9898- instructions](https://nix.dev/manual/nix/2.28/advanced-topics/distributed-builds.html#requirements)
9999- for how to register such a builder in `nix.conf`.
100100-101101- > WARNING: If you'd like to use
102102- > [`nixos-lima`](https://github.com/nixos-lima/nixos-lima) or
103103- > [Orbstack](https://orbstack.dev/), note that setting them up so that `sudo
104104- > ssh` works can be tricky. It seems to be [possible with
105105- > Orbstack](https://github.com/orgs/orbstack/discussions/1669).
106106-107107-</details>
108108-109109-To begin, grab your DID from http://localhost:3000/settings.
110110-Then, set `TANGLED_VM_KNOT_OWNER` and
111111-`TANGLED_VM_SPINDLE_OWNER` to your DID. You can now start a
112112-lightweight NixOS VM like so:
113113-114114-```bash
115115-nix run --impure .#vm
116116-117117-# type `poweroff` at the shell to exit the VM
118118-```
119119-120120-This starts a knot on port 6444, a spindle on port 6555
121121-with `ssh` exposed on port 2222.
122122-123123-Once the services are running, head to
124124-http://localhost:3000/settings/knots and hit verify. It should
125125-verify the ownership of the services instantly if everything
126126-went smoothly.
127127-128128-You can push repositories to this VM with this ssh config
129129-block on your main machine:
130130-131131-```bash
132132-Host nixos-shell
133133- Hostname localhost
134134- Port 2222
135135- User git
136136- IdentityFile ~/.ssh/my_tangled_key
137137-```
138138-139139-Set up a remote called `local-dev` on a git repo:
140140-141141-```bash
142142-git remote add local-dev git@nixos-shell:user/repo
143143-git push local-dev main
144144-```
145145-146146-### running a spindle
147147-148148-The above VM should already be running a spindle on
149149-`localhost:6555`. Head to http://localhost:3000/settings/spindles and
150150-hit verify. You can then configure each repository to use
151151-this spindle and run CI jobs.
152152-153153-Of interest when debugging spindles:
154154-155155-```
156156-# service logs from journald:
157157-journalctl -xeu spindle
158158-159159-# CI job logs from disk:
160160-ls /var/log/spindle
161161-162162-# debugging spindle db:
163163-sqlite3 /var/lib/spindle/spindle.db
164164-165165-# litecli has a nicer REPL interface:
166166-litecli /var/lib/spindle/spindle.db
167167-```
168168-169169-If for any reason you wish to disable either one of the
170170-services in the VM, modify [nix/vm.nix](/nix/vm.nix) and set
171171-`services.tangled.spindle.enable` (or
172172-`services.tangled.knot.enable`) to `false`.
-214
docs/knot-hosting.md
···11-# knot self-hosting guide
22-33-So you want to run your own knot server? Great! Here are a few prerequisites:
44-55-1. A server of some kind (a VPS, a Raspberry Pi, etc.). Preferably running a Linux distribution of some kind.
66-2. A (sub)domain name. People generally use `knot.example.com`.
77-3. A valid SSL certificate for your domain.
88-99-There's a couple of ways to get started:
1010-* NixOS: refer to
1111-[flake.nix](https://tangled.sh/@tangled.sh/core/blob/master/flake.nix)
1212-* Docker: Documented at
1313-[@tangled.sh/knot-docker](https://tangled.sh/@tangled.sh/knot-docker)
1414-(community maintained: support is not guaranteed!)
1515-* Manual: Documented below.
1616-1717-## manual setup
1818-1919-First, clone this repository:
2020-2121-```
2222-git clone https://tangled.org/@tangled.org/core
2323-```
2424-2525-Then, build the `knot` CLI. This is the knot administration and operation tool.
2626-For the purpose of this guide, we're only concerned with these subcommands:
2727-2828-* `knot server`: the main knot server process, typically run as a
2929-supervised service
3030-* `knot guard`: handles role-based access control for git over SSH
3131-(you'll never have to run this yourself)
3232-* `knot keys`: fetches SSH keys associated with your knot; we'll use
3333-this to generate the SSH `AuthorizedKeysCommand`
3434-3535-```
3636-cd core
3737-export CGO_ENABLED=1
3838-go build -o knot ./cmd/knot
3939-```
4040-4141-Next, move the `knot` binary to a location owned by `root` --
4242-`/usr/local/bin/` is a good choice. Make sure the binary itself is also owned by `root`:
4343-4444-```
4545-sudo mv knot /usr/local/bin/knot
4646-sudo chown root:root /usr/local/bin/knot
4747-```
4848-4949-This is necessary because SSH `AuthorizedKeysCommand` requires [really
5050-specific permissions](https://stackoverflow.com/a/27638306). The
5151-`AuthorizedKeysCommand` specifies a command that is run by `sshd` to
5252-retrieve a user's public SSH keys dynamically for authentication. Let's
5353-set that up.
5454-5555-```
5656-sudo tee /etc/ssh/sshd_config.d/authorized_keys_command.conf <<EOF
5757-Match User git
5858- AuthorizedKeysCommand /usr/local/bin/knot keys -o authorized-keys
5959- AuthorizedKeysCommandUser nobody
6060-EOF
6161-```
6262-6363-Then, reload `sshd`:
6464-6565-```
6666-sudo systemctl reload ssh
6767-```
6868-6969-Next, create the `git` user. We'll use the `git` user's home directory
7070-to store repositories:
7171-7272-```
7373-sudo adduser git
7474-```
7575-7676-Create `/home/git/.knot.env` with the following, updating the values as
7777-necessary. The `KNOT_SERVER_OWNER` should be set to your
7878-DID, you can find your DID in the [Settings](https://tangled.sh/settings) page.
7979-8080-```
8181-KNOT_REPO_SCAN_PATH=/home/git
8282-KNOT_SERVER_HOSTNAME=knot.example.com
8383-APPVIEW_ENDPOINT=https://tangled.sh
8484-KNOT_SERVER_OWNER=did:plc:foobar
8585-KNOT_SERVER_INTERNAL_LISTEN_ADDR=127.0.0.1:5444
8686-KNOT_SERVER_LISTEN_ADDR=127.0.0.1:5555
8787-```
8888-8989-If you run a Linux distribution that uses systemd, you can use the provided
9090-service file to run the server. Copy
9191-[`knotserver.service`](/systemd/knotserver.service)
9292-to `/etc/systemd/system/`. Then, run:
9393-9494-```
9595-systemctl enable knotserver
9696-systemctl start knotserver
9797-```
9898-9999-The last step is to configure a reverse proxy like Nginx or Caddy to front your
100100-knot. Here's an example configuration for Nginx:
101101-102102-```
103103-server {
104104- listen 80;
105105- listen [::]:80;
106106- server_name knot.example.com;
107107-108108- location / {
109109- proxy_pass http://localhost:5555;
110110- proxy_set_header Host $host;
111111- proxy_set_header X-Real-IP $remote_addr;
112112- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
113113- proxy_set_header X-Forwarded-Proto $scheme;
114114- }
115115-116116- # wss endpoint for git events
117117- location /events {
118118- proxy_set_header X-Forwarded-For $remote_addr;
119119- proxy_set_header Host $http_host;
120120- proxy_set_header Upgrade websocket;
121121- proxy_set_header Connection Upgrade;
122122- proxy_pass http://localhost:5555;
123123- }
124124- # additional config for SSL/TLS go here.
125125-}
126126-127127-```
128128-129129-Remember to use Let's Encrypt or similar to procure a certificate for your
130130-knot domain.
131131-132132-You should now have a running knot server! You can finalize
133133-your registration by hitting the `verify` button on the
134134-[/settings/knots](https://tangled.org/settings/knots) page. This simply creates
135135-a record on your PDS to announce the existence of the knot.
136136-137137-### custom paths
138138-139139-(This section applies to manual setup only. Docker users should edit the mounts
140140-in `docker-compose.yml` instead.)
141141-142142-Right now, the database and repositories of your knot lives in `/home/git`. You
143143-can move these paths if you'd like to store them in another folder. Be careful
144144-when adjusting these paths:
145145-146146-* Stop your knot when moving data (e.g. `systemctl stop knotserver`) to prevent
147147-any possible side effects. Remember to restart it once you're done.
148148-* Make backups before moving in case something goes wrong.
149149-* Make sure the `git` user can read and write from the new paths.
150150-151151-#### database
152152-153153-As an example, let's say the current database is at `/home/git/knotserver.db`,
154154-and we want to move it to `/home/git/database/knotserver.db`.
155155-156156-Copy the current database to the new location. Make sure to copy the `.db-shm`
157157-and `.db-wal` files if they exist.
158158-159159-```
160160-mkdir /home/git/database
161161-cp /home/git/knotserver.db* /home/git/database
162162-```
163163-164164-In the environment (e.g. `/home/git/.knot.env`), set `KNOT_SERVER_DB_PATH` to
165165-the new file path (_not_ the directory):
166166-167167-```
168168-KNOT_SERVER_DB_PATH=/home/git/database/knotserver.db
169169-```
170170-171171-#### repositories
172172-173173-As an example, let's say the repositories are currently in `/home/git`, and we
174174-want to move them into `/home/git/repositories`.
175175-176176-Create the new folder, then move the existing repositories (if there are any):
177177-178178-```
179179-mkdir /home/git/repositories
180180-# move all DIDs into the new folder; these will vary for you!
181181-mv /home/git/did:plc:wshs7t2adsemcrrd4snkeqli /home/git/repositories
182182-```
183183-184184-In the environment (e.g. `/home/git/.knot.env`), update `KNOT_REPO_SCAN_PATH`
185185-to the new directory:
186186-187187-```
188188-KNOT_REPO_SCAN_PATH=/home/git/repositories
189189-```
190190-191191-Similarly, update your `sshd` `AuthorizedKeysCommand` to use the updated
192192-repository path:
193193-194194-```
195195-sudo tee /etc/ssh/sshd_config.d/authorized_keys_command.conf <<EOF
196196-Match User git
197197- AuthorizedKeysCommand /usr/local/bin/knot keys -o authorized-keys -git-dir /home/git/repositories
198198- AuthorizedKeysCommandUser nobody
199199-EOF
200200-```
201201-202202-Make sure to restart your SSH server!
203203-204204-#### MOTD (message of the day)
205205-206206-To configure the MOTD used ("Welcome to this knot!" by default), edit the
207207-`/home/git/motd` file:
208208-209209-```
210210-printf "Hi from this knot!\n" > /home/git/motd
211211-```
212212-213213-Note that you should add a newline at the end if setting a non-empty message
214214-since the knot won't do this for you.
-59
docs/migrations.md
···11-# Migrations
22-33-This document is laid out in reverse-chronological order.
44-Newer migration guides are listed first, and older guides
55-are further down the page.
66-77-## Upgrading from v1.8.x
88-99-After v1.8.2, the HTTP API for knot and spindles have been
1010-deprecated and replaced with XRPC. Repositories on outdated
1111-knots will not be viewable from the appview. Upgrading is
1212-straightforward however.
1313-1414-For knots:
1515-1616-- Upgrade to latest tag (v1.9.0 or above)
1717-- Head to the [knot dashboard](https://tangled.org/settings/knots) and
1818- hit the "retry" button to verify your knot
1919-2020-For spindles:
2121-2222-- Upgrade to latest tag (v1.9.0 or above)
2323-- Head to the [spindle
2424- dashboard](https://tangled.org/settings/spindles) and hit the
2525- "retry" button to verify your spindle
2626-2727-## Upgrading from v1.7.x
2828-2929-After v1.7.0, knot secrets have been deprecated. You no
3030-longer need a secret from the appview to run a knot. All
3131-authorized commands to knots are managed via [Inter-Service
3232-Authentication](https://atproto.com/specs/xrpc#inter-service-authentication-jwt).
3333-Knots will be read-only until upgraded.
3434-3535-Upgrading is quite easy, in essence:
3636-3737-- `KNOT_SERVER_SECRET` is no more, you can remove this
3838- environment variable entirely
3939-- `KNOT_SERVER_OWNER` is now required on boot, set this to
4040- your DID. You can find your DID in the
4141- [settings](https://tangled.org/settings) page.
4242-- Restart your knot once you have replaced the environment
4343- variable
4444-- Head to the [knot dashboard](https://tangled.org/settings/knots) and
4545- hit the "retry" button to verify your knot. This simply
4646- writes a `sh.tangled.knot` record to your PDS.
4747-4848-If you use the nix module, simply bump the flake to the
4949-latest revision, and change your config block like so:
5050-5151-```diff
5252- services.tangled.knot = {
5353- enable = true;
5454- server = {
5555-- secretFile = /path/to/secret;
5656-+ owner = "did:plc:foo";
5757- };
5858- };
5959-```
-25
docs/spindle/architecture.md
···11-# spindle architecture
22-33-Spindle is a small CI runner service. Here's a high level overview of how it operates:
44-55-* listens for [`sh.tangled.spindle.member`](/lexicons/spindle/member.json) and
66-[`sh.tangled.repo`](/lexicons/repo.json) records on the Jetstream.
77-* when a new repo record comes through (typically when you add a spindle to a
88-repo from the settings), spindle then resolves the underlying knot and
99-subscribes to repo events (see:
1010-[`sh.tangled.pipeline`](/lexicons/pipeline.json)).
1111-* the spindle engine then handles execution of the pipeline, with results and
1212-logs beamed on the spindle event stream over wss
1313-1414-### the engine
1515-1616-At present, the only supported backend is Docker (and Podman, if Docker
1717-compatibility is enabled, so that `/run/docker.sock` is created). Spindle
1818-executes each step in the pipeline in a fresh container, with state persisted
1919-across steps within the `/tangled/workspace` directory.
2020-2121-The base image for the container is constructed on the fly using
2222-[Nixery](https://nixery.dev), which is handy for caching layers for frequently
2323-used packages.
2424-2525-The pipeline manifest is [specified here](/docs/spindle/pipeline.md).
-52
docs/spindle/hosting.md
···11-# spindle self-hosting guide
22-33-## prerequisites
44-55-* Go
66-* Docker (the only supported backend currently)
77-88-## configuration
99-1010-Spindle is configured using environment variables. The following environment variables are available:
1111-1212-* `SPINDLE_SERVER_LISTEN_ADDR`: The address the server listens on (default: `"0.0.0.0:6555"`).
1313-* `SPINDLE_SERVER_DB_PATH`: The path to the SQLite database file (default: `"spindle.db"`).
1414-* `SPINDLE_SERVER_HOSTNAME`: The hostname of the server (required).
1515-* `SPINDLE_SERVER_JETSTREAM_ENDPOINT`: The endpoint of the Jetstream server (default: `"wss://jetstream1.us-west.bsky.network/subscribe"`).
1616-* `SPINDLE_SERVER_DEV`: A boolean indicating whether the server is running in development mode (default: `false`).
1717-* `SPINDLE_SERVER_OWNER`: The DID of the owner (required).
1818-* `SPINDLE_PIPELINES_NIXERY`: The Nixery URL (default: `"nixery.tangled.sh"`).
1919-* `SPINDLE_PIPELINES_WORKFLOW_TIMEOUT`: The default workflow timeout (default: `"5m"`).
2020-* `SPINDLE_PIPELINES_LOG_DIR`: The directory to store workflow logs (default: `"/var/log/spindle"`).
2121-2222-## running spindle
2323-2424-1. **Set the environment variables.** For example:
2525-2626- ```shell
2727- export SPINDLE_SERVER_HOSTNAME="your-hostname"
2828- export SPINDLE_SERVER_OWNER="your-did"
2929- ```
3030-3131-2. **Build the Spindle binary.**
3232-3333- ```shell
3434- cd core
3535- go mod download
3636- go build -o cmd/spindle/spindle cmd/spindle/main.go
3737- ```
3838-3939-3. **Create the log directory.**
4040-4141- ```shell
4242- sudo mkdir -p /var/log/spindle
4343- sudo chown $USER:$USER -R /var/log/spindle
4444- ```
4545-4646-4. **Run the Spindle binary.**
4747-4848- ```shell
4949- ./cmd/spindle/spindle
5050- ```
5151-5252-Spindle will now start, connect to the Jetstream server, and begin processing pipelines.
-285
docs/spindle/openbao.md
···11-# spindle secrets with openbao
22-33-This document covers setting up Spindle to use OpenBao for secrets
44-management via OpenBao Proxy instead of the default SQLite backend.
55-66-## overview
77-88-Spindle now uses OpenBao Proxy for secrets management. The proxy handles
99-authentication automatically using AppRole credentials, while Spindle
1010-connects to the local proxy instead of directly to the OpenBao server.
1111-1212-This approach provides better security, automatic token renewal, and
1313-simplified application code.
1414-1515-## installation
1616-1717-Install OpenBao from nixpkgs:
1818-1919-```bash
2020-nix shell nixpkgs#openbao # for a local server
2121-```
2222-2323-## setup
2424-2525-The setup process can is documented for both local development and production.
2626-2727-### local development
2828-2929-Start OpenBao in dev mode:
3030-3131-```bash
3232-bao server -dev -dev-root-token-id="root" -dev-listen-address=127.0.0.1:8201
3333-```
3434-3535-This starts OpenBao on `http://localhost:8201` with a root token.
3636-3737-Set up environment for bao CLI:
3838-3939-```bash
4040-export BAO_ADDR=http://localhost:8200
4141-export BAO_TOKEN=root
4242-```
4343-4444-### production
4545-4646-You would typically use a systemd service with a configuration file. Refer to
4747-[@tangled.org/infra](https://tangled.org/@tangled.org/infra) for how this can be
4848-achieved using Nix.
4949-5050-Then, initialize the bao server:
5151-```bash
5252-bao operator init -key-shares=1 -key-threshold=1
5353-```
5454-5555-This will print out an unseal key and a root key. Save them somewhere (like a password manager). Then unseal the vault to begin setting it up:
5656-```bash
5757-bao operator unseal <unseal_key>
5858-```
5959-6060-All steps below remain the same across both dev and production setups.
6161-6262-### configure openbao server
6363-6464-Create the spindle KV mount:
6565-6666-```bash
6767-bao secrets enable -path=spindle -version=2 kv
6868-```
6969-7070-Set up AppRole authentication and policy:
7171-7272-Create a policy file `spindle-policy.hcl`:
7373-7474-```hcl
7575-# Full access to spindle KV v2 data
7676-path "spindle/data/*" {
7777- capabilities = ["create", "read", "update", "delete"]
7878-}
7979-8080-# Access to metadata for listing and management
8181-path "spindle/metadata/*" {
8282- capabilities = ["list", "read", "delete", "update"]
8383-}
8484-8585-# Allow listing at root level
8686-path "spindle/" {
8787- capabilities = ["list"]
8888-}
8989-9090-# Required for connection testing and health checks
9191-path "auth/token/lookup-self" {
9292- capabilities = ["read"]
9393-}
9494-```
9595-9696-Apply the policy and create an AppRole:
9797-9898-```bash
9999-bao policy write spindle-policy spindle-policy.hcl
100100-bao auth enable approle
101101-bao write auth/approle/role/spindle \
102102- token_policies="spindle-policy" \
103103- token_ttl=1h \
104104- token_max_ttl=4h \
105105- bind_secret_id=true \
106106- secret_id_ttl=0 \
107107- secret_id_num_uses=0
108108-```
109109-110110-Get the credentials:
111111-112112-```bash
113113-# Get role ID (static)
114114-ROLE_ID=$(bao read -field=role_id auth/approle/role/spindle/role-id)
115115-116116-# Generate secret ID
117117-SECRET_ID=$(bao write -f -field=secret_id auth/approle/role/spindle/secret-id)
118118-119119-echo "Role ID: $ROLE_ID"
120120-echo "Secret ID: $SECRET_ID"
121121-```
122122-123123-### create proxy configuration
124124-125125-Create the credential files:
126126-127127-```bash
128128-# Create directory for OpenBao files
129129-mkdir -p /tmp/openbao
130130-131131-# Save credentials
132132-echo "$ROLE_ID" > /tmp/openbao/role-id
133133-echo "$SECRET_ID" > /tmp/openbao/secret-id
134134-chmod 600 /tmp/openbao/role-id /tmp/openbao/secret-id
135135-```
136136-137137-Create a proxy configuration file `/tmp/openbao/proxy.hcl`:
138138-139139-```hcl
140140-# OpenBao server connection
141141-vault {
142142- address = "http://localhost:8200"
143143-}
144144-145145-# Auto-Auth using AppRole
146146-auto_auth {
147147- method "approle" {
148148- mount_path = "auth/approle"
149149- config = {
150150- role_id_file_path = "/tmp/openbao/role-id"
151151- secret_id_file_path = "/tmp/openbao/secret-id"
152152- }
153153- }
154154-155155- # Optional: write token to file for debugging
156156- sink "file" {
157157- config = {
158158- path = "/tmp/openbao/token"
159159- mode = 0640
160160- }
161161- }
162162-}
163163-164164-# Proxy listener for Spindle
165165-listener "tcp" {
166166- address = "127.0.0.1:8201"
167167- tls_disable = true
168168-}
169169-170170-# Enable API proxy with auto-auth token
171171-api_proxy {
172172- use_auto_auth_token = true
173173-}
174174-175175-# Enable response caching
176176-cache {
177177- use_auto_auth_token = true
178178-}
179179-180180-# Logging
181181-log_level = "info"
182182-```
183183-184184-### start the proxy
185185-186186-Start OpenBao Proxy:
187187-188188-```bash
189189-bao proxy -config=/tmp/openbao/proxy.hcl
190190-```
191191-192192-The proxy will authenticate with OpenBao and start listening on
193193-`127.0.0.1:8201`.
194194-195195-### configure spindle
196196-197197-Set these environment variables for Spindle:
198198-199199-```bash
200200-export SPINDLE_SERVER_SECRETS_PROVIDER=openbao
201201-export SPINDLE_SERVER_SECRETS_OPENBAO_PROXY_ADDR=http://127.0.0.1:8201
202202-export SPINDLE_SERVER_SECRETS_OPENBAO_MOUNT=spindle
203203-```
204204-205205-Start Spindle:
206206-207207-Spindle will now connect to the local proxy, which handles all
208208-authentication automatically.
209209-210210-## production setup for proxy
211211-212212-For production, you'll want to run the proxy as a service:
213213-214214-Place your production configuration in `/etc/openbao/proxy.hcl` with
215215-proper TLS settings for the vault connection.
216216-217217-## verifying setup
218218-219219-Test the proxy directly:
220220-221221-```bash
222222-# Check proxy health
223223-curl -H "X-Vault-Request: true" http://127.0.0.1:8201/v1/sys/health
224224-225225-# Test token lookup through proxy
226226-curl -H "X-Vault-Request: true" http://127.0.0.1:8201/v1/auth/token/lookup-self
227227-```
228228-229229-Test OpenBao operations through the server:
230230-231231-```bash
232232-# List all secrets
233233-bao kv list spindle/
234234-235235-# Add a test secret via Spindle API, then check it exists
236236-bao kv list spindle/repos/
237237-238238-# Get a specific secret
239239-bao kv get spindle/repos/your_repo_path/SECRET_NAME
240240-```
241241-242242-## how it works
243243-244244-- Spindle connects to OpenBao Proxy on localhost (typically port 8200 or 8201)
245245-- The proxy authenticates with OpenBao using AppRole credentials
246246-- All Spindle requests go through the proxy, which injects authentication tokens
247247-- Secrets are stored at `spindle/repos/{sanitized_repo_path}/{secret_key}`
248248-- Repository paths like `did:plc:alice/myrepo` become `did_plc_alice_myrepo`
249249-- The proxy handles all token renewal automatically
250250-- Spindle no longer manages tokens or authentication directly
251251-252252-## troubleshooting
253253-254254-**Connection refused**: Check that the OpenBao Proxy is running and
255255-listening on the configured address.
256256-257257-**403 errors**: Verify the AppRole credentials are correct and the policy
258258-has the necessary permissions.
259259-260260-**404 route errors**: The spindle KV mount probably doesn't exist - run
261261-the mount creation step again.
262262-263263-**Proxy authentication failures**: Check the proxy logs and verify the
264264-role-id and secret-id files are readable and contain valid credentials.
265265-266266-**Secret not found after writing**: This can indicate policy permission
267267-issues. Verify the policy includes both `spindle/data/*` and
268268-`spindle/metadata/*` paths with appropriate capabilities.
269269-270270-Check proxy logs:
271271-272272-```bash
273273-# If running as systemd service
274274-journalctl -u openbao-proxy -f
275275-276276-# If running directly, check the console output
277277-```
278278-279279-Test AppRole authentication manually:
280280-281281-```bash
282282-bao write auth/approle/login \
283283- role_id="$(cat /tmp/openbao/role-id)" \
284284- secret_id="$(cat /tmp/openbao/secret-id)"
285285-```
-183
docs/spindle/pipeline.md
···11-# spindle pipelines
22-33-Spindle workflows allow you to write CI/CD pipelines in a simple format. They're located in the `.tangled/workflows` directory at the root of your repository, and are defined using YAML.
44-55-The fields are:
66-77-- [Trigger](#trigger): A **required** field that defines when a workflow should be triggered.
88-- [Engine](#engine): A **required** field that defines which engine a workflow should run on.
99-- [Clone options](#clone-options): An **optional** field that defines how the repository should be cloned.
1010-- [Dependencies](#dependencies): An **optional** field that allows you to list dependencies you may need.
1111-- [Environment](#environment): An **optional** field that allows you to define environment variables.
1212-- [Steps](#steps): An **optional** field that allows you to define what steps should run in the workflow.
1313-1414-## Trigger
1515-1616-The first thing to add to a workflow is the trigger, which defines when a workflow runs. This is defined using a `when` field, which takes in a list of conditions. Each condition has the following fields:
1717-1818-- `event`: This is a **required** field that defines when your workflow should run. It's a list that can take one or more of the following values:
1919- - `push`: The workflow should run every time a commit is pushed to the repository.
2020- - `pull_request`: The workflow should run every time a pull request is made or updated.
2121- - `manual`: The workflow can be triggered manually.
2222-- `branch`: Defines which branches the workflow should run for. If used with the `push` event, commits to the branch(es) listed here will trigger the workflow. If used with the `pull_request` event, updates to pull requests targeting the branch(es) listed here will trigger the workflow. This field has no effect with the `manual` event. Supports glob patterns using `*` and `**` (e.g., `main`, `develop`, `release-*`). Either `branch` or `tag` (or both) must be specified for `push` events.
2323-- `tag`: Defines which tags the workflow should run for. Only used with the `push` event - when tags matching the pattern(s) listed here are pushed, the workflow will trigger. This field has no effect with `pull_request` or `manual` events. Supports glob patterns using `*` and `**` (e.g., `v*`, `v1.*`, `release-**`). Either `branch` or `tag` (or both) must be specified for `push` events.
2424-2525-For example, if you'd like to define a workflow that runs when commits are pushed to the `main` and `develop` branches, or when pull requests that target the `main` branch are updated, or manually, you can do so with:
2626-2727-```yaml
2828-when:
2929- - event: ["push", "manual"]
3030- branch: ["main", "develop"]
3131- - event: ["pull_request"]
3232- branch: ["main"]
3333-```
3434-3535-You can also trigger workflows on tag pushes. For instance, to run a deployment workflow when tags matching `v*` are pushed:
3636-3737-```yaml
3838-when:
3939- - event: ["push"]
4040- tag: ["v*"]
4141-```
4242-4343-You can even combine branch and tag patterns in a single constraint (the workflow triggers if either matches):
4444-4545-```yaml
4646-when:
4747- - event: ["push"]
4848- branch: ["main", "release-*"]
4949- tag: ["v*", "stable"]
5050-```
5151-5252-## Engine
5353-5454-Next is the engine on which the workflow should run, defined using the **required** `engine` field. The currently supported engines are:
5555-5656-- `nixery`: This uses an instance of [Nixery](https://nixery.dev) to run steps, which allows you to add [dependencies](#dependencies) from [Nixpkgs](https://github.com/NixOS/nixpkgs). You can search for packages on https://search.nixos.org, and there's a pretty good chance the package(s) you're looking for will be there.
5757-5858-Example:
5959-6060-```yaml
6161-engine: "nixery"
6262-```
6363-6464-## Clone options
6565-6666-When a workflow starts, the first step is to clone the repository. You can customize this behavior using the **optional** `clone` field. It has the following fields:
6767-6868-- `skip`: Setting this to `true` will skip cloning the repository. This can be useful if your workflow is doing something that doesn't require anything from the repository itself. This is `false` by default.
6969-- `depth`: This sets the number of commits, or the "clone depth", to fetch from the repository. For example, if you set this to 2, the last 2 commits will be fetched. By default, the depth is set to 1, meaning only the most recent commit will be fetched, which is the commit that triggered the workflow.
7070-- `submodules`: If you use [git submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules) in your repository, setting this field to `true` will recursively fetch all submodules. This is `false` by default.
7171-7272-The default settings are:
7373-7474-```yaml
7575-clone:
7676- skip: false
7777- depth: 1
7878- submodules: false
7979-```
8080-8181-## Dependencies
8282-8383-Usually when you're running a workflow, you'll need additional dependencies. The `dependencies` field lets you define which dependencies to get, and from where. It's a key-value map, with the key being the registry to fetch dependencies from, and the value being the list of dependencies to fetch.
8484-8585-Say you want to fetch Node.js and Go from `nixpkgs`, and a package called `my_pkg` you've made from your own registry at your repository at `https://tangled.sh/@example.com/my_pkg`. You can define those dependencies like so:
8686-8787-```yaml
8888-dependencies:
8989- # nixpkgs
9090- nixpkgs:
9191- - nodejs
9292- - go
9393- # custom registry
9494- git+https://tangled.org/@example.com/my_pkg:
9595- - my_pkg
9696-```
9797-9898-Now these dependencies are available to use in your workflow!
9999-100100-## Environment
101101-102102-The `environment` field allows you define environment variables that will be available throughout the entire workflow. **Do not put secrets here, these environment variables are visible to anyone viewing the repository. You can add secrets for pipelines in your repository's settings.**
103103-104104-Example:
105105-106106-```yaml
107107-environment:
108108- GOOS: "linux"
109109- GOARCH: "arm64"
110110- NODE_ENV: "production"
111111- MY_ENV_VAR: "MY_ENV_VALUE"
112112-```
113113-114114-## Steps
115115-116116-The `steps` field allows you to define what steps should run in the workflow. It's a list of step objects, each with the following fields:
117117-118118-- `name`: This field allows you to give your step a name. This name is visible in your workflow runs, and is used to describe what the step is doing.
119119-- `command`: This field allows you to define a command to run in that step. The step is run in a Bash shell, and the logs from the command will be visible in the pipelines page on the Tangled website. The [dependencies](#dependencies) you added will be available to use here.
120120-- `environment`: Similar to the global [environment](#environment) config, this **optional** field is a key-value map that allows you to set environment variables for the step. **Do not put secrets here, these environment variables are visible to anyone viewing the repository. You can add secrets for pipelines in your repository's settings.**
121121-122122-Example:
123123-124124-```yaml
125125-steps:
126126- - name: "Build backend"
127127- command: "go build"
128128- environment:
129129- GOOS: "darwin"
130130- GOARCH: "arm64"
131131- - name: "Build frontend"
132132- command: "npm run build"
133133- environment:
134134- NODE_ENV: "production"
135135-```
136136-137137-## Complete workflow
138138-139139-```yaml
140140-# .tangled/workflows/build.yml
141141-142142-when:
143143- - event: ["push", "manual"]
144144- branch: ["main", "develop"]
145145- - event: ["pull_request"]
146146- branch: ["main"]
147147-148148-engine: "nixery"
149149-150150-# using the default values
151151-clone:
152152- skip: false
153153- depth: 1
154154- submodules: false
155155-156156-dependencies:
157157- # nixpkgs
158158- nixpkgs:
159159- - nodejs
160160- - go
161161- # custom registry
162162- git+https://tangled.org/@example.com/my_pkg:
163163- - my_pkg
164164-165165-environment:
166166- GOOS: "linux"
167167- GOARCH: "arm64"
168168- NODE_ENV: "production"
169169- MY_ENV_VAR: "MY_ENV_VALUE"
170170-171171-steps:
172172- - name: "Build backend"
173173- command: "go build"
174174- environment:
175175- GOOS: "darwin"
176176- GOARCH: "arm64"
177177- - name: "Build frontend"
178178- command: "npm run build"
179179- environment:
180180- NODE_ENV: "production"
181181-```
182182-183183-If you want another example of a workflow, you can look at the one [Tangled uses to build the project](https://tangled.sh/@tangled.sh/core/blob/master/.tangled/workflows/build.yml).