Skip to content

Introduce token for scoped access - #7044

Draft
6543 wants to merge 5 commits into
woodpecker-ci:mainfrom
6543-forks:introduce-token-concept
Draft

6543 wants to merge 5 commits into
woodpecker-ci:mainfrom
6543-forks:introduce-token-concept

Conversation

@6543

@6543 6543 commented Aug 20, 2026

Copy link
Copy Markdown
Member

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

claude and others added 5 commits August 20, 2026 03:01
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.
@6543 6543 added server enhancement improve existing features labels Aug 20, 2026
Comment thread shared/utils/random.go
// 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 {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this helper we should switch ussage in extra pull of e.g. agent secret generation etc... too it

@woodpecker-bot

woodpecker-bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Surge PR preview deployment succeeded. View it at https://woodpecker-ci-woodpecker-pr-7044.surge.sh

@qwerty287

qwerty287 commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

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

@6543

6543 commented Aug 20, 2026

Copy link
Copy Markdown
Member Author

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

@qwerty287

Copy link
Copy Markdown
Contributor

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.
CCTray is an app that you usually install locally on your PC, so I think having a full-API token there is ok generally...

@6543

6543 commented Aug 24, 2026

Copy link
Copy Markdown
Member Author

the token is optional as long as the repo is public ... and if wanted we can also just not have one for public repos

@qwerty287

Copy link
Copy Markdown
Contributor

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.

@6543

6543 commented Aug 25, 2026

Copy link
Copy Markdown
Member Author

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 ...

@6543
6543 force-pushed the introduce-token-concept branch from c77ba21 to 337ae39 Compare November 17, 2026 17:53
@6543

6543 commented Nov 17, 2026 •

Copy link
Copy Markdown
Member Author

aww well that was the wrong branch :D ... will restore

EDIT: now at #7590

@6543
6543 force-pushed the introduce-token-concept branch from 337ae39 to c77ba21 Compare November 17, 2026 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement improve existing features server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants