Guide
Tokens for package sources
How to create a fine-grained token for a Git package source, read-only for reading and read and write for write-back, and where it goes.
What it is about
This page describes planned behaviour. Git package sources arrive with phase 2, the write-back of accepted changes with phase 4. Until then HenniOKF reads no source and needs no token.
A Git package source is a repository the application fetches bundles from. A public repository needs no token. A private one needs an access token, and a source that the admin makes writable, so that HenniOKF commits accepted job results into it, needs a token that may write. The flow from job to commit is in Trust and provenance.
| The source is | The token needs | On GitHub |
|---|---|---|
| public, only read | no token | – |
| private, only read | read access to the content of that one repository | "Contents: Read-only" |
| writable (phase 4), public or private | read and write access to the content of that one repository | "Contents: Read and write" |
Give a token only the one repository and only the content. No administration, no workflows, no secrets, no other repository.
Create a fine-grained token on GitHub
- Sign in to GitHub with an account that may read (or, for write-back, push to) the repository.
- Open "Settings", then "Developer settings", "Personal access tokens", "Fine-grained tokens", and "Generate new token".
- Token name: something you recognize later, such as
henniokf-<source id>. - Expiration: a date you will notice; write it into your calendar. When
it expires, fetching (and writing) fails and
/statusnames the source. - Resource owner: the owner of the repository. Repository access: "Only select repositories", and choose exactly that repository.
- Permissions, under "Repository permissions": set Contents to "Read-only" for reading or to "Read and write" for a writable source. "Metadata: Read-only" is added by GitHub on its own. Leave everything else at "No access".
- "Generate token" and copy it once. GitHub shows it only now.
If the owner is an organization, it may have to approve the token before it works. If the branch of the source is protected so that nobody may push to it directly, the write-back fails with that reason; either allow the push for the token's account or keep the source read-only.
On Gitea the steps are similar: "Settings", "Applications", "Generate new token", with read access, or read and write access, to the repository.
Where the token goes
A token is a secret. It is never written into sources.json, into the
address of the repository, into the chat with an agent, into a commit, into
an issue or into this documentation. The application never shows it: the
UI and /status name only the variable and whether it is set.
-
Choose the variable name. It is
HENNIOKF_SOURCE_plus uppercase letters, digits and underscores, for exampleHENNIOKF_SOURCE_BUNDLES. The prefix makes sure no source can ask for another secret of the instance. -
Put the value into the environment of the service:
Where File Line on the VPS docker/.env, next to the other values (see On a VPS with Traefik)HENNIOKF_SOURCE_BUNDLES=<token>on your own computer .env.local, a copy of.env.example(see Setup)HENNIOKF_SOURCE_BUNDLES=<token>On the VPS the variable must also be passed to the container in the
environmentofdocker/compose.vps.yml, by name only:HENNIOKF_SOURCE_BUNDLES: ${HENNIOKF_SOURCE_BUNDLES}. Both files with values,docker/.envand.env.local, are in.gitignoreand stay out of the repository. -
Restart the service. The environment is read only at start.
-
Name the variable at the source. Under
/settings/sourcesthe admin enters the variable name in the field "Token variable" of the source, never the value. For write-back the admin also switches on "Writable". -
Check. "Sync now" on
/settings/sources; the source shows the fetched commit, or the reason why fetching failed. The first write-back shows whether writing works.
Change or revoke a token
- Rotate before the expiry: create a new token, replace the value in
docker/.envor.env.local, restart, sync, then delete the old token on GitHub. - Revoke at once if a token was ever shown somewhere it should not be, such as a chat, a log or a commit: delete it on GitHub, create a new one, and replace it as above. Removing it from a commit afterwards does not make it secret again.
- Make a source read-only again by switching off "Writable"; you may then replace the token with a read-only one.
Next: Troubleshooting.