Hi - can I get any sample/demo code which is using...
# community
a
Hi - can I get any sample/demo code which is using git as storage method?
c
We have a few examples of how to configure the git driver at https://docs.cerbos.dev/cerbos/latest/configuration/storage.html#git-driver. Is there something that's not working/unclear?
a
@Charith (Cerbos) cerbos: error: failed to create store: failed to clone from https://github.com/an1l4/git-test-cerbos.git to //tmp/work/policies: couldn't find remote ref "refs/heads/main"
c
Sounds like you have a different default branch. Is it called
master
by any chance? If the default branch is not
main
you have to specify it explicitly using the
branch
config field.
Yep, the repo you linked has a
master
branch. So, you need to set
branch: master
in the Cerbos git config section.
a
yh thanks for pointing out that error
cerbos: error: failed to create store: failed to stat policies: stat //tmp/work/policies/policies: no such file or directory
repo is cloning now but getting the above error
{"log.level":"error","@timestamp":"2023-05-09T112404.816Z","log.logger":"cerbos.git.store","message":"Failed to initialize git store","dir":"//tmp/work/policies","error":"failed to stat policies: stat //tmp/work/policies/policies: no such file or directory"}
c
Remove the
subDir: policies
config line because you don't have a directory named policies in the repo
a
🙌 Thanks @Charith (Cerbos) working now 👍
@Charith (Cerbos) tried to add policy using go sdk
Copy code
{
  "error": "failed to send batch [0,1): rpc error: code = Unimplemented desc = Configured store is not mutable"
}
getting this error
c
You can't add policies to a git store using the Admin API. You have to use the standard git workflow of committing and pushing to the git repository.
a
@Charith (Cerbos) Thanks for the update
some more doubts needs to clarify
we need to view the audit. is there any reference using go sdk?
c
Well, if you use the
local
audit sink, you can query the audit log using the SDK: https://pkg.go.dev/github.com/cerbos/cerbos/client#GrpcAdminClient.AuditLogs. We don't have an example for it though.
a
@Charith (Cerbos) Thank you so much🙌
@Charith (Cerbos) Is multiple git repos supported ?
we have multiple services
c
No, each Cerbos instance is connected to a single repo. Typically people would use a monorepo for the purpose you're describing. If you really must have separate repos, then you could set up a Cerbos instance per repo and put them all behind a proxy with different paths configured for each service-specific Cerbos instance.
The other option is to configure
blob
storage for Cerbos using a S3/GCS bucket and having a CI stage where all your different git repos publish their policies to that bucket.
a
hi @Charith (Cerbos) why this error is coming cerbos: error: failed to create store: failed to clone from https://github.com/an1l4/git-test-cerbos.git to //tmp/work/policies: Get "https://github.com/an1l4/git-test-cerbos.git/info/refs?service=git-upload-pack": context deadline exceeded
c
It's timing out. Probably because of the degraded service from GitHub today. https://www.githubstatus.com/incidents/f0mhbz9xn497