Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Always upload .well-known dotfiles #980

Closed
ndarilek opened this issue Dec 29, 2019 · 26 comments · Fixed by #1566
Closed

Always upload .well-known dotfiles #980

ndarilek opened this issue Dec 29, 2019 · 26 comments · Fixed by #1566
Labels
design feature Feature requests and suggestions good first issue Good for newcomers sites
Milestone

Comments

@ndarilek
Copy link

Wrangler doesn't appear to publish hidden files. In particular, I'm attempting to publish a Hugo site with public/.well-known/* (I.e. .well-known/keybase.txt, .well-known/matrix/server, etc.) These files are definitely in public/, but don't appear in the key list for the created namespace.

@ndarilek
Copy link
Author

Figured out that include = ["*"] in wrangler.toml gets me a bit further with this. But while /.well-known/keybase.txt is served up fine, /.well-known/matrix/client and /.well-known/matrix/server aren't. I see the following in kv:list:

  {
    "name": ".well-known/keybase.8c602ecfc951c47ee9ad9845116e2082d5999a988f145dde543a7a1d1e75ab23.txt"
  }
  {
    "name": ".well-known/matrix/server.f9a5bcb8e11c9fc83a11d31e40daf3083d228ed0396d3abcbd45e8c4ea5ebfac"
  },
  {
    "name": ".well-known/matrix/client.c8ca63cb67a167114e46fc4b5ce38c70b751572b83038dd1ea79cf5bc1c30a6a"
  },

So they seem to be there, but I can't get them via Curl as I can /.well-known/keybase.txt.

What are the hash-looking things after the file's base and before the extension? Wondering if something is confused by the lack of extension on my /.well-known/matrix/* files.

This is kind of unintuitive. Every other platform I've worked with happily assumes that anything in public/ is meant for serving. I may still have some header massaging to do to ensure that, say, /.well-known/matrix/server gets the correct content-type, but it shouldn't be this hard to just ship my directory content and count on it arriving intact.

Thanks.

@exvuma
Copy link
Contributor

exvuma commented Dec 31, 2019

Thanks for the feedback. We don't upload hidden files by default because if there is any sensitive info, it will be served globally on our network.

What are the hash-looking things after the file's base and before the extension?

Hashes of the content contained in the file to ensure unique content is cached on Cloudflare properly. It's pretty fascinating how we implemented this, read more here: https://blog.cloudflare.com/extending-the-workers-platform/

Wondering if something is confused by the lack of extension on my /.well-known/matrix/* files.

A mime library is used to determine the content type to serve from the extension. Would you mind sharing the actual results of the curl with the -v flag?

@ndarilek
Copy link
Author

ndarilek commented Dec 31, 2019 via email

@exvuma
Copy link
Contributor

exvuma commented Dec 31, 2019

A custom 404 is caching:

curl -v https://lightsoutgames.nolan.workers.dev/.well-known/matrix/server  2>&1 | egrep -i "404|cache"
< HTTP/2 404
< cache-control: max-age=8640000
< cf-cache-status: HIT

Did you adjust the cache settings on getAssetFromKV ? Or adjust any other internals of workers-site/index.js? Can you try purging your Cloudflare cache?

@ndarilek
Copy link
Author

ndarilek commented Dec 31, 2019 via email

@exvuma
Copy link
Contributor

exvuma commented Jan 2, 2020

Sorry for the back and forth, we actually don't serve files without extensions. After speaking with the team, we agree the kv asset handler should though, so we are moving this issue to that repo.

In the meantime, you can work around this for your project by passing in a customer modifier to getAssetFromKV. Instead of using the default mapRequestToAsset which maps requests w/o extensions to an index.html, you'd want to have the request just be the root.

Code would look something like

const mapRequestToAsset = (request: Request) => {
  return request //  to NOT append index.html to files with no extensions
  } 

See more docs on this at https://github.com/cloudflare/kv-asset-handler#maprequesttoasset

@ndarilek
Copy link
Author

ndarilek commented Jan 3, 2020 via email

@ashleymichal
Copy link
Contributor

@ndarilek I'm either going to file a new one today or transfer this one there. Need to decide if there is also work we want to do in Wrangler to include dotfiles.

@ndarilek
Copy link
Author

ndarilek commented Jan 3, 2020 via email

@ashleymichal
Copy link
Contributor

@ashleymichal ashleymichal changed the title Not publishing hidden files Allow users to "include" certain dotfile directories, esp .well-known Jan 3, 2020
@ashleymichal ashleymichal added feature Feature requests and suggestions question design sites and removed question labels Jan 3, 2020
@gabbifish
Copy link
Contributor

Following up on the original issue, which is allowing .well-known to be uploaded by default:
Given that the include field is a whitelist that, if specified, overrides ALL upload ignore conditions and only permits the upload of whatever matches whitelist entries, we're stuck with instructing users to specify include = ["*"] or include = [".well-known", <all other directories specified in bucket>]. These solutions are workable but honestly not sastisfactory; since .well-known is an IETF standard, we should support it by default.

The problem with supporting it by default in our preexisting code is that the Ignore crate adopts the include rules that are consistent with cargo; that is, if any whitelist exists, the only files that are uploaded MUST match whatever patterns are in the whitelist. This leaves us in the same situation as before--asking users to specify every directory that gets uploaded.

This leaves us with other options to consider:

  1. Introduce a hidden bool flag to [sites] in wrangler.toml that toggles the upload of hidden files. Potentially more ergonomic than specifying include = ["*"], plus this won't mess with users' preexisting include and exclude fields (conflicts will be resolved with standard gitignore conflict resolution).
  2. Do nothing and just have users specify include = ["*"].

I could gravitate towards either of these options at this point. I don't really love either of them, though, because they simply just allow for the upload of hidden files. I'd prefer more granularity, where only .well-known is uploaded and other hidden files are ignored by default.

@ndarilek
Copy link
Author

ndarilek commented Jan 14, 2020 via email

@gabbifish
Copy link
Contributor

Thank you for the feedback, @ndarilek! This is super helpful. I can definitely add a warning message about hidden files being ignored (and not have this lumped in under verbose output).

@ashleymichal ashleymichal added this to the sites clean up milestone Mar 3, 2020
@chris-erickson
Copy link

I'd second automatically uploading .well-known - I got bit by this as well, and everything about that directory really says I know that this is a directory with some stuff I deliberately put here for deploy!

On the second issue, files w/o an extension, how should I update this so that I serve only these files w/o extensions? I use Gatsby and I'm not exactly sure if I need the file name appending logic. Perhaps there's something a bit more precise than just removing the default behavior of Wrangler setups.

@ndarilek
Copy link
Author

ndarilek commented Mar 18, 2020 via email

@ndarilek
Copy link
Author

Here's a hacky potential workaround for some .well-known routes. In workers-site/index.js:

    if (url.pathname == "/.well-known/matrix/server")
      return new Response(
        '{"m.server": "matrix.my.domain:443"}',
        {
          headers: {
            "Access-Control-Allow-Origin": "*",
            "Content-Type": "application/json"
          }
        }
      )
    else
      return await getAssetFromKV(event, options)

Would love to continue serving that as a static file, but for now it seems to work. Naturally, tweak for your own .well-known routes/path matches.

@chris-erickson
Copy link

For future people, I ended up with this:

if (url.pathname == applePayPath) return new Response(applePayBody);

It’s not really great and adding a lot more of these could get onerous and error-prone. I hope the team allows some built-in mechanism for this someday.

@stale
Copy link

stale bot commented Jun 27, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jun 27, 2020
@ndarilek
Copy link
Author

ndarilek commented Jun 27, 2020 via email

@stale stale bot removed the wontfix label Jun 27, 2020
@ashleymichal
Copy link
Contributor

@ndarilek i'm going to update this issue to always upload .well-known files within the bucket directory. hopefully we can add it to the milestone for 1.11.0, which should go out in a few weeks.

Thank you for re-upping.

@ashleymichal ashleymichal changed the title Allow users to "include" certain dotfile directories, esp .well-known Always upload .well-known dotfiles Jun 29, 2020
@ashleymichal ashleymichal modified the milestones: sites clean up, 1.11.0 Jun 29, 2020
@ispivey ispivey added the good first issue Good for newcomers label Aug 4, 2020
@nataliescottdavidson nataliescottdavidson self-assigned this Aug 7, 2020
@nataliescottdavidson
Copy link
Contributor

I think @gabbifish 's comment still stands. The overrides truly do override all the existing paths in the crate we are depending on to walk the directory. This behavior seems really weird, so I've asked a question on the repository page.

@nataliescottdavidson
Copy link
Contributor

It looks like getting a fix for ignore::WalkBuilder not traversing directories recursively when overrides are given is unlikely. My understanding is that the maintainer of ripgrep isn't accepting changes on the include crate right now.. So, do we want to introduce a hidden bool flag to [sites] in wrangler.toml that toggles the upload of hidden files, or mark this as a wontfix?

@chris-erickson
Copy link

That would be a sad outcome 😔. We could make use of uploading invisibles to remove a bunch of really dumb hacks.

@exvuma
Copy link
Contributor

exvuma commented Aug 25, 2020

Why not an explicit opt-in/opt-out field rather than toggling a boolean for all hidden directories? I'd like one sensical default behavior for what gets uploaded with the ability to opt in or out by directory pattern or file (e.g. include: [.well-known/*, .my-speicla-file]

@nataliescottdavidson nataliescottdavidson removed their assignment Aug 28, 2020
@osdiab
Copy link

osdiab commented Sep 2, 2020

Just wanted to chime in that my company is also trying to use Cloudflare Worker Sites because it was marketed as a static site hosting service, but issues like this make it hard for me to continue advocating for it... Our bundle doesn't currently have anything sensitive so I'll do combination of the above hacks for now - but this is pretty rough.

@ashleymichal ashleymichal modified the milestones: 1.11.0, 1.12.0 Sep 11, 2020
@ispivey
Copy link
Contributor

ispivey commented Sep 18, 2020

Next step: we'll evaluate just doing this ourselves natively without a dependency on the Walkdir/Glob crates, since our use case is rather narrow.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
design feature Feature requests and suggestions good first issue Good for newcomers sites
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants