ANILA SOMAN
12/08/2022, 12:18 PMoguzhan
12/08/2022, 12:27 PMANILA SOMAN
12/08/2022, 12:47 PMversion: "3.9"
services:
cerbos:
container_name: cerbos
image: <http://ghcr.io/cerbos/cerbos:latest|ghcr.io/cerbos/cerbos:latest>
restart: always
command: ["server", "--config=/config/conf.yaml", "--log-level=warn"]
volumes:
- ./cerbos/config:/config
- ./cerbos/policies:/policies
depends_on:
- postgresd
ports:
- 3592:3592
- 3593:3593
networks:
- intranet
postgresd:
image: postgres:latest
ports:
- "5432:5432"
volumes:
- ./pg-init-scripts:/docker-entrypoint-initdb.d
environment:
- POSTGRES_USER=core
- POSTGRES_PASSWORD=core
networks:
- intranet
# pgadmin:
# image: dpage/pgadmin4
# container_name: pgadmin
# restart: "no"
# volumes:
# - pgadmin:/var/lib/pgadmin
# environment:
# - PGADMIN_DEFAULT_EMAIL=core@example.com
# - PGADMIN_DEFAULT_PASSWORD=core
# ports:
# - "5433:80"
# networks:
# - intranet
admin-api:
container_name: admin-api
build: .
environment:
- CERBOS_HOST=cerbos
ports:
- 8080:8080
depends_on:
- cerbos
networks:
- intranet
networks:
intranet:
volumes:
pgadmin:
name: vol-pgadmin
Charith (Cerbos)
12/08/2022, 12:57 PMcerbos
schema?
Also, from your screenshot, it looks like there was some error that postgres tried to recover from. Maybe the database is corrupt? I'd try clearing the storage volume and restarting the containers.ANILA SOMAN
12/09/2022, 4:32 AMCharith (Cerbos)
12/09/2022, 4:36 AMcerbos
? You can do that. Just remember to change the search_path
parameter in the connection URL you provide to Cerbos in its configuration file.foo
, the config should look like the following
storage:
driver: "postgres"
postgres:
url: "postgres://${PG_USER}:${PG_PASSWORD}@localhost:5432/postgres?sslmode=disable&search_path=foo"
ANILA SOMAN
12/09/2022, 4:52 AMfunc AddPolicy(datas *model.CerbosPayload, cli client.AdminClient, g *gin.Context) {
response := model.Response{}
responses := []model.Response{}
for _, data := range datas.Policies {
for _, policy := range data.ResourcePolicy.Rules {
ps := client.PolicySet{}
actions := policy.Actions
rr1 := client.NewAllowResourceRule(actions...).WithRoles(policy.Roles)
resource := data.ResourcePolicy.Resource
resourcePolicy := client.NewResourcePolicy(resource, "default").AddResourceRules(rr1)
// resourcePolicy.WithScope(data.ResourcePolicy.Scope)
policySet := ps.AddResourcePolicies(resourcePolicy)
err := cli.AddOrUpdatePolicy(context.Background(), policySet)
if err != nil {
response = model.Response{
Response: "",
Errors: err.Error(),
}
responses = append(responses, response)
}
response = model.Response{
Response: fmt.Sprintf("response : %+v", policySet.GetPolicies()),
Errors: "",
}
responses = append(responses, response)
}
}
g.JSON(200, gin.H{
"Check Responses": responses,
})
}
func CheckPolicy(datas *model.CerbosPayload, cli client.Client, g *gin.Context) {
response := model.Response{}
responses := []model.Response{}
for _, data := range datas.Policies {
for _, policy := range data.ResourcePolicy.Rules {
principal := client.NewPrincipal(uuid.NewString(), policy.Roles)
// principal.WithScope(data.ResourcePolicy.Scope)
resource := data.ResourcePolicy.Resource
actions := policy.Actions
r1 := client.NewResource(resource, uuid.NewString())
batch := client.NewResourceBatch()
batch.Add(r1, actions...)
resp, err := cli.CheckResources(context.Background(), principal, batch)
if err != nil {
log.Fatalf("Failed to check resources: %v", err)
response = model.Response{
Response: "",
Errors: err.Error(),
}
responses = append(responses, response)
}
response = model.Response{
Response: fmt.Sprintf("response : %v", resp),
Errors: "",
}
responses = append(responses, response)
}
}
g.JSON(200, gin.H{
"Check Responses": responses,
})
}
Charith (Cerbos)
12/09/2022, 4:58 AMpsql
, can you run \dt cerbos.*
and paste the output here?ANILA SOMAN
12/09/2022, 5:09 AMCharith (Cerbos)
12/09/2022, 5:17 AMdb.sh
to db.sql
and restart Docker ComposeANILA SOMAN
12/09/2022, 5:17 AMCharith (Cerbos)
12/09/2022, 5:31 AMdocker-compose restart cerbos
. It looks like the database is taking longer to initialize.ANILA SOMAN
12/09/2022, 5:34 AMCharith (Cerbos)
12/09/2022, 5:35 AMcompose
is a subcommand of docker
. My bad.ANILA SOMAN
12/09/2022, 5:36 AMCharith (Cerbos)
12/09/2022, 5:45 AMcore
, the default database is named core
as well. Therefore, you need to change the connection URL to use the core
database like this:
storage:
driver: "postgres"
postgres:
url: "<postgres://core:core@postgresd:5432/core?sslmode=disable&search_path=cerbos>"
ANILA SOMAN
12/12/2022, 7:27 AMCharith (Cerbos)
12/12/2022, 8:08 AMdocker compose restart cerbos
. But, a better way is to add a healthcheck to postgres like this:
version: "3.9"
services:
postgresd:
image: postgres:latest
ports:
- 5432:5432
volumes:
- ./db:/docker-entrypoint-initdb.d
environment:
- POSTGRES_USER=core
- POSTGRES_PASSWORD=core
healthcheck:
test: ["CMD-SHELL", "pg_isready --username=core"]
interval: 10s
timeout: 5s
retries: 5
cerbos:
image: <http://ghcr.io/cerbos/cerbos:latest|ghcr.io/cerbos/cerbos:latest>
command: ["server", "--config=/conf/cerbos.yaml"]
volumes:
- ./conf:/conf
ports:
- 3592:3592
- 3593:3593
depends_on:
- postgresd
restart: on-failure
ANILA SOMAN
12/12/2022, 8:11 AMCharith (Cerbos)
12/23/2022, 7:09 AM