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

[full-ci] Refactor proxy to get rid of the hardcoded unprotected lists #4461

Merged
merged 6 commits into from
Sep 1, 2022

Conversation

C0rby
Copy link
Contributor

@C0rby C0rby commented Aug 25, 2022

Related Issue

Motivation and Context

How Has This Been Tested?

  • test environment:
  • test case 1:
  • test case 2:
  • ...

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation ticket raised:

@C0rby C0rby self-assigned this Aug 25, 2022
@update-docs
Copy link

update-docs bot commented Aug 25, 2022

Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would create a changelog item based on your changes.

@kulmann
Copy link
Member

kulmann commented Aug 26, 2022

Gave it a spin, with following results:

  • uploads work
  • preview requests throw a http 500, with error message that reveals an internal 401:
    <d:error xmlns:d="DAV" xmlns:s="http://sabredav.org/ns">
       <s:exception></s:exception>
       <s:message>  {&#34;id&#34;:&#34;com.owncloud.api.thumbnails&#34;,&#34;code&#34;:500,&#34;detail&#34;:&#34;could not get image from source: could not get the image \&#34;1284d238-aa92-42ce-bdc4-0b0000009157$06d8eaca-7a6d-4798-9b31-c24ab6b26a91/SpaceX/starship super heavy.jpeg\&#34;. Request returned with statuscode 401 &#34;,&#34;status&#34;:&#34;Internal Server Error&#34;}</s:message>
    </d:error>
  • creating a text file failed: PUT to https://localhost:9200/remote.php/dav/spaces/1284d238-aa92-42ce-bdc4-0b0000009157%2406d8eaca-7a6d-4798-9b31-c24ab6b26a91/asdf.txt -> 401 (Unauthorized)
  • opening a previously uploaded text file failed with basic auth popup and 401 on GET for https://localhost:9200/remote.php/dav/spaces/1284d238-aa92-42ce-bdc4-0b0000009157%2406d8eaca-7a6d-4798-9b31-c24ab6b26a91/SpaceX/clm0008.txt
  • renaming files/folders works
  • copying filles/folders failed: COPY to https://localhost:9200/remote.php/dav/spaces/1284d238-aa92-42ce-bdc4-0b0000009157%2406d8eaca-7a6d-4798-9b31-c24ab6b26a91/SpaceX%20asdf -> 500 (Internal Server Error) -> after page reload the file files/folders are there. 🤔

David Christofas added 2 commits August 30, 2022 12:30
I refactored the proxy so that we execute the routing before the
authentication middleware. This is necessary so that we can determine
which routes are considered unprotected i.e. which routes don't need
authentication.
I added an unprotected flag to the proxy routes which is evaluated by
the authentication middleware. This way we won't have to maintain a
hardcoded list of unprotected paths and path prefixes and we will
hopefully reduce the times we encounter the basic auth prompt by web
browsers.
@ownclouders
Copy link
Contributor

ownclouders commented Aug 30, 2022

💥 Acceptance test Core-API-Tests-ocis-storage-1 failed. Further test are cancelled...

@C0rby C0rby force-pushed the refactor-proxy branch 2 times, most recently from 1b2cdc3 to 46f48de Compare August 30, 2022 12:51
@C0rby C0rby changed the title Refactor proxy to get rid of the hardcoded unprotected lists [full-ci] Refactor proxy to get rid of the hardcoded unprotected lists Aug 30, 2022
@C0rby C0rby marked this pull request as ready for review August 30, 2022 15:47
@sonarcloud
Copy link

sonarcloud bot commented Aug 30, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 6 Code Smells

65.0% 65.0% Coverage
0.0% 0.0% Duplication

Copy link
Member

@kulmann kulmann left a comment

Choose a reason for hiding this comment

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

Retested a lot of different scenarios, all worked well. Only thing I found was on the archiver route for public links (see comment), but also broken on master, so IMO not a blocker for this PR.

Backend: "http://localhost:9130",
Endpoint: "/signin/",
Backend: "http://localhost:9130",
Unprotected: true,
},
{
Endpoint: "/archiver",
Copy link
Member

Choose a reason for hiding this comment

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

tough one: when the archiver is opened from a public link it needs to be unprotected as well. Archiver from public link has ?public-token=xyz in the url query.

Copy link
Member

Choose a reason for hiding this comment

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

I'd be fine solving that in a followup ticket, as it's also currently broken in master.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, I guess this should be fixable with an addtional QueryRoute. I see if I can address this in another PR.

Copy link
Contributor

@rhafer rhafer 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 apart from a little nit picking about the comment.

@@ -91,7 +49,8 @@ func Authentication(auths []Authenticator, opts ...Option) func(next http.Handle

return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if isOIDCTokenAuth(r) || isUnprotectedPath(r) {
ri := router.ContextRoutingInfo(r.Context())
if isOIDCTokenAuth(r) || ri.IsRouteUnprotected() {
// The authentication for this request is handled by the IdP.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: This comment seems to be not quite correct anymore.

Backend: "http://localhost:9130",
Endpoint: "/signin/",
Backend: "http://localhost:9130",
Unprotected: true,
},
{
Endpoint: "/archiver",
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, I guess this should be fixable with an addtional QueryRoute. I see if I can address this in another PR.

@rhafer rhafer merged commit bfb26cc into master Sep 1, 2022
@delete-merged-branch delete-merged-branch bot deleted the refactor-proxy branch September 1, 2022 10:43
@rhafer
Copy link
Contributor

rhafer commented Sep 1, 2022

Turns out that this causes some unstable behavior for routes that match multiple rules 😱. E.g. we have:

                {                                 
                    Endpoint:    "/app/list",
                    Backend:     "http://localhost:9140",
                    Unprotected: true,
                },
                {
                    Endpoint: "/app/", // /app or /apps? ocdav only handles /apps
                    Backend:  "http://localhost:9140",
                },

And now requests on /app/list/ sometimes go through and sometimes fail. (Not this is not exactly a new bug in the code, it just seems that we didn't have overlapping rules of the same type before. I'll open a new issue for that and try to come up with a quick fix. (We might also temporary revert this PR).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor proxy request authentication
4 participants