self-hosted-cookbook/apps/other/brave-sync.md

4.3 KiB

Brave Sync

Brave go-sync server v2 aims to make a wire compatible server side protocol which understands components/sync/protocol/sync.proto used by the official Google sync service.

Differences from chromium sync

Enforce client side encryption Doesn't require sign-in to use sync (Uses "Sync Chain" concept) Uses a Brave-operated sync server so no data is sent to Google servers

Authentication

A "Sync Chain" is configured using a 32-byte random seed generated by the initial client. Then the seed is encoded using BIP39. If another client wants to join the sync chain, they can enter the BIP39 key phrase from the initial client by entering the words manually or scanning a QR code.


- Server code is available at [Github repo](https://github.com/brave/go-sync)

dynamo.Dockerfile

ARG DB_LOCATION=/home/dynamodblocal/db
FROM  amazon/dynamodb-local:1.12.0 AS install
USER root
RUN yum -y install awscli
USER dynamodblocal
ENV AWS_ACCESS_KEY_ID=#
ENV AWS_SECRET_ACCESS_KEY=#
ARG AWS_ENDPOINT=http://localhost:8000
ARG AWS_REGION=us-west-2
ARG DB_LOCATION
ARG TABLE_NAME=client-entity-dev
COPY schema/dynamodb/ .
RUN mkdir -p ${DB_LOCATION} && \
      java -jar DynamoDBLocal.jar -sharedDb -dbPath ${DB_LOCATION} & \
      DYNAMO_PID=$! && \
      aws dynamodb create-table --cli-input-json file://table.json \
      --endpoint-url ${AWS_ENDPOINT} --region ${AWS_REGION} && \
      kill $DYNAMO_PID

FROM amazon/dynamodb-local:1.12.0
ARG DB_LOCATION
COPY --chown=dynamodblocal:dynamodblocal --from=install ${DB_LOCATION} /db
CMD ["-jar", "DynamoDBLocal.jar", "-sharedDb", "-dbPath", "/db"]

Dockerfile

FROM bitnami/golang:1.18 as builder
ARG VERSION
ARG BUILD_TIME
ARG COMMIT
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build \
    -ldflags "-X github.com/brave/go-sync/server.version=${VERSION} -X github.com/brave/go-sync/server.buildTime=${BUILD_TIME} -X github.com/brave/go-sync/server.commit=${COMMIT}" \
    -o main .

FROM alpine:3.6 as artifact
RUN apk add --update ca-certificates # Certificates for SSL
COPY --from=builder /src/main main
EXPOSE 8295
CMD ["./main"]

docker-compose.yml

networks:
  sync:
    driver: bridge

services:
  web:

    build:
      context: .
      target: artifact
      args:
        VERSION: "${VERSION}"
        COMMIT: "${COMMIT}"
        BUILD_TIME: "${BUILD_TIME}"
    depends_on:
      - dynamo-local
      - redis
    networks:
      - sync
    environment:
      - PPROF_ENABLED=true
      - SENTRY_DSN
      - ENV=local
      - DEBUG=1
      - AWS_ACCESS_KEY_ID=#
      - AWS_SECRET_ACCESS_KEY=#
      - AWS_REGION=us-west-2
      - AWS_ENDPOINT=http://dynamo-local:8000
      - TABLE_NAME=client-entity-dev
      - REDIS_URL=redis:6379
    ports:
      - "8295:8295"

  dynamo-local:
    build:
      context: .
      dockerfile: dynamo.Dockerfile
    ports:
      - "8000:8000"
    networks:
      - sync

  redis:
    image: public.ecr.aws/ubuntu/redis:latest
    environment:
      - ALLOW_EMPTY_PASSWORD=yes
    networks:
      - sync
    ports:
      - "6379:6379"

Tips & Tricks

Dynamodb image for ARM

dynamo.Dockerfile uses the amazon/dynamodb-local:1.12.0 image for the dynamo db. Although it builds fine for x86 CPU's it is exiting on ARM64 cpu's (tested on a raspberry pi 400) . The amazon/dynamodb-local:1.13.5@sha256:d39583bcf1a5aab6e9276e15ff681c83f2dac055e1d6604bc0dcd0092c305911 image builds fine on ARM. More recent images may also work.

How to select the selfhosted sync server

Follow the "Run Chromium with command-line switches" how to in the chromium wiki

For android Enable "command line on non-rooted devices" in brave://flags, then create the file /data/local/tmp/chrome-command-line over adb.

adb shell
echo "_ --sync-url=192.168.1.24:8295/v2" > /data/local/tmp/chrome-command-line

When doing that, mind that the first command-line item should be a "_" (underscore) followed by the ones you actually need.The "/v2" should follow your URL path. Finally, manually restart Brave

Verify sync status

Visit brave://sync-internals

Warning message

Brave displays a warning message on every mew tab for some seconds acted enabling a command line feature flag saying it is unsupported. You can ignore it . Havent find a way to disable it