Skip to content

Add preflight check for source sequence SELECT privileges#947

Merged
kvch merged 5 commits into
xataio:mainfrom
lghuy05:feat/access-select-privileges
Jul 1, 2026
Merged

Add preflight check for source sequence SELECT privileges#947
kvch merged 5 commits into
xataio:mainfrom
lghuy05:feat/access-select-privileges

Conversation

@lghuy05

@lghuy05 lghuy05 commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Description

Add a second access preflight check that verifies the source role can SELECT from in-scope sequences used by snapshot tables.

This extends pgstream -check --access beyond table read privileges so sequence-value snapshot failures are caught earlier with a direct remediation message.

Related Issue(s)

Type of Change

Please select the relevant option(s):

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🔧 Refactoring (no functional changes)
  • ⚡ Performance improvement
  • 🧪 Test coverage improvement
  • 🔨 Build/CI changes
  • 🧹 Code cleanup

Changes Made

  • add SourceSequenceSelectPrivilegesCheck to pkg/stream/preflight/access.go
  • query table-to-sequence-relationships from Postgres catalogs and evaluate access with has_sequence_privilege(..., 'SELECT')
  • update BuildAccessChecks to run both table and sequence access checks with the same shared source connection

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • All existing tests pass

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Code is well-commented
  • Documentation updated where necessary

Additional Notes

  • I didn't fully verify the integration job

@kvch

kvch commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Could you please rebase your branch?

@lghuy05 lghuy05 force-pushed the feat/access-select-privileges branch from fe0aadb to f3238be Compare June 29, 2026 17:06
Comment thread pkg/stream/preflight/access.go Outdated
JOIN pg_namespace sn ON sn.oid = s.relnamespace
WHERE t.relkind IN ('r', 'p')
AND s.relkind = 'S'
AND d.deptype = 'a'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does this condition include generated identity columns? Could you please add a test to verify that those columns are checked as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I missed the identity-column case. I've updated the sequence privilege query to account for identity-backed sequences and added integration test covering GENERATED ALWAYS AS IDENTITY

`

const sourceSequenceSelectPrivilegesQuery = `
SELECT

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I've been testing this a bit more, and found that this query cannot find all sequences that are snapshotted. It is missing the sequences that belong to the schema, but not owned by any columns. Sorry for pointing it out now. Could you please make sure the check includes:

  • sequences of the table
  • generated identity columns of the table
  • all sequences in the selected schema

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I've updated the check to cover column-owned sequences, identity-backed sequences and free-standing sequences in selected schemas and added test for those cases.

@kvch kvch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you for both the contribution and your patience.

@kvch kvch enabled auto-merge (squash) July 1, 2026 12:55
@kvch kvch merged commit 74a8853 into xataio:main Jul 1, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants