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

Affix webserver access_denied warning to be configurable #33022

Merged
merged 3 commits into from Aug 3, 2023

Conversation

amoghrajesh
Copy link
Contributor

Add a possibility to make the airflow webserver's access denied message - which occurs when an user tries to perform some operation outside their user rights. Allow this to be configurable through config so that every webserver installation can have a custom message without changing the airflow code.

Note: This message is not per call to the has_access function, but per webserver installation which is a more realistic case.

Took suggestions from community and approached the problem accordingly.

  • Made a function get_access_denied_message so that the "unit" is testable.

^ Add meaningful description above

Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

@boring-cyborg boring-cyborg bot added the area:webserver Webserver related Issues label Aug 2, 2023
@eladkal eladkal added this to the Airflow 2.7.0 milestone Aug 2, 2023
@eladkal eladkal added the type:improvement Changelog: Improvements label Aug 2, 2023
@@ -28,6 +28,10 @@
T = TypeVar("T", bound=Callable)


def get_access_denied_message():
return conf.get("webserver", "access_denied_message")
Copy link
Member

Choose a reason for hiding this comment

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

This should either use get_mandatory or provide a fallback.

Copy link
Member

Choose a reason for hiding this comment

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

Not really. The get_mandatory is needed only when we want to have a value but the value has no default (for example when we want to get a URL that has no default but we really need it to be configured).

The way it works when it is put in config.yml is that "default" is automatically used as fallback if there is no fallback (It's been working like that already for quite some time via defaul_config.cfg - so my recent change has not changed it - jut made it works without the default_config.cfg

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it is needed as @potiuk mentions here. The older default text is passed as the default in the new property in config.yml, which is basically the fallback.

Copy link
Member

@pankajkoti pankajkoti left a comment

Choose a reason for hiding this comment

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

Looks good to me, minor cosmetic suggestions if you'd like to consider :)

@@ -1349,6 +1349,13 @@ operators:
webserver:
description: ~
options:
access_denied_message:
description: |
The message displayed when an user tries to perform operations outside their rights.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
The message displayed when an user tries to perform operations outside their rights.
The notification that appears when a user attempts to execute actions beyond their authorised privileges.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would like to keep it as message because this is not a notification. Maybe I can term it to warning instead

Copy link
Member

@pankajkoti pankajkoti Aug 2, 2023

Choose a reason for hiding this comment

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

okay so
"The message displayed when a user attempts to execute actions beyond their authorised privileges."
?

Copy link
Member

Choose a reason for hiding this comment

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

If not, the minimum suggestion is to correct an user to a user 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah why not, thanks, making the changes

version_added: 2.7.0
type: string
example: ~
default: "Access is Denied"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
default: "Access is Denied"
default: "Unauthorized Access: Denied"

Copy link
Contributor

Choose a reason for hiding this comment

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

I dont think we can do that. The current message is "Access is Denied" so in order to keep the current experience, we got to have this default value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. We do not want to break the backward compatibility experience. If we want to make this change, we should have a different task for it instead

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @vincbeck

version_added: 2.7.0
type: string
example: ~
default: "Access is Denied"
Copy link
Contributor

Choose a reason for hiding this comment

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

I dont think we can do that. The current message is "Access is Denied" so in order to keep the current experience, we got to have this default value

version_added: 2.7.0
type: string
example: ~
default: "Access is Denied"
Copy link
Member

Choose a reason for hiding this comment

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

I agree with @vincbeck

tests/www/test_security.py Outdated Show resolved Hide resolved
@hussein-awala
Copy link
Member

Waiting for a second look from @uranusjr before merge

Copy link
Contributor

@eladkal eladkal left a comment

Choose a reason for hiding this comment

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

Lets merge so it won't miss 2.7.0
we can modify in followup PR if needed

@eladkal eladkal merged commit 12a760f into apache:main Aug 3, 2023
42 checks passed
ephraimbuddy pushed a commit that referenced this pull request Aug 3, 2023
* Affix webserver access_denied warning to be configurable

(cherry picked from commit 12a760f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:webserver Webserver related Issues type:improvement Changelog: Improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants