icgc-argo / platform-api

https://api.platform.icgc-argo.org/graphql
GNU Affero General Public License v3.0
0 stars 0 forks source link

implement metadata access control through arranger integration #294

Closed hlminh2000 closed 3 years ago

hlminh2000 commented 4 years ago

Detailed Description

This is to support this spec: https://wiki.oicr.on.ca/display/icgcargotech/File+Metadata+Access+Control

Possible Implementation

Use the updates from ego-token-utils above. Some pseudo-code (pending arranger investigation & implementation, please do a better job):

      const ownProgramFilter = {
        // filters out files in EMBARGO_OWN_PROGRAM stage from OTHER programs
        op: "and",
        content: [
          {
            op: "in",
            content: {
              field: "release_state",
              values: ["EMBARGO_OWN_PROGRAM"],
            },
          },
          {
            op: "not",
            content: [
              {
                op: "in",
                content: {
                  field: "study_id",
                  values: [...usersProgramIds],
                },
              },
            ],
          },
        ],
      };
      const userAccessLevel = getFileMetadataAccessLevel(jwt)
      const { schema: argoArrangerSchema } = (await createProjectSchema({
         getServerSideFilter: () => {
          switch (userAccessLevel) {
            case "DCC_MEMBER":
              return {
                // sees everything
                op: "not",
                content: [],
              };
            case "FULL_PROGRAM_MEMBER":
              return ownProgramFilter;
            case "ASSOCIATE_PROGRAM_MEMBER":
              return {
                op: "and",
                content: [
                  ownProgramFilter,
                  {
                    // filters out files in EMBARGO_FULL_PROGRAMS from OTHER programs
                    op: "and",
                    content: [
                      {
                        op: "not",
                        content: [
                          {
                            op: "in",
                            content: {
                              field: "study_id",
                              values: [...usersProgramIds],
                            },
                          },
                        ],
                      },
                      {
                        op: "in",
                        content: {
                          field: "release_state",
                          values: ["EMBARGO_FULL_PROGRAMS"],
                        },
                      },
                    ],
                  },
                ],
              };
            default:
              // public user, logged in or not
              return {
                op: "not",  // double negative --> positive
                content: [
                  {
                    op: "in",
                    content: {
                      field: "release_state",
                      values: ["PUBLIC"],
                    },
                  },
                ],
              };
          }
        },
      })) as { schema: GraphQLSchema };

Conceptual, this is to achieve the following access model: image

image

Expected Outcome

As a user, I can login and see only the data that i have permission to from an API query

To test this:

rosibaj commented 3 years ago

@blabadi @ciaranschutte i checled with Minh, and this can go to QA

Yes! It's feature flagged so need an env update if you wanna test. It'll only work with the fake data cause real data doesn't have release stage yet

Would one of you be able to help moving this forward?

blabadi commented 3 years ago

created this PR: https://github.com/icgc-argo/platform-api/pull/350

blabadi commented 3 years ago

tests failed twice, and different tests each time, they seem flaky to me and related to the elastic search container lifecycle

blabadi commented 3 years ago

the PR branch test passed but the branch tests failed, so definitely inconsistent image.png

rosibaj commented 3 years ago

@hlminh2000 can we get this moved to the dev enviroment? Are there any blockers here?

rosibaj commented 3 years ago
hlminh2000 commented 3 years ago

failing test has been disabled in CI, latest has been released to QA. Access control is behind feature flag, so no behavior change is expected out of this release.