- Running an initial sync from your DB to Oso Cloud.
- Keeping facts up-to-date in production with Oso Sync.
- Configuration for PostgreSQL, MongoDB, and CSV.
- Limitations and best practices.
Sync facts in production
Oso Sync (available on Startup and Growth plans) updates Oso Cloud to match your application database. Typical flow:- Decide how to represent authorization data as facts.
- Run a one-time initial sync to populate Oso Cloud.
- Keep facts in sync using dual writes and periodic reconciliation.
Initial sync with Oso Sync
Oso Sync connects to your data source(s) and runs a configured query for each fact type. Run from the CLI:Configure Oso Sync
Yourreconcile.yaml
maps data sources to fact types. We currently support the following data sources: PostgreSQL, MongoDB, and Comma-separated Values (CSV).
PostgreSQL
version
: optional, defaults to1
.source
: optional, defaults topostgres
.facts
:- Fact type uses positional variables (
_
) that map to query columns in order. db
matches an entry indbs
.query
returns all facts of that type.- Example:
has_relation(Repository:_, String:parent, Organization:_)
has variables in the first and third arguments.repository.public_id
fills the first argument (Repository), andorganization.public_id
fills the third argument (Organization).
- Fact type uses positional variables (
dbs
:- Maps unique names to database connection details.
connection_string
is a PostgreSQL connection URI or an environment variable:connection_string: $ENV_VAR_NAME
.
MongoDB
version
: must be1
.source
: must bemongodb
.facts
:- Fact type uses positional variables (
_
) that map to query columns in order. collection
: name containing fact data.fields
: maps to positional arguments in fact type.- At most one field can have
is_array
: true (automatically unwound
).
- At most one field can have
query
can be either:find
: standard find query.aggregate
: aggregation pipeline (cannot use$out
).- Example:
has_relation(Repository:_, String:parent, Organization:_)
has variables in the first and third arguments.
- Fact type uses positional variables (
dbs
:connection_string
must be a valid MongoDB connection URI or an environment variable:connection_string: $ENV_VAR_NAME
.
Comma-separated Values (CSV)
version
: must be1
.source
: must becsv
.facts
:- Fact type uses positional variables (
_
) that map to query columns in order. fields
: must match the CSV header exactly.- Order must match positional arguments in the fact type.
path
: local path to CSV file.- Example:
has_relation(Repository:_, String:parent, Organization:_)
has variables in the first and third arguments.
- Fact type uses positional variables (
Oso Sync limitations
- At most one Oso Sync command should be run at a time for a given environment. If multiple Oso Sync commands are run in parallel for an environment, you may see HTTP 429 errors.
-
The maximum size of the application data per fact type is 10GB. To synchronize larger data sets, you may consider “sharding” a single fact type across multiple fact type definitions in the YAML configuration by substituting a concrete value for one or more of the arguments.
Before:
After:
- The diff may include transient false positives due to our comparing a point-in-time snapshot of your database to Oso Cloud, which continues to receive changes. Transient false positives should not appear on successive invocations of Oso Sync and do not indicate issues with how your application updates facts in Oso Cloud.
Docker
We publish a wrapped up version of the CLI for Oso Sync atpublic.ecr.aws/osohq/reconcile:latest
.
To use it, build your own image on top of this using a Dockerfile like this:
docker build -t reconcile-tool -f reconcile-tool.Dockerfile --build-arg="CONFIG_PATH=./reconcile.yaml" --platform linux/amd64 .
.