Skip to content

Commit 968c664

Browse files
committed
license and readme
1 parent 24fc348 commit 968c664

File tree

10 files changed

+239
-1
lines changed

10 files changed

+239
-1
lines changed

src/binaries/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ Contains all databend binaries:
66
- [`metabench`](./metabench/) -> `databend-metabench`, run meta benchmark.
77
- [`metactl`](./metactl/) -> `databend-metactl`, dump data in json from a sled db.
88
- [`query`](./query/) -> `databend-query`, the query service binary of Databend.
9+
- [`opensharing`](./opensharing/) -> `open-sharing`, tenant level sharing endpoint used in stateful test

src/query/sharing-endpoint/README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Open Sharing
2+
Open Sharing is a cheap and secure data sharing protocol for databend query on multi-cloud environments.
3+
4+
## Features
5+
* **Cheap**: Open Sharing allow data sharing via simple RESTful API sharing protocol, which is cheap and easy to understand.
6+
* **Secure**: Open Sharing protocol would verify allow incoming requesters identity and access permission and provide audit log.
7+
* **Multi-cloud**: Open Sharing is designed to work with different cloud platforms, including AWS, Azure, GCP, etc.
8+
* **Open source**: Open Sharing is an open source project
9+
10+
## Protocol
11+
Databend Sharing protocol is a RESTful protocol, which would understand database and table semantics for data sharing.
12+
and provide short lived presigned url for data under the table.
13+
14+
For detailed descriptions, please take a look at
15+
- [`protocol`](./protocol.md) -> provides detailed dscriptions on sharing protocol api
16+
17+
## How to build?
18+
19+
To build open-sharing for stateful tests, run the following command
20+
```bash
21+
cargo build --bin open-sharing
22+
```
23+
24+
## How to use it?
25+
26+
### Setup the sharing endpoint
27+
28+
Please ensure that the sharing endpoint has read and list access for the bucket being shared.
29+
30+
configure the sharing endpoint
31+
```bash
32+
export STORAGE_TYPE=s3
33+
export STORAGE_S3_REGION=<the shared bucket region>
34+
export STORAGE_S3_BUCKET=<the shared bucket name>
35+
export STORAGE_S3_ACCESS_KEY_ID=<the shared bucket access key id>
36+
export STORAGE_S3_SECRET_ACCESS_KEY=<the shared bucket secret access key>
37+
export STORAGE_S3_ROOT=<the shared bucket root path>
38+
export TENANT_ID=<the tenant id which shares the table>
39+
./open-sharing
40+
```
41+
42+
### Setup the sharing endpoint address for databend query
43+
44+
add `share_endpoint_address` field on your databend query config file
45+
46+
```toml
47+
# Usage:
48+
# databend-query -c databend_query_config_spec.toml
49+
[query]
50+
...
51+
share_endpoint_address = "127.0.0.1:33003" # receive shared information from open sharing
52+
...
53+
```
54+
55+
### How to share a table?
56+
57+
For the tenant who wants to share the table `tabl1` from database `db1` to tenant `vendor`
58+
59+
```sql
60+
CREATE SHARE myshare;
61+
GRANT USAGE ON DATABASE db1 TO SHARE myshare;
62+
GRANT SELECT ON TABLE db1.table1 TO SHARE myshare;
63+
ALTER SHARE myshare ADD TENANTS = vendor;
64+
```
65+
66+
From tenant `vendor` side, the table `db1.table1` would be visible and can be queried.
67+
68+
```sql
69+
CREATE DATABASE db2 FROM SHARE myshare;
70+
SELECT * FROM db2.table1;
71+
```
72+
73+
## How to contribute?
74+
75+
For code changes feel free to open a PR and add necessary unit tests and integration tests.
76+
77+
For **API** changes, please follow the following steps:
78+
1. provide a RFC to explain the reason why we need the additional api or why we need to change the existing api.
79+
2. update the protocol.md to reflect the changes.
80+
3. update the implementation to reflect the changes.
81+
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Databend Sharing protocol
2+
3+
The Databend Sharing Protocol is a protocol that allows tenants in a multi-tenant database system
4+
to securely share files with each other.
5+
6+
The protocol defines a set of API endpoints that can be used to manage file sharing and access control.
7+
8+
## Get Presigned File
9+
### POST /tenant/{tenant_id}/{share_name}/table/{table_name}/presign
10+
This endpoint allows a tenant to create a presigned URL for data files in a specified table.
11+
12+
#### Request
13+
14+
```bash
15+
POST /tenant/{tenant_id}/{share_name}/table/{table_name}/presign
16+
```
17+
18+
**tenant_id** : the tenant id who shares the table
19+
**share_name** : the share name
20+
**table_name** : the shared table name
21+
22+
#### Headers
23+
24+
| Name | Value | Description | Required |
25+
| ---- | ----- | ----------- |----------|
26+
| Authorization | Bearer {token} | The token used to authenticate the request. | Yes |
27+
| Content-Type | application/json | The content type of the request. | No |
28+
29+
#### Body
30+
31+
```json
32+
[
33+
{
34+
"file_name": "file1.txt",
35+
"method": "GET"
36+
},
37+
{
38+
"file_name": "file2.txt",
39+
"method": "HEAD"
40+
}
41+
]
42+
```
43+
44+
An array of objects representing the files for which presigned URLs should be created.
45+
46+
Each object should contain the following properties:
47+
* **file_name**: The name of the file.
48+
* **method**: The HTTP method that should be used for the presigned URL. method should be either **GET** or **HEAD**.
49+
50+
#### Response
51+
```json
52+
[
53+
{
54+
"presigned_url": "https://s3.example.com/table1/file1.txt?AWSAccessKeyId=ABC123&Expires=1560993041&Signature=def456",
55+
"headers": {},
56+
"method": "GET",
57+
"path": "/table1/file1.txt"
58+
},
59+
{
60+
"presigned_url": "https://s3.example.com/table1/file2.txt?AWSAccessKeyId=ABC123&Expires=1560993041&Signature=ghi789",
61+
"headers": {},
62+
"method": "HEAD",
63+
"path": "/table1/file2.txt"
64+
}
65+
]
66+
67+
```
68+
69+
* **presigned_url**: The presigned URL that can be used to access the file.
70+
* **headers**: An object containing any additional headers that should be included in the request to the presigned URL.
71+
* **method**: The HTTP method that is allowed for the presigned URL.
72+
* **path**: The path of the file relative to the table.

src/query/sharing-endpoint/src/accessor.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2022 Datafuse Labs.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
use std::sync::Arc;
216

317
use common_base::base::Singleton;

src/query/sharing-endpoint/src/handlers.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2022 Datafuse Labs.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
use models::Credentials;
216
use models::RequestFile;
317
use poem::error::BadRequest;

src/query/sharing-endpoint/src/middlewares.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2022 Datafuse Labs.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
use poem::async_trait;
216
use poem::Endpoint;
317
use poem::IntoResponse;

src/query/sharing-endpoint/src/models.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2021 Datafuse Labs.
1+
// Copyright 2022 Datafuse Labs.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

src/query/sharing-endpoint/src/services.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2022 Datafuse Labs.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
use std::cell::UnsafeCell;
216
use std::sync::Arc;
317

src/query/sharing-endpoint/tests/it/accessor.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2022 Datafuse Labs.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
use common_base::base::tokio;
216
use common_exception::Result;
317
use sharing_endpoint::accessor::truncate_root;

src/query/sharing-endpoint/tests/it/models.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2022 Datafuse Labs.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
use std::collections::HashMap;
216

317
use common_base::base::tokio;

0 commit comments

Comments
 (0)