Connections & Auth
Bahulam holds the OAuth. Your tool holds the domain logic. That split is the moat.
This page covers how to declare the connections your workspace needs and how Bahulam brokers credentials to your code at tool-call time.
The Split
When a user attaches a “Power BI Workspace” connection to Bahulam, Bahulam runs the OAuth handshake, stores the refresh token in its own secure storage, and — at your tool’s call time — passes a short-lived access token to your MicroVM.
Your tool never sees:
- The user’s password.
- The refresh token.
- The client secret.
- The redirect handshake.
Your tool sees:
- A short-lived credential (bearer token, API key, DSN, whatever the service accepts).
- Metadata (workspace id, tenant id) as needed.
Fork your code to another host and you get the code, not the tokens. That is the “we own the connection” side of the moat.
Declaring connections_required
In your workspace.yaml:
connections_required:
- kind: powerbi.workspace # required kinds shown in UI at attach
scope: read # informational
- kind: slack.workspace
scope: write
- kind: postgres.connection # a user-supplied DSN
scope: read
- kind: github.repo
scope: read
optional: true # workspace loads even without thisAt workspace load Bahulam:
- Reads
connections_required. - Checks the user’s attached connections in the broker.
- Logs a warning for any missing non-optional kinds.
- Lets the load proceed (per-tool errors surface at call time).
Supported Kinds (v1)
Bahulam ships broker support for these kinds. Each maps to a Bahulam- managed OAuth or credential flow:
| Kind | Broker flow | Credential shape passed to tool |
|---|---|---|
powerbi.workspace | Azure AD delegated OAuth | Fabric API bearer + workspace id |
slack.workspace | Slack OAuth v2 | Bot token |
github.repo | GitHub App or user OAuth | Installation / user token |
postgres.connection | User-provided DSN | DSN string |
webhook.outbound | Signed URL registration | Signed URL |
More kinds arrive per PRD. To request a new kind, open an issue on the
bahulam-workspaces repo (see Publishing).
What Your Tool Receives
Bahulam injects connection credentials into your tool at call time via
context — you don’t fetch them yourself. The exact shape depends on the
kind. For powerbi.workspace:
class QueryPowerBiTool(SandboxTool):
name = "bahulam.community.acme.query_pbi"
workspace_id = "community/acme/pbi-analyst"
custom_tool_path = "tools/query_pbi.py"
parameters = {
"type": "object",
"properties": {"dax": {"type": "string"}},
"required": ["dax"],
}
def _inside_sandbox(self, dax: str, ctx=None) -> dict:
# Bahulam passes ctx.connections["powerbi.workspace"] with:
# { "access_token": "<bearer>",
# "workspace_id": "<pbi ws guid>",
# "tenant_id": "..." }
conn = ctx.connections["powerbi.workspace"]
import httpx
r = httpx.post(
f"https://api.powerbi.com/v1.0/myorg/groups/{conn['workspace_id']}/datasets/execute",
headers={"Authorization": f"Bearer {conn['access_token']}"},
json={"query": dax},
timeout=25,
)
return {"rows": r.json()}The ctx parameter is optional in your _inside_sandbox signature — omit
it if your tool doesn’t need connection credentials.
Optional Connections
Mark a connection optional when your tool can gracefully degrade:
connections_required:
- kind: github.repo
optional: trueAt runtime your tool can check:
def _inside_sandbox(self, name: str, ctx=None) -> dict:
github = ctx.connections.get("github.repo")
if github:
return {"result": "Loaded from GitHub", "source": "github"}
return {"result": "Fallback local content", "source": "local"}Non-optional connections trigger a warning at workspace load if missing. The tool itself will fail if invoked without the credential — the broker returns an explicit error rather than a silent None.
Connection Lifecycle
For the user:
- Attach — user goes to the CDE / dashboard and clicks “Attach Power BI”. Bahulam runs the OAuth flow. Token stored in Bahulam.
- Use — user runs a workspace that binds Power BI tools. Broker fetches the token on demand, injects into the MicroVM.
- Refresh — Bahulam refreshes access tokens automatically before they expire; the tool never sees a refresh cycle.
- Revoke — user detaches the connection or Bahulam revokes on
security event. The next tool call gets a
connection_revokederror.
You don’t code for any of this. Just declare connections_required and
call ctx.connections[kind].
Adding a New Kind (Enterprise)
Community workspaces get the kinds Bahulam supports. If your workspace needs a kind that isn’t shipped:
- Open an issue on the
bahulam-workspacesrepo describing the service + the OAuth or credential flow. - Bahulam evaluates against the roadmap. Popular integrations get prioritized.
- Once shipped, your workspace adds the kind to
connections_requiredwithout code changes.
You cannot bring your own OAuth handler in v1 — the broker owns the flow. That constraint is what makes the moat hold.
The IoT / Hardware Special Case
For workspaces that need to talk to a device behind a firewall (Raspberry
Pi, industrial gateway, home lab), the equivalent connection kind is
bahulam.tunnel.link:
connections_required:
- kind: bahulam.tunnel.link
scope: execThe user installs the bahulam CLI on their device and runs
bahulam link register <device-name>. That sets up a persistent secure
tunnel. Your workspace’s tools receive a tunnel handle they can dispatch
commands to.
Claude and other agents cannot reach behind a firewall. Bahulam can, because Bahulam owns the CLI running on the device. This is the concrete form of the “we own the connection” moat for hardware.