Skip to content
Open
Show file tree
Hide file tree
Changes from 99 commits
Commits
Show all changes
200 commits
Select commit Hold shift + click to select a range
9f82d2e
Enable OAuth2 authentication.
Aug 16, 2024
f02094e
Reformat code by running pre-commit run --all-files
Sep 2, 2024
481dee7
Enable OAuth2 authentication.
Aug 16, 2024
d9e970c
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
b568007
Enable OAuth2 authentication.
Aug 16, 2024
80ba7c8
Reformat code by running pre-commit run --all-files
Sep 2, 2024
4d8d8aa
Enable OAuth2 authentication.
Aug 16, 2024
5ef9717
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
2e868ee
Enable OAuth2 authentication.
Aug 16, 2024
04bece5
Reformat code by running pre-commit run --all-files
Sep 2, 2024
3323c1c
Enable OAuth2 authentication.
Aug 16, 2024
e55b6af
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
7cedece
Enable OAuth2 authentication.
Aug 16, 2024
7546031
Reformat code by running pre-commit run --all-files
Sep 2, 2024
b2935ce
Enable OAuth2 authentication.
Aug 16, 2024
8208408
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
793298c
Enable OAuth2 authentication.
Aug 16, 2024
1197c6f
Reformat code by running pre-commit run --all-files
Sep 2, 2024
a108c57
Enable OAuth2 authentication.
Aug 16, 2024
d73280f
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
d51a7d7
Enable OAuth2 authentication.
Aug 16, 2024
1a1f9d7
Reformat code by running pre-commit run --all-files
Sep 2, 2024
b1b5f6c
Enable OAuth2 authentication.
Aug 16, 2024
9a8759d
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
449dace
Enable OAuth2 authentication.
Aug 16, 2024
7b9681b
Reformat code by running pre-commit run --all-files
Sep 2, 2024
3db635b
Enable OAuth2 authentication.
Aug 16, 2024
2ca7a4e
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
90ec9d3
Enable OAuth2 authentication.
Aug 16, 2024
8fda746
Reformat code by running pre-commit run --all-files
Sep 2, 2024
2445b73
Enable OAuth2 authentication.
Aug 16, 2024
396dd09
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
5687c51
Enable OAuth2 authentication.
Aug 16, 2024
adf1959
Reformat code by running pre-commit run --all-files
Sep 2, 2024
8ddc34f
Enable OAuth2 authentication.
Aug 16, 2024
1259c0f
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
0b0e18e
Enable OAuth2 authentication.
Aug 16, 2024
dbe2c6b
Reformat code by running pre-commit run --all-files
Sep 2, 2024
6c6d855
Enable OAuth2 authentication.
Aug 16, 2024
38f7ee4
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
bc04703
Enable OAuth2 authentication.
Aug 16, 2024
0d17669
Reformat code by running pre-commit run --all-files
Sep 2, 2024
cc6ea2e
Enable OAuth2 authentication.
Aug 16, 2024
492115d
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
3df3a20
Enable OAuth2 authentication.
Aug 16, 2024
316188d
Reformat code by running pre-commit run --all-files
Sep 2, 2024
d1eb15e
Enable OAuth2 authentication.
Aug 16, 2024
419fb3d
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
5b8c6e8
Enable OAuth2 authentication.
Aug 16, 2024
1cfe893
Reformat code by running pre-commit run --all-files
Sep 2, 2024
5064bbc
Enable OAuth2 authentication.
Aug 16, 2024
649cc89
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
8c341f9
Enable OAuth2 authentication.
Aug 16, 2024
51fe585
Reformat code by running pre-commit run --all-files
Sep 2, 2024
9a0bb86
Enable OAuth2 authentication.
Aug 16, 2024
d05688b
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
8860e0a
Enable OAuth2 authentication.
Aug 16, 2024
28014a9
Reformat code by running pre-commit run --all-files
Sep 2, 2024
67c946e
Enable OAuth2 authentication.
Aug 16, 2024
3f0d988
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
c8777bc
Enable OAuth2 authentication.
Aug 16, 2024
9b94120
Reformat code by running pre-commit run --all-files
Sep 2, 2024
01d7e92
Enable OAuth2 authentication.
Aug 16, 2024
30cfd15
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
b25aff4
Enable OAuth2 authentication.
Aug 16, 2024
e53dc1c
Reformat code by running pre-commit run --all-files
Sep 2, 2024
e276b8e
Enable OAuth2 authentication.
Aug 16, 2024
9d821b4
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
6775e60
Enable OAuth2 authentication.
Aug 16, 2024
da3136c
Reformat code by running pre-commit run --all-files
Sep 2, 2024
12cf461
Enable OAuth2 authentication.
Aug 16, 2024
29aa06a
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
e9b6549
Enable OAuth2 authentication.
Aug 16, 2024
dfcbb70
Reformat code by running pre-commit run --all-files
Sep 2, 2024
b6e970e
Enable OAuth2 authentication.
Aug 16, 2024
d6a8793
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
3300ef5
Enable OAuth2 authentication.
Aug 16, 2024
63d14fb
Reformat code by running pre-commit run --all-files
Sep 2, 2024
36bcbc3
Enable OAuth2 authentication.
Aug 16, 2024
130d647
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
0c2496a
Enable OAuth2 authentication.
Aug 16, 2024
fc1e0d8
Reformat code by running pre-commit run --all-files
Sep 2, 2024
a22ce3d
Enable OAuth2 authentication.
Aug 16, 2024
50a08b2
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
e5d4945
Enable OAuth2 authentication.
Aug 16, 2024
6b871cf
Reformat code by running pre-commit run --all-files
Sep 2, 2024
9a6bbac
Enable OAuth2 authentication.
Aug 16, 2024
328a3e4
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
581b790
Enable OAuth2 authentication.
Aug 16, 2024
a0bf603
Reformat code by running pre-commit run --all-files
Sep 2, 2024
db0dbbd
Enable OAuth2 authentication.
Aug 16, 2024
5b2cde8
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
2edf4cd
Enable OAuth2 authentication.
Aug 16, 2024
d4c556d
Reformat code by running pre-commit run --all-files
Sep 2, 2024
d290274
Enable OAuth2 authentication.
Aug 16, 2024
73ceea4
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
2f7d4ff
Enable OAuth2 authentication.
Aug 16, 2024
8bf2732
Merge branch 'master' into fork/ojecborec/oauth2-v2
danyi1212 Jul 16, 2025
78b0d7b
Add trust_env for ClientSession to support proxy connections
danyi1212 Jul 16, 2025
3a7919b
Remove unused tls-cert-refresh-period from requirements
danyi1212 Jul 16, 2025
a03c2ed
Enable OAuth2 authentication.
Aug 16, 2024
ac3ec52
Reformat code by running pre-commit run --all-files
Sep 2, 2024
39cca98
Enable OAuth2 authentication.
Aug 16, 2024
15d2358
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
3ed9ac5
Enable OAuth2 authentication.
Aug 16, 2024
07fa5d3
Reformat code by running pre-commit run --all-files
Sep 2, 2024
988ec66
Enable OAuth2 authentication.
Aug 16, 2024
42028db
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
47917b1
Enable OAuth2 authentication.
Aug 16, 2024
55b295a
Reformat code by running pre-commit run --all-files
Sep 2, 2024
54a5afc
Enable OAuth2 authentication.
Aug 16, 2024
35a3334
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
bb22304
Enable OAuth2 authentication.
Aug 16, 2024
ac12ad6
Reformat code by running pre-commit run --all-files
Sep 2, 2024
2f8f710
Enable OAuth2 authentication.
Aug 16, 2024
83c718b
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
11e38c9
Enable OAuth2 authentication.
Aug 16, 2024
4c5c451
Reformat code by running pre-commit run --all-files
Sep 2, 2024
ace73c6
Enable OAuth2 authentication.
Aug 16, 2024
61a1a88
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
9c8e035
Enable OAuth2 authentication.
Aug 16, 2024
c316010
Reformat code by running pre-commit run --all-files
Sep 2, 2024
dc67665
Enable OAuth2 authentication.
Aug 16, 2024
ed8daf8
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
18226c6
Enable OAuth2 authentication.
Aug 16, 2024
f226dfe
Reformat code by running pre-commit run --all-files
Sep 2, 2024
4b1610b
Enable OAuth2 authentication.
Aug 16, 2024
5b0f634
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
6e11cf7
Enable OAuth2 authentication.
Aug 16, 2024
8ac9d85
Reformat code by running pre-commit run --all-files
Sep 2, 2024
7cd5246
Enable OAuth2 authentication.
Aug 16, 2024
db341a9
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
9bcccc3
Enable OAuth2 authentication.
Aug 16, 2024
7ec2bd7
Reformat code by running pre-commit run --all-files
Sep 2, 2024
3862296
Enable OAuth2 authentication.
Aug 16, 2024
8321a22
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
8ef2bed
Enable OAuth2 authentication.
Aug 16, 2024
c8ed2f2
Reformat code by running pre-commit run --all-files
Sep 2, 2024
76817a5
Enable OAuth2 authentication.
Aug 16, 2024
8f7134c
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
1f813b6
Enable OAuth2 authentication.
Aug 16, 2024
dd4a645
Reformat code by running pre-commit run --all-files
Sep 2, 2024
325cb94
Enable OAuth2 authentication.
Aug 16, 2024
667d2de
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
ec0adef
Enable OAuth2 authentication.
Aug 16, 2024
b962eb0
Reformat code by running pre-commit run --all-files
Sep 2, 2024
2ce69af
Enable OAuth2 authentication.
Aug 16, 2024
8750ed5
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
5f04375
Enable OAuth2 authentication.
Aug 16, 2024
044ca59
Reformat code by running pre-commit run --all-files
Sep 2, 2024
e7cccdb
Enable OAuth2 authentication.
Aug 16, 2024
eacab9a
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
6753e99
Enable OAuth2 authentication.
Aug 16, 2024
d5da478
Reformat code by running pre-commit run --all-files
Sep 2, 2024
2802766
Enable OAuth2 authentication.
Aug 16, 2024
c1090fb
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
0e9a952
Enable OAuth2 authentication.
Aug 16, 2024
aeb3926
Reformat code by running pre-commit run --all-files
Sep 2, 2024
c6310ea
Enable OAuth2 authentication.
Aug 16, 2024
2c3a4a4
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
72069f4
Enable OAuth2 authentication.
Aug 16, 2024
a22d624
Reformat code by running pre-commit run --all-files
Sep 2, 2024
0180923
Enable OAuth2 authentication.
Aug 16, 2024
eb5d6e8
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
f7ae8ae
Enable OAuth2 authentication.
Aug 16, 2024
ce803a9
Reformat code by running pre-commit run --all-files
Sep 2, 2024
4a1b60b
Enable OAuth2 authentication.
Aug 16, 2024
5dadf7a
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
b507696
Enable OAuth2 authentication.
Aug 16, 2024
b590bbf
Reformat code by running pre-commit run --all-files
Sep 2, 2024
a5b1a15
Enable OAuth2 authentication.
Aug 16, 2024
3a3ebb0
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
ace2c64
Enable OAuth2 authentication.
Aug 16, 2024
b376a0e
Reformat code by running pre-commit run --all-files
Sep 2, 2024
af83618
Enable OAuth2 authentication.
Aug 16, 2024
6534756
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
77f45c5
Enable OAuth2 authentication.
Aug 16, 2024
92c845a
Reformat code by running pre-commit run --all-files
Sep 2, 2024
d7c4d98
Enable OAuth2 authentication.
Aug 16, 2024
5e6a5ee
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
487c46c
Enable OAuth2 authentication.
Aug 16, 2024
4360dd8
Reformat code by running pre-commit run --all-files
Sep 2, 2024
ab0e6f7
Enable OAuth2 authentication.
Aug 16, 2024
6662d3c
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
d49dee2
Enable OAuth2 authentication.
Aug 16, 2024
ff28733
Reformat code by running pre-commit run --all-files
Sep 2, 2024
eab0551
Enable OAuth2 authentication.
Aug 16, 2024
25afcc9
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
eddccb9
Enable OAuth2 authentication.
Aug 16, 2024
5476508
Reformat code by running pre-commit run --all-files
Sep 2, 2024
0101066
Enable OAuth2 authentication.
Aug 16, 2024
d73ee76
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
50e3263
Enable OAuth2 authentication.
Aug 16, 2024
f4f4d62
Reformat code by running pre-commit run --all-files
Sep 2, 2024
e5b25e6
Enable OAuth2 authentication.
Aug 16, 2024
548e8a9
Refactor Authenticator to interface and initialize one with provided …
Sep 4, 2024
570888a
Enable OAuth2 authentication.
Aug 16, 2024
2d779af
Enable OAuth2 authentication.
Aug 25, 2025
87e205b
Merge remote-tracking branch 'origin/oauth2-v2' into oauth2-v2
Aug 25, 2025
1fc33ae
Enable OAuth2 authentication.
Aug 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions docker/docker-compose-with-oauth-jwt-token.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
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
# to protect resources with OAuth2 Opaque token provided by dedicated server
- OPAL_AUTH_TYPE=oauth2
# URL to generate new OAuth 2.0 Client Credentials Grant token
- OPAL_OAUTH2_TOKEN_URL=https://example/oauth2/token
# JWT validation
- OPAL_OAUTH2_OPENID_CONFIGURATION_URL=https://example/.well-known/openid-configuration
- OPAL_OAUTH2_EXACT_MATCH_CLAIMS=aud=some_audience,iss=some_issuer
- OPAL_OAUTH2_REQUIRED_CLAIMS=sub,iat,exp
- OPAL_OAUTH2_JWT_ALGORITHM=RS256
- OPAL_OAUTH2_JWT_AUDIENCE=some_audience
- OPAL_OAUTH2_JWT_ISSUER=https://example/issuer
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
# to protect resources with OAuth2 Opaque token provided by dedicated server
- OPAL_AUTH_TYPE=oauth2
# client credentials
- OPAL_OAUTH2_CLIENT_ID=some_client_id
- OPAL_OAUTH2_CLIENT_SECRET=some_client_secret
# URL to generate new OAuth 2.0 Client Credentials Grant token
- OPAL_OAUTH2_TOKEN_URL=https://example/oauth2/token
# JWT validation
- OPAL_OAUTH2_OPENID_CONFIGURATION_URL=https://example/.well-known/openid-configuration
- OPAL_OAUTH2_EXACT_MATCH_CLAIMS=aud=some_audience,iss=some_issuer
- OPAL_OAUTH2_REQUIRED_CLAIMS=sub,iat,exp
- OPAL_OAUTH2_JWT_ALGORITHM=RS256
- OPAL_OAUTH2_JWT_AUDIENCE=some_audience
- OPAL_OAUTH2_JWT_ISSUER=https://example/issuer
# Enable Authorization / Authentication in OPA
- 'OPAL_INLINE_OPA_CONFIG={"authentication":"token", "authorization":"basic", "files": ["authz.rego"]}'
volumes:
# The goal is to create an initial authorization rego that allows OPAL to write the first policy from the POLICY_REPO_URL.
# This is achieved through policy overwrite based on the "id" attribute.
# When the authz.rego file is placed in the root directory of OPA, it is given the id 'authz.rego'.
# Similarly, if there is another authz.rego file in the root of POLICY_REPO_URL, it will also be given the id 'authz.rego'.
# Therefore, if the authz.rego file from the POLICY_REPO_URL exists, it will overwrite the initial authz.rego file.
- ./docker_files/policy_test/authz.rego:/opal/authz.rego
ports:
# exposes opal client on the host machine, you can access the client at: http://localhost:7766
- "7766: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 "exec ./wait-for.sh opal_server:7002 --timeout=20 -- ./start.sh"
83 changes: 83 additions & 0 deletions docker/docker-compose-with-oauth-opaque-token.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
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
# to protect resources with OAuth2 Opaque token provided by dedicated server
- OPAL_AUTH_TYPE=oauth2
# URL to generate new OAuth 2.0 Client Credentials Grant token
- OPAL_OAUTH2_TOKEN_URL=https://example/oauth2/token
# introspect URL for Opaque token validation
- OPAL_OAUTH2_INTROSPECT_URL=https://example/oauth2/introspect
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
# to protect resources with OAuth2 Opaque token provided by dedicated server
- OPAL_AUTH_TYPE=oauth2
# client credentials
- OPAL_OAUTH2_CLIENT_ID=some_client_id
- OPAL_OAUTH2_CLIENT_SECRET=some_client_secret
# URL to generate new OAuth 2.0 Client Credentials Grant token
- OPAL_OAUTH2_TOKEN_URL=https://example/oauth2/token
# introspect URL for Opaque token validation
- OPAL_OAUTH2_INTROSPECT_URL=https://example/oauth2/introspect
# Enable Authorization / Authentication in OPA
- 'OPAL_INLINE_OPA_CONFIG={"authentication":"token", "authorization":"basic", "files": ["authz.rego"]}'
volumes:
# The goal is to create an initial authorization rego that allows OPAL to write the first policy from the POLICY_REPO_URL.
# This is achieved through policy overwrite based on the "id" attribute.
# When the authz.rego file is placed in the root directory of OPA, it is given the id 'authz.rego'.
# Similarly, if there is another authz.rego file in the root of POLICY_REPO_URL, it will also be given the id 'authz.rego'.
# Therefore, if the authz.rego file from the POLICY_REPO_URL exists, it will overwrite the initial authz.rego file.
- ./docker_files/policy_test/authz.rego:/opal/authz.rego
ports:
# exposes opal client on the host machine, you can access the client at: http://localhost:7766
- "7766: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 "exec ./wait-for.sh opal_server:7002 --timeout=20 -- ./start.sh"
4 changes: 2 additions & 2 deletions packages/opal-client/opal_client/callbacks/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from fastapi import APIRouter, Depends, HTTPException, Response, status
from opal_client.callbacks.register import CallbacksRegister
from opal_client.config import opal_client_config
from opal_common.authentication.authenticator import Authenticator
from opal_common.authentication.authz import require_peer_type
from opal_common.authentication.deps import JWTAuthenticator
from opal_common.authentication.types import JWTClaims
from opal_common.authentication.verifier import Unauthorized
from opal_common.logger import logger
Expand All @@ -13,7 +13,7 @@
from starlette.status import HTTP_500_INTERNAL_SERVER_ERROR


def init_callbacks_api(authenticator: JWTAuthenticator, register: CallbacksRegister):
def init_callbacks_api(authenticator: Authenticator, register: CallbacksRegister):
async def require_listener_token(claims: JWTClaims = Depends(authenticator)):
try:
require_peer_type(
Expand Down
39 changes: 15 additions & 24 deletions packages/opal-client/opal_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
import functools
import os
import signal
import tempfile
import uuid
from logging import disable
from typing import Awaitable, Callable, List, Literal, Optional, Union

import aiofiles
Expand All @@ -19,8 +17,8 @@
from opal_client.callbacks.register import CallbacksRegister
from opal_client.config import PolicyStoreTypes, opal_client_config
from opal_client.data.api import init_data_router
from opal_client.data.fetcher import DataFetcher
from opal_client.data.updater import DataUpdater
from opal_client.data.updater_factory import DataUpdaterFactory
from opal_client.engine.options import CedarServerOptions, OpaServerOptions
from opal_client.engine.runner import CedarRunner, OpaRunner
from opal_client.limiter import StartupLoadLimiter
Expand All @@ -31,8 +29,8 @@
from opal_client.policy_store.policy_store_client_factory import (
PolicyStoreClientFactory,
)
from opal_common.authentication.deps import JWTAuthenticator
from opal_common.authentication.verifier import JWTVerifier
from opal_common.authentication.authenticator import Authenticator
from opal_common.authentication.authenticator_factory import AuthenticatorFactory
from opal_common.config import opal_common_config
from opal_common.logger import configure_logs, logger
from opal_common.middleware import configure_middleware
Expand All @@ -51,7 +49,7 @@ def __init__(
inline_opa_options: OpaServerOptions = None,
inline_cedar_enabled: bool = None,
inline_cedar_options: CedarServerOptions = None,
verifier: Optional[JWTVerifier] = None,
authenticator: Optional[Authenticator] = None,
store_backup_path: Optional[str] = None,
store_backup_interval: Optional[int] = None,
offline_mode_enabled: bool = False,
Expand All @@ -70,6 +68,10 @@ def __init__(
data_updater (DataUpdater, optional): Defaults to None.
policy_updater (PolicyUpdater, optional): Defaults to None.
"""
if authenticator is not None:
self.authenticator = authenticator
else:
self.authenticator = AuthenticatorFactory.create()
self._shard_id = shard_id
# defaults
policy_store_type: PolicyStoreTypes = (
Expand Down Expand Up @@ -127,6 +129,7 @@ def __init__(
opal_client_id=opal_client_identifier,
on_connect=on_policy_updater_connect,
on_disconnect=on_policy_updater_disconnect,
authenticator=self.authenticator,
)
else:
self.policy_updater = None
Expand All @@ -142,14 +145,15 @@ def __init__(
else opal_client_config.DATA_TOPICS
)

self.data_updater = DataUpdater(
self.data_updater = DataUpdaterFactory.create(
policy_store=self.policy_store,
data_topics=data_topics,
callbacks_register=self._callbacks_register,
opal_client_id=opal_client_identifier,
shard_id=self._shard_id,
on_connect=on_data_updater_connect,
on_disconnect=on_data_updater_disconnect,
authenticator=self.authenticator,
)
else:
self.data_updater = None
Expand All @@ -172,19 +176,6 @@ def __init__(
"OPAL client is configured to trust self-signed certificates"
)

if verifier is not None:
self.verifier = verifier
else:
self.verifier = JWTVerifier(
public_key=opal_common_config.AUTH_PUBLIC_KEY,
algorithm=opal_common_config.AUTH_JWT_ALGORITHM,
audience=opal_common_config.AUTH_JWT_AUDIENCE,
issuer=opal_common_config.AUTH_JWT_ISSUER,
)
if not self.verifier.enabled:
logger.info(
"API authentication disabled (public encryption key was not provided)"
)
self.store_backup_path = (
store_backup_path or opal_client_config.STORE_BACKUP_PATH
)
Expand Down Expand Up @@ -264,13 +255,13 @@ async def _is_ready(self):
def _configure_api_routes(self, app: FastAPI):
"""Mounts the api routes on the app object."""

authenticator = JWTAuthenticator(self.verifier)

# Init api routers with required dependencies
policy_router = init_policy_router(policy_updater=self.policy_updater)
data_router = init_data_router(data_updater=self.data_updater)
policy_store_router = init_policy_store_router(authenticator)
callbacks_router = init_callbacks_api(authenticator, self._callbacks_register)
policy_store_router = init_policy_store_router(self.authenticator)
callbacks_router = init_callbacks_api(
self.authenticator, self._callbacks_register
)

# mount the api routes on the app object
app.include_router(policy_router, tags=["Policy Updater"])
Expand Down
46 changes: 46 additions & 0 deletions packages/opal-client/opal_client/data/oauth2_updater.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from urllib.parse import parse_qs, urlencode, urlparse

import aiohttp
from aiohttp.client import ClientSession
from opal_client.logger import logger

from .updater import DefaultDataUpdater


class OAuth2DataUpdater(DefaultDataUpdater):
async def _load_policy_data_config(
self, url: str, headers
) -> aiohttp.ClientResponse:
await self._authenticator.authenticate(headers)

async with ClientSession(headers=headers, trust_env=True) as session:
response = await session.get(
url, **self._ssl_context_kwargs, allow_redirects=False
)

if response.status == 307:
return await self._load_redirected_policy_data_config(
response.headers["location"], headers
)
else:
return response

async def _load_redirected_policy_data_config(self, url: str, headers):
redirect_url = self.__redirect_url(url)

logger.info(
"Redirecting to data-sources configuration '{source}'", source=redirect_url
)

async with ClientSession(headers=headers, trust_env=True) as session:
return await session.get(
redirect_url, **self._ssl_context_kwargs, allow_redirects=False
)

def __redirect_url(self, url: str) -> str:
u = urlparse(url)
query = parse_qs(u.query, keep_blank_values=True)
query.pop("token", None)
u = u._replace(query=urlencode(query, True))

return u.geturl()
Loading
Loading