Skip to content

Stop user without access permissions#30

Merged
marcelofern merged 5 commits into
mainfrom
forbid-user-without-access
May 14, 2025
Merged

Stop user without access permissions#30
marcelofern merged 5 commits into
mainfrom
forbid-user-without-access

Conversation

@marcelofern

@marcelofern marcelofern commented May 9, 2025

Copy link
Copy Markdown
Collaborator

Description

This PR adds some sanity checks to make sure the user has the permissions they
ought to have to Psycopack a table.

@github-actions

github-actions Bot commented May 9, 2025

Copy link
Copy Markdown

Coverage Report Results

Name Stmts Miss Branch BrPart Cover
src/psycopack/__init__.py 4 0 0 0 100%
src/psycopack/_commands.py 109 0 8 0 100%
src/psycopack/_conn.py 5 0 0 0 100%
src/psycopack/_const.py 2 0 0 0 100%
src/psycopack/_cur.py 16 0 0 0 100%
src/psycopack/_identifiers.py 12 0 2 0 100%
src/psycopack/_introspect.py 155 0 12 0 100%
src/psycopack/_logging.py 4 0 0 0 100%
src/psycopack/_psycopg.py 5 0 0 0 100%
src/psycopack/_repack.py 343 0 114 0 100%
src/psycopack/_tracker.py 165 0 36 0 100%
tests/conftest.py 18 0 0 0 100%
tests/factories.py 33 0 4 0 100%
tests/test_cur.py 20 0 2 0 100%
tests/test_fixtures.py 5 0 0 0 100%
tests/test_package.py 3 0 0 0 100%
tests/test_repack.py 659 0 0 0 100%
TOTAL 1558 0 178 0 100%

1 empty file skipped.

Prior to this change, Psycopack did not check for any schema privileges.
It was assumed, that the user would have CREATE and USAGE privilege for
the schema.

- USAGE: for introspecting objects in the schema.
- CREATE: for creating new objects in the schema.

This change adds a check to validate whether the user has both of these
privileges or not.
@marcelofern marcelofern force-pushed the forbid-user-without-access branch from 55afd36 to fb6acfd Compare May 14, 2025 04:31
@marcelofern marcelofern changed the title Stop user without schema permissions Stop user without access permissions May 14, 2025
Prior to this change, there was no check to verify that the user was an
OWNER of the table to be repacked.

This is a problem because only the owner can rename and delete the table
(needed once it has been swapped).

This change adds an explicit check to ensure the user is the owner of
the table before proceeding.
@marcelofern marcelofern force-pushed the forbid-user-without-access branch from fb6acfd to d54dbf2 Compare May 14, 2025 04:38
@marcelofern marcelofern requested a review from a team May 14, 2025 05:13
@marcelofern marcelofern marked this pull request as ready for review May 14, 2025 05:13

@felcury felcury left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Beautiful! Just leaving a suggestion

Comment thread src/psycopack/_introspect.py Outdated
is_validated: bool
referring_table: str
schema: str
is_owner: bool

@felcury felcury May 14, 2025

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could I suggest calling these something along the lines of is_owned_by_user or something similar?
I appreciate it's a bit more verbose, but I think it's more consistent with the other properties of the FK (e.g. "the FK is validated, and the FK is owned by the user", instead of "the FK is validated, and the FK is owner(?)")

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fair enough, here are the fixups @flpcury:

  • 5e40fef
  • [The ownership info is not needed for referred PKs, so ended up removing it] 0de4572

Comment thread src/psycopack/_introspect.py Outdated
name: str
schema: str
privileges: list[str]
is_owner: bool

@felcury felcury May 14, 2025

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same here

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Addressed above (link)

Prior to this change, there was no check to verify that the user was an
OWNER of the referring tables (tables that have fks pointing to the
table to be repacked).

This is a problem because Psycopack needs to create new foreign keys on
that table that point to the shadow table, and that is not possible
unless the user is the table owner.

This change adds an explicit check to ensure the user is the owner of
the referring tables before proceeding.
Prior to this change, there was no check to verify that the user had the
REFERENCES privilege on the referred tables (tables the table to be
repacked has a fk to).

This is a problem because Psycopack needs to create new foreign keys on
the shadow table that point to the referred tables, and that is not
possible unless the user has REFERENCES privilege.

This change adds an explicit check to ensure the user has this privilege
for all referred tables before proceeding.
@marcelofern marcelofern force-pushed the forbid-user-without-access branch from 0de4572 to 180dcd6 Compare May 14, 2025 20:54
@marcelofern marcelofern merged commit 41ebf9b into main May 14, 2025
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