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

chore: deprecate restricted metrics #8197

Merged
merged 3 commits into from
Sep 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion UPDATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ assists people when migrating to a new version.

## Next Version

* We're deprecating the concept of "restricted metric", this feature
was not fully working anyhow.
* [8117](https://github.com/apache/incubator-superset/pull/8117): If you are
using `ENABLE_PROXY_FIX = True`, review the newly-introducted variable,
`PROXY_FIX_CONFIG`, which changes the proxy behavior in accordance with
Expand All @@ -34,7 +36,7 @@ using `ENABLE_PROXY_FIX = True`, review the newly-introducted variable,
backend serialization. To disable set `RESULTS_BACKEND_USE_MSGPACK = False`
in your configuration.

* [7848](https://github.com/apache/incubator-superset/pull/7848): If you are
* [7848](https://github.com/apache/incubator-superset/pull/7848): If you are
running redis with celery, celery bump to 4.3.0 requires redis-py upgrade to
3.2.0 or later.

Expand Down
25 changes: 1 addition & 24 deletions docs/security.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Security
Security in Superset is handled by Flask AppBuilder (FAB). FAB is a
"Simple and rapid application development framework, built on top of Flask.".
FAB provides authentication, user management, permissions and roles.
Please read its `Security documentation
Please read its `Security documentation
<https://flask-appbuilder.readthedocs.io/en/latest/security.html>`_.

Provided Roles
Expand Down Expand Up @@ -153,26 +153,3 @@ a set of data sources that power dashboards only made available to executives.
When looking at its dashboard list, this user will only see the
list of dashboards it has access to, based on the roles and
permissions that were attributed.


Restricting the access to some metrics
""""""""""""""""""""""""""""""""""""""

Sometimes some metrics are relatively sensitive (e.g. revenue).
We may want to restrict those metrics to only a few roles.
For example, assumed there is a metric ``[cluster1].[datasource1].[revenue]``
and only Admin users are allowed to see it. Here’s how to restrict the access.

1. Edit the datasource (``Menu -> Source -> Druid datasources -> edit the
record "datasource1"``) and go to the tab ``List Druid Metric``. Check
the checkbox ``Is Restricted`` in the row of the metric ``revenue``.

2. Edit the role (``Menu -> Security -> List Roles -> edit the record
“Admin”``), in the permissions field, type-and-search the permission
``metric access on [cluster1].[datasource1].[revenue] (id: 1)``, then
click the Save button on the bottom of the page.

Any users without the permission will see the error message
*Access to the metrics denied: revenue (Status: 500)* in the slices.
It also happens when the user wants to access a post-aggregation metric that
is dependent on revenue.
2 changes: 1 addition & 1 deletion superset/assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"scripts": {
"tdd": "jest --watch",
"test": "jest",
"cover": "jest --maxWorkers=8 --coverage",
"cover": "jest --coverage",
Copy link
Member Author

Choose a reason for hiding this comment

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

unrelated to this PR, but this seems to help quite a bit with broken JS builds. For reference, not specifying maxWorkers will lead to use all CPUs cores on the box minus one

"dev": "webpack --mode=development --colors --progress --debug --watch",
"dev-server": "webpack-dev-server --mode=development --progress",
"prod": "node --max_old_space_size=4096 webpack --mode=production --colors --progress",
Expand Down
1 change: 0 additions & 1 deletion superset/connectors/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,6 @@ class BaseMetric(AuditMixinNullable, ImportMixin):
verbose_name = Column(String(1024))
metric_type = Column(String(32))
description = Column(Text)
is_restricted = Column(Boolean, default=False, nullable=True)
d3format = Column(String(128))
warning_text = Column(Text)

Expand Down
18 changes: 1 addition & 17 deletions superset/connectors/druid/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

from superset import conf, db, security_manager
from superset.connectors.base.models import BaseColumn, BaseDatasource, BaseMetric
from superset.exceptions import MetricPermException, SupersetException
from superset.exceptions import SupersetException
from superset.models.helpers import AuditMixinNullable, ImportMixin, QueryResult
from superset.utils import core as utils, import_datasource

Expand Down Expand Up @@ -389,7 +389,6 @@ class DruidMetric(Model, BaseMetric):
"datasource_id",
"json",
"description",
"is_restricted",
"d3format",
"warning_text",
)
Expand Down Expand Up @@ -1044,19 +1043,6 @@ def get_aggregations(metrics_dict, saved_metrics, adhoc_metrics=[]):
}
return aggregations

def check_restricted_metrics(self, aggregations):
rejected_metrics = [
m.metric_name
for m in self.metrics
if m.is_restricted
and m.metric_name in aggregations.keys()
and not security_manager.has_access("metric_access", m.perm)
]
if rejected_metrics:
raise MetricPermException(
"Access to the metrics denied: " + ", ".join(rejected_metrics)
)

def get_dimensions(self, groupby, columns_dict):
dimensions = []
groupby = [gb for gb in groupby if gb in columns_dict]
Expand Down Expand Up @@ -1164,8 +1150,6 @@ def run_query( # noqa / druid
metrics, metrics_dict
)

self.check_restricted_metrics(aggregations)

# the dimensions list with dimensionSpecs expanded
dimensions = self.get_dimensions(groupby, columns_dict)
extras = extras or {}
Expand Down
22 changes: 1 addition & 21 deletions superset/connectors/druid/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ class DruidMetricInlineView(CompactCRUDMixin, SupersetModelView): # noqa
"json",
"datasource",
"d3format",
"is_restricted",
"warning_text",
]
add_columns = edit_columns
Expand All @@ -163,13 +162,7 @@ class DruidMetricInlineView(CompactCRUDMixin, SupersetModelView): # noqa
"[Druid Post Aggregation]"
"(http://druid.io/docs/latest/querying/post-aggregations.html)",
True,
),
"is_restricted": _(
"Whether access to this metric is restricted "
"to certain roles. Only roles with the permission "
"'metric access on XXX (the name of this metric)' "
"are allowed to access this metric"
),
)
}
label_columns = {
"metric_name": _("Metric"),
Expand All @@ -179,7 +172,6 @@ class DruidMetricInlineView(CompactCRUDMixin, SupersetModelView): # noqa
"json": _("JSON"),
"datasource": _("Druid Datasource"),
"warning_text": _("Warning Message"),
"is_restricted": _("Is Restricted"),
}

add_form_extra_fields = {
Expand All @@ -193,18 +185,6 @@ class DruidMetricInlineView(CompactCRUDMixin, SupersetModelView): # noqa

edit_form_extra_fields = add_form_extra_fields

def post_add(self, metric):
if metric.is_restricted:
security_manager.add_permission_view_menu(
"metric_access", metric.get_perm()
)

def post_update(self, metric):
if metric.is_restricted:
security_manager.add_permission_view_menu(
"metric_access", metric.get_perm()
)


appbuilder.add_view_no_menu(DruidMetricInlineView)

Expand Down
1 change: 0 additions & 1 deletion superset/connectors/sqla/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ class SqlMetric(Model, BaseMetric):
"table_id",
"expression",
"description",
"is_restricted",
"d3format",
"warning_text",
)
Expand Down
20 changes: 0 additions & 20 deletions superset/connectors/sqla/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ class SqlMetricInlineView(CompactCRUDMixin, SupersetModelView): # noqa
"expression",
"table",
"d3format",
"is_restricted",
"warning_text",
]
description_columns = {
Expand All @@ -163,12 +162,6 @@ class SqlMetricInlineView(CompactCRUDMixin, SupersetModelView): # noqa
"underlying backend. Example: `count(DISTINCT userid)`",
True,
),
"is_restricted": _(
"Whether access to this metric is restricted "
"to certain roles. Only roles with the permission "
"'metric access on XXX (the name of this metric)' "
"are allowed to access this metric"
),
"d3format": utils.markdown(
"d3 formatting string as defined [here]"
"(https://github.com/d3/d3-format/blob/master/README.md#format). "
Expand All @@ -188,7 +181,6 @@ class SqlMetricInlineView(CompactCRUDMixin, SupersetModelView): # noqa
"expression": _("SQL Expression"),
"table": _("Table"),
"d3format": _("D3 Format"),
"is_restricted": _("Is Restricted"),
"warning_text": _("Warning Message"),
}

Expand All @@ -203,18 +195,6 @@ class SqlMetricInlineView(CompactCRUDMixin, SupersetModelView): # noqa

edit_form_extra_fields = add_form_extra_fields

def post_add(self, metric):
if metric.is_restricted:
security_manager.add_permission_view_menu(
"metric_access", metric.get_perm()
)

def post_update(self, metric):
if metric.is_restricted:
security_manager.add_permission_view_menu(
"metric_access", metric.get_perm()
)


appbuilder.add_view_no_menu(SqlMetricInlineView)

Expand Down
4 changes: 0 additions & 4 deletions superset/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ def __init__(self, msg, link=None):
self.link = link


class MetricPermException(SupersetException):
pass


class NoDataException(SupersetException):
status = 400

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 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.
"""deprecate_restricted_metrics

Revision ID: 11c737c17cc6
Revises: def97f26fdfb
Create Date: 2019-09-08 21:50:58.200229

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "11c737c17cc6"
down_revision = "def97f26fdfb"


def upgrade():
with op.batch_alter_table("metrics") as batch_op:
batch_op.drop_column("is_restricted")
with op.batch_alter_table("sql_metrics") as batch_op:
batch_op.drop_column("is_restricted")


def downgrade():
op.add_column(
"sql_metrics", sa.Column("is_restricted", sa.BOOLEAN(), nullable=True)
)
op.add_column("metrics", sa.Column("is_restricted", sa.BOOLEAN(), nullable=True))
4 changes: 0 additions & 4 deletions superset/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,10 +535,6 @@ def merge_pv(view_menu, perm):
for datasource_class in ConnectorRegistry.sources.values():
metrics += list(db.session.query(datasource_class.metric_class).all())

for metric in metrics:
if metric.is_restricted:
merge_pv("metric_access", metric.perm)

def clean_perms(self) -> None:
"""
Clean up the FAB faulty permissions.
Expand Down