Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagate SECURITY LABEL ON ROLE stmt #7304

Merged
merged 10 commits into from
Nov 16, 2023
Merged

Propagate SECURITY LABEL ON ROLE stmt #7304

merged 10 commits into from
Nov 16, 2023

Conversation

naisila
Copy link
Member

@naisila naisila commented Nov 1, 2023

DESCRIPTION: Propagates SECURITY LABEL ON ROLE statement

See official docs for explanation on how this command works: https://www.postgresql.org/docs/current/sql-security-label.html This command stores the label in the pg_shseclabel catalog table.

We propagate SECURITY LABEL [for provider] ON ROLE rolename IS labelname to the worker nodes.
We also make sure to run the relevant SecLabelStmt commands on a newly added node by looking at roles found in pg_shseclabel.

This commit also fixes the regex string in check_gucs_are_alphabetically_sorted.sh script such that it escapes the dot. Previously it was looking for all strings starting with "citus" instead of "citus." as it should.

New Note to reviewer: To test this feature, I currently make use of a special GUC to control label provider registration in PG_init when creating the Citus extension.

Old Note to reviewer: in the current test, I did what I could to ensure that I am connecting to the worker node with the same connection. This is needed to ensure that when I create the label provider, it is visible by the next command. If there is a better way to ensure commands to be in the same connection, let me know. There is a small issue in citus_add_node() - I couldn't find a way to test the successful completion of that one. However, through logged remote commands, we can see it fails when trying to propagate the SecLabel statement.

Old TODOs:

  • fix citus_add_node() to update pg_seclabel on worker node
  • tests
  • comments

@naisila naisila force-pushed the naisila/sec_label_role branch 3 times, most recently from aca5abf to 14394a9 Compare November 2, 2023 09:49
Copy link

codecov bot commented Nov 2, 2023

Codecov Report

Merging #7304 (c36a71a) into main (c6fbb72) will decrease coverage by 0.15%.
Report is 1 commits behind head on main.
The diff coverage is 89.41%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7304      +/-   ##
==========================================
- Coverage   89.58%   89.44%   -0.15%     
==========================================
  Files         275      277       +2     
  Lines       59610    59687      +77     
  Branches     7427     7437      +10     
==========================================
- Hits        53403    53388      -15     
- Misses       4076     4137      +61     
- Partials     2131     2162      +31     

@naisila naisila marked this pull request as ready for review November 6, 2023 12:53
@naisila naisila force-pushed the naisila/sec_label_role branch 2 times, most recently from d92e621 to d4b0b32 Compare November 8, 2023 12:17
src/backend/distributed/commands/seclabel.c Outdated Show resolved Hide resolved
src/backend/distributed/commands/seclabel.c Outdated Show resolved Hide resolved
src/backend/distributed/commands/seclabel.c Show resolved Hide resolved
src/backend/distributed/deparser/deparse_seclabel_stmts.c Outdated Show resolved Hide resolved
src/backend/distributed/deparser/deparse_seclabel_stmts.c Outdated Show resolved Hide resolved
src/backend/distributed/commands/seclabel.c Outdated Show resolved Hide resolved
src/backend/distributed/commands/role.c Outdated Show resolved Hide resolved
src/backend/distributed/commands/role.c Outdated Show resolved Hide resolved
src/backend/distributed/commands/role.c Show resolved Hide resolved
src/backend/distributed/commands/role.c Show resolved Hide resolved
src/test/regress/expected/seclabel.out Outdated Show resolved Hide resolved
src/test/regress/expected/seclabel.out Outdated Show resolved Hide resolved
src/test/regress/sql/seclabel.sql Outdated Show resolved Hide resolved
@naisila naisila force-pushed the naisila/sec_label_role branch 4 times, most recently from 1251ab5 to 963e1b9 Compare November 9, 2023 11:28
src/backend/distributed/commands/role.c Outdated Show resolved Hide resolved
src/backend/distributed/shared_library_init.c Show resolved Hide resolved
src/test/regress/sql/seclabel.sql Show resolved Hide resolved
src/test/regress/sql/seclabel.sql Show resolved Hide resolved
Copy link
Contributor

@gurkanindibay gurkanindibay left a comment

Choose a reason for hiding this comment

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

After fixing other comments, it is OK for me to merge

ci/gucs.out Outdated Show resolved Hide resolved
@naisila naisila force-pushed the naisila/sec_label_role branch 2 times, most recently from b4111ed to 5ebaa80 Compare November 14, 2023 08:23
@@ -550,3 +550,35 @@ BEGIN
RETURN result;
END;
$func$ LANGUAGE plpgsql;

-- Returns pg_seclabels entries from all nodes in the cluster
-- for which the provider is citus_tests_label_provider and the object name is the input
Copy link
Member

Choose a reason for hiding this comment

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

nit: missing dot

Suggested change
-- for which the provider is citus_tests_label_provider and the object name is the input
-- for which the provider is citus_tests_label_provider and the object name is the input.

Copy link
Member

@onurctirtir onurctirtir left a comment

Choose a reason for hiding this comment

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

Those are my final comments, LGTM.

SECURITY LABEL for citus_tests_label_provider ON ROLE user1 IS NULL;
NOTICE: issuing SECURITY LABEL FOR citus_tests_label_provider ON ROLE user1 IS NULL
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
SECURITY LABEL for citus_tests_label_provider ON ROLE user1 IS 'citus unclassified';
Copy link
Member

Choose a reason for hiding this comment

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

Should we also add a test where we don't provide the "provider" at all?

SECURITY LABEL ON ROLE brand_new_role IS 'citus unclassified';

From the docs:

The name of the provider with which this label is to be associated. The named provider must be loaded and must consent to the proposed labeling operation. If exactly one provider is loaded, the provider name may be omitted for brevity.

Copy link
Member Author

Choose a reason for hiding this comment

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

I am skipping this test since I am loading two providers to test the character escaping thing.

Copy link
Member

Choose a reason for hiding this comment

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

Can't we reduce the number of providers we have to one; such that we only have the one that requires proper quoting?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm okay, then we will not be testing the general case with name that doesn't need quoting, therefore I didn't want to do that. But it's okay I guess.

src/backend/distributed/shared_library_init.c Outdated Show resolved Hide resolved
src/backend/distributed/commands/role.c Outdated Show resolved Hide resolved
src/backend/distributed/commands/seclabel.c Outdated Show resolved Hide resolved
return;
}

ereport(ERROR,
Copy link
Member

Choose a reason for hiding this comment

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

let's add such a test for that to make codecov happy, if possible

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually I have added this test, I don't know why codecov is not happy xD

SECURITY LABEL for citus_tests_label_provider ON ROLE user1 IS NULL;
NOTICE: issuing SECURITY LABEL FOR citus_tests_label_provider ON ROLE user1 IS NULL
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
SECURITY LABEL for citus_tests_label_provider ON ROLE user1 IS 'citus unclassified';
Copy link
Member

Choose a reason for hiding this comment

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

Can't we reduce the number of providers we have to one; such that we only have the one that requires proper quoting?

@naisila naisila merged commit 0d1f188 into main Nov 16, 2023
157 checks passed
@naisila naisila deleted the naisila/sec_label_role branch November 16, 2023 10:12
@onurctirtir onurctirtir mentioned this pull request Nov 29, 2023
57 tasks
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.

4 participants