Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions docs/self-host/knowledge-sources.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Knowledge sources
description: Sanity connects by signing in on every install with nothing to set up; the OAuth apps and webhook settings here give Notion, Confluence and Google Drive one-click sign-in and instant updates.
description: Sanity connects by signing in on every install with nothing to set up; the OAuth apps and webhook settings here give Notion, Confluence and Google Drive one-click sign-in and instant updates. Bedrock knowledge bases and MCP search tools connect in place; S3 buckets, Bedrock knowledge bases and export archives import.
order: 14
---

Expand Down Expand Up @@ -165,9 +165,40 @@ Until an admin applies it, connecting a knowledge base in the install's own acco

An install whose functions have no internet route needs interface VPC endpoints for `bedrock-agent-runtime` (search) and `bedrock-agent` (the list), in each region a connected knowledge base lives in. Without them the dialog says CoderHelm couldn't reach Bedrock.

### Who sees what
## Connecting a search tool through MCP

Everyone who can read the CoderHelm knowledge base sees what the search returns, whatever their rights in the systems the Bedrock knowledge base was built from. Agents search the bases attached to them, so anyone who can start a run reaches everything the role can search in those bases. Connect only knowledge bases that everyone with that access may read.
Any search tool your team already runs behind an MCP server can be connected in place too: Azure AI Search or Foundry IQ, Pinecone Assistant, Glean, Atlassian Rovo, Dropbox Dash, a Bedrock knowledge base behind an AgentCore gateway, or your own retrieval server. Add the server on **Settings**, **Connected apps** first, then open **Knowledge**, **New knowledge base**, **Search tool (MCP)** and pick it.

- **The tools.** CoderHelm calls the server's search tool (`search`, `knowledge_base_retrieve`, `retrieve`, `get_context` and similar names are found by themselves, or pick one) and, for results without text, its fetch tool (`fetch` or similar). Nothing else is called, and a tool the server marks as destructive is never picked.
- **Check on save.** One test search runs before anything is saved. When it fails, the dialog says why in one sentence (not signed in, no search tool, an answer it couldn't read, the server's own error, unreachable) and what to do.
- **Who it searches as.** A server the team shares is searched with the team's connection. A server that signs each person in is searched with the asking person's own sign-in, so they only get what the tool lets them see; agent runs search it as the person who started them, and runs nobody started skip it.
- **Nothing new in AWS.** It uses the Connected apps sign-in and tokens (sealed with your KMS key) and needs no permission change. If you restrict outbound traffic, allow the server's address.

## Importing an existing knowledge base

### From Amazon S3

A bucket of documents (or a folder in one) becomes a source of a knowledge base: **Add source**, **Amazon S3**, pick the AWS account, type the bucket name, and pick folders or files. CoderHelm reads supported files (PDF, Word, Markdown, text, CSV, Excel, HTML), embeds them with Titan and keeps them in sync like any other source: an object whose ETag didn't change isn't read again, a changed one re-embeds only its changed passages, and a deleted one is removed. A `<file>.metadata.json` sidecar next to a document (the Bedrock data source format) gives it its title, original link and date.

The bucket is always read with that account's `CoderHelmLogReader` role (connect the account on **Settings**, **Integrations**, **AWS**, including the install's own account), never with the install's own role. The role may read only the buckets named in its stack's `ImportBuckets` parameter: `s3:ListBucket`, `s3:GetBucketLocation` and `s3:GetObject` on them, and `kms:Decrypt` only through S3 for a bucket with its own KMS key. When the role can't read a bucket, the dialog offers the one-click update stack with the bucket named. The install's permissions boundary already allows S3 and KMS, so there is no admin step on the install itself.

### From a Bedrock knowledge base

**Import from a Bedrock knowledge base** reads the knowledge base's settings (`bedrock:GetKnowledgeBase`, `bedrock:ListDataSources`, `bedrock:GetDataSource`) and turns each S3 data source into an S3 source on its bucket and prefixes. Bedrock can't export its passages, so CoderHelm reads the original documents and indexes them itself; nothing in Bedrock changes. A Confluence or web data source points you at CoderHelm's own connector instead; SharePoint and Salesforce data sources can't be imported, so connect the knowledge base in place to search them. On a self-hosted install, a knowledge base in its own account is read with the install's own role (the boundary's `bedrock:Get*` and `bedrock:List*`, which arrive with the version update); one in another account with that account's role, whose `ReadKnowledgeBases` statement now includes these three actions.

### From an export archive

**Upload an archive** takes a `.zip` (up to 200 MB) of a Notion export (Markdown and CSV), a Confluence HTML export or a zipped docs folder, and unpacks it on the server. Every supported entry becomes a page of the base, titled without the export's ids. Uploading a newer export to the same archive keeps unchanged pages, re-reads changed ones and removes pages it no longer has. The archive is kept in the team's folder of the data bucket and goes with its source. Before the upload the dialog warns that every page becomes readable by everyone who can read the base, and that a Confluence Full Export includes restricted pages.

### Limits

An import keeps up to 2,500 documents per source (other sources keep 1,000). CoderHelm ranks its own bases in memory, so a bigger corpus is better connected in place; the page says so when an import is cut short. Each search reads up to 16 indexes at once and keeps recently used indexes in memory (up to 160 MB per process).

## Who sees what

Every knowledge base has a lowest read role, and can also be limited to named people and roles (**Only these people or roles**). A person only gets passages from bases they may read, in the brain chat and on the Knowledge page.

Agents search the bases attached to them. A base limited to named people is searched only in runs one of them started; a search tool that signs each person in is searched as the person who started the run. Every other attached base is searched by every run, whatever the starter's rights in the systems the content came from, and the page says so when a base is attached. Connect and attach only content that everyone with that access may read.

## What runs

Expand Down
60 changes: 58 additions & 2 deletions infra/cfn/coderhelm-log-reader-update.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
AWSTemplateFormatVersion: "2010-09-09"
Description: >
Brings the existing CoderHelmLogReader role up to date with the read-only
permissions the current CoderHelm release uses, and lets it search the
Bedrock knowledge bases named in KnowledgeBases. Every permission here is
permissions the current CoderHelm release uses, lets it search the
Bedrock knowledge bases named in KnowledgeBases, and lets it read the
documents in the S3 buckets named in ImportBuckets. Every permission here is
read-only: CoderHelm can list, describe and query, never change anything.
It only adds: to drop a permission an older release granted, update the
CoderHelmLogReader stack itself with the current role template.
Expand All @@ -26,9 +27,20 @@ Parameters:
AllowedPattern: "^(|all|arn:aws:bedrock:[a-z0-9-]+:[0-9]{12}:knowledge-base/[A-Z0-9]{10}(,arn:aws:bedrock:[a-z0-9-]+:[0-9]{12}:knowledge-base/[A-Z0-9]{10})*)$"
ConstraintDescription: Knowledge base ARNs separated by commas, "all", or empty.

ImportBuckets:
Type: String
Default: ""
Description: >
S3 buckets CoderHelm may import knowledge base documents from,
read-only: their names separated by commas. Empty: none (the role reads
no object in any bucket).
AllowedPattern: "^(|[a-z0-9][a-z0-9.-]{1,61}[a-z0-9](,[a-z0-9][a-z0-9.-]{1,61}[a-z0-9])*)$"
ConstraintDescription: Bucket names separated by commas, or empty.

Conditions:
ReadsKnowledgeBases: !Not [!Equals [!Ref KnowledgeBases, ""]]
ReadsEveryKnowledgeBase: !Equals [!Ref KnowledgeBases, "all"]
ReadsImportBuckets: !Not [!Equals [!Ref ImportBuckets, ""]]

Resources:
CoderHelmReadOnlyUpdate:
Expand Down Expand Up @@ -130,6 +142,9 @@ Resources:
Action:
- "bedrock:Retrieve"
- "bedrock:GetDocumentContent"
- "bedrock:GetKnowledgeBase"
- "bedrock:ListDataSources"
- "bedrock:GetDataSource"
Resource: !If
- ReadsEveryKnowledgeBase
- !Sub "arn:aws:bedrock:*:${AWS::AccountId}:knowledge-base/*"
Expand All @@ -143,3 +158,44 @@ Resources:
- "bedrock:ListKnowledgeBases"
Resource: "*"
- !Ref AWS::NoValue
# Imports: the documents in the buckets named in ImportBuckets,
# read so a knowledge base can index them; never a write, never
# another bucket.
- !If
- ReadsImportBuckets
- Sid: ReadImportBuckets
Effect: Allow
Action:
- "s3:ListBucket"
- "s3:GetBucketLocation"
Resource: !Split
- ","
- !Sub
- "arn:aws:s3:::${Names}"
- Names: !Join [",arn:aws:s3:::", !Split [",", !Ref ImportBuckets]]
- !Ref AWS::NoValue
- !If
- ReadsImportBuckets
- Sid: ReadImportObjects
Effect: Allow
Action:
- "s3:GetObject"
Resource: !Split
- ","
- !Sub
- "arn:aws:s3:::${Names}/*"
- Names: !Join ["/*,arn:aws:s3:::", !Split [",", !Ref ImportBuckets]]
- !Ref AWS::NoValue
# A bucket encrypted with its own KMS key: decrypt only through S3,
# so only objects the role may read anyway.
- !If
- ReadsImportBuckets
- Sid: DecryptImportsThroughS3
Effect: Allow
Action:
- "kms:Decrypt"
Resource: "*"
Condition:
StringLike:
kms:ViaService: "s3.*.amazonaws.com"
- !Ref AWS::NoValue
53 changes: 53 additions & 0 deletions infra/cfn/coderhelm-log-reader.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,20 @@ Parameters:
AllowedPattern: "^(|all|arn:aws:bedrock:[a-z0-9-]+:[0-9]{12}:knowledge-base/[A-Z0-9]{10}(,arn:aws:bedrock:[a-z0-9-]+:[0-9]{12}:knowledge-base/[A-Z0-9]{10})*)$"
ConstraintDescription: Knowledge base ARNs separated by commas, "all", or empty.

ImportBuckets:
Type: String
Default: ""
Description: >
S3 buckets CoderHelm may import knowledge base documents from,
read-only: their names separated by commas. Empty: none (the role reads
no object in any bucket).
AllowedPattern: "^(|[a-z0-9][a-z0-9.-]{1,61}[a-z0-9](,[a-z0-9][a-z0-9.-]{1,61}[a-z0-9])*)$"
ConstraintDescription: Bucket names separated by commas, or empty.

Conditions:
ReadsKnowledgeBases: !Not [!Equals [!Ref KnowledgeBases, ""]]
ReadsEveryKnowledgeBase: !Equals [!Ref KnowledgeBases, "all"]
ReadsImportBuckets: !Not [!Equals [!Ref ImportBuckets, ""]]

Resources:
CoderHelmLogReaderRole:
Expand Down Expand Up @@ -201,6 +212,9 @@ Resources:
Action:
- "bedrock:Retrieve"
- "bedrock:GetDocumentContent"
- "bedrock:GetKnowledgeBase"
- "bedrock:ListDataSources"
- "bedrock:GetDataSource"
Resource: !If
- ReadsEveryKnowledgeBase
- !Sub "arn:aws:bedrock:*:${AWS::AccountId}:knowledge-base/*"
Expand All @@ -214,6 +228,45 @@ Resources:
Resource: "*"
- !Ref AWS::NoValue
- !Ref AWS::NoValue
# Imports: the documents in the buckets named in ImportBuckets, read
# so a knowledge base can index them; never a write, never another
# bucket.
- !If
- ReadsImportBuckets
- PolicyName: KnowledgeImportsReadOnly
PolicyDocument:
Version: "2012-10-17"
Statement:
- Sid: ReadImportBuckets
Effect: Allow
Action:
- "s3:ListBucket"
- "s3:GetBucketLocation"
Resource: !Split
- ","
- !Sub
- "arn:aws:s3:::${Names}"
- Names: !Join [",arn:aws:s3:::", !Split [",", !Ref ImportBuckets]]
- Sid: ReadImportObjects
Effect: Allow
Action:
- "s3:GetObject"
Resource: !Split
- ","
- !Sub
- "arn:aws:s3:::${Names}/*"
- Names: !Join ["/*,arn:aws:s3:::", !Split [",", !Ref ImportBuckets]]
# A bucket encrypted with its own KMS key: decrypt only through S3,
# so only objects the role may read anyway.
- Sid: DecryptImportsThroughS3
Effect: Allow
Action:
- "kms:Decrypt"
Resource: "*"
Condition:
StringLike:
kms:ViaService: "s3.*.amazonaws.com"
- !Ref AWS::NoValue

Outputs:
RoleArn:
Expand Down
10 changes: 8 additions & 2 deletions infra/lib/own-account-read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
* for the picker. Admins still choose which ones a team connects. Retrieve also
* needs the permissions boundary to allow bedrock:Retrieve, which reaches an
* install only through the access stack an AWS admin applies (native/access-stack.ts).
*
* Knowledge imports from S3 (services/common/src/knowledge/sources/s3.rs) never
* use the install's own role: the template's ImportBuckets is empty here, so
* the role gains no read on the account's buckets. An import reads a bucket
* with the team's CoderHelmLogReader role in that account, whose stack names
* every bucket an admin chose.
*/
import * as cdk from "aws-cdk-lib";
import * as iam from "aws-cdk-lib/aws-iam";
Expand All @@ -34,7 +40,7 @@ const ROLE_NAME_MARK = "__CODERHELM_ROLE__";
/** The install's own role searches every knowledge base in its own account. */
const OWN_KNOWLEDGE_BASES = "all";
/** The template's conditions for that value. A condition not listed here fails the build. */
const OWN_CONDITIONS: Record<string, boolean> = { ReadsKnowledgeBases: true, ReadsEveryKnowledgeBase: true };
const OWN_CONDITIONS: Record<string, boolean> = { ReadsKnowledgeBases: true, ReadsEveryKnowledgeBase: true, ReadsImportBuckets: false };

type Statement = { Sid?: string; Effect: string; Action: string | string[]; Resource: unknown };

Expand All @@ -61,7 +67,7 @@ export function decideConditions(v: unknown, conditions: Record<string, boolean>
/** The update template's statements for the install's own role: its knowledge bases are every one in its account. */
export function updateTemplateStatements(): Statement[] {
const scratch = new cdk.Stack(new cdk.App(), "Scratch");
const inc = new CfnInclude(scratch, "T", { templateFile: repoPath(UPDATE_TEMPLATE), parameters: { RoleName: ROLE_NAME_MARK, KnowledgeBases: OWN_KNOWLEDGE_BASES } });
const inc = new CfnInclude(scratch, "T", { templateFile: repoPath(UPDATE_TEMPLATE), parameters: { RoleName: ROLE_NAME_MARK, KnowledgeBases: OWN_KNOWLEDGE_BASES, ImportBuckets: "" } });
const p = inc.getResource(UPDATE_POLICY_ID) as iam.CfnPolicy;
return decideConditions(scratch.resolve(p.policyDocument).Statement, OWN_CONDITIONS) as Statement[];
}
Expand Down
10 changes: 9 additions & 1 deletion infra/test/synth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,14 @@ test("self-host: the gateway and worker read the install's own account with this
const t = synth(selfHost());
// Every permission the services check a role against (services/common/src/log_reader.rs ABILITIES).
const rs = fs.readFileSync(path.join(INFRA, "..", "services", "common", "src", "log_reader.rs"), "utf8");
const abilities = rs.slice(rs.indexOf("pub const ABILITIES"), rs.indexOf("];", rs.indexOf("pub const ABILITIES")));
const all = rs.slice(rs.indexOf("pub const ABILITIES"), rs.indexOf("];", rs.indexOf("pub const ABILITIES")));
// Knowledge imports from S3 read a bucket only with the team's CoderHelmLogReader role, whose stack
// names each bucket (services/common/src/knowledge/sources/s3.rs): the install's own role never gains
// read on the account's buckets.
const importsAt = all.indexOf('key: "imports"');
assert.ok(importsAt > 0, "the imports ability");
const nextAt = all.indexOf("Ability {", importsAt);
const abilities = all.slice(0, importsAt) + (nextAt > 0 ? all.slice(nextAt) : "");
const needed = [...new Set([...abilities.matchAll(/"([a-z0-9-]+:[A-Za-z]+)"/g)].map((m) => m[1]))];
assert.ok(needed.length > 20, `${needed.length} actions`);
for (const [stack, fn] of [
Expand All @@ -193,6 +200,7 @@ test("self-host: the gateway and worker read the install's own account with this
assert.equal(policies.length, 1, `${fn}: one read policy`);
const doc = JSON.stringify(policies[0].Properties.PolicyDocument);
for (const a of needed) assert.ok(doc.includes(`"${a}"`), `${fn} lacks ${a}`);
for (const a of ["s3:GetObject", "s3:ListBucket", "kms:Decrypt"]) assert.ok(!doc.includes(`"${a}"`), `${fn} must not read buckets with ${a}`);
// Only reads: list, describe, get, query, never a write.
const actions: string[] = policies[0].Properties.PolicyDocument.Statement.flatMap((s: any) => ([] as string[]).concat(s.Action));
for (const a of actions) assert.match(a, /^[a-z0-9-]+:(List|Describe|Get|Filter|Start(Query)?$|Stop(Query)?$|BatchGet|Simulate|InvokeRestApi|Retrieve$)/, a);
Expand Down
Loading
Loading