# Run a private cron endpoint without exposing it to the internet

Gregale · Updated 2026-12-03

Schedule an HTTP task on an internal-only Gregale worker and verify that public requests are denied while the internal scheduled run succeeds.

Run the scheduler and its HTTP worker on the same platform, then keep the worker
off public ingress. On Gregale, set a dedicated app's access to `internal_only`
and schedule a POST to its handler. A caller on the public URL should be refused,
while Gregale's own scheduler can invoke the app.

This setting applies to the **whole app**. If your API must stay public, put the
cron handler in a separate app. For a scheduler running outside Gregale, use
an authenticated endpoint instead; it isn't a Gregale internal caller.

[Download the runnable drill](https://gregale.dev/examples/private-cron-endpoint.zip). It runs one
synthetic scheduled task, uses no database or shared cron secret, and removes the
disposable app afterward.

## 1. Make the worker internal before deploying it

Reserve a fresh worker app, then configure its
[public access mode](https://gregale.dev/docs/auth.md#app-access-control) before putting the handler
on it:

```sh
gregale app update my-nightly-worker --public-auth internal_only
```

Keep the handler narrow. In the starter, only `POST /nightly` succeeds;
unknown paths get a 404. In a real worker, make retries safe before adding
side effects. Don't copy credentials or real customer data into this example.

## 2. Schedule a POST to the private handler

```sh
gregale cron create --app my-nightly-worker \
  --schedule '0 2 * * *' --timezone UTC --path /nightly
```

That example runs at 02:00 UTC daily. The starter uses a minute cadence
so you don't have to wait until tomorrow. Use a workspace with HTTP crons and
internal-only access enabled. The starter does not create a cron in the main API.

## 3. Verify both sides of the access boundary

First, make an unauthenticated `POST /nightly` to the worker's public hostname.
A DNS error, missing route, or app-generated failure doesn't prove the worker
was private. Check that the platform refused it because internal-only access
is enabled.

Then inspect the scheduler's run history:

```sh
gregale cron runs CRON_ID
```

A configured cron is not a successful run. The starter waits for a real
scheduled run, matches its invocation ID to a completed `POST /nightly` on the
same app, checks the synthetic JSON returned by the handler, and repeats the
anonymous request afterward. It never calls
the manual-run command. This verifies the observed HTTP scheduler path, not
access from every possible internal caller.

Install the [Gregale CLI](https://gregale.dev/docs/install.md), Bash, curl, jq and OpenSSL. Export a
test workspace key as `GREGALE_TOKEN`, extract the starter and run
`bash run-demo.sh`. The script creates one disposable app and disables the
demo schedule during cleanup. No changes to your own API or DNS are needed.

See [scheduled HTTP crons](https://gregale.dev/docs/crons.md) for schedules and timezones, or
[Jobs](https://gregale.dev/docs/jobs.md) if your task is a batch process rather than an HTTP handler.

## Questions

### How do I keep a cron endpoint private on Gregale?

Place the endpoint on a dedicated internal-only app and use a Gregale HTTP cron to invoke it. Keep your public API on a separate app.

### Does internal-only protect just the cron path?

No. It sets access for the whole app. Use a dedicated worker if your main application needs public ingress.

### How do I tell whether the private cron actually ran?

Check its run history and match the successful run ID to the completed invocation and handler result. A saved cron configuration is not proof that the handler ran.

Canonical URL: https://gregale.dev/articles/private-cron-endpoint

