Digital Ocean Spaces não implementa a API AWS S3 para a regra CORS

,

Ainda estou com dificuldades para mover os uploads para o Spaces. Quando s3_cdn_url está definido, o Discourse aponta para o s3_cdn para os ativos, mas eles não estão lá. Tentei executar rake s3:upload_assets e obtive:

root@shadrack-rbx:/var/www/discourse# rake s3:upload_assets                                                             
instalando a regra CORS
Enviando: assets/vendor-3037640def3beef9cc83cef108868f2bac887cf141d032c6b7388c7879c19601.js
OPÇÕES: {:cache_control=>"max-age=31556952, public, immutable", :content_type=>"application/ecmascript", :acl=>"public-read", :tagging=>""} # NOTA: Pfaffman adicionou esta linha de depuração. . . 
rake aborted!
Aws::S3::Errors::InvalidArgument: 
/var/www/discourse/vendor/bundle/ruby/2.5.0/gems/aws-sdk-core-3.46.1/lib/seahorse/client/plugins/raise_response_errors.rb:15:in `call'
/var/www/discourse/vendor/bundle/ruby/2.5.0/gems/aws-sdk-s3-1.30.1/lib/aws-sdk-s3/plugins/sse_cpk.rb:22:in `call'
/var/www/discourse/vendor/bundle/ruby/2.5.0/gems/aws-sdk-s3-1.30.1/lib/aws-sdk-s3/plugins/dualstack.rb:26:in `call'
/var/www/discourse/vendor/bundle/ruby/2.5.0/gems/aws-sdk-s3-1.30.1/lib/aws-sdk-s3/plugins/accelerate.rb:35:in `call'
/var/www/discourse/vendor/bundle/ruby/2.5.0/gems/aws-sdk-core-3.46.1/lib/aws-sdk-core/plugins/jsonvalue_converter.rb:20:in `call'
/var/www/discourse/vendor/bundle/ruby/2.5.0/gems/aws-sdk-core-3.46.1/lib/aws-sdk-core/plugins/idempotency_token.rb:17:in `call'
/var/www/discourse/vendor/bundle/ruby/2.5.0/gems/aws-sdk-core-3.46.1/lib/aws-sdk-core/plugins/param_converter.rb:24:in `call'
/var/www/discourse/vendor/bundle/ruby/2.5.0/gems/aws-sdk-core-3.46.1/lib/aws-sdk-core/plugins/response_paging.rb:10:in `call'
/var/www/discourse/vendor/bundle/ruby/2.5.0/gems/aws-sdk-core-3.46.1/lib/seahorse/client/plugins/response_target.rb:23:in `call'
/var/www/discourse/vendor/bundle/ruby/2.5.0/gems/aws-sdk-core-3.46.1/lib/seahorse/client/request.rb:70:in `send_request'
/var/www/discourse/vendor/bundle/ruby/2.5.0/gems/aws-sdk-s3-1.30.1/lib/aws-sdk-s3/client.rb:5856:in `put_object'
/var/www/discourse/vendor/bundle/ruby/2.5.0/gems/aws-sdk-s3-1.30.1/lib/aws-sdk-s3/object.rb:928:in `put'
/var/www/discourse/lib/s3_helper.rb:44:in `upload'
/var/www/discourse/lib/tasks/s3.rake:38:in `block in upload'
/var/www/discourse/lib/tasks/s3.rake:37:in `open'
/var/www/discourse/lib/tasks/s3.rake:37:in `upload'
/var/www/discourse/lib/tasks/s3.rake:148:in `block (2 levels) in <top (required)>'
/var/www/discourse/lib/tasks/s3.rake:147:in `each'
/var/www/discourse/lib/tasks/s3.rake:147:in `block in <top (required)>'
/usr/local/bin/bundle:23:in `load'
/usr/local/bin/bundle:23:in `<main>'
Tasks: TOP => s3:upload_assets
(Veja o rastreamento completo executando a tarefa com --trace)
root@shadrack-rbx:/var/www/discourse# vi config/discourse.
discourse.conf           discourse.config.sample  discourse.pill.sample    
root@shadrack-rbx:/var/www/discourse# vi config/discourse.conf
root@shadrack-rbx:/var/www/discourse# rails c

Só para constar, essa configuração consegue enviar imagens para o S3 sem problemas.

E, se isso funcionasse, os ativos seriam enviados para o S3 durante o bootstrap? Quero muito mover este site para o S3 (73 GB de imagens) para migrar para uma configuração de servidor diferente. O Spaces é atraente porque tenho créditos de indicação e CDN gratuito. Mas talvez eu deva desistir e migrar diretamente para o AWS S3?

Why do you need to push assets to S3? Can’t they be served from a push CDN like normal? Uploads assets means JS files not uploads.

That’s what I thought, but what’s happening is that all the assets are linked to the S3 CDN url and they aren’t there. I’d assumed that they’d either be served by the CDN like normal (I have one site configured with regular CDN and it points to S3 cdn when that’s configured) or from local storage (I have another site configured with no regular CDN and when I have s3_cdn_url in global settings, all the assets are linked to the s3 CDN.

So, I either need to push assets to S3 or have Discourse not point to assets in S3. I don’t really care, but they need to be somewhere that they can be found, as without assets the whole site is hosed and I have to make changes in console.

Making sure you saw this @pfaffman because this topic makes very little sense the way it is phrased now.

Do you mean “uploads” as in “uploaded files”?

No, I really mean assets (uploads seem fine). It seems that when GlobalSettings.s3_cdn_url is defined, discourse expects assets (i.e., the javascript stuff) to be in the S3 CDN, so the site is broken because none of the assets are available.

It makes zero sense to me either. :frowning_face:

I just set SiteSettings.s3_cdn_url (not in GlobalSettings) and assets seem to still be coming from the server, not the CDN. So maybe it’s a bug with GlobalSettings.s3_cdn_url?

Yup. Re-setting the value in discourse.conf does this:

All those red things link to the CDN for the assets.

I turned it back on/off and defining it as a global makes assets link to the s3_cdn_url.

So I guess the thing to do is configure those values in a plugin and hide them from the UX that way.

Looks like spaces don’t implement the AWS S3 API for the CORS rule. That is a must have since assets can contain fonts, and those really need CORS.

Maybe work on a way to disable the rules insertion and took care of that manually?

@rishabh did this already with the tombstone rule to allow our S3 compatibility with more providers, so makes sense to expand on that.

So if I want to move this site to S3 maybe I should just give in and stick this on AWS S3 and then stick CloudFlare or KeyCDN in front of it?

No.

That means that if you want to use the GlobalSettings for S3 in the current state you will need to deal with the missing feature in the S3-like service in Digital Ocean, patching around it somehow.

You already have a workaround (use a normal site setting), and we know that we need a setting to disable the CORS rule (pr-welcome for that).

Sorry I’m dense. I’ve been working on this off and on for months.

Ah, so as long as I don’t use GlobalSettings it’ll work just fine? (Because GlobalSettings also wants assets to be in S3?)

Não tenho certeza se você (ou qualquer outra pessoa) ainda está tendo problemas com isso, ou se o abaixo resolveria, mas como encontrei isso ao solucionar meu próprio problema, achei que deveria compartilhar:

  • Se você está usando o Digital Ocean Spaces para armazenamento S3, e
  • Você possui temas com fontes carregadas, como WOFF, que são copiadas para o armazenamento S3, e
  • Você está recebendo erros de CORS ao carregar as fontes no seu site Discourse, então –

O Digital Ocean Spaces agora possui configurações de CORS no Endpoint que você está usando para armazenamento S3. Defina a URL do seu site Discourse como Origem, GET para métodos permitidos e algo razoável como 86400 para o tempo.

Portanto, a conclusão de todo o tópico foi um mal-entendido.

Passei um dia inteiro testando a compatibilidade do Discourse com as ofertas da DO, e a questão do CORS aqui foi uma distração.

O problema é que os DO Spaces não implementam o cabeçalho tagging em sua réplica do S3.

A correção para a tarefa upload_assets é bastante simples e está em uma branch.

O problema é que realmente usamos tagging de verdade em outra tarefa rake, então, se estiver usando DO Spaces, não será possível usar a tarefa s3:expire_missing_assets. Isso pode ser uma troca “aceitável” para alguns.

Planejo atualizar e criar alguns novos guias sobre isso na próxima semana.

Uggggh, podemos reportar isso ao DO? Para que eles possam corrigir a clonagem deles?

Estou documentando um grande experimento usando serviços da DO com o Discourse (como serviço Redis, serviço PostgreSQL, serviço de armazenamento de objetos, serviço CDN), para que possamos apresentar isso em um documento conciso. Já encontrei um problema muito pior. A CDN clonada da S3 deles remove o cabeçalho Content-Encoding dos arquivos, então não é possível servir nossos JavaScripts GZip e Brotli, o que simplesmente quebra tudo.

O melhor resultado a longo prazo para todos é que todas as clonagens do AWS S3 sejam realmente… precisas? Então, se pudermos acompanhar e cobrar os provedores para melhorar suas clonagens, esse é o caminho superior.

Com certeza.

Isso seria fantástico, mas não estou contando com isso.

Por outro lado, eles não podem consertar o que não sabem que está quebrado. Talvez isso dê a eles o empurrão de que precisam.

Entrei em contato com a Digital Ocean e parece que eles estão executando o MinIO nos bastidores. O MinIO recebeu suporte a tags há um mês. Eles terão suporte para isso assim que lançarem essa nova versão.

Isso está funcionando agora.

Basta seguir Usando Armazenamento de Objetos para Uploads (Clones S3)