Skip to main content

Overview

An Amazon Bedrock AgentCore Harness runs each agent session in its own Firecracker microVM, where you usually can’t install the Formal Endpoint. Putting a database password in the environment instead would give every session standing access. This guide has the agent exchange its Harness execution role for a short-lived Formal token and log in to the with it. The Connector swaps in the real credentials and applies your , so the agent never sees a database password. A Harness skill walks the agent through the exchange, and the only setup in the VM is a Python script that comes with the skill.

Prerequisites

  • A Postgres behind a Formal Connector listener that the Harness can reach
  • A native user on the resource with the database credentials, set as the default for the resource
  • A working AgentCore Harness and permission to edit its execution role

Turn on outbound identity federation

The agent proves its identity to Formal with a JWT that AWS signs for the Harness execution role. Turn this on once per AWS account:
The second command prints your account’s issuer URL, for example https://<ID>.tokens.sts.global.api.aws. Keep it for the next step.

Connect the execution role to Formal

Create a Formal machine user and an OIDC integration that maps the execution role to it, then allow the role to request tokens for that integration. The role doesn’t need any database permissions.
1

Create a machine user

Go to Users and create a machine user, for example agentcore-harness. The agent’s sessions are logged and checked against policies as this user.
2

Create the OIDC integration

Go to OIDC Integrations and click Create Integration. Set Issuer to your account’s issuer URL. Select the machine user, and restrict the claim condition to the execution role:
Set the integration to Active. Copy the audience, oidc.formal.ai/integrationoidc_....
3

Allow the role to request tokens

Let the role request tokens for the integration’s audience only, so it can’t mint AWS-signed tokens for other services that trust your account:
4

Restrict the machine user to federation tokens

By default, the agent’s OIDC JWT works with any Control Plane API, but the agent only needs CreateFederationToken. Go to Permissions, click Create Permission, name it agentcore-harness, and paste:
Set the Permission to Active.

Add the skill to your Harness

The formal-connector skill is in formalco/example-use-cases. Add it to your Harness’s harness.yaml as a Git source, and point it at your Connector:
You can also set:
  • FORMAL_DATABASE: the database to connect to. Defaults to postgres.
  • FORMAL_NATIVE_USER: the label of a native user to request instead of the resource’s default.
  • FORMAL_SSLMODE: verify-full (default), require, or disable.
In the system prompt, tell the agent to use the skill for database access:
Deploy:
Git skill sources always load the default branch. To pin the skill to a version you’ve reviewed, fork the repository and point url at your fork.

How the skill works

The skill runs scripts/formal_pg.py. On the first run in a session, the script installs its hash-pinned dependencies into a virtualenv under /tmp, which takes about ten seconds. It then calls STS GetWebIdentityToken with the execution role’s credentials and your integration’s audience, and exchanges the resulting JWT for a federation token at CreateFederationToken. Finally, it logs in to the Connector with the federation username and token and runs the query.

Verify the setup

Invoke the Harness:
The script prints the identity it used to stderr:
The query should return the native user’s database role. In Logs, the session shows up under the agentcore-harness machine user, with the AWS claims under user.oidc.claims. To check that the agent can’t go around Formal, connect to the listener as the native database user with a wrong password. The database should reject the login.

Restrict network access

The execution role lets the agent mint tokens for Formal, and the skill isn’t a security boundary. To keep a prompt-injected agent from sending its tokens elsewhere, run the Harness in VPC mode and configure an egress policy.

Troubleshooting

The execution role lacks sts:GetWebIdentityToken, the audience in FORMAL_OIDC_AUDIENCE doesn’t match the one in the role’s policy, or outbound identity federation is off. Run aws iam get-outbound-web-identity-federation-info and check that JwtVendingEnabled is true.
By default, the script encrypts the connection and checks that the Connector’s certificate is valid for FORMAL_CONNECTOR_HOST.
  • CERTIFICATE_VERIFY_FAILED: the listener’s certificate isn’t valid for that hostname, for example because it’s self-signed or issued for a different name. Give the listener a certificate for the hostname the Harness connects to.
  • Server refuses SSL: the listener doesn’t have TLS configured. Configure TLS on the listener.
You can set FORMAL_SSLMODE to require to encrypt without checking the certificate, or to disable to turn off TLS entirely.
The Harness cannot reach the package index. In VPC mode, allow egress to pypi.org and files.pythonhosted.org, or set PIP_INDEX_URL to your mirror in environmentVariables.
Confirm the integration is Active and its issuer is your account’s issuer URL. Confirm the claim condition matches the execution role ARN, not the assumed-role session ARN.
FORMAL_NATIVE_USER is set to a native user label that doesn’t exist on the resource. Fix the label, or unset it to use the resource’s default native user.

Next steps

OIDC Integrations

Configure claims and federated access

Native Users

Store the database credentials in Formal

Devin Database Access

Add Slack approval before each session

ECS Egress

Run the Endpoint where you can install it