In this section we explore a number of ways to get you started using, deploying, operating and developing BitBroker.
If you are new to BitBroker, you may want to start with this quick overview or this deeper introduction.
This the multi-page printable view of this section. Click here to print.
In this section we explore a number of ways to get you started using, deploying, operating and developing BitBroker.
If you are new to BitBroker, you may want to start with this quick overview or this deeper introduction.
Here you will find information about a range of BitBroker demo applications and connectors to help you understand what BitBroker is and how it can operate in complex data sharing scenarios.
Most importantly, it will help you get started building your own applications which use BitBroker data or your own data connectors to contribute data into the system.
We have a number of example applications, which allow users to explore policy based access to data via the Consumer API.
This application allows you to explore the entire Consumer API by directly trying out a number of interactive scenarios. It has a set of example data and polices already pre-installed and running.
You can explore using the Catalog API to try different, complex catalog queries. You can see how the results of these queries differ in the light of different policies - which you can switch between simply in the application.
Once you have executed a query and obtain entity instance records, you can use the Entity API to browse the whole list and inspect the details of individual entities.
Finally, for country
data, you can also see the Timeseries API in actions and integrated with a charting library.
This application allows you to explore the Consumer API via the medium of a mapping application. It has a set of example data and polices already pre-installed and running. The geographical attributes within the example data are used to populate a map view of the data records.
You can explore how the application outputs are changed in the light of different policies - which you can switch between simply in the application.
Here we provide a range of data connectors to help you understand what they are and how to build your own. Indeed, it is hoped that you can simply modify one of these data connectors to achieve your own data submission aims.
We currently have two types of example connector:
All implementations upload data to the BitBroker catalog. They also fetch and return third-party data in their entity webhooks for the example country
dataset, and both support time series data for the country
dataset.
This example connector is implemented in NodeJS and uses a simple file as its source data store. Key characteristics of this connector are:
This example connector is implemented in NodeJS and uses a PostgreSQL database as its source data store. Key characteristics of this connector are:
There are several ways in which you can install BitBroker, depending on what you are trying to achieve.
Are you trying to deploy to a public cloud or to a local environment? Are you wanting to use BitBroker in a production environment, or as a local sandbox, perhaps you are developing data connectors or even trying to enhance BitBroker itself?
In this section, we will cover in detail and step-by-step, all the different ways in which you can install a BitBroker instance using Kubernetes, to help you achieve your goals.
For all Kubernetes installations, you should be aware of the ways in which fresh installations perform certain bootstrap operations.
Every fresh installation of BitBroker comes with one preinstalled user (uid: 1
). This user is automatically created when the system is bought-up for the first time.
As we will explain below, this user is linked to the authorization of API calls. The user is also important for the up-coming web portal BitBroker control interface.
All interactions with BitBroker stem, ultimately, from interactions with the Coordinator API. This is the main administrative API for the whole system. In order to use this API, you need an access token.
Using this API, new users can be created and then promoted to have coordinator status. This results in the production of a new coordinator access token for them. But this act of promotion itself, requires permission. So how can we get started with this circular scenario?
Whenever a fresh system is installed using Kubernetes, a special bootstrap coordinator authorization token is produced. This token is valid for use with the Coordinator API. You can use this token to get going with the process of then creating your own users and giving them coordinator status.
The detailed install steps below, will contain more information about how to extract and use this bootstrap token.
In the section, we will explore how to you can use our pre-prepared Helm charts to install a complete BitBroker instance into your cloud of choice. These charts will be downloaded directly from Docker Hub.
https://your-cloud-host
for the host base URL. Enter your cloud host base URL into the box below, in order to update the sample calls with your install details:Start with a clean machine, with no remnants of previous BitBroker installations. Please ensure you have the following software installed, configured and operational:
Create a brand new directory to act as a workspace for your installation:
mkdir bbk
cd bbk
Make sure that your current Kubernetes context is pointing at your cloud of choice:
kubectl config get-contexts
First, let’s prepare the context we want to install:
helm repo add bit-broker https://bit-broker.github.io/charts
JWKS=$(docker run bbkr/auth-service:latest npm run --silent create-jwks)
kubectl apply -f https://app.getambassador.io/yaml/emissary/2.2.2/emissary-crds.yaml
Next, let’s extract and save the default chart values:
helm show values bit-broker/bit-broker > values.yaml
Next update values.yaml
with your required values:
Value | Description |
---|---|
global.portal.host |
Your base DNS host |
global.gateway.certificateIssuer |
Set to true for automatic certificates with Let’s Encrypt |
global.gateway.tlsSecret |
if certificateIssuer is false, setup your own secret here |
Now we are ready to run the cloud installation with the selected values:
helm install --values values.yaml \
--create-namespace bit-broker \
--set bbk-auth-service.JWKS=$JWKS \
--namespace bit-broker \
bit-broker/bit-broker
This step takes a few moments to complete. After it has finished, you will see a series of notes which discuss some key points about your installation. The sections on JWKS, Auth Service and Rate Service are for advanced use cases, and you can ignore these for now.
It can take a few moments for the system to come into existence and for it to complete its initialization steps. You can test that the system is up-and-ready, by the using this command:
if [ $(curl --max-time 5 --write-out '%{http_code}' --silent --head --output /dev/null https://your-cloud-host/coordinator/v1) == "401" ]; then echo "Ready"; else echo "Not Ready"; fi;
This will output Not Ready
until all the servers are up, after which it will output Ready
. Keep trying this command until it signals it’s OK to proceed.
If you want to add an alias to this installation into your DNS record, then you need to first get the service load balancer address:
kubectl get svc --no-headers -o custom-columns=":status.loadBalancer.ingress[0].hostname" --selector=app.kubernetes.io/name=bbk-emissary-ingress -n bit-broker | head -1
Then you can use this to add an ALIAS into your DNS record. Depending on the domain and the registrar, the procedure and naming terminology will be different. Here is an example procedure for AWS’s Route 53.
A key thing to note in the results output, is the section which says: “Here is how to get the Coordinator token”. Extracting and recording this token is a vital step to proceed with the install. This is the bootstrap coordinator token, which we outlined earlier in this document.
As the results output states, you can get hold of this bootstrap coordinator token as follows:
kubectl exec $(kubectl get pods --no-headers -o custom-columns=":metadata.name" --selector=app=bit-broker-bbk-auth-service -n bit-broker | head -1) -n bit-broker -c auth-service -- npm run sign-token coordinator $(kubectl get secret --namespace bit-broker bit-broker-bbk-admin-jti -o jsonpath="{.data.ADMIN_JTI}" | base64 --decode)
This is a long command and it will take a few seconds to complete. It will output the token, which will be in the format of a long string. Copy this token and store in a secure location. Be careful if sharing this token, as it has full rights to the entire Coordinator API.
If everything worked as expected, the BitBroker API servers will be up-and-running in your cloud waiting for calls. You can test this by using the sample call below:
curl https://your-cloud-host/coordinator/v1 \
--header "x-bbk-auth-token: bootstrap-token-goes-here"
The base end-points of all the three API servers respond with a small announcement:
{
"now": "2022-06-16T10:44:53.970Z",
"name": "bit-broker coordinator service",
"base": "https://your-cloud-host/coordinator/v1",
"status": "production"
}
Like all BitBroker API end-points, these require a working authorization to be in place. Hence, this announcement can be used for testing or verification purposes.
If you want to completely uninstall this instance of BitBroker, you should follow these steps:
helm uninstall bit-broker -n bit-broker
kubectl delete -f https://app.getambassador.io/yaml/emissary/2.2.2/emissary-crds.yaml
kubectl delete namespace bit-broker
helm repo remove bit-broker
docker ps -a | grep "bbkr/" | awk '{print $1}' | xargs docker rm
rm values_local.*
This will remove all the key elements which were created as part of the installation. If you want to go further and clear out all the images which were downloaded too, use the following:
docker images -a | grep "bbkr/" | awk '{print $3}' | uniq | xargs docker rmi
In the section, we will explore how to you can use our pre-prepared Helm charts to install a complete BitBroker instance on your local machine. These charts will be downloaded directly from Docker Hub.
Start with a clean machine, with no remnants of previous BitBroker installations. Please ensure you have the following software installed, configured and operational:
port 80
of your localhost
.
Create a brand new directory to act as a workspace for your installation:
mkdir bbk
cd bbk
Make sure that your current Kubernetes context is docker-desktop
:
kubectl config get-contexts
kubectl config use-context docker-desktop
First, let’s prepare the context we want to install:
helm repo add bit-broker https://bit-broker.github.io/charts
JWKS=$(docker run bbkr/auth-service:latest npm run --silent create-jwks)
kubectl apply -f https://app.getambassador.io/yaml/emissary/2.2.2/emissary-crds.yaml
Our pre-prepared Helm charts are, by default, configured for production, cloud environments. However, here we want to install to localhost
only. So we need to make some modifications to the default chart to cater for this:
helm show values bit-broker/bit-broker > values_local.yaml
sed -e 's/gateway[ ]*:/gateway: {}/g' \
-e 's/acmeProvider/# acmeProvider/g' \
-e 's/certificateIssuer/# certificateIssuer/g' \
-e 's/#[ ]*host:[ ]*"https:\/\/bit-broker.io"/host: "http:\/\/localhost"/g' \
-i '_old' \
values_local.yaml
Now we are ready to run the local installation:
helm install --values values_local.yaml \
--create-namespace bit-broker \
--set bbk-auth-service.JWKS=$JWKS \
--namespace bit-broker \
bit-broker/bit-broker
This step takes a few moments to complete. After it has finished, you will see a series of notes which discuss some key points about your installation. The sections on JWKS, Auth Service and Rate Service are for advanced use cases, and you can ignore these for now.
It can take a few moments for the system to come into existence and for it to complete its initialization steps. You can test that the system is up-and-ready, by the using this command:
if [ $(curl --max-time 5 --write-out '%{http_code}' --silent --head --output /dev/null http://localhost/coordinator/v1) == "401" ]; then echo "Ready"; else echo "Not Ready"; fi;
This will output Not Ready
until all the servers are up, after which it will output Ready
. Keep trying this command until it signals it’s OK to proceed.
A key thing to note in the results output, is the section which says: “Here is how to get the Coordinator token”. Extracting and recording this token is a vital step to proceed with the install. This is the bootstrap coordinator token, which we outlined earlier in this document.
As the results output states, you can get hold of this bootstrap coordinator token as follows:
kubectl exec $(kubectl get pods --no-headers -o custom-columns=":metadata.name" --selector=app=bit-broker-bbk-auth-service -n bit-broker | head -1) -n bit-broker -c auth-service -- npm run sign-token coordinator $(kubectl get secret --namespace bit-broker bit-broker-bbk-admin-jti -o jsonpath="{.data.ADMIN_JTI}" | base64 --decode)
This is a long command and it will take a few seconds to complete. It will output the token, which will be in the format of a long string. Copy this token and store in a secure location. Be careful if sharing this token, as it has full rights to the entire Coordinator API.
If everything worked as expected, the BitBroker API servers will be up-and-running on localhost
waiting for calls. You can test this by using the sample call below:
curl http://localhost/coordinator/v1 \
--header "x-bbk-auth-token: bootstrap-token-goes-here"
The base end-points of all the three API servers respond with a small announcement:
{
"now": "2022-06-16T10:44:53.970Z",
"name": "bit-broker coordinator service",
"base": "http://localhost/coordinator/v1",
"status": "production"
}
Like all BitBroker API end-points, these require a working authorization to be in place. Hence, this announcement can be used for testing or verification purposes.
If you want to completely uninstall this instance of BitBroker, you should follow these steps:
helm uninstall bit-broker -n bit-broker
kubectl delete -f https://app.getambassador.io/yaml/emissary/2.2.2/emissary-crds.yaml
kubectl delete namespace bit-broker
helm repo remove bit-broker
docker ps -a | grep "bbkr/" | awk '{print $1}' | xargs docker rm
rm values_local.*
This will remove all the key elements which were created as part of the installation. If you want to go further and clear out all the images which were downloaded too, use the following:
docker images -a | grep "bbkr/" | awk '{print $3}' | uniq | xargs docker rmi
There are several ways in which you can install BitBroker, depending on what you are trying to achieve.
Local installations using Docker Compose or even direct on to your physical machine, can be a useful option for some use cases. For example, where you are developing data connectors or even trying to enhance BitBroker itself.
In this section, we will cover in detail and step-by-step, all the different ways in which you can install a BitBroker instance locally, to help you achieve your goals.
For consistency across the system, in local and development mode we use a set of standard logical server name and port for addressing the three principle API services.
This helps with readability and removes ambiguity, since some APIs share resource names. Also, it reduces confusion, if you start multiple API servers on the same physical machine.
We use a convention of assigning each API service a logical server name as follows:
API Service | Logical Server Name |
---|---|
Coordinator API | bbk-coordinator |
Contributor API | bbk-contributor |
Consumer API | bbk-consumer |
You will find these names used across all the documentation and in the sample code. This is merely a convention; you do not need to use these names in your code. You can, instead, use your cloud URLs or even base IP addresses.
If you choose to stick to this convention, you will need to map these name to their ultimate end-points inside your system hosts file. Here is an example, mapping the standard logical server names to localhost
.
127.0.0.1 bbk-coordinator
127.0.0.1 bbk-contributor
127.0.0.1 bbk-consumer
Each API service listens on a distinct, non-clashing port. Unless you configure it otherwise, even the docker images are designed to start each service on its designated port.
This port mapping makes it simple and unambiguous to bring up multiple (or indeed all) of these API services on the same physical machine, without them interfering with each other. The assigned service ports are as follows:
API Service | Server Port |
---|---|
Coordinator API | 8001 |
Contributor API | 8002 |
Consumer API | 8003 |
When installing BitBroker locally, authorization is bypassed. In this scenario, you do not need to supply authorization tokens to any API.
However, when using the Consumer API, you do still need to specify the policy you are using. This is so that BitBroker is aware of the data segment which is in-play for consumer calls. This is achieved by specifying a development header value.
Rather than the authorization header:
x-bbk-auth-token: your-token-will-go-here
You instead use the development header, as follows:
x-bbk-audience: your-policy-id-will-go-here
Failure to specify the development header on Consumer API calls when in local mode, will lead to those requests being rejected.
Every fresh installation of BitBroker comes with one preinstalled user (uid: 1
). This user is automatically created when the system is bought-up for the first time.
As we will explain below, this user is linked to the authorization of API calls. The user is also important for the up-coming web portal BitBroker control interface.
In the section we will explore how to you can use our pre-prepared Docker Compose files to install a BitBroker instance on your local machine.
Start with a clean machine, with no remnants of previous BitBroker installations. Please ensure you have the following software installed, configured and operational:
Create a brand new directory to act as a workspace for your installation:
mkdir bbk
cd bbk
Let’s start by cloning the main BitBroker engine from its GitHub repository:
git clone https://github.com/bit-broker/bit-broker.git
This will have created a bit-broker
directory and you should move into it:
cd bit-broker
First, let’s start by preparing our instance’s environment file. For a standard local install, we can simply copy the existing one which came with the repository:
cp .env.example .env
Now we can use our docker compose scripts to install and launch our local instance:
docker-compose -f ./development/docker-compose/docker-compose.yml up
At this point, your BitBroker installation is up and running on your local machine. You can test it by running the steps below.
If you are going to develop on BitBroker, either for building data connectors or for contributing to the core system, then this mode of install can provide a fast and low friction installation technique.
If everything worked as expected, the BitBroker API servers will be up-and-running on localhost
waiting for calls. You can test this by using the sample call below. In this local mode, you don’t need to specify any authorization tokens.
curl http://bbk-coordinator:8001/v1
If you have not applied the standard server name and port format, then you should use http://localhost:8001
here as your API host base URL. The base end-points of all the three API servers respond with a small announcement:
{
"now": "2022-06-16T10:44:53.970Z",
"name": "bit-broker coordinator service",
"base": "http://localhost/coordinator/v1",
"status": "production"
}
If you want to completely uninstall this instance of BitBroker, you can follow these steps, from the top-level bit-broker
folder:
docker-compose -f ./development/docker-compose/docker-compose.yml down
cd ..
rm -rm bit-broker
This will delete the Git cloned folder created earlier.
In the section, we will explore how to you can install a BitBroker instance directly onto your local machine.
Start with a clean machine, with no remnants of previous BitBroker installations. Please ensure you have the following software installed, configured and operational:
Create a brand new directory to act as a workspace for your installation:
mkdir bbk
cd bbk
Let’s start by cloning the main BitBroker engine from its GitHub repository:
git clone https://github.com/bit-broker/bit-broker.git
This will have created a bit-broker
directory and you should move into it:
cd bit-broker
For development purposes, BitBroker has a handy shell script called bbk.sh
which can be used to manage the system in local install mode. You can use this to prepare your new clone:
./development/scripts/bbk.sh unpack
The unpack
step, makes sure that all the dependent node packages needed to operate the system are downloaded and ready. It also creates a .env
file automatically, by using the settings in the .env.example
file.
Now you can start BitBroker by simply using:
./development/scripts/bbk.sh reset
The reset
command given the following output:
» no services running
» wiping the database...
» starting services...
┌────── services running ──────┐
│ │
│ 90808 » bbk-consumer │
│ 90812 » bbk-rate-limit │
│ 90813 » bbk-auth-service │
│ 90816 » bbk-contributor │
│ 90817 » bbk-coordinator │
│ │
└──────────────────────────────┘
At this point, your BitBroker installation is up and running on your local machine. You can test it by running the steps below. But first, let’s just see what other commands the bbk.sh
script supports:
./development/scripts/bbk.sh <command>
command:
unpack → prepares a fresh git clone
start → starts bbk services
stop → stops bbk services
status → show bbk service status
logs → tails all bbk services logs
db → start a sql session
wipe → resets the bbk database
drop → drops the bbk database
bounce → stop » start
reset → stop » wipe » start
clean → stop » drop
If you are going to develop on BitBroker, either for building data connectors or for contributing to the core system, then this mode of install can provide a fast and low friction installation technique.
If everything worked as expected, the BitBroker API servers will be up-and-running on localhost
waiting for calls. You can test this by using the sample call below. In this local mode, you don’t need to specify any authorization tokens.
curl http://bbk-coordinator:8001/v1
If you have not applied the standard server name and port format, then you should use http://localhost:8001
here as your API host base URL. The base end-points of all the three API servers respond with a small announcement:
{
"now": "2022-06-16T10:44:53.970Z",
"name": "bit-broker coordinator service",
"base": "http://localhost/coordinator/v1",
"status": "production"
}
If you want to completely uninstall this instance of BitBroker, you can follow these steps, from the top-level bit-broker
folder:
./development/scripts/bbk.sh clean
cd ..
rm -rm bit-broker
This will delete the Git cloned folder created earlier.
In the section, we cover how you can configure your BitBroker instance to align to your specific needs.
In this section, we outline the details of our installation environment file. This file is called .env
and resides at the root of the BitBroker file layout.
There is no master record for this in the repository, however there is a file called .env.example
, which contains all the most common parameters. You can activate this common set by simply copying this file:
cd bit-broker
cp .env.example .env
Here are all the settings in .env
which can be modified:
Parameter | Default | Description |
---|---|---|
APP_MODE |
standard |
This is reserved for a future feature |
APP_SERVER_METRICS |
false |
Enables express-prom-bundle to each API server |
APP_SERVER_LOGGING |
false |
Enables stdout logging to each API server |
APP_FILE_LOGGING |
false |
Enables file based logging to each API server |
APP_DATABASE |
see .env.example |
PostgreSQL connection string - use CREDENTIALS as per the default |
APP_SECRET |
see .env.example |
Instance level secret used to create secure hashes |
BOOTSTRAP_USER_EMAIL |
noreply@bit-broker.io |
The email for the bootstrap user |
BOOTSTRAP_USER_NAME |
Admin |
The name of the bootstrap user |
BOOTSTRAP_USER_KEY_ID |
see .env.example |
This parameter reserved |
COORDINATOR_PORT |
8001 |
The listening port for the coordinator API |
COORDINATOR_BASE |
v1 |
The version of the coordinator API |
COORDINATOR_USER |
see .env.example |
Database access for the coordinator API |
CONTRIBUTOR_PORT |
8002 |
The listening port for the contributor API |
CONTRIBUTOR_BASE |
v1 |
The version of the contributor API |
CONTRIBUTOR_USER |
see .env.example |
Database access for the contributor API |
CONSUMER_PORT |
8003 |
The listening port for the consumer API |
CONSUMER_BASE |
v1 |
The version of the consumer API |
CONSUMER_USER |
see .env.example |
Database access for the consumer API |
POLICY_CACHE |
see .env.example |
Redis connection string for the policy cache |
AUTH_SERVICE |
see .env.example |
End-point for the auth service |
RATE_SERVICE |
see .env.example |
End-point for the rate service |
You will also see some parameters starting with TESTS_
in the .env.example
. These are reserved parameters used by the Mocha test suite. You can ignore these values unless you are developing the core system itself.
In this section, we outline the details of some more advanced use cases.