Hello team, having some challenges with go sdk che...
# permit-saas
r
Hello team, having some challenges with go sdk check function for resource/instance roles. I thought if I put the resource as 'resource_name:instance_name' in the resource value it would work but the Audit shows no resource found. How do I configure roles/user for instance roles and pass the appropriate information in the Check function?
a
Hi @Ryan Barriger, I'm an AI assistant for Permit.io. I'll analyze available sources and get back to you shortly.
For resource instance roles in the Go SDK, you need to: 1. Assign Resource Instance Roles When assigning roles to users for specific resource instances, use the
AssignResourceRole
method with the resource instance format (1) :
Copy code
userRoleCreate := *models.NewUserRoleCreate(roleKey, tenantKey)
userRoleCreate.SetResourceInstance("document:mydoc")
user, httpRes, err := u.client.UsersApi.AssignRoleToUser(ctx, u.config.Context.GetProject() , u.config.Context.GetEnvironment() , userKey) .UserRoleCreate(userRoleCreate) .Execute()
The resource instance format is
resource_type:instance_id
(2) . 2. Check Permissions with Resource Instances For the Check function, you don't pass the instance directly in the resource string. Instead, build the resource with the instance ID (3) :
Copy code
user := enforcement.UserBuilder("<mailto:john@doe.com|john@doe.com>") .Build()
resource := enforcement.ResourceBuilder("document") .Build()
permitted, err := Permit.Check(user, "create", resource)
, (4) However, based on the Mesa Verde demo application, when checking permissions for a specific instance, you would pass the resource with its attributes (5) :
Copy code
const transactionAllowed = await permit.check(
 {
  key: user,
  attributes: { strongAuth: !!OTP, location },
 },
 "create",
 {
  type: "Transaction",
  attributes: { ...transaction },
  tenant,
 }
) ;
3. Unassign Resource Roles To unassign a resource instance role (1) :
Copy code
userRoleRemove := *models.NewUserRoleRemove(roleKey, tenantKey)
userRoleRemove.SetResourceInstance(resourceInstance)
user, httpRes, err := u.client.UsersApi.UnassignRoleFromUser(ctx, u.config.Context.GetProject() , u.config.Context.GetEnvironment() , userKey) .UserRoleRemove(userRoleRemove) .Execute()
The key is that resource instances follow the format
resource_type:instance_id
when assigning/unassigning roles (2) , but when checking permissions, you use the ResourceBuilder to construct the resource object (3) . To help debug your issue, could you please provide: 1. Which Workspace / Project / Env you are using 2. What calls you are performing (as SDK code or CURL) 3. Which PDP version you are running 4. Relevant logs from your PDP This will help our engineers investigate the "no resource found" error you're seeing in the Audit.
o
Hi Ryan we’ll be right with you
r
My theory is the Go SDK check function isnt parsing the resource string to account for the instance. My guess is I need to add attributes on the resource builder call, which attributes should I leverage?
well I may have it working, but of course CloudPDP doesn't support ReBAC
t
Some SDKs do support simple check(string,string,string) not sure about go, but AI is right in the creation of the objects working.
and you are correct, the public cloud PDP doesn't support ReBAC. it's easy enough to start one locally 🙂 @Ask Inkeep can help with the command.
a
Thanks for tagging me @Thomas. I'll look through relevant sources and get back to you shortly.
You're correct that the Cloud PDP doesn't support ReBAC (1) . To run a local PDP container that supports ReBAC, here's the command: First, pull the PDP container :
Copy code
docker pull permitio/pdp-v2:latest
Then run it with your API key :
Copy code
docker run -it -p 7766:7000 --env PDP_DEBUG=True --env PDP_API_KEY=<YOUR_API_KEY> permitio/pdp-v2:latest
Once running, configure your Go SDK to point to the local PDP instead of the cloud PDP. The local PDP will listen on port 7766 and fully supports ReBAC policies including resource instances and relationship-based permissions (2) . The Cloud PDP at
<https://cloudpdp.api.permit.io>
is great for quick experimentation but doesn't support ABAC or ReBAC policies (1) . For production deployments with ReBAC, using the Docker Container PDP provides better latency and full feature support .
To learn more, see the sources I considered: [[1] Running a demo](https://docs.permit.io/overview/connecting-your-app) [[2] What is ReBAC?](https://docs.permit.io/how-to/build-policies/rebac/overview)
r
getting a docker image to run behind corporate firewalls is not an easy command. flooded with certificate/SSL errors atm when I try running it
seems like a lot of features are missing in the cloudpdp, are those being addressed at any time or on the roadmap?
t
yeah, the cloudpdp has some big improvements coming in the next few months so stay tuned.
if you have a corporate proxy sometimes you can add the proxy certs into the container and it works
Resolving SSL Certificate Issues with PDP Behind a Proxy.md