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: return security errors in the SIP-40 format #9796

Merged
merged 1 commit into from May 14, 2020

Conversation

etr2460
Copy link
Member

@etr2460 etr2460 commented May 13, 2020

SUMMARY

Adds functions to the security manager to return errors in the SIP-40 format. These are then returned using the new json_errors_response function

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

After screenshots representing the new API responses and unchanged error rendering:
Screen Shot 2020-05-12 at 8 14 25 PM
Screen Shot 2020-05-12 at 8 14 31 PM
Screen Shot 2020-05-12 at 8 30 54 PM
Screen Shot 2020-05-12 at 8 57 29 PM
Screen Shot 2020-05-12 at 8 57 47 PM

TEST PLAN

On SQL Lab, Dashboards, and Explore:

  • Ensure everything renders properly with no security errors
  • Hardcode security failures and see the error messages render properly

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

to: @john-bodley @villebro @craig-rueda

@etr2460 etr2460 force-pushed the erik-ritter--error-messages-3 branch from 8ad5574 to ef53c88 Compare May 13, 2020 05:18
payload = {}

payload["errors"] = [dataclasses.asdict(error) for error in errors]
return Response(
Copy link
Member

Choose a reason for hiding this comment

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

Could json_errors_response or similar work here? Ideally we use the same mechanism for constructing JSON responses.

Copy link
Member Author

Choose a reason for hiding this comment

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

huh? this is inside json_errors_response

Copy link
Member

Choose a reason for hiding this comment

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

🤦

return json_error_response(
utils.error_msg_from_exception(ex), status=ex.status, link=ex.link
return json_errors_response(
[ex.error], status=ex.status, payload=ex.payload
Copy link
Member

Choose a reason for hiding this comment

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

Nit. Though the keyword is optional, personally when the names don't match I think there's merit in explicitly defining them, i.e., errors=[ex.error], which helps with readability.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@@ -14,7 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# pylint: disable=too-few-public-methods
# pylint: disable=too-few-public-methods,invalid-name
Copy link
Member

Choose a reason for hiding this comment

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

Rather than adding the blanket disable could we put this on the specific line? Note the long term goal would be to remedy all pylint issues.

Copy link
Member Author

Choose a reason for hiding this comment

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

Since this is for the Enum names, and I want them to match the string they're equivalent to, I think this might be ok to disable for the whole file. Alternatively, we could change the max variable name length pylint config (not sure why we have it in the first place, I've rarely seen names that are too long, far more often names that are too short)

"""
Return the error object for the denied Superset datasource.

:param tables: The denied Superset datasource
Copy link
Member

Choose a reason for hiding this comment

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

tables -> datasource.

Copy link
Member Author

Choose a reason for hiding this comment

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

oops, fixed

@@ -96,6 +98,20 @@ def json_error_response(
)


def json_errors_response(
errors: List[SupersetError], status: int = 500, payload: Optional[dict] = None,
Copy link
Member

Choose a reason for hiding this comment

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

Could we type the dict i.e., Dict[..., ...].

Copy link
Member Author

Choose a reason for hiding this comment

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

yup, also changing the type for json_error_response too to match

@etr2460 etr2460 force-pushed the erik-ritter--error-messages-3 branch from ef53c88 to 7b0c168 Compare May 13, 2020 21:32
Copy link
Member Author

@etr2460 etr2460 left a comment

Choose a reason for hiding this comment

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

@john-bodley comments addressed

@@ -14,7 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# pylint: disable=too-few-public-methods
# pylint: disable=too-few-public-methods,invalid-name
Copy link
Member Author

Choose a reason for hiding this comment

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

Since this is for the Enum names, and I want them to match the string they're equivalent to, I think this might be ok to disable for the whole file. Alternatively, we could change the max variable name length pylint config (not sure why we have it in the first place, I've rarely seen names that are too long, far more often names that are too short)

"""
Return the error object for the denied Superset datasource.

:param tables: The denied Superset datasource
Copy link
Member Author

Choose a reason for hiding this comment

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

oops, fixed

@@ -96,6 +98,20 @@ def json_error_response(
)


def json_errors_response(
errors: List[SupersetError], status: int = 500, payload: Optional[dict] = None,
Copy link
Member Author

Choose a reason for hiding this comment

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

yup, also changing the type for json_error_response too to match

return json_error_response(
utils.error_msg_from_exception(ex), status=ex.status, link=ex.link
return json_errors_response(
[ex.error], status=ex.status, payload=ex.payload
Copy link
Member Author

Choose a reason for hiding this comment

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

done

def json_errors_response(
errors: List[SupersetError],
status: int = 500,
payload: Optional[Dict[str, any]] = None,
Copy link
Member

Choose a reason for hiding this comment

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

any -> Any.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@etr2460 etr2460 force-pushed the erik-ritter--error-messages-3 branch from 7b0c168 to c8a25b7 Compare May 13, 2020 21:54
@codecov-io
Copy link

codecov-io commented May 13, 2020

Codecov Report

Merging #9796 into master will increase coverage by 6.51%.
The diff coverage is 86.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9796      +/-   ##
==========================================
+ Coverage   64.35%   70.86%   +6.51%     
==========================================
  Files         536      588      +52     
  Lines       29106    30493    +1387     
  Branches     2806     3154     +348     
==========================================
+ Hits        18732    21610    +2878     
+ Misses      10194     8770    -1424     
+ Partials      180      113      -67     
Flag Coverage Δ
#cypress 53.63% <0.00%> (-0.07%) ⬇️
#javascript 59.03% <100.00%> (?)
#python 71.07% <86.20%> (+<0.01%) ⬆️
Impacted Files Coverage Δ
...rset-frontend/src/components/ErrorMessage/types.ts 100.00% <ø> (ø)
superset/views/core.py 75.13% <40.00%> (+0.01%) ⬆️
superset/security/manager.py 88.96% <80.00%> (-0.16%) ⬇️
...uperset-frontend/src/utils/getClientErrorObject.ts 87.09% <100.00%> (+87.09%) ⬆️
superset/errors.py 100.00% <100.00%> (ø)
superset/exceptions.py 100.00% <100.00%> (ø)
superset/views/base.py 73.21% <100.00%> (+0.86%) ⬆️
superset-frontend/src/setup/setupPlugins.ts 8.00% <0.00%> (-92.00%) ⬇️
...rset-frontend/src/setup/setupErrorMessagesExtra.ts 50.00% <0.00%> (-50.00%) ⬇️
superset-frontend/src/setup/setupErrorMessages.ts 66.66% <0.00%> (-33.34%) ⬇️
... and 193 more

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 cf30e16...c8a25b7. Read the comment docs.

@etr2460 etr2460 merged commit d02f2d1 into apache:master May 14, 2020
michellethomas pushed a commit to airbnb/superset-fork that referenced this pull request May 14, 2020
@etr2460 etr2460 added the SIP-40 label Jun 2, 2020
// Security access errors
TABLE_SECURITY_ACCESS_ERROR: 'TABLE_SECURITY_ACCESS_ERROR',
DATASOURCE_SECURITY_ACCESS_ERROR: 'DATASOURCE_SECURITY_ACCESS_ERROR',
MISSING_OWNERSHIP_ERROR: 'MISSING_OWNERSHIP_ERROR',
Copy link
Member

Choose a reason for hiding this comment

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

@etr2460 What do you think of removing _ERROR suffix for the more specific errors and make it read like natural English? E.g.

SupersetError.UNKNOWN_DATASOURCE_TYPE
SupersetError.FAILED_FETCHING_DATASORUCE_INFO
SupersetError.TABLE_ACCESS_DENIED
SupersetError.DATASOURCE_ACCESS_DENITED
SupersetError.MISSING_OWNERSHIP

@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.37.0 labels Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/L 🚢 0.37.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants