Skip to content

[Access] Fix OpenCode casing and use long-form --header flag#29711

Open
caley-b wants to merge 1 commit intoproductionfrom
caley/authenticate-agents
Open

[Access] Fix OpenCode casing and use long-form --header flag#29711
caley-b wants to merge 1 commit intoproductionfrom
caley/authenticate-agents

Conversation

@caley-b
Copy link
Copy Markdown
Contributor

@caley-b caley-b commented Apr 8, 2026

Adds the authenticate-agents page for coding agents behind Cloudflare Access. Pertains to PCX-21534.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

This pull request requires reviews from CODEOWNERS as it changes files that match the following patterns:

Pattern Owners
/src/content/docs/cloudflare-one/access-controls/ @kennyj42, @ranbel, @cloudflare/pcx-technical-writing

- [**Service tokens**](#use-service-tokens) — authenticates with a static credential pair. Use for headless or automated workflows where no browser is available.

:::note
Cloudflare Access also supports Managed OAuth to protected resources, which you can use to grant authorization to coding agents.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we have a docs page for this yet? If so, we should link it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it's in progress: #29590

With `cloudflared`, your agent authenticates under your user identity. On first use, `cloudflared` opens a browser window for an interactive login. After that, the session persists for the [session duration](/cloudflare-one/access-controls/access-settings/session-management/) configured for the application. After the session expires, the next request requires a new browser login.

:::caution
`cloudflared` authentication relies on WebSockets, which may close unexpectedly during long-running sessions. If your agent requires persistent, unattended access, [service tokens](#use-service-tokens) are more reliable.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This line doesn't really make sense. The websockets bit doesn't have much to do with the login. I would remove this whole caution block.


- The response is a 302 redirect to a URL containing `cloudflareaccess.com`
- The response is a 403 with a `Cf-Access-Error` header
- The response includes a `WWW-Authenticate: Bearer` challenge header referencing a Cloudflare Access policy
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We return something that looks like this. It doesn't really reference a cloudflare access policy.

www-authenticate: Cloudflare-Access resource_metadata="https://test.almightyzero.com/.well-known/cloudflare-access-protected-resource/headers"

A resource is protected by Cloudflare Access if any of the following are true:

- The response is a 302 redirect to a URL containing `cloudflareaccess.com`
- The response is a 403 with a `Cf-Access-Error` header
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think that cf-access-error is a thing.

Some agents make HTTP requests using their own client libraries instead of calling `cloudflared` directly. In this case, fetch a reusable token and pass it as a header:

```bash
CF_TOKEN=$(cloudflared access token -app=https://example.com)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For both this and the skill file below I wouldn't refer to it like this. This is basically what cloudflared access curl does.

If you want to embed it in your program you should have it shell out to cloudflared access login <hostname> and get the token that way and include it as cf-access-token. I would reference it as curl.


## Configure your agent

Coding agents read project-level instruction files (commonly named `AGENTS.md`) to learn how to interact with tools and services in your development environment. Add the following snippet to your `AGENTS.md` file or agent skill configuration so that the agent can detect and authenticate to Access-protected resources:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm gonna send a doc that kyle just made internally for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants