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

Fix error printout on correct security label #3799

Merged
merged 1 commit into from
Nov 18, 2021

Conversation

mkindahl
Copy link
Contributor

For all security labels from provider timescaledb an error was
printed, which make pg_restore fail because the security labels are
printed to the dump.

Instead, we only print an error if the security label is not of the
correct format.

Fixes #3760

@mkindahl mkindahl self-assigned this Nov 12, 2021
@mkindahl mkindahl marked this pull request as ready for review November 12, 2021 12:40
@mkindahl mkindahl requested a review from a team as a code owner November 12, 2021 12:40
@mkindahl mkindahl requested review from berkley, afiskon, svenklemm and akuzm and removed request for a team and berkley November 12, 2021 12:40
@codecov
Copy link

codecov bot commented Nov 15, 2021

Codecov Report

Merging #3799 (9b1c575) into master (1df000e) will decrease coverage by 0.07%.
The diff coverage is 100.00%.

❗ Current head 9b1c575 differs from pull request most recent head 3fed2d0. Consider uploading reports for the commit 3fed2d0 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3799      +/-   ##
==========================================
- Coverage   90.56%   90.49%   -0.08%     
==========================================
  Files         213      213              
  Lines       37771    37773       +2     
==========================================
- Hits        34209    34182      -27     
- Misses       3562     3591      +29     
Impacted Files Coverage Δ
src/loader/loader.c 92.49% <100.00%> (+0.54%) ⬆️
tsl/src/fdw/deparse.c 66.12% <0.00%> (-2.82%) ⬇️
src/loader/bgw_message_queue.c 85.52% <0.00%> (-2.64%) ⬇️
tsl/src/bgw_policy/job.c 87.50% <0.00%> (-0.06%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1df000e...3fed2d0. Read the comment docs.

@afiskon
Copy link
Contributor

afiskon commented Nov 15, 2021

Looks OK but it would be nice to add a few more test cases to improve the code coverage.

src/loader/loader.c Outdated Show resolved Hide resolved
* containing 4 dashes, and with groups of digits of the size 8-4-4-4-12.
*/
static bool
is_uuid(const char *str)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it makes sense to reuse PostgreSQL types/functions for such validation

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking the same thing. Why not just call uuid_in on this string? If necessary, capture and rewrite the error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The function is uuid_in, which generate an error if it fails parsing, and capturing the error and replacing it with a different one was more complicated than writing this function. If you feel strongly about it, I can replace it.

Copy link
Contributor Author

@mkindahl mkindahl Nov 15, 2021

Choose a reason for hiding this comment

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

Switched to use uuid_in, as suggested, after our discussion.

ereport(ERROR,
(errmsg("TimescaleDB label is for internal use only"),
errdetail("Security label is \"%s\".", stmt->label),
errhint("Security label has to be of format \"dist_uuid:<UUID>\".")));
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this hint is appropriate since dist_uuid is not something a user should set. If this error happens, then either the dist_uuid is corrupted or the code mistook another UUID for the dist_uuid. In neither case should the user try to change the format to fix this issue or add this label him/herself.

I would probably just get rid of the hint.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Understanding why something is a problem and tracking down the issue is just as important as being able to fix it. This hint is intended for users to understand what is wrong, and not so much for being able to repair it, so I think there is value in having this hint for debugging purposes.

@mkindahl
Copy link
Contributor Author

Looks OK but it would be nice to add a few more test cases to improve the code coverage.

Added test cases to cover the cases highlighted by coverity.

ereport(ERROR,
(errmsg("TimescaleDB label is for internal use only"),
errdetail("Security label is \"%s\".", label),
errhint("Security label has to be of format \"dist_uuid:<UUID>\".")));
Copy link
Contributor

Choose a reason for hiding this comment

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

My previous comment about dropping the hint still applies.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I prefer to have this present for debugging purposes and trust users rather than to hide useful information that could help in resolving an issue.

@mkindahl mkindahl enabled auto-merge (rebase) November 16, 2021 12:13
@mkindahl mkindahl force-pushed the fix-seclabel-error branch 3 times, most recently from c3019d7 to 9b1c575 Compare November 17, 2021 08:59
@mkindahl mkindahl force-pushed the fix-seclabel-error branch 3 times, most recently from 1cc87ca to 7dd3728 Compare November 18, 2021 08:31
@mkindahl mkindahl enabled auto-merge (rebase) November 18, 2021 08:34
For all security labels from provider `timescaledb` an error was
printed, which make `pg_restore` fail because the security labels are
printed to the dump.

Instead, we only print an error if the security label is not of the
correct format.

Fixes timescale#3760
@mkindahl mkindahl enabled auto-merge (rebase) November 18, 2021 08:45
@mkindahl mkindahl merged commit ca82a9b into timescale:master Nov 18, 2021
@mkindahl mkindahl deleted the fix-seclabel-error branch November 18, 2021 09:52
This was referenced Nov 29, 2021
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.

postgresql upgrade results in error TimescaleDB label is for internal use only
5 participants