Service principals
A service principal is a Workload's own identity. It exists so that a hub's code can create duel servers without anyone pasting a key into an environment variable.
- At most one principal per Workload, created by a person with manage access.
- It holds grants: a target Workload of the same project (itself included) and one capability each:
units.readreads units and the event stream.units.controlalso creates, starts, stops, destroys and allocates, and includes reading.
- It can never change the scaling policy, the webhooks, or its own grants.
Create it and grant access
curl
Code
TypeScript
Code
Python
Code
PUT .../principal is idempotent and a new principal holds no grant. PUT .../principal/grants replaces the whole list (at most 64; an empty list removes everything). You must be able to manage every Workload you name: otherwise grant_target_unavailable and nothing changes. A grant takes effect on the program's next request.
Enabling a principal changes the Workload's pod template, so it applies as units restart, by the Workload's rollout rule.
Code inside a unit
Every unit of a Workload with a principal gets two things: ZAROZ_API_URL in its environment and a token file at /zaroz/credentials/token. The token lives 60 minutes and the platform replaces it before it expires, so read the file on every request (or when you get a 401) and never cache it.
curl
Code
TypeScript
Code
Python
Code
A program outside Zaroz
A matchmaker running on your own server, or a CI job, uses a project API token, not a credential of the principal. Create it in the console under Tokens, scope it to the project that holds the Workload, give it only the permissions the program needs, and choose an expiry (1 to 365 days, 90 by default). Replace it before it expires. API tokens has the details.
External credentials are retired
POST .../principal/credentials no longer creates credentials: it answers 410 with the code use-a-project-token. Credentials you created before (zaroz_sp_...) keep working until their own expiry, which was never more than 365 days. You can list them with GET .../principal/credentials and revoke one with DELETE .../principal/credentials/{credential_id}, but you cannot renew them. Switch the program to a project token before the credential ends.
Limits and audit
A principal is limited to 50 requests per second. A mounted token's routine units access is not audited: each change it makes is in the unit event log. The first use of an existing external credential, per target and action each day, is recorded in the organization audit log. Disabling the principal (DELETE .../principal) revokes every token. Tearing down the Workload that owns it revokes it too, and tearing down a target Workload deletes the grants that name it.
