Slackbot
07/15/2023, 10:05 AMAsaf Cohen
07/15/2023, 10:49 AMOPAL_INLINE_OPA_CONFIG
variableAsaf Cohen
07/15/2023, 10:49 AMOscar
07/15/2023, 2:06 PM2023-07-15T14:46:24.432789+0000 | 15 | fastapi_websocket_rpc.websocket_rpc_c...| INFO | Trying server - <ws://opal_server:7002/ws>
2023-07-15T14:46:24.492944+0000 | 15 | opal_client.policy.updater | INFO | Connected to server
2023-07-15T14:46:24.493178+0000 | 15 | opal_client.policy.updater | INFO | Refetching policy code (full bundle)
2023-07-15T14:46:24.493437+0000 | 15 | opal_client.policy.fetcher | INFO | Fetching policy bundle from <http://opal_server:7002/policy>
2023-07-15T14:46:24.518211+0000 | 15 | opal_client.policy.fetcher | INFO | Fetched valid bundle, id: 94c88a2bba339947b0e76f0afb7d5d102cb44788
2023-07-15T14:46:24.518649+0000 | 15 | opal_client.policy.updater | INFO | Got policy bundle with 2 rego files, 1 data files, commit hash: '94c88a2bba339947b0e76f0afb7d5d102cb44788'
2023-07-15T14:46:24.521674+0000 | 15 | opal_client.policy_store.opa_client |WARNING | Opa connection error: ContentTypeError(RequestInfo(url=URL('<http://localhost:8181/v1/policies>'), method='GET', headers=<CIMultiDictProxy('Host': 'localhost:8181', 'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'User-Agent': 'Python/3.10 aiohttp/3.8.4')>, real_url=URL('<http://localhost:8181/v1/policies'))>, (), message='Attempt to decode JSON with unexpected mimetype: ', headers=<CIMultiDictProxy()>)
2023-07-15T14:46:26.528447+0000 | 15 | opal_client.policy_store.opa_client |WARNING | Opa connection error: ContentTypeError(RequestInfo(url=URL('<http://localhost:8181/v1/policies>'), method='GET', headers=<CIMultiDictProxy('Host': 'localhost:8181', 'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'User-Agent': 'Python/3.10 aiohttp/3.8.4')>, real_url=URL('<http://localhost:8181/v1/policies'))>, (), message='Attempt to decode JSON with unexpected mimetype: ', headers=<CIMultiDictProxy()>)
2023-07-15T14:46:26.529665+0000 | 15 | opal_client...base_policy_store_client |ERROR | OPA transaction failed, transaction id=94c88a2bba339947b0e76f0afb7d5d102cb44788, actions=['set_policies'], error=RetryError(<Future at 0x7f413af86890 state=finished raised ContentTypeError>)
2023-07-15T14:46:26.534528+0000 | 15 | fastapi_websocket_rpc.websocket_rpc_c...| INFO | Connection was terminated.
2023-07-15T14:46:26.534858+0000 | 15 | fastapi_websocket_rpc.websocket_rpc_c...| INFO | Closing RPC client
2023-07-15T14:46:26.535486+0000 | 15 | opal_client.policy.updater | INFO | Disconnected from server
2023-07-15T14:46:26.536081+0000 | 15 | fastapi_websocket_rpc.websocket_rpc_c...|ERROR | RPC Error
Traceback (most recent call last):
Oscar
07/15/2023, 3:15 PM2023-07-15T14:28:07.670527+0000 | 15 | fastapi_websocket_rpc.websocket_rpc_c...|ERROR | RPC Error
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/tenacity/_asyncio.py", line 50, in __call__
result = await fn(*args, **kwargs)
│ │ └ {}
│ └ (<opal_client.policy_store.opa_client.OpaClient object at 0x7f86f9045a80>,)
└ <function OpaClient.get_policies at 0x7f86f9017760>
File "/usr/local/lib/python3.10/site-packages/opal_client-0.7.3-py3.10.egg/opal_client/policy_store/opa_client.py", line 508, in get_policies
result = await opa_response.json()
│ └ <function ClientResponse.json at 0x7f86f95335b0>
└ <ClientResponse(<http://localhost:8181/v1/policies>) [400 Bad Request]>
<CIMultiDictProxy()>
File "/usr/local/lib/python3.10/site-packages/aiohttp/client_reqrep.py", line 1104, in json
raise ContentTypeError(
└ <class 'aiohttp.client_exceptions.ContentTypeError'>
aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: ', url=URL('<http://localhost:8181/v1/policies>')
The above exception was the direct cause of the following exception:
It looks like the OPAL still calling http to connect OPA, not https.Or Weis
07/15/2023, 3:33 PMOr Weis
07/15/2023, 3:34 PMOscar
07/16/2023, 2:27 AMopa-opal_client-1 | 2023-07-16T03:38:40.751134+0000 | 14 | fastapi_websocket_rpc.websocket_rpc_c...| INFO | Trying server - <wss://opal_server:7002/ws>
opa-opal_server-1 | 2023-07-16T03:38:40.758776+0000 | 11 | uvicorn.protocols.http.httptools_impl |WARNING | Invalid HTTP request received.
opa-opal_client-1 | 2023-07-16T03:38:40.760194+0000 | 14 | fastapi_websocket_rpc.websocket_rpc_c...| INFO | RPC Connection failed - [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1007)
Are the command incorrect? I copied them from the example.
openssl req -x509 -newkey rsa:4096 -nodes -keyout server.key -out server.crt -days 365
openssl req -newkey rsa:4096 -nodes -keyout client.key -out client.csr
openssl x509 -req -in client.csr -CA server.crt -CAkey server.key -CAcreateserial -out client.crt -days 365
permit support automation2
07/16/2023, 2:28 AMAsaf Cohen
07/16/2023, 7:05 AMOscar
07/16/2023, 7:13 AM[opa@ypvirtualserver06 opa]$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
permitio/opal-server latest 6e07435c5b51 2 weeks ago 442MB
permitio/opal-client latest dc657b771347 2 weeks ago 398MB
I use docker compose to install the OPAL. All version are the latest.Oscar
07/16/2023, 7:14 AMimage: permitio/opal-server:latest
image: permitio/opal-client:latest
Oscar
07/16/2023, 7:15 AMAsaf Cohen
07/16/2023, 7:17 AMAsaf Cohen
07/16/2023, 7:21 AMAsaf Cohen
07/16/2023, 7:21 AMOscar
07/16/2023, 7:24 AMopenssl genrsa -out private.key 2048
openssl req -new -x509 -sha256 -key private.key -out public.crt -days 365
This is for OPAL
openssl req -x509 -newkey rsa:4096 -nodes -keyout server.key -out server.crt -days 365
openssl req -newkey rsa:4096 -nodes -keyout client.key -out client.csr
openssl x509 -req -in client.csr -CA server.crt -CAkey server.key -CAcreateserial -out client.crt -days 365
I set up TLS for both OPA and OPAL.Oscar
07/16/2023, 7:29 AM[opa@ypvirtualserver06 opa]$ curl <http://localhost:8181/>
Client sent an HTTP request to an HTTPS server.
[opa@ypvirtualserver06 opa]$ curl -k <https://localhost:8181/v1/data>
{"result":{}}
[opa@ypvirtualserver06 opa]$
[opa@ypvirtualserver06 opa]$ curl <https://localhost:7002/>
curl: (35) SSL received a record that exceeded the maximum permissible length.
[opa@ypvirtualserver06 opa]$ curl <http://localhost:7002/>
{"status":"ok"}
[opa@ypvirtualserver06 opa]$ curl <https://localhost:7766/>
curl: (35) SSL received a record that exceeded the maximum permissible length.
[opa@ypvirtualserver06 opa]$ curl <http://localhost:7766/>
{"status":"unavailable"}
It looks the OPA is running as HTTPS. But the OPAL server and client are not correct.Asaf Cohen
07/16/2023, 10:47 AMAsaf Cohen
07/16/2023, 10:47 AMAsaf Cohen
07/16/2023, 10:47 AMRo'e Katz
07/17/2023, 3:03 PMOPAL_INLINE_OPA_CONFIG
.
But you also have to make OPAL use TLS when connecting to OPA - this is a relatively new feature.
To use it, set OPAL_POLICY_STORE_AUTH_TYPE=tls
and then set POLICY_STORE_TLS_CLIENT_CERT
, POLICY_STORE_TLS_CLIENT_KEY
& POLICY_STORE_TLS_CA
accordingly (all of which expect paths to files).
But please notice that if you use OPA inline - there’s no real need to secure its connection with OPAL (they’re running in the same container),
unless of course you have other consumers of OPA which communicate over the internet - in that case, setting TLS for OPA makes sense.
Secure the connection between OPAL client & OPAL server
I think there’s some kind of confusion here - OPAL server doesn’t support TLS.
(We never bothered because so far users either deployed both the server & client in the same cloud environment (thus securing the connection isn’t that crucial, or can be achieved by some kind of service mesh),
Or they deployed the client & server on different environments, but the server’s TLS is terminated by some kind of external load balancer (which is usually much more convenient because it handles TLS with the right certificates for multiple services under the same domain).
For that second scenario, the client supports enabling self-signed certificates or configuring a custom CA.)
However, OPAL server does support secure mode in which clients are being authenticated. to use that feature please refer to this manual, and this example script
Hope that helps, Let us know if you have further questions (I would advice trying out those features one by one rather than at the same time!)Oscar
07/18/2023, 1:08 AMpermit support automation2
07/18/2023, 1:08 AM