No key on the server: how we let our CMS call AI
Our CMS calls AI to fact-check and edit articles. Whatever credential sits on that server is the one thing an attacker would want most, because it can easily be used to exploit our credits.
So, we decided on no Google credential on our CMS server.
Why an API key is the wrong thing to hold
The quickest setup is an API key in an environment variable. It is also the riskiest, because of how keys escape and what they do once out.
How keys get out. Rarely through a dramatic breach. Usually through ordinary things:
- An
.envfile committed by accident, or copied into a ticket - A log line or error page that prints the config
- CI output, a debug endpoint, or a support screenshot
- A compromised dependency that reads environment variables on install or at runtime
- These days AIs connected to desktop accidentally read and leak them too.
Why a leaked AI key hurts.
- It works from anywhere. Whoever holds it is us, as far as the provider can tell.
- It does not expire on its own. It keeps working until someone notices and revokes it.
- It turns straight into money. Stolen model keys are used and resold to run other people's workloads, sometimes called LLMjacking. The first sign is often the bill.
- It is hard to scope. A key usually opens every model the account can use, at whatever volume the quota allows.
So the question we set ourselves was not "Where do we store the key safely?" It was "Can the server have no Google key at all?"
Service accounts help, but a key file is still a key
On Google Cloud, the better answer is a service account: an identity for a program rather than a person, given only the roles it needs. Ours needs one role, Vertex AI User. It can call specific models and nothing else in the project.
That narrows what a credential can do. It does not change how the credential travels. To use a service account from outside Google Cloud, you normally download a JSON key file and point the app at it. That file is a long-lived secret, sitting on the server, readable by the same things that read an API key:
| Property | API Key | Service Account Key File |
|---|---|---|
| Scoped to a role | Rarely | Yes |
| Expires on its own | No | No, unless you rotate it |
| Works from anywhere | Yes | Yes |
| Sits on our server | Yes | Yes |
Scoping is worth having, and we kept it. But a key file in an environment variable has the same leak risk as an API key. We wanted the server to hold neither.
The OIDC gap
The clean answer to "no key on the server" is Workload Identity Federation. The hosting platform signs a short OIDC token that says "this request comes from this app". Google checks the signature and swaps it for an access token that expires in about an hour. No long-lived secret is stored anywhere. GitHub Actions, AWS, and most large clouds can do this.
Our CMS runs on Sevalla. When we looked, Sevalla had no way to issue OIDC tokens to an app, so there was nothing for Google to verify. Without that, the only way for the app to sign in to Google directly is to bring a stored key.
That changed the question again: if the server has to hold some secret, how little can that secret be allowed to do?
The options we compared
We had five realistic choices. Each pairs with the same baseline: a Google Cloud project used only for this, plus quotas and billing alerts.
| Option | What our server holds | Where the Google credential lives | If our server's secret leaks | Extra moving parts |
|---|---|---|---|---|
| Service account key file | The JSON key file | On our server | Full Vertex AI access until revoked | None |
| Runtime secrets manager (Doppler, 1Password) | A token for the manager; the key in memory at runtime | In the manager, still a static key | The key, or a token that fetches it | A SaaS tool; rotation to set up |
| Dynamic secrets (HashiCorp Vault, Akeyless) | A login for the vault | Short-lived tokens minted on demand | New tokens, until the vault login is revoked | A vault to run or pay for, which itself needs a Google identity |
| AI gateway or credential-injecting proxy (Cloudflare AI Gateway, Infisical Agent Vault) | A gateway token | At the gateway's vendor | Calls through the gateway, within its limits | A third party in the path of every article |
| Our own proxy on Cloud Run | A signing secret | Nowhere stored: Google attaches the service account at runtime | Our allowed models, at our rate limit, through our proxy | One small service we run |
The first two keep a long-lived Google key alive somewhere; they only move it. The third replaces it with short-lived tokens, but moves the problem to the vault's own login. The last two keep the Google credential away from our host entirely.
Narrowing down
Every option leaves one secret on our server. Security people call this "secret zero": the first secret, the one that unlocks the rest. You cannot get rid of it without OIDC, so the real choice is what secret zero can do. We judged each option on four questions:
- Does a long-lived Google key exist anywhere? If yes, it can leak from wherever it lives, not just from us.
- What does a leak of our server's secret buy? Ideally something narrow, useless elsewhere, and quick to rotate.
- Can we enforce our own limits? We wanted to allow only the models and tools the pipeline uses, cap tokens, and rate-limit, in code we control.
- What does it add? Each new service, vendor, or dependency is one more thing to secure and keep running.
That ruled options out one by one:
- Key file: fails question 1 outright.
- Secrets manager: better hygiene, same answer to question 1. The key still exists and still works from anywhere.
- Dynamic secrets: good on question 1, heavy on question 4. Running Vault well is a project of its own, and it still needs its own way into Google.
- AI gateway: good on question 3, but for Vertex the gateway vendor holds our Google credential. It also puts every article we review through a third party.
- Our own Cloud Run proxy: no stored Google key, and a leaked secret only reaches our narrow endpoint. The limits are in our code, and it adds one small service in a project we already control.
We picked the proxy.
How the proxy gates traffic
Because Sevalla cannot issue OIDC tokens, Cloud Run cannot require a Google sign-in from the CMS without putting a static Google key back on the server. Instead, the Cloud Run URL accepts incoming HTTP requests, and our proxy code checks an HMAC signature and timestamp on every call before touching Vertex AI:
| Request | Cloud Run (Google sign-in) | Proxy code (HMAC signature) | Result |
|---|---|---|---|
| A stranger hitting the URL | Lets it through | No valid signature | 401, AI never called |
| An old request someone captured and resends | Lets it through | Timestamp more than 5 min old | 401 |
| Our CMS, signing with the shared secret | Lets it through | Valid signature | Calls AI |
The door is open to the internet, so only someone holding the signing secret gets past the proxy. That is either our CMS or an attacker who stole the secret from Sevalla. A quick curl test without a signature proves the second column works: if an unsigned request returns anything other than a 401, the proxy is wide open.
What we gave up, and how we contain it
The proxy is not free. These are the costs we accepted and what keeps each one small.
| Trade-off | Why it happens | How we contain it |
|---|---|---|
| The proxy URL is reachable without a Google sign-in | Requiring Cloud Run IAM authentication needs a Google identity token, which Sevalla cannot mint without a stored key | Every request carries an HMAC of its timestamp and body; anything unsigned or older than 5 minutes gets a 401 |
| The signing secret is still a static secret | Secret zero has to be something | It only reaches our proxy, is stored in Secret Manager for the proxy, and rotates without IAM changes |
| One more service to run | We wrote and own the proxy | It does one thing, runs on at most one instance, and logs every call |
| Another network hop, and cold starts | The call goes from the CMS to Cloud Run, then to Vertex | Bounded retries for errors that never reached the proxy, all inside each call's deadline |
| Long calls hit default timeouts | Node's fetch gives up after 300 s with no response headers, and the editor can take 10 minutes |
A custom HTTP client allows up to 900 s, matching the 900 s timeout we set on Cloud Run, and model timeouts are capped to match |
| Some calls can be billed twice | A connection can drop after the proxy has already called Vertex | At most 2 retries, never for an error the proxy itself returned |
| Budget alerts do not stop spending | Google Cloud budgets notify; they do not cut off | The proxy's rate limit (20 requests a minute) and a single Cloud Run instance are the hard ceilings |
Failure behavior in the CMS keeps a slow call, timeout, or failed review from blocking publishing: if the review cannot be queued or fails, the CMS logs the failure and publishes the article as delivered.
None of these are as bad as a Google key that works from anywhere. That was the comparison that mattered.
The setup in short
- A dedicated Google Cloud project kept for this alone, so its budget, quotas, and permissions cover nothing else.
- A keyless service account with one role, Vertex AI User, attached to the Cloud Run service. No key is downloaded, and an org policy blocks creating one.
- The signing secret in Secret Manager, readable only by that service account. Our CMS gets the same value as an environment variable.
- Clear ownership: the Cloud Run owner handles IAM policy writes, secret binding, and reading the secret, while deploying engineers can deploy as the service account without widening Vertex AI access elsewhere.
- Limits in the proxy: it allows only listed models and tools, caps tokens, and allows 20 requests a minute. Cloud Run runs at most one instance. At four or five articles a day, that leaves room for revisions.
- Billing alerts and quotas on the project, as the early warning.
If Sevalla adds OIDC tokens, the signing secret can go. The CMS would exchange its identity token for a short-lived Google token, either to call the proxy or to call Vertex directly. The proxy's limits are worth keeping either way. Until then, the one secret on our server is the least useful one we could find.

