HenniOKF
Documentation

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 isThe token needsOn GitHub
public, only readno token–
private, only readread access to the content of that one repository"Contents: Read-only"
writable (phase 4), public or privateread 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

  1. Sign in to GitHub with an account that may read (or, for write-back, push to) the repository.
  2. Open "Settings", then "Developer settings", "Personal access tokens", "Fine-grained tokens", and "Generate new token".
  3. Token name: something you recognize later, such as henniokf-<source id>.
  4. Expiration: a date you will notice; write it into your calendar. When it expires, fetching (and writing) fails and /status names the source.
  5. Resource owner: the owner of the repository. Repository access: "Only select repositories", and choose exactly that repository.
  6. 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".
  7. "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.

  1. Choose the variable name. It is HENNIOKF_SOURCE_ plus uppercase letters, digits and underscores, for example HENNIOKF_SOURCE_BUNDLES. The prefix makes sure no source can ask for another secret of the instance.

  2. Put the value into the environment of the service:

    WhereFileLine
    on the VPSdocker/.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 environment of docker/compose.vps.yml, by name only: HENNIOKF_SOURCE_BUNDLES: ${HENNIOKF_SOURCE_BUNDLES}. Both files with values, docker/.env and .env.local, are in .gitignore and stay out of the repository.

  3. Restart the service. The environment is read only at start.

  4. Name the variable at the source. Under /settings/sources the 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".

  5. 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/.env or .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.