Skip to content

Commit d3e6ece

Browse files
authored
docs: Data access policies + LDAP integration (#9161)
* Rebase changes * LDAP * .
1 parent 4c8de88 commit d3e6ece

27 files changed

+1297
-327
lines changed

docs/pages/guides/recipes/multitenancy/custom-data-model-per-tenant.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ module.exports = {
6767

6868
## Data modeling
6969

70-
### Customizing publicity
70+
### Customizing member-level access
7171

72-
The simplest way to customize the data models is by changing the [publicity][ref-publicity]
73-
of data model entities. It works great for use cases when tenants share parts of
72+
The simplest way to customize the data models is by changing the [member-level access][ref-mls]
73+
to data model entities. It works great for use cases when tenants share parts of
7474
their data models.
7575

7676
By setting the `public` parameter of [cubes][ref-cubes-public], [views][ref-views-public],
@@ -168,7 +168,7 @@ cube(`cube_x`, {
168168

169169
</CodeTabs>
170170

171-
For your convenience, [Playground][ref-playground] ignores publicity configration
171+
For your convenience, [Playground][ref-playground] ignores member-level access configration
172172
and marks data model entities that are not accessible for querying through
173173
[APIs][ref-apis] with the lock icon.
174174

@@ -182,8 +182,8 @@ And here's the *perspective* of `Bob`:
182182

183183
### Customizing other parameters
184184

185-
Similarly to [customizing publicity](#customizing-publicity), you can set other
186-
parameters of data model entities for each tenant individually:
185+
Similarly to [customizing member-level access](#customizing-member-level-access),
186+
you can set other parameters of data model entities for each tenant individually:
187187

188188
- By setting `sql` or [`sql_table` parameters][ref-cube-sql-table] of cubes, you
189189
can ensure that each tenant accesses data from its own tables or database schemas.
@@ -364,7 +364,7 @@ code that fetches data model files for each tenant.
364364
[ref-scheduled-refresh-contexts]: /reference/configuration/config#scheduled_refresh_contexts
365365
[ref-context-to-app-id]: /reference/configuration/config#context_to_app_id
366366
[ref-config-files]: /product/configuration#cubepy-and-cubejs-files
367-
[ref-publicity]: /product/data-modeling/concepts/publicity
367+
[ref-mls]: /product/auth/member-level-security
368368
[ref-cubes-public]: /reference/data-model/cube#public
369369
[ref-views-public]: /reference/data-model/view#public
370370
[ref-measures-public]: /reference/data-model/measures#public

docs/pages/guides/style-guide.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,14 @@ cube_project
7070
- `description`
7171
- `public`
7272
- `refresh_key`
73+
- `meta`
7374
- `pre_aggregations`
7475
- `joins`
7576
- `dimensions`
7677
- `hierarchies`
7778
- `segments`
7879
- `measures`
80+
- `access_policy`
7981

8082
### Dimensions & measures
8183

@@ -141,6 +143,7 @@ cubes:
141143
- `public`
142144
- `cubes`
143145
- `folders`
146+
- `access_policy`
144147

145148
### Example view
146149

docs/pages/product/_meta.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = {
44
"configuration": "Configuration",
55
"data-modeling": "Data modeling",
66
"caching": "Caching",
7-
"auth": "Authentication & authorization",
7+
"auth": "Access control",
88
"apis-integrations": "APIs & integrations",
99
"workspace": "Workspace",
1010
"deployment": "Deployment",

docs/pages/product/apis-integrations.mdx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ for an unofficial, community-maintained [client library for Python](https://gith
4848

4949
</ReferenceBox>
5050

51-
### Support for data modeling
51+
### Data modeling
5252

5353
Support for data modeling features differ across APIs, integrations, and [visualization
5454
tools][ref-viz-tools]. Some of the features with partial support are listed below:
@@ -58,6 +58,17 @@ tools][ref-viz-tools]. Some of the features with partial support are listed belo
5858
| [Hierarchies][ref-hierarchies] |[Tableau][ref-tableau] via [Semantic Layer Sync][ref-sls]<br/>✅ Cube Cloud for Excel<br/>✅ [Cube Cloud for Sheets][ref-cube-cloud-for-sheets] | ❌ All other tools |
5959
| [Folders][ref-folders] |[Tableau][ref-tableau] via [Semantic Layer Sync][ref-sls]<br/>✅ Cube Cloud for Excel<br/>✅ [Cube Cloud for Sheets][ref-cube-cloud-for-sheets] | ❌ All other tools |
6060

61+
### Authentication methods
62+
63+
Support for authentication methods differ across APIs, integrations, and [visualization
64+
tools][ref-viz-tools]:
65+
66+
| Method | Supported in |
67+
| --- | --- |
68+
| [User name and password][ref-auth-user-pass] |[SQL API][ref-sql-api] and [Semantic Layer Sync][ref-sls]<br/>✅ [MDX API][ref-mdx-api] |
69+
| [Identity provider][ref-auth-idp] | ✅ Cube Cloud for Excel<br/>✅ [Cube Cloud for Sheets][ref-cube-cloud-for-sheets] |
70+
| [Access token][ref-auth-tokens] |[REST API][ref-rest-api]<br/>✅ [GraphQL API][ref-graphql-api]<br/>✅ [AI API][ref-ai-api] |
71+
6172
## Management APIs
6273

6374
In case you'd like Cube to work with data orchestration tools and let them push
@@ -83,4 +94,7 @@ API][ref-orchestration-api].
8394
[ref-viz-tools]: /product/configuration/visualization-tools
8495
[ref-hierarchies]: /reference/data-model/hierarchies
8596
[ref-folders]: /reference/data-model/view#folders
86-
[ref-tableau]: /product/configuration/visualization-tools/tableau
97+
[ref-tableau]: /product/configuration/visualization-tools/tableau
98+
[ref-auth-user-pass]: /product/auth#user-name-and-password
99+
[ref-auth-idp]: /product/auth#identity-provider
100+
[ref-auth-tokens]: /product/auth#access-token

docs/pages/product/auth.mdx

Lines changed: 115 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,55 @@
1-
---
2-
redirect_from:
3-
- /security
4-
---
1+
# Access control
52

6-
# Overview
3+
Cube supports a few methods to authenticates requests to [APIs & integrations][ref-apis].
4+
Usually, an API supports authentication via [one of these methods][ref-apis-methods]:
5+
6+
* [User name and password](#user-name-and-password) (e.g., used by the [SQL API][ref-sql-api]).
7+
* [Identity provider](#identity-provider) (e.g., used by the [Cube Cloud for Sheets][ref-cube-cloud-sheets]).
8+
* [Access token](#access-token) (e.g., used by the [REST API][ref-rest-api]).
9+
10+
Regardless of the method, the authentication flow includes the following steps:
11+
12+
* User identity information (e.g., password or access token) is passed to Cube.
13+
* Cube validates the identity information or trusts the identity provider.
14+
* User identity information is optionally enriched with additional attributes,
15+
such the user's role, via [authentication integration](#authentication-integration).
16+
* Finally, the API request is associated with a [security context][ref-sec-ctx].
17+
It is then used to configure [member-level security][ref-mls]
18+
and [row-level security][ref-rls] as well as set [data access policies][ref-dap].
19+
20+
## User name and password
21+
22+
Some visualization tools (e.g., BI tools) can pass user name and, sometimes, password to Cube.
23+
24+
### Configuration
25+
26+
Relevant configuration options: [`check_sql_auth`][ref-config-check-sql-auth] and [`can_switch_sql_user`][ref-config-can-switch-sql-user].
27+
28+
Relevant environment variables: `CUBEJS_SQL_USER`, `CUBEJS_SQL_PASSWORD`, `CUBEJS_SQL_SUPER_USER`.
29+
30+
## Identity provider
31+
32+
Some visualization tools (e.g., [Cube Cloud for Sheets][ref-cube-cloud-sheets]) implement
33+
an OAuth 2.0 flow to authenticate users.
34+
35+
<SuccessBox>
36+
37+
OAuth 2.0 flow is available in Cube Cloud on [Premium and above](https://cube.dev/pricing) product tiers.
38+
39+
</SuccessBox>
40+
41+
During this flow, users are redirected to a login page of an identity provider (e.g., Google)
42+
where they enter their credentials. Then, the identity provider passes the user identity
43+
information to Cube Cloud.
44+
45+
This method does not require any configuration.
46+
47+
## Access token
48+
49+
Some visualization tools (e.g., custom front-end applications) can pass access tokens based
50+
on the [JSON Web Token][wiki-jwt] (JWT) standard to Cube. These tokens can be either generated
51+
by these applications or obtained from an identity provider. Cube then validates these tokens.
752

8-
In Cube, authorization (or access control) is based on the **security context**.
953
The diagram below shows how it works during the request processing in Cube:
1054

1155
<div style={{ textAlign: "center" }}>
@@ -16,18 +60,44 @@ The diagram below shows how it works during the request processing in Cube:
1660
/>
1761
</div>
1862

19-
Authentication is handled outside of Cube. A typical use case would be:
63+
### Configuration
64+
65+
Relevant configuration options: [`check_auth`][ref-config-check-auth] and [`jwt`][ref-config-jwt].
66+
67+
Relevant environment variables: `CUBEJS_API_SECRET`, `CUBEJS_JWT_KEY`, `CUBEJS_JWK_URL`,
68+
`CUBEJS_JWT_AUDIENCE`, `CUBEJS_JWT_ISSUER`, `CUBEJS_JWT_SUBJECT`, `CUBEJS_JWT_CLAIMS_NAMESPACE`.
69+
70+
### Custom authentication
71+
72+
Cube allows you to provide your own JWT verification logic. You can use the
73+
[`check_auth`][ref-config-check-auth] configuration option to verify a JWT and set the security context.
2074

21-
1. A web server serves an HTML page containing the Cube client, which needs to
22-
communicate securely with the Cube API.
23-
2. The web server should generate a JWT with an expiry to achieve this. The
24-
server could include the token in the HTML it serves or provide the token to
25-
the frontend via an XHR request, which is then stored it in local storage or
75+
For example, if you needed to retrieve user information from an LDAP server,
76+
you might do the following:
77+
78+
```javascript
79+
module.exports = {
80+
checkAuth: async (req, auth) => {
81+
try {
82+
const userInfo = await getUserFromLDAP(req.get("X-LDAP-User-ID"))
83+
return { security_context: userInfo }
84+
}
85+
catch {
86+
throw new Error("Could not authenticate user from LDAP")
87+
}
88+
}
89+
}
90+
```
91+
92+
A typical use case would be:
93+
94+
1. A web server serves a page which needs to communicate with the Cube API.
95+
2. The web server generates a JWT. The
96+
server includes the token in the page or provides the token to
97+
the frontend via an XHR request. The token is then stored in the local storage or
2698
a cookie.
27-
3. The JavaScript client is initialized using this token, and includes it in
28-
calls to the Cube API.
29-
4. The token is received by Cube, and verified using any available JWKS (if
30-
configured)
99+
3. The token is used for calls to the Cube API.
100+
4. The token is received by Cube, and verified using any available JWKS (if configured)
31101
5. Once decoded, the token claims are injected into the [security
32102
context][ref-sec-ctx].
33103

@@ -38,7 +108,7 @@ can still use it to [pass a security context][ref-sec-ctx].
38108

39109
</InfoBox>
40110

41-
## Generating JSON Web Tokens (JWT)
111+
### Generating JSON Web Tokens
42112

43113
Authentication tokens are generated based on your API secret. Cube CLI generates
44114
an API Secret when a project is scaffolded and saves this value in the `.env`
@@ -118,7 +188,7 @@ const cubeApi = cube(
118188
You can optionally store this token in local storage or in a cookie, so that you
119189
can then use it to query the Cube API.
120190

121-
## Using JSON Web Key Sets (JWKS)
191+
### Using JSON Web Key Sets
122192

123193
<InfoBox>
124194

@@ -128,8 +198,6 @@ Cognito][ref-recipe-cognito] with Cube.
128198

129199
</InfoBox>
130200

131-
### Configuration
132-
133201
As mentioned previously, Cube supports verifying JWTs using industry-standard
134202
JWKS. The JWKS can be provided either from a URL, or as a JSON object conforming
135203
to [JWK specification RFC 7517 Section 4][link-jwk-ref], encoded as a string.
@@ -177,7 +245,7 @@ Or configure the same using environment variables:
177245
CUBEJS_JWK_URL='<URL_TO_JWKS_JSON>'
178246
```
179247

180-
### Verifying claims
248+
#### Verifying claims
181249

182250
Cube can also verify the audience, subject and issuer claims in JWTs. Similarly
183251
to JWK configuration, these can also be configured in the `cube.js`
@@ -201,7 +269,7 @@ CUBEJS_JWT_ISSUER='<ISSUER_FROM_IDENTITY_PROVIDER>'
201269
CUBEJS_JWT_SUBJECT='<SUBJECT_FROM_IDENTITY_PROVIDER>'
202270
```
203271

204-
### Custom claims namespace
272+
#### Custom claims namespace
205273

206274
Cube can also extract claims defined in custom namespaces. Simply specify the
207275
namespace in your `cube.js` configuration file:
@@ -214,49 +282,42 @@ module.exports = {
214282
};
215283
```
216284

217-
### Caching
285+
## Authentication integration
218286

219-
Cube caches JWKS by default when
220-
[`CUBEJS_JWK_URL` or `jwt.jwkUrl` is specified](#configuration).
287+
When using Cube Cloud, you can enrich the security context with information about
288+
an authenticated user, obtained during their authentication or loaded via an
289+
[LDAP integration][ref-ldap-integration].
221290

222-
- If the response contains a `Cache-Control` header, then Cube uses it to
223-
determine cache expiry.
224-
- The keys inside the JWKS are checked for expiry values and used for cache
225-
expiry.
226-
- If an inbound request supplies a JWT referencing a key not found in the cache,
227-
the cache is refreshed.
291+
<SuccessBox>
228292

229-
## Custom authentication
293+
Authentication integration is available in Cube Cloud on [all product tiers](https://cube.dev/pricing).
230294

231-
Cube also allows you to provide your own JWT verification logic by setting a
232-
[`checkAuth()`][ref-config-check-auth] function in the `cube.js` configuration
233-
file. This function is expected to verify a JWT and return its claims as the
234-
security context.
295+
</SuccessBox>
235296

236-
As an example, if you needed to retrieve user information from an LDAP server,
237-
you might do the following:
297+
You can enable the authentication integration by navigating to the <Btn>Settings → Configuration</Btn>
298+
of your Cube Cloud deployment and using the <Btn>Enable Cloud Auth Integration</Btn> toggle.
238299

239-
```javascript
240-
module.exports = {
241-
checkAuth: async (req, auth) => {
242-
try {
243-
const userInfo = await getUserFromLDAP(req.get("X-LDAP-User-ID"));
244-
return { security_context: userInfo };
245-
} catch {
246-
throw new Error("Could not authenticate user from LDAP");
247-
}
248-
},
249-
};
250-
```
251300

252-
[link-jwt-docs]:
253-
https://github.com/auth0/node-jsonwebtoken#token-expiration-exp-claim
301+
[wiki-jwt]: https://en.wikipedia.org/wiki/JSON_Web_Token
302+
[link-jwt-docs]: https://github.com/auth0/node-jsonwebtoken#token-expiration-exp-claim
254303
[link-jwt-libs]: https://jwt.io/#libraries-io
255304
[link-jwk-ref]: https://tools.ietf.org/html/rfc7517#section-4
256-
[ref-config-check-auth]: /reference/configuration/config#checkauth
305+
[ref-config-check-auth]: /reference/configuration/config#check_auth
306+
[ref-config-jwt]: /reference/configuration/config#jwt
307+
[ref-config-check-sql-auth]: /reference/configuration/config#check_sql_auth
308+
[ref-config-can-switch-sql-user]: /reference/configuration/config#can_switch_sql_user
257309
[ref-config-migrate-cube]:
258310
/product/configuration#migration-from-express-to-docker-template
259311
[ref-recipe-auth0]: /guides/recipes/auth/auth0-guide
260312
[ref-recipe-cognito]: /guides/recipes/auth/aws-cognito
261313
[ref-sec-ctx]: /product/auth/context
262-
[link-slack]: https://slack.cube.dev/
314+
[ref-apis]: /product/apis-integrations
315+
[ref-apis-methods]: /product/apis-integrations#authentication-methods
316+
[ref-rest-api]: /product/apis-integrations/rest-api
317+
[ref-sql-api]: /product/apis-integrations/sql-api
318+
[ref-dap]: /product/auth/data-access-policies
319+
[ref-mls]: /product/auth/member-level-security
320+
[ref-rls]: /product/auth/row-level-security
321+
[ref-auth-sso]: /product/workspace/sso
322+
[ref-ldap-integration]: /product/workspace/sso#ldap-integration
323+
[ref-cube-cloud-sheets]: /product/apis-integrations/google-sheets

docs/pages/product/auth/_meta.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
module.exports = {
2-
"context": "Security context"
2+
"context": "Security context",
3+
"member-level-security": "Member-level security",
4+
"row-level-security": "Row-level security",
5+
"data-access-policies": "Data access policies"
36
}

0 commit comments

Comments
 (0)