-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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(datasets): security perm simplification #12000
Merged
dpgaspar
merged 12 commits into
apache:master
from
preset-io:feat/security-converge-datasets
Dec 16, 2020
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b00cb3d
feat(datasets): security perm simplification
dpgaspar 778a338
feat(datasets): security perm simplification
dpgaspar cbc53a7
Merge branch 'master' into feat/security-converge-datasets
dpgaspar dbbd388
fix tests
dpgaspar bee6178
fix tests
dpgaspar 3b410d8
fix tests
dpgaspar 9d0357a
fix tests
dpgaspar 2461651
fix tests
dpgaspar 8ae5f53
include SqlMetricInlineView converge and fix JS tests
dpgaspar f211ff1
update to current alembic revision
dpgaspar 74081be
Merge branch 'master' into feat/security-converge-datasets
dpgaspar 209cb7b
Merge branch 'master' into feat/security-converge-datasets
dpgaspar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
superset/migrations/versions/45731db65d9c_security_converge_datasets.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
"""security converge datasets | ||
|
||
Revision ID: 45731db65d9c | ||
Revises: 5daced1f0e76 | ||
Create Date: 2020-12-10 15:05:44.928020 | ||
|
||
""" | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "45731db65d9c" | ||
down_revision = "5daced1f0e76" | ||
|
||
from alembic import op | ||
from sqlalchemy.exc import SQLAlchemyError | ||
from sqlalchemy.orm import Session | ||
|
||
from superset.migrations.shared.security_converge import ( | ||
add_pvms, | ||
get_reversed_new_pvms, | ||
get_reversed_pvm_map, | ||
migrate_roles, | ||
Pvm, | ||
) | ||
|
||
NEW_PVMS = {"Dataset": ("can_read", "can_write",)} | ||
PVM_MAP = { | ||
Pvm("SqlMetricInlineView", "can_add"): (Pvm("Dataset", "can_write"),), | ||
Pvm("SqlMetricInlineView", "can_delete"): (Pvm("Dataset", "can_write"),), | ||
Pvm("SqlMetricInlineView", "can_edit"): (Pvm("Dataset", "can_write"),), | ||
Pvm("SqlMetricInlineView", "can_list"): (Pvm("Dataset", "can_read"),), | ||
Pvm("SqlMetricInlineView", "can_show"): (Pvm("Dataset", "can_read"),), | ||
Pvm("TableColumnInlineView", "can_add"): (Pvm("Dataset", "can_write"),), | ||
Pvm("TableColumnInlineView", "can_delete"): (Pvm("Dataset", "can_write"),), | ||
Pvm("TableColumnInlineView", "can_edit"): (Pvm("Dataset", "can_write"),), | ||
Pvm("TableColumnInlineView", "can_list"): (Pvm("Dataset", "can_read"),), | ||
Pvm("TableColumnInlineView", "can_show"): (Pvm("Dataset", "can_read"),), | ||
Pvm("TableModelView", "can_add",): (Pvm("Dataset", "can_write"),), | ||
Pvm("TableModelView", "can_delete",): (Pvm("Dataset", "can_write"),), | ||
Pvm("TableModelView", "can_edit",): (Pvm("Dataset", "can_write"),), | ||
Pvm("TableModelView", "can_list"): (Pvm("Dataset", "can_read"),), | ||
Pvm("TableModelView", "can_mulexport"): (Pvm("Dataset", "can_read"),), | ||
Pvm("TableModelView", "can_show"): (Pvm("Dataset", "can_read"),), | ||
Pvm("TableModelView", "muldelete",): (Pvm("Dataset", "can_write"),), | ||
Pvm("TableModelView", "refresh",): (Pvm("Dataset", "can_write"),), | ||
Pvm("TableModelView", "yaml_export",): (Pvm("Dataset", "can_read"),), | ||
} | ||
|
||
|
||
def upgrade(): | ||
bind = op.get_bind() | ||
session = Session(bind=bind) | ||
|
||
# Add the new permissions on the migration itself | ||
add_pvms(session, NEW_PVMS) | ||
migrate_roles(session, PVM_MAP) | ||
try: | ||
session.commit() | ||
except SQLAlchemyError as ex: | ||
print(f"An error occurred while upgrading permissions: {ex}") | ||
session.rollback() | ||
|
||
|
||
def downgrade(): | ||
bind = op.get_bind() | ||
session = Session(bind=bind) | ||
|
||
# Add the old permissions on the migration itself | ||
add_pvms(session, get_reversed_new_pvms(PVM_MAP)) | ||
migrate_roles(session, get_reversed_pvm_map(PVM_MAP)) | ||
try: | ||
session.commit() | ||
except SQLAlchemyError as ex: | ||
print(f"An error occurred while downgrading permissions: {ex}") | ||
session.rollback() | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@betodealmeida export and import datasets will not need a separate permission now. import needs
can_write
onDataset
and exportcan_read
onDataset