Skip to content

Commit fb44b5c

Browse files
authored
[DOC] nits and fixes (#2107)
- Fix broken links - Fix broken styles - Move auth out of usage-guide and into a new Auth page - Fix code styling - Lessen code "overflow" with new lines
1 parent 1f3749f commit fb44b5c

30 files changed

+614
-259
lines changed

.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,4 @@
132132
"unordered_set": "cpp",
133133
"algorithm": "cpp"
134134
},
135-
}
135+
}

docs/docs.trychroma.com/components/CodeBlock.tsx

+17-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Prism from 'prismjs';
88
require(`prismjs/components/prism-python.min.js`);
99
require(`prismjs/components/prism-bash.min.js`);
1010
require(`prismjs/components/prism-javascript.min.js`);
11+
require(`prismjs/components/prism-yaml.js`);
1112
require(`prismjs/components/prism-json.min.js`);
1213

1314
Prism.languages.python = {
@@ -52,6 +53,18 @@ export function CodeBlock({children, 'data-language': language, filename, codeta
5253
}
5354

5455
const [highlightedCode, setHighlightedCode] = React.useState('');
56+
const [codeWithoutSyntax, setCodeWithoutSyntax] = React.useState('');
57+
var code$Regex = /^(.*?)#\s*\[\!code\s*\$\]\s*(.*)$/;
58+
59+
// children without code$Regex
60+
// iterate over the children and remove the code$Regex
61+
let newChildren = children.split('\n').map((line) => {
62+
let match = line.match(code$Regex);
63+
if (match) {
64+
return match[1].trim()
65+
}
66+
return line
67+
}).join('\n')
5568

5669
React.useEffect(() => {
5770
async function highlight() {
@@ -66,8 +79,8 @@ export function CodeBlock({children, 'data-language': language, filename, codeta
6679

6780
var wrappedLines = lines.map(function(line) {
6881
// Regex to match the marker with flexible whitespace
69-
var regex = /^(.*?)#\s*\[\!code\s*\$\]\s*(.*)$/;
70-
var match = line.match(regex);
82+
83+
var match = line.match(code$Regex);
7184
if (match) {
7285
// If it does, remove the marker and wrap the line with div.line and add the class
7386
// `match[1]` contains the line without the marker
@@ -76,6 +89,7 @@ export function CodeBlock({children, 'data-language': language, filename, codeta
7689
// Otherwise, just wrap the line with div.line
7790
return '<div class="line">' + line + '</div>';
7891
}
92+
7993
}).join('');
8094

8195
// Replace the highlightedCode with the wrapped lines
@@ -121,7 +135,7 @@ export function CodeBlock({children, 'data-language': language, filename, codeta
121135
<div className="rounded-md code reset text-sm" aria-live="polite"
122136
style={{borderRadius: '0.5rem', position: 'relative', marginBottom: marginBottom}}
123137
>
124-
<CopyToClipboardButton className={`absolute ${copyIconColor} border-0 right-3 p-0.5`} textToCopy={children} customStyle={{top: copyButtonTop}}/>
138+
<CopyToClipboardButton className={`absolute ${copyIconColor} border-0 right-3 p-0.5`} textToCopy={newChildren} customStyle={{top: copyButtonTop}}/>
125139
<CustomHeader language={language} filename={filename} codetab={codetab}/>
126140
<pre className='py-4 px-6 overflow-x-scroll'>
127141
<code className={`language-${language}`} dangerouslySetInnerHTML={{ __html: highlightedCode }}>

docs/docs.trychroma.com/pages/about.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ title: "👽 About"
88
We are hiring software engineers and applied research scientists.
99
{% /note %}
1010

11-
[➡️ View open roles on Notion](https://www.notion.so/trychroma/careers-chroma-9d017c3007c7478ebd85bad854101497?pvs=4)
11+
[➡️ View open roles](https://careers.trychroma.com/)
1212

1313
Chroma as a project is coordinated by a small team of full-time employees who work at a company also called Chroma.
1414

15-
We work in the sunny neighborhood of Potrero Hill in San Francisco.
15+
We work in the sunny Mission District in San Francisco.
1616

1717
Chroma is co-founded by [Jeff Huber](https://twitter.com/jeffreyhuber) (left) and [Anton Troynikov](https://twitter.com/atroyn) (right).
1818

docs/docs.trychroma.com/pages/deployment/_sidenav.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const items = [
2424
{ href: '/deployment/migration', children: '✈️ Migration' },
2525
// { href: '/deployment/security', children: 'Security' },
2626
// { href: '/deployment/encryption', children: 'Encryption' },
27-
// { href: '/deployment/auth', children: 'Auth' },
27+
{ href: '/deployment/auth', children: '🔒 Auth' },
2828
// { href: '/deployment/performance', children: 'Performance' },
2929
]
3030
},
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,186 @@
11
---
2-
title: Auth
2+
title: 🔒 Auth
33
---
4+
5+
6+
You can configure Chroma to use authentication when in server/client mode only.
7+
8+
Supported authentication methods:
9+
10+
{% special_table %}
11+
{% /special_table %}
12+
13+
| Authentication Method | Basic Auth (Pre-emptive) | Static API Token |
14+
| --------------------- | ------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
15+
| Description | [RFC 7617](https://www.rfc-editor.org/rfc/rfc7617) Basic Auth with `user:password` base64-encoded `Authorization` header. | Static auth token in `Authorization: Bearer <token>` or in `X-Chroma-Token: <token>` headers. |
16+
| Status | `Alpha` | `Alpha` |
17+
| Server-Side Support |`Alpha` |`Alpha` |
18+
| Client/Python |`Alpha` |`Alpha` |
19+
| Client/JS |`Alpha` |`Alpha` |
20+
21+
### Basic Authentication
22+
23+
#### Server Setup
24+
25+
##### Generate Server-Side Credentials
26+
27+
{% note type="note" title="Security Practices" %}
28+
A good security practice is to store the password securely. In the example below we use [bcrypt](https://en.wikipedia.org/wiki/Bcrypt) (currently the only supported hash in Chroma server side auth) to hash the plaintext password.
29+
{% /note %}
30+
31+
To generate the password hash, run the following command:
32+
33+
```bash
34+
docker run --rm --entrypoint htpasswd httpd:2 -Bbn admin admin > server.htpasswd
35+
```
36+
37+
This creates the bcrypt password hash for the password `admin` and puts it into `server.htpasswd` alongside the user `admin`. It will look like `admin:<password hash>`.
38+
39+
##### Running the Server
40+
41+
Set the following environment variables:
42+
43+
```bash
44+
export CHROMA_SERVER_AUTHN_CREDENTIALS_FILE="server.htpasswd"
45+
export CHROMA_SERVER_AUTHN_PROVIDER="chromadb.auth.basic_authn.BasicAuthenticationServerProvider"
46+
```
47+
48+
And run the server as normal:
49+
50+
```bash
51+
chroma run --path /db_path
52+
```
53+
54+
{% tabs group="code-lang" hideTabs=true %}
55+
{% tab label="Python" %}
56+
57+
#### Client Setup
58+
59+
```python
60+
import chromadb
61+
from chromadb.config import Settings
62+
63+
client = chromadb.HttpClient(
64+
settings=Settings(chroma_client_auth_provider="chromadb.auth.basic_authn.BasicAuthClientProvider",chroma_client_auth_credentials="admin:admin"))
65+
client.heartbeat() # this should work with or without authentication - it is a public endpoint
66+
67+
client.get_version() # this should work with or without authentication - it is a public endpoint
68+
69+
client.list_collections() # this is a protected endpoint and requires authentication
70+
```
71+
72+
{% /tab %}
73+
{% tab label="Javascript" %}
74+
75+
#### Client Setup
76+
77+
```js
78+
import { ChromaClient } from "chromadb";
79+
80+
const client = new ChromaClient({
81+
auth: { provider: "basic", credentials: "admin:admin" },
82+
});
83+
```
84+
85+
86+
{% /tab %}
87+
88+
{% /tabs %}
89+
90+
### Static API Token Authentication
91+
92+
{% note type="note" title="Tokens" %}
93+
Tokens must be alphanumeric ASCII strings. Tokens are case-sensitive.
94+
{% /note %}
95+
96+
#### Server Setup
97+
98+
{% note type="note" title="Security Note" %}
99+
Current implementation of static API token auth supports only ENV based tokens.
100+
{% /note %}
101+
102+
##### Running the Server
103+
104+
Set the following environment variables to use `Authorization: Bearer test-token` to be your authentication header. All environment variables can also be set as [Settings](https://docs.trychroma.com/deployment#step-5-configure-the-chroma-library).
105+
106+
```bash
107+
export CHROMA_SERVER_AUTHN_CREDENTIALS="test-token"
108+
export CHROMA_SERVER_AUTHN_PROVIDER="chromadb.auth.token_authn.TokenAuthenticationServerProvider"
109+
```
110+
111+
To configure multiple tokens and use them for role-based access control (RBAC), use a file like [this](https://github.com/chroma-core/chroma/blob/main/examples/basic_functionality/authz/authz.yaml) and the following configuration settings:
112+
113+
```bash
114+
export CHROMA_SERVER_AUTHN_CREDENTIALS_FILE=<path_to_authz.yaml>
115+
export CHROMA_SERVER_AUTHZ_CONFIG_FILE=<path_to_authz.yaml> # Note: these are the same!
116+
export CHROMA_SERVER_AUTHN_PROVIDER="chromadb.auth.token_authn.TokenAuthenticationServerProvider"
117+
export CHROMA_SERVER_AUTHZ_PROVIDER="chromadb.auth.simple_rbac_authz.SimpleRBACAuthorizationProvider"
118+
```
119+
120+
To use `X-Chroma-Token: test-token` type of authentication header you can set the `CHROMA_AUTH_TOKEN_TRANSPORT_HEADER` environment variable or configuration setting.
121+
122+
```bash
123+
export CHROMA_SERVER_AUTHN_CREDENTIALS="test-token"
124+
export CHROMA_SERVER_AUTHN_PROVIDER="chromadb.auth.token_authn.TokenAuthenticationServerProvider"
125+
export CHROMA_AUTH_TOKEN_TRANSPORT_HEADER="X_CHROMA_TOKEN"
126+
127+
{% tabs group="code-lang" hideTabs=true %}
128+
{% tab label="Python" %}
129+
130+
#### Client Setup
131+
132+
```python
133+
import chromadb
134+
from chromadb.config import Settings
135+
136+
client = chromadb.HttpClient(
137+
settings=Settings(chroma_client_auth_provider="chromadb.auth.token_authn.TokenAuthClientProvider",
138+
chroma_client_auth_credentials="test-token"))
139+
client.heartbeat() # this should work with or without authentication - it is a public endpoint
140+
141+
client.get_version() # this should work with or without authentication - it is a public endpoint
142+
143+
client.list_collections() # this is a protected endpoint and requires authentication
144+
```
145+
146+
{% /tab %}
147+
{% tab label="Javascript" %}
148+
149+
#### Client Setup
150+
151+
Using the default `Authorization: Bearer <token>` header:
152+
153+
```js
154+
import { ChromaClient } from "chromadb";
155+
156+
const client = new ChromaClient({
157+
auth: { provider: "token", credentials: "test-token" },
158+
});
159+
//or explicitly specifying the auth header type
160+
const client = new ChromaClient({
161+
auth: {
162+
provider: "token",
163+
credentials: "test-token",
164+
tokenHeaderType: "AUTHORIZATION",
165+
},
166+
});
167+
```
168+
169+
Using custom Chroma auth token `X-Chroma-Token: <token>` header:
170+
171+
```js
172+
import { ChromaClient } from "chromadb";
173+
174+
const client = new ChromaClient({
175+
auth: {
176+
provider: "token",
177+
credentials: "test-token",
178+
tokenHeaderType: "X_CHROMA_TOKEN",
179+
},
180+
});
181+
```
182+
183+
184+
{% /tab %}
185+
186+
{% /tabs %}

docs/docs.trychroma.com/pages/deployment/aws.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "☁️ Deployment"
2+
title: "☁️ AWS Deployment"
33
---
44

55
{% note type="caution" title="Alpha" %}

docs/docs.trychroma.com/pages/deployment/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ Running a server in production requires a few additional steps to ensure the ser
2929
|--------------|
3030
| [👀 Observability](/deployment/observability) |
3131
| [✈️ Migration](/deployment/migration) |
32+
| [🔒 Auth](/deployment/auth) |
3233
| 🚧 *More Coming Soon* |

0 commit comments

Comments
 (0)