couchbase mobile 102 – couchbase live new york 2015

41
©2015 Couchbase Inc. 1 Couchbase Mobile 102: Sync Gateway William Hoang | Mobile Developer Advocate | @sweetiewill

Upload: couchbase

Post on 16-Apr-2017

824 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 1

Couchbase Mobile 102:

Sync GatewayWilliam Hoang | Mobile Developer Advocate |

@sweetiewill

Page 2: Couchbase Mobile 102 – Couchbase Live New York 2015

Couchbase Lite

Page 3: Couchbase Mobile 102 – Couchbase Live New York 2015

3

Sync Gateway Couchbase ServerCouchbase Lite

Page 4: Couchbase Mobile 102 – Couchbase Live New York 2015

Couchbase Peer to Peer …will be introduced in Couchbase Mobile 103

Page 5: Couchbase Mobile 102 – Couchbase Live New York 2015

Intro to Couchbase Sync Gateway

Page 6: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 6

Features: Introduction to Sync Gateway

Key Mobile Data Security Concerns

Security Solutions with Sync Gateway

LIVE Demo

Overview:

How to Add Secure Sync to Mobile Apps

Page 7: Couchbase Mobile 102 – Couchbase Live New York 2015

Couchbase Lite Sync Gateway

Replication

Authentication

Data Partitioning

Data Access Control

Page 8: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 8

Key Mobile Data Security Concerns

User Authentication

Data Read & Write Access

Data Transport on the Wire

Data Storage on Device & In the Cloud

Page 9: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 9

Key Mobile Data Security Concerns

User Authentication

Data Read & Write Access

Data Transport on the Wire

Data Storage on Device & In the Cloud

Page 10: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 10

Authentication - Pluggable

Public Providers

Custom Providers

Anonymous Users

Page 11: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 11

Authentication – Public Providers

Basic Auth

Persona

Page 12: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 12

Authentication:

Public Provider-Facebook

{

"facebook" : { "register" : false },

"databases": {

"grocery-sync": {

“server”:”http://cbserver:8091”,

“bucket":"grocery-sync",

"users": {"GUEST": {"disabled": true}},

"sync":`function(doc)

{channel(doc.channels);}`

}

}

}

Page 13: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 13

Authentication:

Custom Provider[1]:-Authentication

[2]:-Valid user Session

[3]:-App to Sync Gateway

Page 14: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 14

Key Mobile Data Security Concerns

User Authentication

Data Read & Write Access

Data Transport on the Wire

Data Storage on Device & In the Cloud

Page 15: Couchbase Mobile 102 – Couchbase Live New York 2015

Couchbase Lite Sync Gateway

Security Policies

Document Level Read Side Permissions

Field Level Write Side Permissions

JavaScript Policy Enforcement

{ … sync func. .. }

Page 16: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 16

Data Access:

Sync Function-config file

{ "databases": { "grocery-sync": { “server”:"http://walrus:", “bucket":"grocery-sync", "users": {"GUEST": {"disabled": true}},

“sync”:`function(doc,oldDoc) { channel(doc.channels); }`

}

}

}

Page 17: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 17

Data Access:

Sync Function-Write Permissions { …

o requireUser (username)o requireRole (rolename)o requireAccess (channels)o throw()

… }

Page 18: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 18

Data Access:

Sync Function-Read Permissions• channel(…)

For documents

• access(…)For users

-Special Channels• *• !

Page 19: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 19

Couchbase Lite Sync Gateway Couchbase Server

Page 20: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 20

Grocery Sync App Summary

Page 21: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 21

Grocery Sync App Summary

Page 22: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 22

Grocery Sync App Summary

Page 23: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 23

{

"log" : [“*”],

"databases": {

"grocery-sync": {

“server”:”walrus:”,

“bucket":"grocery-sync",

"users": { "GUEST": {

"disabled": false,

“admin_channels” : [“*”] }

}

}

}

}

Sync Gateway:

Configure-O-Default-All Channels

Page 24: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 24

{

”log" : [“*”],

"databases": {

"grocery-sync": {

“server”:”walrus:”,

“bucket":"grocery-sync",

"users": {

“alice”: {

“disabled” : false,

“password”: “password”,

“admin_channels”:[“*”] },

“bob”: {

“disabled” : false,

“password”: “password”,

“admin_channels”:[“*”] }

}

}

}

Sync Gateway:

Configure-1-Create Users-Remove Guest

Page 25: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 25

{

”log" : [“*”],

"databases": {

"grocery-sync": {

“server”:”walrus:”,

“bucket":"grocery-sync",

"users": {

“alice”: {

“disabled” : false,

“password”: “password”,

“admin_channels”:[“*”] },

“bob”: {

“disabled” : false,

“password”: “password”,

“admin_channels”:[“*”] }

},

“sync” : ‘

function(doc, oldDoc) {

//Add placeholder sync function, add custom read/write

logic here }

‘ }

}

}

Sync Gateway:

Configure-2-Sync Function-Owner Field

Page 26: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 26

{

”log" : [“*”],

"databases": {

"grocery-sync": {

“server”:”walrus:”,

“bucket":"grocery-sync",

"users": {

“alice”: {

“disabled” : false,

“password”: “password”,

“admin_channels”:[“items-alice”] },

“bob”: {

“disabled” : false,

“password”: “password”,

“admin_channels”:[“items-bob”] }

},

“sync” : ‘

function(doc, oldDoc) {

//Add placeholder sync function, add custom read/write

logic here }

‘ }

}

}

Sync Gateway:

Configure-3-Private Channel-Remove *

Page 27: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 27

{

”log" : [“*”],

"databases": {

"grocery-sync": {

“server”:”walrus:”,

“bucket":"grocery-sync",

"users": {

“alice”: {

“disabled” : false,

“password”: “password”,

“admin_channels”:[“items-alice”] },

“bob”: {

“disabled” : false,

“password”: “password”,

“admin_channels”:[“items-bob”] }

},

“sync” : ‘

function(doc, oldDoc) {

channel(“items-”+doc.owner); }

//Add item document to owner’s items channel

‘ }

}

}

Sync Gateway:

Configure-4-Document to Channel

-Programmatic Access

Page 28: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 28

{

”log" : [“*”],

"databases": {

"grocery-sync": {

“server”:”walrus:”,

“bucket":"grocery-sync",

"users": {

“alice”: {

“disabled” : false,

“password”: “password”,

“admin_channels”:[“items-alice”] },

“bob”: {

“disabled” : false,

“password”: “password”,

“admin_channels”:[“items-bob”] }

},

“sync” : ‘

function(doc, oldDoc) {

requireUser(doc.owner); //The owner of the item document must

be the authenticated user

channel(“items-”+doc.owner); } ‘

}

}

}

Sync Gateway:

Configure-5-requireUser-owner property

Page 29: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 29

{

”log" : [“*”],

"databases": {

"grocery-sync": {

“server”:”walrus:”,

“bucket":"grocery-sync",

"users": {

“alice”: {

“disabled” : false,

“password”: “password”,

“admin_channels”:[“items-alice”] },

“bob”: {

“disabled” : false,

“password”: “password”,

“admin_channels”:[“items-bob”] }

},

“sync” : ‘

function(doc, oldDoc) {

if (doc.type == “friends”) { //process new friends

document

requireUser(doc.owner); //The owner of the friends

access(doc.friends, “items-”+doc.owner);

channel(“private-”+doc.owner);

access(doc.owner, “private-”+doc.owner)

} else {

requireUser(doc.owner)

channel(“items-”+doc.owner); }

} ‘ }

}

Sync Gateway:

Configure-6-Document Type-Authentication

Page 30: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 30

{

”log" : [“*”],

"databases": {

"grocery-sync": {

“server”:”walrus:”,

“bucket":"grocery-sync",

"users": {

“alice”: {

“disabled” : false,

“password”: “password”,

“admin_channels”:[“items-alice”] },

“bob”: {

“disabled” : false,

“password”: “password”,

“admin_channels”:[“items-bob”] }

},

“sync” : ‘

function(doc, oldDoc) { if (doc.type == “friends”) { //process new friends document

requireUser(doc.owner); //The owner of the friends

access(doc.friends, “items-”+doc.owner);

channel(“private-”+doc.owner);

access(doc.owner, “private-”+doc.owner);

} else if (doc.type == “item”) {

requireUser(doc.owner)

channel(“items-”+doc.owner); }

else{ throw({forbidden: “Invalid document

type”}); }

} ‘ }

}

Sync Gateway:

Configure-7-throw()-Other Doc Types

Page 31: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 31

{

”log" : [“*”],

"databases": {

"grocery-sync": {

“server”:”walrus:”,

“bucket":"grocery-sync",

"users": {

“alice”: {

“disabled” : false,

“password”: “password”,

“admin_channels”:[“items-alice”] },

“bob”: {

“disabled” : false,

“password”: “password”,

“admin_channels”:[“items-bob”] }

},

“sync” : ‘

function(doc, oldDoc) { if (doc.type == “friends”) { //process new friends document

requireUser(doc.owner); //The owner of the friends

access(doc.friends, “items-”+doc.owner);

channel(“private-”+doc.owner);

access(doc.owner, “private-”+doc.owner);

} else if (doc.type == “item”) {

requireAccess(“items-”+doc.owner)

channel(“items-”+doc.owner); }

else{ throw({forbidden: “Invalid document

type”}); }

} ‘ }

}

Sync Gateway:

Configure-8-requireAccess-friends

Page 32: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 32

{

”log" : [“*”],

"databases": {

"grocery-sync": {

“server”:”walrus:”,

“bucket":"grocery-sync",

"users": {

“alice”: {

“disabled” : false,

“password”: “password”,

“admin_channels”:[“items-alice”] },

“bob”: {

“disabled” : false,

“password”: “password”,

“admin_channels”:[“items-bob”] }

},

“sync” : ‘

function(doc, oldDoc) { if (doc.type == “friends”) { //process new friends document

requireUser(doc.owner); //The owner of the friends

access(doc.friends, “items-”+doc.owner);

channel(“private-”+doc.owner);

access(doc.owner, “private-”+doc.owner);

} else if (doc.type == “item”) {

requireAccess(“items-”+doc.owner)

if (oldDoc == null) {

if (doc.check == true) { throw( {forbidden: “new items

cannot be checked”}); }

}

channel(“items-”+doc.owner); }

else { throw( {forbidden: “Invalid document type”}); }

} ‘

}

}

Sync Gateway:

Configure-9-oldDoc-doc.check

Page 33: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 33

{ ”log" : [“*”],

"databases": {

"grocery-sync": {

“server”:”walrus:”,

“bucket":"grocery-sync",

"users": {

“alice”: {

“disabled” : false,

“password”: “password”,

“admin_channels”:[“items-alice”] },

“bob”: {

“disabled” : false,

“password”: “password”,

“admin_channels”:[“items-bob”] }

},

“sync” : ‘

function(doc, oldDoc) { if (doc.type == “friends”) { //process new friends document

requireUser(doc.owner); //The owner of the friends

access(doc.friends, “items-”+doc.owner);

channel(“private-”+doc.owner);

access(doc.owner, “private-”+doc.owner);

} else if (doc.type == “item”) {

requireAccess(“items-”+doc.owner)

if (oldDoc == null) {

if (doc.check == true) { throw( {forbidden: “new items

cannot be checked”}); }

else {

if (doc.check != oldDoc.check)

{ requireUser(doc.owner); }

}

}

channel(“items-”+doc.owner); }

else { throw( {forbidden: “Invalid document type”}); }

} ‘

}

}

Sync Gateway:

Configure-10-doc vs oldDoc-requireUser

Page 34: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 34

{ ”log" : [“*”],

"databases": {

"grocery-sync": {

“server”:”walrus:”,

“bucket":"grocery-sync",

"users": {

“alice”: {

“disabled” : false,

“password”: “password”,

“admin_channels”:[“items-alice”] },

“bob”: {

“disabled” : false,

“password”: “password”,

“admin_channels”:[“items-bob”] }

},

“sync” : ‘

function(doc, oldDoc) { if (doc.type == “friends”) { //process new friends document

requireUser(doc.owner); //The owner of the friends

access(doc.friends, “items-”+doc.owner);

channel(“private-”+doc.owner);

access(doc.owner, “private-”+doc.owner);

} else if (doc.type == “item”) {

requireAccess(“items-”+doc.owner)

if (oldDoc == null) {

if (doc.check == true) { throw( {forbidden: “new items

cannot be checked”}); }

else {

if (doc.owner != oldDoc.owner) { throw({forbidden:

“Quits Stealing Items”}); }

if (doc.check != oldDoc.check)

{ requireUser(doc.owner); }

}

}

channel(“items-”+doc.owner); }

else { throw( {forbidden: “Invalid document type”}); }

} ‘

}

}

Sync Gateway:

Configure-11-doc vs oldDoc-Owner Property

Page 35: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 35

User Authentication

Data Read & Write Access

Data Transport on the Wire

Data Storage on Device & In the Cloud

Key Mobile Data Security Concerns

Page 36: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 36

Security Concerns:

Data Transport-On the Wire

SSL / TLS

Sync Gateway Config

Page 37: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 37

Key Mobile Data Security Concerns

User Authentication

Data Read & Write Access

Data Transport on the Wire

Data Storage on Device & In the Cloud

Page 38: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 38

Security Concerns:

Data Storage-On Device-In Cloud

File System Encryption

Secure Cloud Environment

Configure for File System Encryption

Page 39: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 39

Getting Started

Documentations on Sync Gateway: bit.ly/sync_gateway

Grocery-Sync-iOS: https://github.com/couchbaselabs/

Grocery-Sync-iOS

Sync Gateway Demo:https://github.com/couchbaselabs/

Downloadbit.ly/couchbase_downloads

Sync Gateway

Page 40: Couchbase Mobile 102 – Couchbase Live New York 2015

©2015 Couchbase Inc. 40

Couchbase Peer to Peer – 103 Session

Page 41: Couchbase Mobile 102 – Couchbase Live New York 2015

Thank you.@sweetiewill