github.com/dgraph-io/dgraph@v1.2.8/wiki/content/enterprise-features/index.md (about) 1 +++ 2 date = "2017-03-20T19:35:35+11:00" 3 title = "Enterprise Features" 4 +++ 5 6 Dgraph enterprise features are proprietary licensed under the [Dgraph Community 7 License][dcl]. All Dgraph releases contain proprietary code for enterprise features. 8 Enabling these features requires an enterprise contract from 9 [contact@dgraph.io](mailto:contact@dgraph.io) or the [discuss 10 forum](https://discuss.dgraph.io). 11 12 **Dgraph enterprise features are enabled by default for 30 days in a new cluster**. 13 After the trial period of thirty (30) days, the cluster must obtain a license from Dgraph to 14 continue enjoying the enterprise features released in the proprietary code. The license can 15 be applied to the cluster by including it as the body of a POST request and calling 16 `/enterpriseLicense` HTTP endpoint on any Zero server. 17 18 19 {{% notice "note" %}} 20 At the conclusion of your 30-day trial period if a license has not been applied to the cluster, 21 access to the enterprise features will be suspended. The cluster will continue to operate without 22 enterprise features. 23 {{% /notice %}} 24 25 26 [dcl]: https://github.com/dgraph-io/dgraph/blob/master/licenses/DCL.txt 27 28 ## Binary Backups 29 30 {{% notice "note" %}} 31 This feature was introduced in [v1.1.0](https://github.com/dgraph-io/dgraph/releases/tag/v1.1.0). 32 {{% /notice %}} 33 34 Binary backups are full backups of Dgraph that are backed up directly to cloud 35 storage such as Amazon S3 or any Minio storage backend. Backups can also be 36 saved to an on-premise network file system shared by all alpha instances. These 37 backups can be used to restore a new Dgraph cluster to the previous state from 38 the backup. Unlike [exports]({{< relref "deploy/index.md#export-database" >}}), 39 binary backups are Dgraph-specific and can be used to restore a cluster quickly. 40 41 ### Configure Backup 42 43 Backup is only enabled when a valid license file is supplied to a Zero server OR within the thirty 44 (30) day trial period, no exceptions. 45 46 #### Configure Amazon S3 Credentials 47 48 To backup to Amazon S3, the Alpha must have the following AWS credentials set 49 via environment variables: 50 51 Environment Variable | Description 52 -------------------- | ----------- 53 `AWS_ACCESS_KEY_ID` or `AWS_ACCESS_KEY` | AWS access key with permissions to write to the destination bucket. 54 `AWS_SECRET_ACCESS_KEY` or `AWS_SECRET_KEY` | AWS access key with permissions to write to the destination bucket. 55 `AWS_SESSION_TOKEN` | AWS session token (if required). 56 57 #### Configure Minio Credentials 58 59 To backup to Minio, the Alpha must have the following Minio credentials set via 60 environment variables: 61 62 Environment Variable | Description 63 -------------------- | ----------- 64 `MINIO_ACCESS_KEY` | Minio access key with permissions to write to the destination bucket. 65 `MINIO_SECRET_KEY` | Minio secret key with permissions to write to the destination bucket. 66 67 ### Create a Backup 68 69 To create a backup, make an HTTP POST request to `/admin/backup` to a Dgraph 70 Alpha HTTP address and port (default, "localhost:8080"). Like with all `/admin` 71 endpoints, this is only accessible on the same machine as the Alpha unless 72 [whitelisted for admin operations]({{< relref "deploy/index.md#whitelist-admin-operations" >}}). 73 74 #### Backup to Amazon S3 75 76 ```sh 77 $ curl -XPOST localhost:8080/admin/backup -d "destination=s3://s3.us-west-2.amazonaws.com/<bucketname>" 78 ``` 79 80 #### Backup to Minio 81 82 ```sh 83 $ curl -XPOST localhost:8080/admin/backup -d "destination=minio://127.0.0.1:9000/<bucketname>" 84 ``` 85 86 #### Disabling HTTPS for S3 and Minio backups 87 88 By default, Dgraph assumes the destination bucket is using HTTPS. If that is not 89 the case, the backup will fail. To send a backup to a bucket using HTTP 90 (insecure), set the query parameter `secure=false` with the destination 91 endpoint: 92 93 ```sh 94 $ curl -XPOST localhost:8080/admin/backup -d "destination=minio://127.0.0.1:9000/<bucketname>?secure=false" 95 ``` 96 97 #### Overriding Credentials 98 99 The `access_key`, `secret_key`, and `session_token` parameters can be used to 100 override the default credentials. Please note that unless HTTPS is used, the 101 credentials will be transmitted in plain text so use these parameters with 102 discretion. The environment variables should be used by default but these 103 options are there to allow for greater flexibility. 104 105 The `anonymous` parameter can be set to "true" to a allow backing up to S3 or 106 Minio bucket that requires no credentials (i.e a public bucket). 107 108 #### Backup to NFS 109 110 ``` 111 # localhost:8080 is the default Alpha HTTP port 112 $ curl -XPOST localhost:8080/admin/backup -d "destination=/path/to/local/directory" 113 ``` 114 115 A local filesystem will work only if all the Alphas have access to it (e.g all 116 the Alphas are running on the same filesystems as a normal process, not a Docker 117 container). However, a NFS is recommended so that backups work seamlessly across 118 multiple machines and/or containers. 119 120 #### Forcing a Full Backup 121 122 By default, an incremental backup will be created if there's another full backup 123 in the specified location. To create a full backup, set the `force_full` parameter 124 to `true`. Each series of backups can be 125 identified by a unique ID and each backup in the series is assigned a 126 monotonically increasing number. The following section contains more details on 127 how to restore a backup series. 128 129 ### Encrypted Backups 130 131 Encrypted backups are a Enterprise feature that are available from v20.03.1 and v1.2.3 and allow you to encrypt your backups and restore them. This documentation describes how to implement encryption into your binary backups 132 133 ### New flag “Encrypted” in manifest.json 134 135 A new flag “Encrypted” is added to the `manifest.json`. This flag indicates if the corresponding binary backup is encrypted or not. To be backward compatible, if this flag is absent, it is presumed that the corresponding backup is not encrypted. 136 137 For a series of full and incremental backups, per the current design, we don't allow mixing of encrypted and unencrypted backups. As a result, all full and incremental backups in a series must either be encrypted fully or not at all. This flag helps with checking this restriction. 138 139 ### AES And Chaining with Gzip 140 141 If encryption is turned on an alpha, then we use the configured encryption key. The key size (16, 24, 32 bytes) determines AES-128/192/256 cipher chosen. We use the AES CTR mode. Currently, the binary backup is already gzipped. With encryption, we will encrypt the gzipped data. 142 143 During **backup**: the 16 bytes IV is prepended to the Cipher-text data after encryption. 144 145 ### Backup 146 147 Backup is an online tool, meaning it is available when alpha is running. For encrypted backups, the alpha must be configured with the “encryption_key_file”. 148 149 {{% notice "note" %}} 150 encryption_key_file was used for encryption-at-rest and will now also be used for encrypted backups. 151 {{% /notice %}} 152 153 The restore utility is a standalone tool today. Hence, a new flag “keyfile” is added to the restore utility so it can decrypt the backup. This keyfile must be the same key that was used for encryption during backup. 154 155 ### Restore from Backup 156 157 The `dgraph restore` command restores the postings directory from a previously 158 created backup to a directory in the local filesystem. Restore is intended to 159 restore a backup to a new Dgraph cluster not a currently live one. During a 160 restore, a new Dgraph Zero may be running to fully restore the backup state. 161 162 The `--location` (`-l`) flag specifies a source URI with Dgraph backup objects. 163 This URI supports all the schemes used for backup. 164 165 The `--postings` (`-p`) flag sets the directory to which the restored posting 166 directories will be saved. This directory will contain a posting directory for 167 each group in the restored backup. 168 169 The `--zero` (`-z`) flag specifies a Dgraph Zero address to update the start 170 timestamp and UID lease using the restored version. If no zero address is 171 passed, the command will complain unless you set the value of the 172 `--force_zero` flag to false. If do not pass a zero value to this command, 173 the timestamp and UID lease must be manually updated through Zero's HTTP 174 'assign' endpoint using the values printed near the end of the command's output. 175 176 The `--backup_id` optional flag specifies the ID of the backup series to 177 restore. A backup series consists of a full backup and all the incremental 178 backups built on top of it. Each time a new full backup is created, a new backup 179 series with a different ID is started. The backup series ID is stored in each 180 `manifest.json` file stored in every backup folder. 181 182 The `--encryption_key_file` flag is required if you took the backup in an 183 encrypted cluster and should point to the location of the same key used to 184 run the cluster. 185 186 The restore feature will create a cluster with as many groups as the original 187 cluster had at the time of the last backup. For each group, `dgraph restore` 188 creates a posting directory `p<N>` corresponding to the backup group ID. For 189 example, a backup for Alpha group 2 would have the name `.../r32-g2.backup` 190 and would be loaded to posting directory `p2`. 191 192 After running the restore command, the directories inside the `postings` 193 directory need to be manually copied over to the machines/containers running the 194 alphas before running the `dgraph alpha` command. For example, in a database 195 cluster with two Alpha groups and one replica each, `p1` needs to be moved to 196 the location of the first Alpha and `p2` needs to be moved to the location of 197 the second Alpha. 198 199 By default, Dgraph will look for a posting directory with the name `p`, so make 200 sure to rename the directories after moving them. You can also use the `-p` 201 option of the `dgraph alpha` command to specify a different path from the default. 202 203 #### Restore from Amazon S3 204 ```sh 205 $ dgraph restore -p /var/db/dgraph -l s3://s3.us-west-2.amazonaws.com/<bucketname> 206 ``` 207 208 #### Restore from Minio 209 ```sh 210 $ dgraph restore -p /var/db/dgraph -l minio://127.0.0.1:9000/<bucketname> 211 ``` 212 213 #### Restore from Local Directory or NFS 214 ```sh 215 $ dgraph restore -p /var/db/dgraph -l /var/backups/dgraph 216 ``` 217 218 #### Restore and Update Timestamp 219 220 Specify the Zero address and port for the new cluster with `--zero`/`-z` to update the timestamp. 221 ```sh 222 $ dgraph restore -p /var/db/dgraph -l /var/backups/dgraph -z localhost:5080 223 ``` 224 ## Access Control Lists 225 226 {{% notice "note" %}} 227 This feature was introduced in [v1.1.0](https://github.com/dgraph-io/dgraph/releases/tag/v1.1.0). 228 {{% /notice %}} 229 230 Access Control List (ACL) provides access protection to your data stored in 231 Dgraph. When the ACL feature is turned on, a client, e.g. dgo or dgraph4j, must 232 authenticate with a username and password before executing any transactions, and 233 is only allowed to access the data permitted by the ACL rules. 234 235 This document has two parts: first we will talk about the admin operations 236 needed for setting up ACL; then we will explain how to use a client to access 237 the data protected by ACL rules. 238 239 ### Turn on ACLs 240 241 The ACL Feature can be turned on by following these steps 242 243 1. Since ACL is an enterprise feature, make sure your use case is covered under 244 a contract with Dgraph Labs Inc. You can contact us by sending an email to 245 [contact@dgraph.io](mailto:contact@dgraph.io) or post your request at [our discuss 246 forum](https://discuss.dgraph.io) to get an enterprise license. 247 248 2. Create a plain text file, and store a randomly generated secret key in it. The secret 249 key is used by Alpha servers to sign JSON Web Tokens (JWT). As you’ve probably guessed, 250 it’s critical to keep the secret key as a secret. Another requirement for the secret key 251 is that it must have at least 256-bits, i.e. 32 ASCII characters, as we are using 252 HMAC-SHA256 as the signing algorithm. 253 254 3. Start all the alpha servers in your cluster with the option `--acl_secret_file`, and 255 make sure they are all using the same secret key file created in Step 2. 256 257 Here is an example that starts one zero server and one alpha server with the ACL feature turned on: 258 259 ```bash 260 dgraph zero --my=localhost:5080 --replicas 1 --idx 1 --bindall --expose_trace --profile_mode block --block_rate 10 --logtostderr -v=2 261 dgraph alpha --my=localhost:7080 --lru_mb=1024 --zero=localhost:5080 --logtostderr -v=3 --acl_secret_file ./hmac-secret 262 ``` 263 264 If you are using docker-compose, a sample cluster can be set up by: 265 266 1. `cd $GOPATH/src/github.com/dgraph-io/dgraph/compose/` 267 2. `make` 268 3. `./compose -e --acl_secret <path to your hmac secret file>`, after which a `docker-compose.yml` file will be generated. 269 4. `docker-compose up` to start the cluster using the `docker-compose.yml` generated above. 270 271 ### Set up ACL Rules 272 273 Now that your cluster is running with the ACL feature turned on, let's set up the ACL 274 rules. A typical workflow is the following: 275 276 1. Reset the root password. The example below uses the dgraph endpoint `localhost:9080` 277 as a demo, make sure to choose the correct IP and port for your environment: 278 ```bash 279 dgraph acl -a localhost:9080 mod -u groot --new_password 280 ``` 281 Now type in the password for the groot account, which is the superuser that has access to everything. The default password is `password`. 282 `groot` is part of a special group called `guardians`. Members of `guardians` group will have access to everything. You can add more users 283 to this group if required. 284 2. Create a regular user 285 ```bash 286 dgraph acl -a localhost:9080 add -u alice 287 ``` 288 Now you should see the following output 289 ```console 290 Current password for groot: 291 Running transaction with dgraph endpoint: localhost:9080 292 Login successful. 293 New password for alice: 294 Retype new password for alice: 295 Created new user with id alice 296 ``` 297 3. Create a group 298 ```bash 299 dgraph acl -a localhost:9080 add -g dev 300 ``` 301 Again type in the groot password, and you should see the following output 302 ```console 303 Current password for groot: 304 Running transaction with dgraph endpoint: localhost:9080 305 Login successful. 306 Created new group with id dev 307 ``` 308 4. Assign the user to the group 309 ```bash 310 dgraph acl -a localhost:9080 mod -u alice -l dev 311 ``` 312 The command above will add `alice` to the `dev` group. A user can be assigned to multiple groups. 313 The multiple groups should be formated as a single string separated by `,`. 314 For example, to assign the user `alice` to both the group `dev` and the group `sre`, the command should be 315 ```bash 316 dgraph acl -a localhost:9080 mod -u alice -l dev,sre 317 ``` 318 5. Assign predicate permissions to the group 319 ```bash 320 dgraph acl mod -a localhost:9080 -g dev -p friend -m 7 321 ``` 322 The command above grants the `dev` group the `READ`+`WRITE`+`MODIFY` permission on the 323 `friend` predicate. Permissions are represented by a number following the UNIX file 324 permission convention. That is, 4 (binary 100) represents `READ`, 2 (binary 010) 325 represents `WRITE`, and 1 (binary 001) represents `MODIFY` (the permission to change a 326 predicate's schema). Similarly, permisson numbers can be bitwise OR-ed to represent 327 multiple permissions. For example, 7 (binary 111) represents all of `READ`, `WRITE` and 328 `MODIFY`. In order for the example in the next section to work, we also need to grant 329 full permissions on another predicate `name` to the group `dev`. If there are no rules for 330 a predicate, the default behavior is to block all (`READ`, `WRITE` and `MODIFY`) operations. 331 ```bash 332 dgraph acl mod -a localhost:9080 -g dev -p name -m 7 333 ``` 334 6. Check information about a user 335 ```bash 336 dgraph acl info -a localhost:9080 -u alice 337 ``` 338 and the output should show the groups that the user has been added to, e.g. 339 ```bash 340 Running transaction with dgraph endpoint: localhost:9080 341 Login successful. 342 User : alice 343 UID : 0x3 344 Group : dev 345 Group : sre 346 ``` 347 7. Check information about a group 348 ```bash 349 dgraph acl info -a localhost:9080 -g dev 350 ``` 351 and the output should include the users in the group, as well as the permissions the 352 group's ACL rules, e.g. 353 ```bash 354 Current password for groot: 355 Running transaction with dgraph endpoint: localhost:9080 356 Login successful. 357 Group: dev 358 UID : 0x4 359 ID : dev 360 Users: alice 361 ACL : {friend 7} 362 ACL : {name 7} 363 ``` 364 365 8. Run ACL commands as another guardian (Member of `guardians` group) 366 You can also run ACL commands with other users. Say we have a user `alice` which is member 367 of `guardians` group and its password is `simple_alice`. We can run ACL commands as shown below. 368 ```bash 369 dgraph acl info -a localhost:9180 -u groot -w alice -x simple_alice 370 ``` 371 Above command will show information about user `groot`. 372 ### Access Data Using a Client 373 374 Now that the ACL data are set, to access the data protected by ACL rules, we need to 375 first log in through a user. A sample code using the dgo client can be found 376 [here](https://github.com/dgraph-io/dgraph/blob/master/tlstest/acl/acl_over_tls_test.go). 377 378 ### Access Data Using Curl 379 380 Dgraph's HTTP API also supports authenticated operations to access ACL-protected 381 data. 382 383 To login, send a POST request to `/login` with the userid and password. For example, to log in as the root user groot: 384 385 ```sh 386 $ curl -X POST localhost:8080/login -d '{ 387 "userid": "groot", 388 "password": "password" 389 }' 390 ``` 391 392 Response: 393 ``` 394 { 395 "data": { 396 "accessJWT": "<accessJWT>", 397 "refreshJWT": "<refreshJWT>" 398 } 399 } 400 ``` 401 The response includes the access and refresh JWTs which are used for the authentication itself and refreshing the authentication token, respectively. Save the JWTs from the response for later HTTP requests. 402 403 You can run authenticated requests by passing the accessJWT to a request via the `X-Dgraph-AccessToken` header. For example: 404 405 ```sh 406 $ curl -X POST -H 'Content-Type: application/graphql+-' -H 'X-Dgraph-AccessToken: <accessJWT>' localhost:8080/query -d '...' 407 $ curl -X POST -H 'Content-Type: application/json' -H 'X-Dgraph-AccessToken: <accessJWT>' localhost:8080/mutate -d '...' 408 $ curl -X POST -H 'X-Dgraph-AccessToken: <accessJWT>' localhost:8080/alter -d '...' 409 ``` 410 411 The refresh token can be used in the `/login` POST body to receive new access and refresh JWTs, which is useful to renew the authenticated session once the ACL access TTL expires (controlled by Dgraph Alpha's flag `--acl_access_ttl` which is set to 6h0m0s by default). 412 413 ```sh 414 $ curl -X POST localhost:8080/login -d '{ 415 "refresh_token": "<refreshJWT>" 416 }' 417 ``` 418 419 ## Encryption at Rest 420 421 {{% notice "note" %}} 422 This feature was introduced in [v1.1.1](https://github.com/dgraph-io/dgraph/releases/tag/v1.1.1). 423 For migrating unencrypted data to a new Dgraph cluster with encryption enabled, you need to 424 [export the database](https://docs.dgraph.io/deploy/#export-database) and [fast data load](https://docs.dgraph.io/deploy/#fast-data-loading), 425 preferably using the [bulk loader](https://docs.dgraph.io/deploy/#bulk-loader). 426 {{% /notice %}} 427 428 Encryption at rest refers to the encryption of data that is stored physically in any 429 digital form. It ensures that sensitive data on disks is not readable by any user 430 or application without a valid key that is required for decryption. Dgraph provides 431 encryption at rest as an enterprise feature. If encryption is enabled, Dgraph uses 432 [Advanced Encryption Standard (AES)](https://en.wikipedia.org/wiki/Advanced_Encryption_Standard) 433 algorithm to encrypt the data and secure it. 434 435 ### Set up Encryption 436 437 To enable encryption, we need to pass a file that stores the data encryption key with the option 438 `--encryption_key_file`. The key size must be 16, 24, or 32 bytes long, and the key size determines 439 the corresponding block size for AES encryption ,i.e. AES-128, AES-192, and AES-256, respectively. 440 441 Here is an example encryption key file of size 16 bytes: 442 443 *enc_key_file* 444 445 ``` 446 123456789012345 447 ``` 448 449 ### Turn on Encryption 450 451 Here is an example that starts one zero server and one alpha server with the encryption feature turned on: 452 453 ```bash 454 dgraph zero --my=localhost:5080 --replicas 1 --idx 1 455 dgraph alpha --encryption_key_file "./enc_key_file" --my=localhost:7080 --lru_mb=1024 --zero=localhost:5080 456 ```