Skip to content

Conversation

@Gamecock
Copy link
Contributor

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

@Victrid
Copy link
Contributor

Victrid commented Jul 31, 2022

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.

@Gamecock
Copy link
Contributor Author

Gamecock commented Jul 31, 2022 via email

- Added a variable `STATIC_SITE_HOSTING` to enable
- Tests modified to include the static site hosting
@Gamecock
Copy link
Contributor Author

Gamecock commented Aug 2, 2022

@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
/some/path
instead of /some/path/index.html

I thought this should work,
set $s3uri "${s3uri}/index.html";

   Any thoughts, I can share the current state of the branch if you are interested.

@Victrid
Copy link
Contributor

Victrid commented Aug 3, 2022

@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 @trailslash, which will send a 301 to user.

    location @staticPageHandler {
        # Checks if requesting a folder without trailing slash, and return 302 
        # appending a slash to it when using for static site hosting.
        js_content s3gateway.staticPageHandler;
    }


    location @trailslash {
        # 301 to request without slashes
        rewrite ^ $scheme://$http_host$request_uri/ redirect;
    }

@dekobon
Copy link
Collaborator

dekobon commented Aug 3, 2022

@Gamecock Thank you for your PR! I'm going to start reviewing it now.

@dekobon
Copy link
Collaborator

dekobon commented Aug 3, 2022

Here are some high level thoughts about the feature.

This feature should be configurable using a flag separate from ALLOW_DIRECTORY_LIST because it is a distinct feature with security implications.

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.

@dekobon
Copy link
Collaborator

dekobon commented Aug 3, 2022

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:

  • Add a setting to enable or disable the feature, with the default being disabled
  • Add documentation for the setting and proper use of the feature
  • Move the string literal index.html to a top level variable

@Gamecock
Copy link
Contributor Author

Gamecock commented Aug 3, 2022

@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?

@dekobon
Copy link
Collaborator

dekobon commented Aug 3, 2022 via email

@Gamecock
Copy link
Contributor Author

Gamecock commented Aug 3, 2022

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.

@dekobon
Copy link
Collaborator

dekobon commented Aug 3, 2022

@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
@Gamecock
Copy link
Contributor Author

Gamecock commented Aug 8, 2022

@dekobon The build issue looks like a permissions issue on push. I don't think I can resolve.

@dekobon
Copy link
Collaborator

dekobon commented Aug 8, 2022

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.

@dekobon
Copy link
Collaborator

dekobon commented Aug 8, 2022

We are almost ready to merge. This is exciting seeing this functionality getting added.

Next, we need to:

  • Rebase in the latest master branch into this branch.
  • Fix the minor issues highlighted in code review.
  • Update the documentation to reflect the new features added.

Copy link
Collaborator

@dekobon dekobon left a 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"
Copy link
Collaborator

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.

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'll submit s separate PR for windows support to make it cleaner, unless you have an objection.

Copy link
Collaborator

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.

Copy link
Contributor Author

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"
Copy link
Collaborator

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.

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've merged @Victrid 's PR with mine. Still have some cleanup and documentation, will get it in in the next few days.

Copy link
Contributor Author

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.

@Gamecock Gamecock changed the title WIP: Support static websites Support static websites with index pages Aug 10, 2022
Copy link
Collaborator

@dekobon dekobon left a 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!

@dekobon dekobon closed this in 33840bd Aug 11, 2022
@sochotnicky
Copy link

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?

@Gamecock
Copy link
Contributor Author

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.

@dekobon
Copy link
Collaborator

dekobon commented Aug 15, 2022

Yes, that was a complete mistake on my part when doing the merge.

@dekobon
Copy link
Collaborator

dekobon commented Aug 15, 2022

The change has been re-applied. Thank you for catching the issue.

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.

Support for index documents

4 participants