Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ The connector is configured using a YAML file that defines:
- **Entitlements**: Permissions and roles that can be granted to resources
- **Provisioning Actions**: SQL queries for granting/revoking entitlements; see [docs/provisioning.md](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)

When `static_entitlements` is configured for a resource type, it takes precedence
over dynamic `entitlements` for both sync and provisioning. A static entitlement
without provisioning configured, or an unknown entitlement in static mode, cannot
fall back to a dynamic mapping's grant/revoke queries.

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`).

```yaml
Expand Down
6 changes: 6 additions & 0 deletions pkg/bsql/provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ func (s *SQLSyncer) getProvisioningConfig(ctx context.Context, entitlementID str
}
}

// Static entitlements take precedence during sync, so dynamic mappings must
// not supply provisioning for an unsupported or unknown static entitlement.
if s.config.StaticEntitlements != nil {
return nil, false
}

// Check dynamic entitlements
if s.config.Entitlements != nil {
for _, e := range s.config.Entitlements.Map {
Expand Down
79 changes: 79 additions & 0 deletions pkg/bsql/provisioning_static_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package bsql

import (
"testing"

v2 "github.com/conductorone/baton-sdk/pb/c1/connector/v2"
sdkEntitlement "github.com/conductorone/baton-sdk/pkg/types/entitlement"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestStaticProvisioningDoesNotFallThrough(t *testing.T) {
for _, operation := range []string{"grant", "revoke"} {
for _, mode := range []string{"unsupported", "unknown", "empty_static", "supported", "dynamic_only"} {
t.Run(operation+"/"+mode, func(t *testing.T) {
s, db := newRevokeProvisioningTestSyncer(t)
provisioning := func(role string) *EntitlementProvisioning {
return &EntitlementProvisioning{
Grant: &GrantEntitlementProvisioningQueries{EntitlementProvisioningQueries: EntitlementProvisioningQueries{
Queries: []string{`INSERT INTO user_roles (user_id, role) VALUES ('user-1', '` + role + `')`},
}},
Revoke: &RevokeEntitlementProvisioningQueries{EntitlementProvisioningQueries: EntitlementProvisioningQueries{
Queries: []string{`DELETE FROM user_roles WHERE user_id = 'user-1' AND role = '` + role + `'`},
}},
}
}
static := &EntitlementMapping{Id: "viewer", DisplayName: "'Viewer'"}
s.config.StaticEntitlements = []*EntitlementMapping{static}
s.config.Entitlements = &EntitlementsQuery{Map: []*EntitlementMapping{{Provisioning: provisioning("admin")}}}
switch mode {
case "supported":
static.Provisioning = provisioning("viewer")
case "empty_static":
s.config.StaticEntitlements = []*EntitlementMapping{}
case "dynamic_only":
s.config.StaticEntitlements = nil
}
resource := &v2.Resource{Id: &v2.ResourceId{ResourceType: "role", Resource: "role-1"}}
requested := &v2.Entitlement{Id: sdkEntitlement.NewEntitlementID(resource, "viewer"), Resource: resource}
if mode == "unsupported" || mode == "supported" {
entitlements, _, _, err := s.Entitlements(t.Context(), resource, nil)
require.NoError(t, err)
require.Len(t, entitlements, 1)
requested = entitlements[0]
}
if mode == "unknown" {
requested.Id = sdkEntitlement.NewEntitlementID(resource, "unknown")
}
if operation == "revoke" {
seedUserWithRoles(t, db, "user-1", "admin", "viewer")
}
var err error
if operation == "grant" {
_, err = s.Grant(t.Context(), userPrincipal("user-1"), requested)
} else {
_, err = s.Revoke(t.Context(), &v2.Grant{Entitlement: requested, Principal: userPrincipal("user-1")})
}
supported := mode == "supported" || mode == "dynamic_only"
if supported {
assert.NoError(t, err)
} else {
assert.Error(t, err)
}
wantAdmin, wantViewer := 0, 0
if operation == "revoke" {
wantAdmin, wantViewer = 1, 1
}
if mode == "supported" {
wantViewer = 1 - wantViewer
}
if mode == "dynamic_only" {
wantAdmin = 1 - wantAdmin
}
assert.Equal(t, wantAdmin, countRows(t, db, `SELECT COUNT(*) FROM user_roles WHERE role = 'admin'`))
assert.Equal(t, wantViewer, countRows(t, db, `SELECT COUNT(*) FROM user_roles WHERE role = 'viewer'`))
})
}
}
}
Loading