Skip to content

Commit ecd6c42

Browse files
committed
docs: add DataFusion security guidance
1 parent b40d696 commit ecd6c42

3 files changed

Lines changed: 76 additions & 0 deletions

File tree

‎docs/source/index.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ To get started, see
137137
:caption: Library User Guide
138138

139139
library-user-guide/index
140+
library-user-guide/securing-datafusion
140141
library-user-guide/upgrading/index
141142
library-user-guide/extensions
142143
library-user-guide/using-the-sql-api

‎docs/source/library-user-guide/index.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ for details on how to contribute to DataFusion.
2929
If you haven't reviewed the [architecture section in the docs][docs], it's a
3030
useful place to get the lay of the land before starting down a specific path.
3131

32+
For guidance on running DataFusion with SQL from untrusted users, see
33+
[Securing DataFusion](securing-datafusion.md).
34+
3235
DataFusion is designed to be extensible at all points, including
3336

3437
- [x] User Defined Functions (UDFs)
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<!---
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
-->
19+
20+
# Securing DataFusion
21+
22+
DataFusion is an embedded query engine, not an authorization boundary. If an
23+
application accepts SQL from users, the application is responsible for deciding
24+
which data and operations each user may access. The settings below can reduce
25+
what a query can do, but they do not replace application authorization or
26+
operating-system isolation.
27+
28+
## Restrict SQL statements
29+
30+
[`SQLOptions`] allows an application to reject classes of SQL statements when
31+
creating a `DataFrame`. DDL, DML, and other statements are all allowed by
32+
default. Disable the classes that the application does not need and pass the
33+
options to `SessionContext::sql_with_options` for every user-provided query:
34+
35+
```rust
36+
use datafusion::prelude::*;
37+
38+
let options = SQLOptions::new()
39+
.with_allow_ddl(false)
40+
.with_allow_dml(false)
41+
.with_allow_statements(false);
42+
43+
let dataframe = ctx.sql_with_options(sql, options).await?;
44+
```
45+
46+
These checks reject statement types such as `CREATE TABLE`, `INSERT`, and
47+
`SET`; they do not decide which tables or rows a user is authorized to read.
48+
Expose only the appropriate catalogs and tables to each user, and enforce
49+
application-specific access rules separately.
50+
51+
## Limit file access
52+
53+
[`SessionContext::enable_url_table()`] is an opt-in feature that lets SQL query
54+
local files by path. Leave it disabled when users should only query tables
55+
registered by the application. If it is needed, run DataFusion with filesystem
56+
permissions limited to the files the application intends to expose.
57+
58+
## Set query memory limits
59+
60+
The `datafusion.runtime.memory_limit` setting defaults to `NULL` (no configured
61+
query memory limit). Set an appropriate limit for the workload using the
62+
[runtime configuration settings](../user-guide/configs.md#runtime-configuration-settings).
63+
This limits memory used by DataFusion's query execution memory pool; use
64+
process- or container-level resource limits as well when a hard bound on total
65+
application memory is required.
66+
67+
Also review the capabilities of custom table providers, functions, and other
68+
extensions registered by the application: they determine which external data
69+
and operations queries can reach.
70+
71+
[sqloptions]: https://docs.rs/datafusion/latest/datafusion/execution/context/struct.SQLOptions.html
72+
[sessioncontext::enable_url_table()]: https://docs.rs/datafusion/latest/datafusion/execution/context/struct.SessionContext.html#method.enable_url_table

0 commit comments

Comments
 (0)