-
Notifications
You must be signed in to change notification settings - Fork 158
Support static websites with index pages #42
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
Conversation
|
Hello. I've tried your patch and it works nice on requests like But when the requests is like When hosting a local folder with configurations like Maybe this could be achieved by transforming the 404 not found from s3 upstream to a 301 redirect with a trailing slash on some conditions (like when no dots after last slash)? If this is possible, hosting static sites with this gateway would be much more robust on different styles of paths. |
|
Thanks for testing, and I think that can be done. Need the maintainers
to comment on what impacts that would have on the existing behavior.
…On Sun, Jul 31, 2022, 10:52 AM Jiang Weihao ***@***.***> wrote:
Hello.
I've tried your patch and it works nice on requests like
example.com/some/path/ to get somebucket.aws/some/path/index.html, which
have a trailing slash and function _isDirectory will recognize it as a
directory.
But when the requests is like example.com/some/path, the function will
not work, as it recognizes with local string processing, which detects
strings end with a slash and returns false, and will finally send 404 to
clients.
When hosting a local folder with configurations like root /some/path;,
nginx would issue a redirect adding a trailing slash as default.
Maybe this could be achieved by transforming the 404 not found from s3
upstream to a 301 redirect with a trailing slash on some conditions (like
when no dots after last slash)?
User -> http/some/path -> s3-gateway -> s3/some/path
301 http/some/path/ <- s3-gateway <- 404
User -> http/some/path/ -> s3-gateway -> s3/some/path/index.html
If this is possible, hosting static sites with this gateway would be much
more robust on different styles of paths.
—
Reply to this email directly, view it on GitHub
<#42 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABMSCSUL2DTH52IJZVXIJPDVW2HMFANCNFSM546SCNVA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
- Added a variable `STATIC_SITE_HOSTING` to enable - Tests modified to include the static site hosting
|
@Victrid I can get the logic to trigger the redirect, but I dont seem to be able to change the $s3uri variable. It keeps retrying I thought this should work, |
|
@Gamecock I've opened a PR to your branch implementing this. It will not change the s3 uri, but let user's browser to perform the redirection. It is performed with nginx itself. On s3 returned 404, it will be internal redirected to @staticPageHandler, and if is not a dir with static site hosting enabled, it will be internal redirected to |
|
@Gamecock Thank you for your PR! I'm going to start reviewing it now. |
|
Here are some high level thoughts about the feature. This feature should be configurable using a flag separate from As you no doubt discovered, both any index page feature will interact with the directory list feature. For example, if directory listing is enabled and index pages are enabled, then you want the index page to display only if it is present in the S3 bucket, and when it is not present, you would display the directory listing. The approach that I see you went with was one where we have mutually exclusive settings, such that you cannot enable index pages AND directory listings. I like this approach because it avoids a bunch of the problems with race conditions you would hit if you tried to enable both. |
|
I just looked through the code and it is a good PR! Thank you so much for your work. I get a bit excited every time I see a contribution. The changes needed are:
|
|
@dekobon If they are two separate settings for |
|
Runtime error would be preferable. What do you think?
…On Wed, Aug 3, 2022 at 6:43 PM Mike Finch ***@***.***> wrote:
@dekobon <https://github.com/dekobon> If they are two separate settings
for ALLOW_DIRECTORY_LIST and RETURN_INDEX_PAGES do you want a runtime
error or just ignore one of them?
—
Reply to this email directly, view it on GitHub
<#42 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADXXGDE7UVZFXRNG45WGB3VXK4UFANCNFSM546SCNVA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
--
-Elijah
|
|
Are you OK with including @Victrid's suggestion to redirect with a 301/308 on items that don't have either a file extension or a trailing slash? I'm not checking that it actually exists. |
|
@Gamecock Perhaps the environment variable that enables index pages should allow a setting that enables redirects. This seems like the kind of thing that you sometimes want, but surely not always. |
Add 301 redirection to non-slash trailing requests
|
@dekobon The build issue looks like a permissions issue on push. I don't think I can resolve. |
|
The build succeeded, but PR checkins like this do not have permissions to push a new container image to the repository. There is probably a way to set up the build so it will conditionally skip the container image push step, but I haven't figured it out yet. |
|
We are almost ready to merge. This is exciting seeing this functionality getting added. Next, we need to:
|
dekobon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really good. I see only a few minor changes.
|
|
||
| integration_test() { | ||
| printf "\033[34;1m▶\033[0m" | ||
| printf "\e[1m Integration test suite for v%s signatures\e[22m\n" "$1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Around line 34, we will need to add:
export COMPOSE_COMPATIBILITY=true
Because with the addition of the health check in the docker-compose.yaml, I had to upgrade my Docker Compose version to support it - previously I was using the version provided by Ubuntu's package repository. After upgrading, Docker Compose changes how it names containers and thereby breaking this script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll submit s separate PR for windows support to make it cleaner, unless you have an objection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd put it in this PR because without this environment variable, v2 of docker-compose on Linux fails to work with the test script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it.
| var uri = _isDirectory(r.variables.uri_path) ? '/' : r.variables.uri_path; | ||
| // For static website we want the path + index.html | ||
| if (static_hosting && _isDirectory(r.variables.uri_path)){ | ||
| uri = r.variables.uri_path + "index.html" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put the string literal index.html in a top level variable and reference it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've merged @Victrid 's PR with mine. Still have some cleanup and documentation, will get it in in the next few days.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dekobon I think all the changes you requested have been made.
dekobon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the contribution!
|
So - this MR basically reverted the V4 auth fix that was merged in #43 My question is - was that fix breaking something or was the revert a mistake that was unintended? |
|
It was not intentional on my part, it looks like a merge conflict not addressed properly. Having said that if it's something that only causes an issue for one client, there should probably be a unit test update also so no one else breaks this by mistake again. |
|
Yes, that was a complete mistake on my part when doing the merge. |
|
The change has been re-applied. Thank you for catching the issue. |
Please review the direct and provide suggestions. If this looks good I can add a commit to update the documentation. I've done preliminary testing with the OSS version and V2 & V4 signatures and AccessKey auth. However additional testing is welcome.
Sort of inelegant that I have to append the 'index.html' 3 times, once to update the URL, and then again in the V2 and V4 signatures. I'll take annother look and see if I can avoid that.
Uses the ALLOW_DIRECTORY_LIST flag to decide to return list(true) or index(false).
Returns a 404 if no index.html in that directory.
fixes #13