Repository navigation
Conversation
The badge endpoints are unauthenticated and therefore need a shared secret to gate access to non-public repos with. A dedicated table keeps that secret out of the repo row and leaves room for further per-repo secrets through the type enum, of which badge is the only member for now. Token values come from a shared helper rather than yet another inline base32 of random bytes, so their strength no longer depends on every call site getting the encoding right. No backfill migration is needed: repos get their token on activation, and repos activated by an older version get theirs the first time it is read.
Both badge endpoints answered for every repo in the database, regardless of its visibility. status.svg told anonymous callers apart which repo ids and names exist by answering 404 for unknown ones and a status badge for known ones, and cc.xml went further and handed out the full name, pipeline number and start time of private repos. Public repos keep working untouched, everything else now requires the repo's badge token. Access is decided on the repo visibility alone, the same rule the session middleware applies for pull access. A repo that may not be seen renders exactly what a repo that does not exist renders, so the response no longer carries the answer. The badge token is served by a new endpoint for the badge settings to build its URL from.
The badge settings page is where users copy their badge URL from, so it has to carry the token for non-public repos, otherwise the copied URL renders the placeholder badge. The repo header shows the same badge and hides it where no token can be read, rather than showing the placeholder to the repo's own team. Escaping of the HTML snippet replaced the first ampersand only, which the added token parameter makes easy to hit.
Prevent stale or missing private badge tokens from producing copyable URLs. Cover route authorization and reject invalid token and random-string inputs.
Leaked badge URLs need revocation without deleting the repository. Rotate repo-bound tokens atomically, restrict the operation to repository admins, and keep cached badge URLs synchronized with the returned token. Badge is the only persistent repository token today, so rotation creates that type directly and drops all prior rows in one transaction. A code comment records the separate handling future short-lived execution tokens will need. Reject replacement batches crossing repository boundaries. Warn before invalidating published URLs. Cover authorization, rollback, and UI behavior.
| // length characters, drawn from the base32 alphabet. It is the single place | ||
| // tokens, secrets and hashes are generated, so their strength does not depend | ||
| // on every call site getting the encoding right. | ||
| func RandomString(length int) string { |
There was a problem hiding this comment.
this helper we should switch ussage in extra pull of e.g. agent secret generation etc... too it
|
Surge PR preview deployment succeeded. View it at https://woodpecker-ci-woodpecker-pr-7044.surge.sh |
|
Thanks, it's a good addition in general (we also have #665), but it does not really fix the issue I mentioned on matrix. We already have an API token (which is non-scoped) so we can just use this token to protect the cctray endpoint |
|
the token we have grans full access to the account it belongs to ... that's a bit to much to ask for embeding in cctray or badge i would say |
|
I'm not sure whether badge should get a token at all. Do you think it really matters if I can link between last pipeline status and repo ID? It's a bit user-unfriendly to always require a token when inserting a badge into a readme I think. |
|
the token is optional as long as the repo is public ... and if wanted we can also just not have one for public repos |
|
That's not my point. I'm totally in favor of merging this PR if it's finished. But I think we could already add authentication to the cc.xml endpoint (this would be breaking though I think...). Yes, we only have the full-api token, but the CC endpoint is used for this CCTray application which is a local app. You can just put your token in there, it's as safe as using our CLI. But as this would be breaking change it's probably better to change this at a later point. |
|
this pull was made to have different scoped tokens later on. why not add user tokens ... ... we need tl add different indexes and checks in code to ensure some tokens exist only per repo while others can have multible ... |
c77ba21 to
337ae39
Compare
|
aww well that was the wrong branch :D ... will restore EDIT: now at #7590 |
337ae39 to
c77ba21
Compare
This adds tokens to woodpecker for scoped access.
currently this is only used for badges to gate private repos ... but more could come.
dRAFT because only spec drafted, ai coded and heavy reviewed ... but no real execution done jet