Protection
Lock a branch so it only changes through a merge that an admin makes.
Protect a branch when you want every change to it to be reviewed first. Usually that is main. Agents keep working on their own forks, and their work reaches main only when an admin merges it.
v2 has no call to protect a branch yet, so you set it on the v1 API. The disk's v1 name is its v2 name, prefixed with the environment unless that is default (prod/app for app in prod, written prod%2Fapp in the URL). /v1 goes away one release after v2.
echo "retries = 3" | skywake write app/config.toml
curl -sf -X PATCH "$SKYWAKE_URL/v1/namespaces/app/branches/main" \
-H "authorization: Bearer $SKYWAKE_API_KEY" -H "content-type: application/json" \
-d '{"protected": true}'
if echo "retries = 0" | skywake write app/config.toml; then exit 1; fi
skywake fork app agent-1
echo "retries = 5" | skywake write app@agent-1/config.toml
skywake merge app@agent-1
skywake read app/config.tomlSend {"protected": false} to undo it. You need a key with the admin role to protect a branch or to remove protection.
What changes
Once a branch is protected:
- Nobody can write files to it directly. A write fails with
PermissionError:branch main is protected; change it with a merge. Change it with a merge instead. - Only an
adminkey can merge into it. - It can't be destroyed, reverted or restored.
- Scoped store credentials can't move its head.
The request to protect a branch waits for any commits, deletes and merges that were already running, so none of them lands afterwards. If they are still running after two minutes, you get a 503, but the branch is protected anyway.
Store credentials handed out before you protected the branch keep working until they expire (900 seconds by default). A client that holds the bucket's own keys is not bound by protection at all, so give agents API keys or scoped credentials, never the bucket's keys.
For the full request and response, see updateBranch in the API reference.