gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
75.72k stars 7.53k forks source link

Add a concept of HUGOBIN and a way to install binary dependencies #10757

Open bep opened 1 year ago

bep commented 1 year ago

Dart Sass with Hugo is incredibly powerful, but it's also a pain to install. #8299 has been stranded because 1. Go doesn't have a way of doing this built-in and 2. Building a custom solution would be a challenge to do securely.

This proposal outlines a way to do this. This is deliberately a little vague about the details.

Since GitHub releases is separated from the Git repo, we need to somehow wrap these binaries in a module somehow:

The above should

  1. Have a security model that's fairly easy to reason about.
  2. Have a familiar versioning scheme.
  3. Allows theme authors to define "Dart Sass" as a dependency.
jmooring commented 1 year ago

just store version information + file hashes and then download the correct architecture when needed.

Agree. This is what the Scoop, Chocolatey, and Snap packages for Embedded Dart Sass do.

bep commented 1 year ago

@jmooring can I borrow your attention for a minute. I have a working prototype of this running and, as usual, I'm a little paranoid about security. After a little testing I have concluded that having the user do PATH fiddling to make this work, isn't ... great. So with what I have now I use abs paths to the "imported" binaries, and this should be enough to get Dart Sass:

[[module.imports]]
path="github.com/gohugoio/hugo-mod-bin-dartsass"

The SHA56 of the downloaded archive (stored in the Hugo Module) is checked on installation.

The one thing I'm a little worried about then is someone creating a fake Hugo Module with a fake dartsass binary. A little far fetched, perhaps, but to improve on this I have added a new whitelist to the security config: AllowBinFromModules: "^github.com/gohugoio/" -- thinking that most such binaries will be hosted by us, and we can be trusted.

What do you think?

Some links:

jmooring commented 1 year ago

Thoughts, in no particular order...

  1. Can we hardcode AllowBinFromModules: "^github.com/gohugoio/", without the ability to override via site configuration or env vars? You and I export env vars from our .bashrc files or whatever to make sure that, when we clone a project, we're not exposed when the cloned project overrides the default security config. But I think this is rare; I would be surprised if more than a handful of users have configured their systems this way.
  2. Will there be any challenges setting the perms to 711, or 700 if the exec will be owned by the user?
  3. What happens if I vendor the module?
  4. Will the execs end up in HUGO_CACHEDIR, which for most users is volatile?

Finally, and please be don't be offended, but it seems like installing Go is a little more complicated than using a package manager, assuming they've already installed the package manager, which many have not, so maybe requiring Go is OK.

And a couple of FYI's:

jmooring commented 1 year ago

There's also this: https://www.npmjs.com/package/sass-embedded

npm i sass-embedded

It is platform aware. Not sure you want to go down that path, but we do have precedence with POSTCSS.

bep commented 1 year ago

I'm not totally sure I'm able to land this issue anytime soon, but I appreciate your feedback.

bep commented 1 year ago

Thinking a little more on this, I'll let this be as it is for now:

brycewray commented 1 year ago

The way 0.114.0 works with the new Dart Sass packaging is truly outstanding; kudos! Does this in any way suggest a path to resolving this particular issue (and/or https://github.com/gohugoio/hugo/issues/8299), or is it of no value in that regard?

Edit, 2023-06-23: Actually, on the other hand, @jmooring has now made an excellent argument against further worrying about this.