Slackbot
04/18/2023, 1:11 PMShuvy Ankor
04/18/2023, 1:13 PMOded Bd
04/18/2023, 1:31 PMINLINE_OPA_ENABLED=false
?David Hamilton
04/18/2023, 1:31 PMOded Bd
04/18/2023, 1:32 PMDavid Hamilton
04/18/2023, 1:33 PMDavid Hamilton
04/18/2023, 1:51 PMopal_client_1 | 2023-04-18T13:36:50.285126+0000 | 16 | opal_client.opa.runner | INFO | Running OPA inline: opa run --server --addr=:8181 --authentication=off --authorization=off --config-file=/opal/config/config.yaml --log-level=debug
opal_client_1 | 2023-04-18T13:36:50.312097+0000 | 16 | opal_client.opa.logger | INFO | Initializing server. {"addrs": [":8181"], "diagnostic-addrs": [], "time": "2023-04-18T13:36:50Z"}
opal_client_1 | 2023-04-18T13:36:50.313281+0000 | 16 | opal_client.opa.logger | INFO | Starting decision logger. {"plugin": "decision_logs", "time": "2023-04-18T13:36:50Z"}
Not only do I not see decision logs, but I also don't ee the request/response pair when i make a query. However, I see logs like this
opal_client_1 | 2023-04-18T13:46:06.269338+0000 | 16 | opal_client.opa.logger | INFO | Received request. {"client_addr": "127.0.0.1:54582", "req_body": "", "req_id": 2, "req_method": "GET", "req_params": {}, "req_path": "/v1/policies", "time": "2023-04-18T13:46:06Z"}
opal_client_1 | 2023-04-18T13:46:06.270038+0000 | 16 | opal_client.opa.logger | INFO | Sent response. {"client_addr": "127.0.0.1:54582", "req_id": 2, "req_method": "GET", "req_path": "/v1/policies", "resp_body": "{\"result\":[]}\n", "resp_bytes": 14, "resp_duration": 0.7213, "resp_status": 200, "time": "2023-04-18T13:46:06Z"}
Oded Bd
04/18/2023, 1:57 PMdocker-opal_client-1 | 2023-04-18T13:40:26.633528+0000 | 56 | opal_client.opa.logger | INFO | Received request. GET /v1/policies
docker-opal_client-1 | 2023-04-18T13:40:26.635689+0000 | 56 | opal_client.opa.logger | INFO | Sent response. GET /v1/policies -> 200
docker-opal_client-1 | 2023-04-18T13:40:26.649214+0000 | 56 | opal_client.opa.logger | INFO | Received request. PUT /v1/data
docker-opal_client-1 | 2023-04-18T13:40:26.653022+0000 | 56 | opal_client.opa.logger | INFO | Sent response. PUT /v1/data -> 204
docker-opal_client-1 | 2023-04-18T13:40:26.661507+0000 | 56 | opal_client.opa.logger | INFO | Received request. PUT /v1/policies/utils.rego
Oded Bd
04/18/2023, 1:59 PMdocker compose -f docker-compose-example.yml up
without any config changeOded Bd
04/18/2023, 2:05 PMdocker-opal_client-1 | 2023-04-18T14:04:25.406845+0000 | 56 | opal_client.opa.logger | INFO | Sent response. {"client_addr": "172.18.0.1:59754", "req_id": 13, "req_method": "GET", "req_path": "/v1/data/app/rbac", "resp_body": "{\"result\":{\"allow\":false,\"user_is_granted\":[]}}", "resp_bytes": 47, "resp_duration": 19.641375, "resp_status": 200, "time": "2023-04-18T14:04:25Z"}
Oded Bd
04/18/2023, 2:06 PMversion: "3.8"
services:
# When scaling the opal-server to multiple nodes and/or multiple workers, we use
# a *broadcast* channel to sync between all the instances of opal-server.
# Under the hood, this channel is implemented by encode/broadcaster (see link below).
# At the moment, the broadcast channel can be either: postgresdb, redis or kafka.
# The format of the broadcaster URI string (the one we pass to opal server as `OPAL_BROADCAST_URI`) is specified here:
# <https://github.com/encode/broadcaster#available-backends>
broadcast_channel:
image: postgres:alpine
environment:
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
opal_server:
# by default we run opal-server from latest official image
image: permitio/opal-server:latest
environment:
# the broadcast backbone uri used by opal server workers (see comments above for: broadcast_channel)
- OPAL_BROADCAST_URI=<postgres://postgres:postgres@broadcast_channel:5432/postgres>
# number of uvicorn workers to run inside the opal-server container
- UVICORN_NUM_WORKERS=4
# the git repo hosting our policy
# - if this repo is not public, you can pass an ssh key via `OPAL_POLICY_REPO_SSH_KEY`)
# - the repo we pass in this example is *public* and acts as an example repo with dummy rego policy
# - for more info, see: <https://docs.opal.ac/tutorials/track_a_git_repo>
- OPAL_POLICY_REPO_URL=<https://github.com/permitio/opal-example-policy-repo>
# in this example we will use a polling interval of 30 seconds to check for new policy updates (git commits affecting the rego policy).
# however, it is better to utilize a git *webhook* to trigger the server to check for changes only when the repo has new commits.
# for more info see: <https://docs.opal.ac/tutorials/track_a_git_repo>
- OPAL_POLICY_REPO_POLLING_INTERVAL=30
# configures from where the opal client should initially fetch data (when it first goes up, after disconnection, etc).
# the data sources represents from where the opal clients should get a "complete picture" of the data they need.
# after the initial sources are fetched, the client will subscribe only to update notifications sent by the server.
- OPAL_DATA_CONFIG_SOURCES={"config":{"entries":[{"url":"<http://opal_server:7002/policy-data>","topics":["policy_data"],"dst_path":"/static"}]}}
- OPAL_LOG_FORMAT_INCLUDE_PID=true
ports:
# exposes opal server on the host machine, you can access the server at: <http://localhost:7002>
- "7002:7002"
depends_on:
- broadcast_channel
opal_client:
# by default we run opal-client from latest official image
image: permitio/opal-client:latest
environment:
- OPAL_SERVER_URL=<http://opal_server:7002>
- OPAL_LOG_FORMAT_INCLUDE_PID=true
- OPAL_INLINE_OPA_LOG_FORMAT=http
- OPAL_INLINE_OPA_LOG_FORMAT=full
- OPAL_INLINE_OPA_CONFIG={"log_level":"debug"}
ports:
# exposes opal client on the host machine, you can access the client at: <http://localhost:7000>
- "7004:7000"
# exposes the OPA agent (being run by OPAL) on the host machine
# you can access the OPA api that you know and love at: <http://localhost:8181>
# OPA api docs are at: <https://www.openpolicyagent.org/docs/latest/rest-api/>
- "8181:8181"
depends_on:
- opal_server
# this command is not necessary when deploying OPAL for real, it is simply a trick for dev environments
# to make sure that opal-server is already up before starting the client.
command: sh -c "./wait-for.sh opal_server:7002 --timeout=20 -- ./start.sh"
Oded Bd
04/18/2023, 2:06 PMcurl --location --request GET '<http://localhost:8181/v1/data/app/rbac>' \
--data-raw ''
David Hamilton
04/18/2023, 2:07 PMOded Bd
04/18/2023, 2:12 PMDavid Hamilton
04/18/2023, 2:25 PM- OPAL_POLICY_REPO_URL
- OPAL_POLICY_REPO_SSH_KEY
- OPAL_POLICY_REPO_MAIN_BRANCH
and in the client:
- OPAL_POLICY_SUBSCRIPTION_DIRS
David Hamilton
04/18/2023, 2:26 PMOded Bd
04/18/2023, 2:31 PMDavid Hamilton
04/18/2023, 2:33 PMDavid Hamilton
04/18/2023, 6:07 PMOPAL_POLICY_SUBSCRIPTION_DIRS=common:tenant_petshop
and having a util function within the common
directory. I've included a docker-compose and postman collection.
To be clear, this sample DOES work as expected. It is only when I apply my real policies and data that it breaks, so I'll just have to keep digging.David Hamilton
04/18/2023, 6:09 PMDavid Hamilton
04/18/2023, 6:11 PMdata.tenant_petshop.*
for exampleDavid Hamilton
05/12/2023, 6:38 PMopa run --server --log-format json-pretty -c config.yaml ./server -l debug
Then in my docker-compose opal_client env
- OPAL_INLINE_OPA_ENABLED=false
- OPAL_POLICY_STORE_URL=<http://host.docker.internal:8181>
David Hamilton
05/12/2023, 6:39 PM./server
is an empty directory, so I am starting up OPA with no policiesDavid Hamilton
05/12/2023, 6:40 PMOded Bd
05/14/2023, 7:55 AMRo'e Katz
05/14/2023, 8:33 AMDavid Hamilton
05/15/2023, 1:02 PMDavid Hamilton
05/15/2023, 1:05 PMDavid Hamilton
05/15/2023, 1:13 PMGot policy bundle with 49 rego files, 1 data files
Docker stats prior to running any requests
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
9350f5de83e1 bip-baaz-opal-opal_client-1 0.33% 101.4MiB / 1.938GiB 5.11% 390kB / 19.2kB 35.9MB / 0B 15
then after
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
9350f5de83e1 bip-baaz-opal-opal_client-1 0.28% 103.5MiB / 1.938GiB 5.21% 401kB / 550kB 38.2MB / 0B 15
No significant changes to resourcesDavid Hamilton
05/15/2023, 1:41 PMRo'e Katz
05/16/2023, 8:01 AMSent response. PUT …
logs lines where not still being printed?Ro'e Katz
05/16/2023, 8:11 AMopa run --server --log-format json-pretty -c config.yaml ./server -l debug
), does the ./server
directory contain all policies? (that are also stored in your git repo)David Hamilton
05/16/2023, 10:39 AMDavid Hamilton
05/16/2023, 10:40 AMDavid Hamilton
05/16/2023, 10:40 AM