Get started with Cerbos Hub
Tags: webdev, opensource, productivity, tutorial
Published: 2023-12-08 07:12:27

Managing permissions and authorization for SaaS applications is a critical challenge that developers, security, and product teams face. And we’re not exaggerating it, the Open Worldwide Application Security Project (OWASP) has named authorization a [top 10 API security risk](https://owasp.org/API-Security/editions/2023/en/0x11-t10/) multiple years in a row.

Everyone at Cerbos strives to make solving permissions and authZ challenges as smooth as possible for software development teams. In software development, setting up access rules, known as authorization policies, is crucial for security and proper functioning. However, making and updating these rules can often be tricky and take a lot of time, especially in large or complex projects.

## Cerbos PDP vs Hub
You may already know of our open source solution - [Cerbos Policy Decision Point (PDP)](https://github.com/cerbos/cerbos); a devtool which helps developers enforce access control over different parts of their software. If you need to learn more about Cerbos in general, we strongly recommend checking out the [website](https://cerbos.dev/product-cerbos-pdp) and the [docs](https://docs.cerbos.dev/). 

{% twitter 1721543746200711272 %}

While Cerbos PDP enables you to make decisions against your access control policies, Cerbos Hub helps you manage and synchronize PDP instances across all your apps and services, increasing security through consistency in policies everywhere, and saving you hours of time.

Cerbos Hub also helps you collaborate, validate, and test policies in real-time in an IDE environment and quickly adapt to changing app requirements.

Cerbos Hub can deploy authorization within browsers, serverless architectures, embedded devices, and at the edge. This is especially helpful for teams that need to frequently adjust their rules or manage a large number of them. 

By using Cerbos Hub, developers can focus on building and improving their software, rather than spending too much time updating access management.

So far, so good? Great!

Now, let me walk you through the process of getting started with [Cerbos Hub](https://hub.cerbos.cloud).

## Setting up Cerbos Hub

Go to https://hub.cerbos.cloud/ and you will land on a page looking like the one from the screenshot below.

![Cerbos Hub Landing](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e36mu2je7f4zk7tl7him.png)

Click on the `Log in or sign up` button on the left-hand side. That will lead you to the login/signup page. Choose to sign in with your Google or GitHub ID, or create a new ID with your email address. 

![Cerbos Hub Login](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1kwn6pwlenybirs7cbwp.png)

Next you’ll see the set-up wizard appear with instructions on how to set up your workspace. Take your time and read the instructions there, before clicking the `Connect my policy repository` button.

![Setup workspace intro](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4qx74e4h4pe27ru0iui1.png)

If you already use Cerbos PDP, you’ve most likely created a policy repository. You’ll need to grant Cerbos Hub access to your GitHub profile/organization by navigating to your GitHub account. Then click the ‘Refresh list’, and your repository will appear listed in the dropdown.


![Setup workspace step 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sn96w8aag2qk8cz2wghb.png)

If you don’t have a ready policy repository, you can get started with one of our templates, which is linked in the prompt right below the GitHub access prompt. The example repository contains all the necessary features to let you experiment with Cerbos Hub and get you up to speed with its capabilities.

When you’ve successfully selected the policy repository you want to use in your workspace, click ‘Continue’ and move on to the final step of your workspace setup. Make sure to set a proper name for your workspace, and define the branch from which you want the Hub to read your `.cerbos-hub.yaml` file. And if the repository you’re connecting is a full-fledged project, make sure to define a path to the directory that holds your Cerbos policies.

![Setup workspace step 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/td7jxsmb1hhnehqb6nmk.png)

With that, your workspace is set, and you’ll be provided with a secret key. Make sure to safely store it before closing the dialog box.


![Save workspace credentials](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z4j9timv0ibgaax2sn2a.png)

Now that everything is set, you’re ready to access your Cerbos Hub.

Your Hub homepage will look something like this:

![Cerbos Hub Homepage](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gfqr2q7wnt5zqab4c5c0.png)

On the left-hand side, you’ll see a sidebar menu, and the majority of your screen will be filled with whatever item on that sidebar is selected. Right now you’re looking at the screenshot for the ‘Home’ page of this demo workspace. 

## Managing The Hub
Right after successfully connecting, the Hub will try to run builds against the configuration found in your repository.

![Failed Build](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x94cmiob1tot0xyml3d9.png)

My build seems to be failing at the compilation level. Let me check the commit to find out more about what is going wrong.

![Failed build details](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cztnhent845858gln0h8.png)

It seems when connecting the repository, we didn’t set the correct path for where our policies are stored. If you make a similar mistake, you’ll want to correct it right away. So let’s fix that real quick.

Select the Settings option of the sidebar, type the correct policy directory, and click the `Update` button.

![Update settings policy path](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xqltr9de3d6qd3lctson.png)

This change will trigger an automatic rebuild, so quickly go back to the Builds page, and check what happened.

![Build OK](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dqisgwsdkqr9w42y10td.png)

Everything seems to be working just fine; the build is generated, and all of the labels and options provided in configuration are recognized. Now whenever we update our connected policy repository, those changes will be recognized and the builds for each of the changes will run automatically.

What we showed here is how easily you can connect your policy repositories with the Cerbos Hub, and how to troubleshoot on the fly.

## Connect the PDP to the Hub
Now let’s deploy the Cerbos PDP instance that will be connected to the Cerbos Hub.

Navigate to the `Decision points` page in the sidebar. This page keeps all the important information regarding your deployed PDPs, as well as the tools to deploy more of them.

Considering you’ve just created your Hub a couple of minutes ago, this should be a fairly empty page, looking similar to the screenshot below.

![PDP Page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vido58jhvklg3mw9ymcb.png)

Click on the `Deploy a decision point` button, and you’ll see a modal with several options, each containing its own set of instructions.

![Deploy PDP Options](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/95uisi8xd66mkt5ge5hv.png)

Being a Mac person, for this piece I chose to select Homebrew. Whatever you choose, take some time to read and understand the provided steps.

![Deploy PDP Homebrew](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gy2dm5pzcc64lgrj0q05.png)

Upon selecting your preferred deployment method, you’ll be able to select what deployment label you’d like to link it to. Our demo came with `latest`, `main` and `production` labels included in the `.cerbos-hub.yaml` file, so I’ll deploy an instance linked to `latest`.

![Labels config file](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dx6qet37f3km6mmx9yis.png)

That means every single time I make a change to a policy repository having the label `latest`, Hub will automatically notify the PDP, resulting in a seamless real-time delivery, with no service redeployments or downtime whatsoever.

For more PDP configuration details, make sure to read the [full configuration reference](https://docs.cerbos.dev/cerbos/latest/configuration/index.html).

Given I already have Cerbos installed, the `brew tap cerbos/tap` along with the `brew install cerbos` step would be redundant, but it doesn’t hurt to double-check.

![brew install terminal](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8u9fyijeexwv2eeh4nq3.png)

Pay special attention to the contents of the `conf.yaml` file. For the sake of getting started, in the desired directory create a config.yaml file, then click on the copy icon at the top right of the `config.yaml` snippet on the instructions modal and paste it to the created file, then save it.

![Copy conf.yaml content](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i90a0wmc7xli6dld7cs3.png)

Upon creating the workspace, you were asked to save the private key provided to you. You will use that key now to replace the value of the `workspaceSecret` field of the credentials part of your `config.yaml` file.

![conf.yaml content preview](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n6ctpy595eydwx9q58up.png)

For the `clientID` and the `clientSecret` fields, navigate to the `Settings` page in your left sidebar, and click the `Generate a client credential` button in the right lower corner.

![Generate client credential](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/be57yqbtualci9cupblh.png)

You’ll then be prompted to name the credential. After you do, click `Create client credential`.

![Create client credential](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l1wayu1x6qsu4qbl8edi.png)

Make sure to copy the Client ID, and paste it as the values of the `clientID` and `clientSecret` fields of your  `config.yaml` file. Upon finishing, you’ll now have it listed on the Settings page, right beneath the Policy Repository details.

![Copy client credentials](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yxffosdu98ni6q7rt2z5.png)

![Listed client credentials](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4sfwt70vjo0fml8nw2s2.png)

Now that you’ve replaced the credentials fields with the values relevant to your workspace, and (if you’re also doing it via Homebrew) simply run the `cerbos server –config=./conf.yaml` command in the terminal, positioned in the directory where you created the `conf.yaml` file.

Your PDP instance(s) should now appear on the `Decision points` page.

![List deployed Cerbos PDPs](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1m1tdt8vy63pe49hv953.png)

That’s it! Your policy repository is now connected to the Hub, as well as the PDP instance(s) we just deployed. You can deploy as many of them as you wish. Cerbos is stateless so you can scale as you need, without worrying about instances being out of sync or losing performance on heavy load periods.

## To Conclude
Cerbos Hub helps developers focus on building and improving their software, rather than spending too much time on upgrading access management. It helps connect your Cerbos policy repository and your Cerbos PDP instances and manage them collaboratively and smoothly from a single place.

This piece was an intro to Cerbos Hub, showing all the basic steps needed to get it up and running. In upcoming posts we will show you more complex and detailed cases to help you navigate through the Hub with ease.

If you’ve been following this tutorial step-by-step, your policy repo and PDP should be connected to the Hub by now. Let us know how it went in our [Cerbos Slack Community](https://go.cerbos.io/slack). If you stumbled upon any challenges, don’t hesitate to reach out. We’ll be happy to help!