Skip to content
ConductorOnePublic

About

No description, website, or topics provided.

Resources

Code of conduct

Stars

1 star

Watchers

7 watching

Forks

Latest commit

 

History

634 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Baton Logo

baton-sql Go Reference ci verify

baton-sql is a connector for built using the Baton SDK.

Overview

baton-sql is a flexible connector that enables you to sync identities, resources, and permissions from SQL databases. It provides a powerful configuration system that allows you to map database queries to resources and entitlements, with full support for account provisioning and automated password management.

Key Features

  • Multi-Database Support: Works with a range of SQL engines (see Supported Database Engines below)
  • Account Provisioning: Create user accounts with automatic random password generation
  • Secure Password Management: Database-appropriate password hashing (SHA2, bcrypt, MD5)
  • Flexible Configuration: Map any SQL query results to resources and entitlements
  • Role Management: Sync and manage role assignments and permissions
  • Custom Schemas: Support for any database schema through configurable SQL queries

Supported Database Engines

  • MySQL
  • Microsoft SQL Server
  • Oracle — see docs/oracle.md for idempotent grant/revoke
  • PostgreSQL
  • SAP HANA
  • Vertica
  • Amazon Redshift
  • WordPress (MySQL-based)
  • IBM DB2 — opt-in: requires a binary built with the db2 tag and IBM's native CLI driver; see docs/db2.md

Configuration

The connector is configured using a YAML file that defines:

  • Database Connection: Connection details via DSN (Data Source Name) and optional connect.params
  • Resource Types: Map database tables/queries to resources (users, roles, etc.)
  • Account Provisioning: Define schemas and credential options for user creation
  • Entitlements: Permissions and roles that can be granted to resources
  • Provisioning Actions: SQL queries for granting/revoking entitlements; see docs/provisioning.md for validation_queries semantics (a no-rows validation is treated as idempotent success on the DDL engines Db2 and Oracle: on by default for Db2, opt-in via validation_queries_signal_idempotency for Oracle)

For Postgres behind a transaction-mode pooler (PgBouncer, Supabase pooler on port 6543, etc.), set default_query_exec_mode to simple_protocol via the DSN query string or connect.params to avoid prepared-statement conflicts (SQLSTATE 42P05). When unset, baton-sql leaves the URL unchanged and pgx uses its default (cache_statement).

connect:
  dsn: "postgres://${HOST}:6543/${DB}"
  params:
    default_query_exec_mode: simple_protocol

See examples in the examples directory.

Query placeholders

SQL queries reference variables with ?<name> placeholders. Three modifiers are supported:

  • ?<name>: parameterized value. Bound through the driver ($1, ?, @p1, :1 depending on engine). Safe against SQL injection.
  • ?<name|unquoted>: strips non-alphanumeric characters from the value and inlines it directly. Intended for numeric pagination knobs (LIMIT/OFFSET) and trusted identifier-shaped values. Not safe for arbitrary user input (the sanitizer silently drops characters rather than escaping).
  • ?<name|identifier>: inlines the value as a properly-quoted SQL identifier. Engine-aware (backticks for MySQL, ANSI double-quotes elsewhere) with embedded quote characters doubled. Use this for identifier substitution in GRANT / REVOKE / DDL where parameter binding is not supported by the SQL grammar, e.g. GRANT SELECT ON ?<schema|identifier>.?<tbl|identifier> TO ?<grantee|identifier>.

Multi-database iteration

A connector can be configured to iterate every database in a cluster instead of operating on a single handle. Add a databases block under connect:

connect:
  dsn: "postgres://${HOST}:${PORT}/${ADMIN_DB}"
  user: "${USER}"
  password: "${PASSWORD}"
  databases:
    # Either a static list…
    static: ["analytics", "reporting"]
    # …or a discovery query whose first column is the list of database names.
    discovery_query: |
      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. Event feed and get queries run only against the primary database; see 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 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:
  baton-sql [flags]
  baton-sql [command]

Available Commands:
  capabilities       Get connector capabilities
  completion         Generate the autocompletion script for the specified shell
  help               Help about any command

Flags:
      --client-id string       The client ID used to authenticate with ConductorOne ($BATON_CLIENT_ID)
      --client-secret string   The client secret used to authenticate with ConductorOne ($BATON_CLIENT_SECRET)
      --config-path string     required: The file path to the baton-sql config to use ($BATON_CONFIG_PATH)
  -f, --file string            The path to the c1z file to sync with ($BATON_FILE) (default "sync.c1z")
  -h, --help                   help for baton-sql
      --log-format string      The output format for logs: json, console ($BATON_LOG_FORMAT) (default "json")
      --log-level string       The log level: debug, info, warn, error ($BATON_LOG_LEVEL) (default "info")
  -p, --provisioning           This must be set in order for provisioning actions to be enabled ($BATON_PROVISIONING)
      --skip-full-sync         This must be set to skip a full sync ($BATON_SKIP_FULL_SYNC)
      --ticketing              This must be set to enable ticketing support ($BATON_TICKETING)
  -v, --version                version for baton-sql

Use "baton-sql [command] --help" for more information about a command.

Contributing, Support and Issues

We started Baton because we were tired of taking screenshots and manually building spreadsheets. We welcome contributions, and ideas, no matter how small—our goal is to make identity and permissions sprawl less painful for everyone. If you have questions, problems, or ideas: Please open a GitHub Issue!

Check out Baton to learn more the project in general.

See CONTRIBUTING.md for more details.

About

No description, website, or topics provided.

Resources

Code of conduct

Stars

1 star

Watchers

7 watching

Forks

Releases

Packages

Used by

Contributors

Languages