
main.go:"go get github.com/cerbos/cerbos-sdk-go/cerbos" downloads and installs the Cerbos package, adding the dependency to our application.
resourcePolicy.yaml and derivedRoles.yaml located in the policies folder to define and hold the roles and attributes that Cerbos will use to make authorization decisions. The policy file is where you specify the rules and constraints that determine whether a particular action is allowed or denied. We will be defining policies that allow various access to a students’ attendance register depending on who is trying to access the page. There are two primary principals: the USER and the ADMIN. However, there are three categories for the user: the REP, ASISTANT_REP and the COURSE_LECTURER. Each of the categories have different access levels, depending on who they are. The admin has access to all features.main.go file to handle access to the attendance sheet, check access with Cerbos, and handle errors. var c, err = client.New("localhost:3593",cerbos.WithPlaintext())client.New function takes two arguments: the hostname and a list of options.localhost:3593 is the hostname and port number of the Cerbos server. You should replace this with the actual hostname and port number of your Cerbos server.cerbos.WithPlaintext() is an option that enables plaintext communication with the Cerbos server. This option is for our testing environment only, and would not normally be enabled in production.resourcePolicy.yaml and derivedRoles.yaml).localhost:3593: in your main.go file, ensure that the line, var c, err = client.New("localhost:3593", cerbos.WithPlaintext()) is included./dashboard endpoint with different user roles and attributes.

/dashboard endpoint with different X-Cerbos-Principal header values, simulating users with various roles and attributes.resourcePolicy.yaml and derivedRoles.yaml files.
200, meaning it was successful.
Posted Oct 29, 2024
In this tutorial, you will learn how to use the Cerbos client to configure authorization policies in a Gorilla application.