Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
566a40c
feat: include support for incremental sync
JavierCarnelli-ConductorOne Apr 22, 2026
a79d0e0
feat: add primary_key to resource-level incremental_sync pagination i…
JavierCarnelli-ConductorOne Apr 22, 2026
f1c9e74
fix: guard earliestEvent lower-bound to committed cursors only in eve…
JavierCarnelli-ConductorOne Apr 22, 2026
cff220b
fix: address review bugs in incremental sync implementation
JavierCarnelli-ConductorOne Apr 23, 2026
2d9eded
fix: address review feedback on incremental sync implementation
JavierCarnelli-ConductorOne Apr 23, 2026
28c9e4e
fix: address PR comments
JavierCarnelli-ConductorOne Apr 23, 2026
695c81a
test: add tests for event feed incremental sync
JavierCarnelli-ConductorOne Apr 28, 2026
f5e1226
fix: address PR comments on sql_syncer Get method
JavierCarnelli-ConductorOne May 1, 2026
caf49c6
refactor: rename incremental_sync config to event_feed
JavierCarnelli-ConductorOne Nov 11, 2026
10d89e7
refactor: rename get query placeholder ?<id> to ?<resource_id>
JavierCarnelli-ConductorOne Nov 11, 2026
c33b364
refactor: build resource syncers once and log failures at error level
JavierCarnelli-ConductorOne Nov 11, 2026
4813715
fix: require pagination on event feed queries and guard nil pagination
JavierCarnelli-ConductorOne Nov 11, 2026
4ad2f4a
fix: re-read an overlap window in the event feed and order rows stably
JavierCarnelli-ConductorOne Nov 11, 2026
077423f
fix: include the entitlement ID in grant and revoke event IDs
JavierCarnelli-ConductorOne Nov 11, 2026
8385e9c
fix: keep expandable annotations on event feed grants
JavierCarnelli-ConductorOne Nov 11, 2026
7e32e4d
fix: return Unimplemented from Get when no get query is configured
JavierCarnelli-ConductorOne Nov 11, 2026
94ee628
fix: allow only offset pagination for event feed queries
JavierCarnelli-ConductorOne Nov 11, 2026
15cbd40
Merge branch 'main' into feat/CXH-1390
JavierCarnelli-ConductorOne Nov 11, 2026
0667867
fix: fail event feed polls when the cursor column is missing
JavierCarnelli-ConductorOne Nov 11, 2026
edfd9ea
fix: compile the grants event feed resource_id expression at startup
JavierCarnelli-ConductorOne Nov 11, 2026
5b62739
fix: parse event feed cursor values with the database engine and acce…
JavierCarnelli-ConductorOne Nov 11, 2026
9b3b8ed
docs: note that event feeds and get only query the primary database
JavierCarnelli-ConductorOne Nov 16, 2026
3745cfc
fix: require ?<Offset> in event feed queries
JavierCarnelli-ConductorOne Nov 16, 2026
8247b6b
refactor: build resource syncers in New and give the event feed its o…
JavierCarnelli-ConductorOne Nov 16, 2026
ea155a9
CXP-1395 Make the event feed examples runnable and keep revokes consi…
JavierCarnelli-ConductorOne Nov 23, 2026
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
7 changes: 7 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,10 @@ jobs:
psql -h localhost --user postgres -d batondb -t -c "SELECT attr_first_name, attr_job_title FROM users WHERE username = 'jane.doe'" | grep -q "Janet.*Senior Software Engineer"
env:
PGPASSWORD: secretpassword
# Uses the baton CLI that the sync-test action installs.
- name: Run event feed smoke test
run: test/event_feed_smoke.sh postgres
env:
PGPASSWORD: secretpassword
CHANGED_USER: jane.doe
SQL_CMD: psql -h localhost --user postgres -d batondb -t -A
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,39 @@ connect:
SELECT datname FROM pg_database WHERE datistemplate = false
```

When `databases` is set, each `list:` / `entitlements:` / `grants:` block runs once per database. Add `scope: cluster` to a query that should only run once (against the lexicographically first database), useful for catalogs that return the same data from any database, like `pg_user`. The active database name is injected into every row as the synthetic column `database`, so `map:` blocks and `skip_if` expressions can reference `.database`. Provisioning queries route to the database named by the `database` provisioning var, falling back to the primary handle when unset.
When `databases` is set, each `list:` / `entitlements:` / `grants:` block runs once per database. Add `scope: cluster` to a query that should only run once (against the lexicographically first database), useful for catalogs that return the same data from any database, like `pg_user`. The active database name is injected into every row as the synthetic column `database`, so `map:` blocks and `skip_if` expressions can reference `.database`. Provisioning queries route to the database named by the `database` provisioning var, falling back to the primary handle when unset. Event feed and `get` queries run only against the primary database; see [Event Feed](#event-feed).

Single-database configurations are unchanged. The `databases` block is opt-in and existing examples (`postgres-test.yml`, `mysql-test.yml`, etc.) continue to work identically.

### Event Feed

Resource types and grants queries can define an `event_feed` section so ConductorOne picks up changes between full syncs. Each event feed query:

- Must use `?<since>`, which the connector fills with the last processed timestamp minus the `event_feed.overlap` window (default `60s`).
- Should filter with `>= ?<since>` and order by the cursor column plus the pagination primary key (for example `ORDER BY updated_at, id`), so rows that share a timestamp are paged in a stable order.
- Must configure `pagination` with `strategy: "offset"` and a `primary_key`, and use `?<Limit>` and `?<Offset>`. The `cursor` strategy is not allowed, because a primary-key cursor cannot resume a query ordered by timestamp.

The overlap window re-reads recent rows so rows with tied or late-committed timestamps are not missed. Re-read rows produce the same event IDs, and ConductorOne ignores the duplicates. Resource types with an `event_feed` also need a `get` query that uses `?<resource_id>`. See [`examples/example.yml`](examples/example.yml) for a complete configuration.

The cursor column (for example `updated_at`) must change on every insert and update, including updates made by provisioning and actions. Use a trigger or an `ON UPDATE` default; otherwise every writer has to set it explicitly.

#### Grant revokes and soft deletes

A grants `event_feed` reports revokes through `revokes_query`, which can only see rows that are soft-deleted (for example, rows with a `deleted_at` timestamp). A hard `DELETE` leaves nothing to read, so the revoke is only picked up at the next full sync. If your table hard-deletes, add a soft-delete column or an audit table filled by a trigger. When you configure `revokes_query`:

- The full-sync grants `query` must exclude soft-deleted rows (for example `WHERE deleted_at IS NULL`). Otherwise every full sync restores the grants the feed revoked.
- Revoke provisioning must soft-delete the row (set `deleted_at` and `updated_at`) instead of deleting it.
- Grant provisioning must revive a soft-deleted row (clear `deleted_at`, update `updated_at`) instead of inserting a duplicate or doing nothing.

The test examples (`postgres-test.yml`, `sqlserver-test.yml`, `mysql-test.yml`, `vertica-test.yml`) follow these rules, and `test/event_feed_smoke.sh` checks them against the matching `test/*-init.sql` database.

**Multi-database limitation:** event feed queries and `get` queries run only against the primary database (the lexicographically first one), even when `connect.databases` is configured. Full syncs still cover every database, but between full syncs:

- Changes in any other database produce no events.
- `get` returns NotFound for resources that live only in another database.

Changes in non-primary databases are picked up at the next full sync. Avoid `event_feed` with `connect.databases` unless all event-relevant data lives in the primary database.

## `baton-sql` Command Line Usage
```
Usage:
Expand Down
6 changes: 5 additions & 1 deletion baton_capabilities.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@
},
"capabilities": [
"CAPABILITY_SYNC",
"CAPABILITY_TARGETED_SYNC",
"CAPABILITY_PROVISION"
],
"permissions": {}
}
],
"connectorCapabilities": [
"CAPABILITY_PROVISION",
"CAPABILITY_SYNC"
"CAPABILITY_SYNC",
"CAPABILITY_TARGETED_SYNC",
"CAPABILITY_EVENT_FEED_V2",
"CAPABILITY_SERVICE_MODE_TARGETED_SYNC"
],
"credentialDetails": {}
}
192 changes: 121 additions & 71 deletions examples/example.yml
Comment thread
JavierCarnelli-ConductorOne marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# Connector Configuration Reference
# ===============================
# ===================================
# This is a reference configuration demonstrating all available options
# and their purposes in a connector configuration file.

Expand All @@ -10,7 +10,7 @@ app_name: Example Application
# Connection Configuration
# ----------------------
# Specifies how to connect to the data source. Supports various connection methods.
#
#
# RECOMMENDED: Use structured fields!
connect:
scheme: "mysql"
Expand All @@ -32,135 +32,185 @@ connect:
# connect:
# dsn: "mysql://${DB_USER}:${DB_PASS}@${DB_HOST}:3306/${DB_NAME}?parseTime=true"

# Event Feed Settings (Optional)
# ------------------------------
# Global settings for the event feed (incremental change detection).
# When any resource type or grants query has event_feed configured, the connector
# automatically exposes an EventFeed to ConductorOne for efficient change detection.
#
# Each poll re-reads rows from `overlap` before the last committed timestamp, so rows that share
# a timestamp or commit late are not missed. Re-read rows produce the same event IDs and are
# de-duplicated by ConductorOne. Event feed queries should filter with `>= ?<since>` and order by
# the cursor column plus the pagination primary key, so offset paging is stable.
event_feed:
default_lookback: 3h # How far back to look on first run; any Go duration string
overlap: 60s # How far before the committed cursor each poll starts; defaults to 60s

# Resource Types
# -------------
# Defines the resources that can be synchronized from the data source.
# Each resource type represents a distinct entity type (e.g., users, groups, roles).
resource_types:

# Example User Resource
# -------------------
# ---------------------
user:
name: "User" # Display name for this resource type
name: "User"
description: "Represents a user account in the system"

# Targeted Sync — Get Query
# -------------------------
# Fetches a single resource by ID. Required when event_feed is configured
# on this resource type. Uses the same list.map for column mapping.
get:
query: |
SELECT id, username, email, created_at, status, department, updated_at
FROM users
WHERE id = ?<resource_id>

# List Configuration
# ----------------
# Defines how to retrieve a list of resources
# ------------------
# Defines how to retrieve a paginated list of resources.
list:
# SQL query to fetch resources. Supports multiple query types:
# - Direct SQL queries
# - Stored procedure calls
# - Complex joins and subqueries
query: |
SELECT
SELECT
id,
username,
email,
created_at,
status,
department
department,
updated_at
FROM users
WHERE status = 'active'
AND id > ?<Cursor>
WHERE id > ?<Cursor>
ORDER BY id ASC
LIMIT ?<Limit>

# Mapping Configuration
# -------------------
# Defines how to transform raw data into standardized resource objects
map:
# Required Fields
# --------------
# These fields are required for all resources
id: ".id" # Maps the 'id' column to the resource ID
display_name: ".username" # Human-readable name
description: "string(.department) + ' department user'" # Can use CEL expressions

# Optional Traits
# --------------
# Custom attributes specific to this resource type
id: ".id"
display_name: ".username"
description: "string(.department) + ' department user'"
traits:
user:
# The trait name defines the schema
emails:
# Array fields
- ".email" # Direct field mapping
- "lowercase(.email)" # CEL transformation
status: ".status" # Simple field mapping
- ".email"
status: ".status"
profile:
department: ".department"
joined_date: ".created_at"
# Complex CEL transformation example
full_name: "titleCase(.first_name) + ' ' + titleCase(.last_name)"
pagination:
strategy: "cursor"
primary_key: "id"

# Pagination Configuration
# ----------------------
# Defines how to handle large result sets
# Resource Event Feed
# -------------------
# Detects new/modified resources via timestamp filtering. Emits a ResourceChangeEvent
# per row; C1 then calls the get query above to re-fetch the full resource.
# ?<since> is automatically injected with the cursor timestamp for this source.
event_feed:
query: |
SELECT id, username, email, created_at, status, department, updated_at
FROM users
WHERE updated_at >= ?<since>
ORDER BY updated_at ASC, id ASC
LIMIT ?<Limit> OFFSET ?<Offset>
cursor_column: updated_at # Column whose max value advances this source's cursor
pagination:
strategy: "cursor" # Options: "cursor", "offset"
primary_key: "id" # Column used for pagination tracking
strategy: offset
primary_key: id

# Static Entitlements
# ------------------
# Pre-defined permissions that can be granted
# -------------------
# Pre-defined permissions that can be granted.
static_entitlements:
- id: "access" # Unique identifier for this entitlement
- id: "access"
display_name: "Basic Access"
description: "Provides basic access to the application"
purpose: "access" # Purpose: "access", "assignment", "permission"
purpose: "assignment"
grantable_to:
# Resource types that can receive this entitlement
- "user"
- "service_account"
# Provisioning Configuration
# ------------------------
# Defines how to implement entitlement changes
provisioning:
vars:
# Variables available in provisioning queries
user_id: "principal.ID"
access_level: "'basic'"

# Grant Operations
# ---------------
# Grant revives a soft-deleted row, or inserts a new one. Upsert syntax depends on
# the database (e.g. ON CONFLICT in PostgreSQL, MERGE in SQL Server or Oracle).
grant:
# SQL statements to execute when granting
queries:
- |
UPDATE user_access
SET deleted_at = NULL, updated_at = CURRENT_TIMESTAMP
WHERE user_id = ?<user_id> AND level = ?<access_level> AND deleted_at IS NOT NULL
- |
INSERT INTO user_access (user_id, level)
VALUES (?<user_id>, ?<access_level>)

# Revoke Operations
# ----------------
SELECT ?<user_id>, ?<access_level> FROM DUAL
WHERE NOT EXISTS (
SELECT 1 FROM user_access WHERE user_id = ?<user_id> AND level = ?<access_level>
Comment on lines +145 to +150

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Suggestion (medium confidence): The grant queries read and write a level column on user_access, but the full-sync grants query and both event-feed queries select access_level from that same table (lines 168, 192, 205). Only one of these names can match a real schema, so this reference example will fail on either grant or sync if copied as-is. Pick one column name and use it in all of these queries.

)
# Revoke soft-deletes so the grants event feed's revokes_query can report it.
revoke:
# SQL statements to execute when revoking
queries:
- |
DELETE FROM user_access
WHERE user_id = ?<user_id>
UPDATE user_access
SET deleted_at = CURRENT_TIMESTAMP, updated_at = CURRENT_TIMESTAMP
WHERE user_id = ?<user_id> AND deleted_at IS NULL

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Suggestion (medium confidence): The revoke is scoped by user_id only, but grant and the grants map scope by level = 'basic'. If a user has more than one live user_access row, this UPDATE either soft-deletes the non-basic rows too, which then show up as revokes in the event feed, or affects more than one row and fails with ErrQueryAffectedMoreThanOneRow (pkg/bsql/query.go:811). Add AND level = ?<access_level> (or the matching column) to keep revoke symmetric with grant.


# Grants Query Configuration
# ------------------------
# Defines how to discover existing entitlements
# --------------------------
# Defines how to discover existing entitlement assignments.
grants:
- query: |
SELECT
SELECT
id AS grant_id,
user_id,
access_level,
granted_at
updated_at
FROM user_access
WHERE deleted_at IS NULL
LIMIT ?<Limit> OFFSET ?<Offset>

# Grant Mapping
# ------------
# Defines how to interpret grant query results
map:
- skip_if: ".access_level != 'basic'" # CEL condition to filter results
- skip_if: ".access_level != 'basic'"
principal_id: ".user_id"
principal_type: "user"
entitlement_id: "access"
# Grants Pagination
# ----------------
pagination:
strategy: "offset"
primary_key: "user_id"
# Example: groups, roles, applications, etc.
primary_key: "grant_id"

# Grants Event Feed
# -----------------
# Detects new and revoked grants without a full re-sync.
# The parent map is reused for row-to-grant mapping.
# NOTE: CEL expressions in map must not reference resource trait fields
# (display_name, description, etc.) in this context — only row columns are available.
event_feed:
resource_id: ".user_id" # CEL expr: extracts resource ID from each row
# (required — event feed queries span ALL resources)
changes_query: |
SELECT id AS grant_id, user_id, access_level, updated_at
FROM user_access
WHERE deleted_at IS NULL
AND updated_at >= ?<since>
ORDER BY updated_at ASC, id ASC
LIMIT ?<Limit> OFFSET ?<Offset>
# updated_at must change on every insert and update (a trigger or ON UPDATE default).
changes_cursor_column: updated_at

# Optional: only configure when the table soft-deletes rows. Hard deletes can't be
# detected. When set, the full-sync grants query must exclude soft-deleted rows, revoke
# must soft-delete, and grant must revive a soft-deleted row (see provisioning above).
revokes_query: |
SELECT id AS grant_id, user_id, access_level, deleted_at
FROM user_access
WHERE deleted_at >= ?<since>
ORDER BY deleted_at ASC, id ASC
LIMIT ?<Limit> OFFSET ?<Offset>
revokes_cursor_column: deleted_at

pagination:
strategy: offset
primary_key: grant_id # Must be present in both changes_query and revokes_query SELECTs

# Example: add groups, roles, applications, etc. following the same pattern.
Loading
Loading