Skip to content

[master] rest_cherrypy: accept / force credentials via HTTP header - #66814

Open
Malte-Wagner wants to merge 3 commits into
saltstack:masterfrom
Malte-Wagner:master
Open

Malte-Wagner wants to merge 3 commits into
saltstack:masterfrom
Malte-Wagner:master

Conversation

@Malte-Wagner

Copy link
Copy Markdown

The acceptance of HTTP headers opens the possibility to either set or force credentials for a session.
A reverse proxy, can handle authentication and
inject the custom headers X-Forwarded-User, X-Forwarded-Password and/or X-Forwarded-Eauth. In general, these headers can work in conjunction with the eauth sharedsecret / rest / auto methods to externalize and flexibilize authentication, without raising code complexity for new or niche authentication methods inside salt.

What does this PR do?

This PR enables rest_cherrypy to gather credentials via HTTP headers, that may be set by reverse proxy, to use them for session creation or session checking.

What issues does this PR fix or reference?

#22046

Previous Behavior

Credentials are only allowed via request body.

New Behavior

Credentials are allowed via request body and http header.
Prevalence is http header over request body values.

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

Yes

Please review Salt's Contributing Guide for best practices, including the
PR Guidelines.

See GitHub's page on GPG signing for more information about signing commits with GPG.

@Malte-Wagner
Malte-Wagner requested a review from a team as a code owner August 19, 2024 11:14
@Malte-Wagner
Malte-Wagner requested a review from dwoz August 19, 2024 11:14
@welcome

welcome Bot commented Aug 19, 2024

Copy link
Copy Markdown

Hi there! Welcome to the Salt Community! Thank you for making your first contribution. We have a lengthy process for issues and PRs. Someone from the Core Team will follow up as soon as possible. In the meantime, here’s some information that may help as you continue your Salt journey.
Please be sure to review our Code of Conduct. Also, check out some of our community resources including:

There are lots of ways to get involved in our community. Every month, there are around a dozen opportunities to meet with other contributors and the Salt Core team and collaborate in real time. The best way to keep track is by subscribing to the Salt Community Events Calendar.
If you have additional questions, email us at [email protected]. We’re glad you’ve joined our community and look forward to doing awesome things with you!

@salt-project-bot-prod-environment salt-project-bot-prod-environment Bot changed the title rest_cherrypy: accept / force credentials via HTTP header [master] rest_cherrypy: accept / force credentials via HTTP header Aug 19, 2024
@Malte-Wagner

Copy link
Copy Markdown
Author

Hi @dwoz ,

is something still needed for this MR?

Thanks
Malte

@Malte-Wagner
Malte-Wagner requested a review from a team as a code owner January 12, 2025 12:03

@twangboy twangboy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also needs a changelog and some tests, please.

Comment thread salt/netapi/rest_cherrypy/app.py Resolved
@Malte-Wagner

Copy link
Copy Markdown
Author

Thanks - i'll work on that.

@twangboy twangboy added the test:full Run the full test suite label Jul 1, 2025
@twangboy twangboy added this to the Argon v3008.0 milestone Jul 1, 2025
@twangboy twangboy added needs-testcase PR needs test cases written, or the issue is about a bug/feature that needs test cases needs-changelog labels Jul 1, 2025
@twangboy twangboy modified the milestones: Argon v3008.0, Argon v3008.1 Jun 5, 2026
@twangboy twangboy modified the milestones: Argon v3008.1, Argon v3008.2 Jun 24, 2026
@dwoz dwoz modified the milestones: Argon v3008.2, Potassium v3009.0 Jun 26, 2026
@dwoz dwoz removed needs-testcase PR needs test cases written, or the issue is about a bug/feature that needs test cases needs-changelog labels Jun 26, 2026
twangboy
twangboy previously approved these changes Jul 2, 2026
- Fix docstring bug: X-Forwarded-User listed twice instead of X-Forwarded-Password
- Fix RST heading format (### is not valid RST; use underline style)
- Fix typos: "diffent" -> "different", grammar in comment
- Fix trailing whitespace in doc block
- Fix indentation in _is_valid_token (2-space -> 4-space)
- Fix inline comment spacing (PEP8: two spaces before #)
- Fix missing blank line before force_header_creds()
- Add changelog/66814.added.md
- Add tests/pytests/unit/netapi/cherrypy/test_header_creds.py with 12 unit tests
  covering force_header_creds(), salt_auth_tool(), and Events._is_valid_token()
``_is_valid_token`` now reads ``cherrypy.request.headers`` to honor
the X-Forwarded-User / X-Forwarded-Eauth header-credential feature.
The pre-existing ``MockCherryPy`` shim in test_events.py lacked a
``request`` attribute, so both existing tests hit AttributeError.

Add an empty ``request.headers`` dict to the shim; absent forwarded
headers preserves the original "token only" semantics these tests
exercise.

This branch was previously deployed

1 inactive (outdated) deployment
ci — f187c4c2 Deployed Nov 26, 2026 by dwoz via Build Onedir Packages / macOS (x86_64) #29713
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add oauth and SAML support to salt-api

3 participants