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

feat: use user tags to check PSA auth #1008

Merged
merged 10 commits into from
Mar 4, 2022
Merged

Conversation

alexandrastoica
Copy link
Contributor

Removes the old pinning_authorization table and uses user tags instead

@alexandrastoica alexandrastoica marked this pull request as ready for review February 18, 2022 16:00
@alexandrastoica alexandrastoica linked an issue Feb 18, 2022 that may be closed by this pull request
@flea89 flea89 self-assigned this Feb 21, 2022
ghost
ghost previously requested changes Feb 21, 2022
packages/api/test/fixtures/init-data.sql Outdated Show resolved Hide resolved
packages/db/postgres/pg-rest-api-types.d.ts Outdated Show resolved Hide resolved
packages/db/index.js Outdated Show resolved Hide resolved
@alexandrastoica
Copy link
Contributor Author

SQL for migrating the existing data from pinning_authorization to user_tag

BEGIN TRANSACTION;
INSERT INTO public.user_tag
(
    user_id,
    tag,
    value,
    reason,
	inserted_at
)
SELECT
     user_id,
     'HasPsaAccess' as tag,
     'true' as value,
     'Approved access' as reason,
	 inserted_at
 FROM public.pinning_authorization
 WHERE deleted_at IS NULL;
 
INSERT INTO public.user_tag
(
    user_id,
    tag,
    value,
    reason,
	inserted_at,
	deleted_at
)
SELECT
     user_id,
     'HasPsaAccess' as tag,
     'false' as value,
     'Revoked access' as reason,
	 inserted_at,
	 deleted_at
 FROM public.pinning_authorization
 WHERE deleted_at IS NOT NULL;

DROP TABLE public.pinning_authorization;
COMMIT;

@alexandrastoica alexandrastoica requested a review from a user February 23, 2022 11:26
@alanshaw
Copy link
Member

@flea89
Copy link
Contributor

flea89 commented Feb 24, 2022

@alanshaw thanks for pointing that out! We noticed this morning that folder was created 🎉

While I understand this is not the full, polished solution for migrations, (since we're still missing the automation side of it) I do believe moving migrations scripts to version control is a great improvement to what we're doing now.
So big plus and thanks 🙏 !

I'm wondering if we should be adding some documentation to make sure developers know what's expected when altering schemas?
Created a minimal PR.

Do we have an issue tracking the bigger DB migration epic/approach?

@flea89 flea89 removed their assignment Feb 25, 2022
@alexandrastoica
Copy link
Contributor Author

@alanshaw added the migration file. Let me know if this is ok to merge. Thanks!

@alexandrastoica alexandrastoica dismissed ghost ’s stale review March 2, 2022 12:13

Made the changes requested. Thanks!

@alexandrastoica alexandrastoica removed the request for review from a user March 2, 2022 13:46
Copy link
Member

@alanshaw alanshaw left a comment

Choose a reason for hiding this comment

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

LGTM

@alexandrastoica alexandrastoica merged commit 6fc29e6 into main Mar 4, 2022
@alexandrastoica alexandrastoica deleted the feat/user-tag-pinning branch March 4, 2022 14:04
@vasco-santos
Copy link
Contributor

vasco-santos commented Mar 9, 2022

Runing SQL migration for deploy got:

web3-storage-prod::HEROKU_POSTGRESQL_AQUA=> INSERT INTO public.user_tag
(
    user_id,
    tag,
    value,
    reason,
    inserted_at
)
SELECT
    user_id,
    'HasPsaAccess' as tag,
    'true' as value,
    'Approved access' as reason,
    inserted_at
 FROM public.pinning_authorization
 WHERE deleted_at IS NULL;
ERROR:  invalid input value for enum user_tag_type: "HasPsaAccess"
LINE 11:     'HasPsaAccess' as tag,

Looking into it

cc @alexandrastoica

@flea89
Copy link
Contributor

flea89 commented Mar 9, 2022

@vasco-santos the user_tag enum was created (and values updated) as part of 2 separate PRs from trigram folks, is it possible they haven't created a migration to create the ENUM?

-- User tags are associated to a user for the purpose of granting/restricting them
-- in the application.
CREATE TYPE user_tag_type AS ENUM
(
  'HasAccountRestriction',
  'HasPsaAccess',
  'StorageLimitBytes'
);

@vasco-santos
Copy link
Contributor

@flea89 thanks, you were right! The type was outdated and it was merged without updating the type. We need to improve communication on DB changes

@ghost
Copy link

ghost commented Mar 9, 2022

@flea89 thanks, you were right! The type was outdated and it was merged without updating the type. We need to improve communication on DB changes

@vasco-santos i'll take ownership for this in this instance. if you recall the conversations we were having a few weeks ago about naming... i meant to follow up once we were all in agreement and the conversations had died down to avoid unnecessary DB updates in prod, but i forgot to do so. i apologize for that.

i also feel this brings to light the need for an automated migration strategy as part of our deployments.

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.

Use new user tags to authorise user to use pinning service APIs
4 participants