S3 CDN URL ignored when uploading into posts

AI-generated summary

A long-standing issue in Discourse is the S3 CDN URL being ignored when uploading into posts. This results in a generic bucket URL being used instead of the custom CDN URL set in s3 cdn url. This problem is particularly significant for users with private ACLs on their S3 buckets, as it causes broken images in the post preview window.

@DanielMarquard first reported the issue, and @timkelty expressed disappointment that it had gone unfixed for so long. @Stephen suggested that the implementation was not fully supported, but @timkelty argued that the behavior was broken and forced users to adopt an S3 configuration that AWS recommends against.

@sam proposed a potential fix, which was implemented by @vinothkannans. However, the issue regressed, as reported by @RGJ. @vinothkannans provided another fix, but it did not cover custom emojis in the preview, as noted by @Falco. Additionally, the fix did not apply to attachments, as pointed out by @applebee1558. A pull request to fix the attachment issue was submitted by @nbianca.

All of our traffic goes through CloudFront, and static content is fetched by CloudFront from one of several S3 buckets.

With uploads being sent to S3, Discourse embeds the content with a generic bucket URL despite our having s3 cdn url set. Once submitted, posts appear to use the correct URL set in s3 cdn url, although this may also be because we have DISCOURSE_CDN_URL set as well (both are set to the same URL).

The post preview window references the standard S3 URL seen in the unbaked post, though. This is a problem because we use a private ACL on files uploaded to our Discourse uploads bucket, as content on this bucket should never be accessed outside of CloudFront. The result is a broken image in the preview window.

2 Mi Piace

È deludente che questo problema sia stato segnalato da così tanti anni senza una soluzione.

@DanielMarquard Hai mai trovato una soluzione alternativa o sei stato costretto a rendere pubblica la tua ACL S3?

Non sono sicuro che sia corretto affermare che questo sia rotto, quanto piuttosto che l’implementazione più complessa non sia completamente supportata.

I caricamenti S3, come documentato, funzionano e si comportano correttamente.

@Stephen Certamente aperto a interpretazioni…

A mio avviso, è “rotto” il fatto che utilizzi l’URL CDN in un caso e non nell’altro, e che imponga una configurazione S3 che AWS sconsiglia effettivamente (ACL pubblica per un bucket S3).

Sono nuovo del progetto Discourse in generale, ma posso certamente lavorare su una PR.

Potrebbe valere la pena risolvere il problema ora: AWS sta diventando più severa nel informare gli utenti delle ACL di lettura pubblica.

4 Mi Piace

Dato che la nostra implementazione attuale non ha più un tag IMG, ad esempio:

![image|690x298,50%](upload://eGAOR4Xy4aRM2lwPIuTokBf60jS.png)

Dovrebbe essere abbastanza semplice applicare una CDN alla riga sopra, il che riduce il traffico.

@vinothkannans, puoi sistemare questa cosa in modo che l’anteprima utilizzi l’URL della CDN?

Invece di mostrare nell’anteprima:

<img src="//cdck-file-uploads-global.s3.dualstack.us-west-2.amazonaws.com/meta/original/3X/6/6/66ef078b3ef9da9aa1b3356cb21fe22a0d25eaf0.png" alt="image" class="resizable" width="345" height="149">

Dovremmo mostrare l’URL della CDN, che è questo:

<img src="https://global.discourse-cdn.com/meta/original/3X/6/6/66ef078b3ef9da9aa1b3356cb21fe22a0d25eaf0.png" alt="image" class="resizable" width="345" height="149">
6 Mi Piace

Ora è stato corretto come indicato nel commit sottostante

6 Mi Piace

Questo argomento è stato automaticamente chiuso dopo 32 ore. Non sono più consentite nuove risposte.

Continuando la discussione da L’URL CDN S3 viene ignorato durante il caricamento nei post:

Sembra che questo problema sia ricomparso; riesco a riprodurlo qui su meta.

3 Mi Piace

Possiamo verificare questo @vinothkannans o @falco?

3 Mi Piace

Come da recente modifica, ora otteniamo l’URL del file caricato direttamente dalla richiesta di caricamento iniziale. In precedenza, lo ricevevamo dall’endpoint /uploads/lookup-urls.json. Questo commit dovrebbe risolvere il problema.

5 Mi Piace

Sembra che questa correzione non includa le emoji personalizzate nell’anteprima, ad esempio :allthethings:.

4 Mi Piace

Mancano anche gli allegati, come le esportazioni dei dati o qualsiasi altro file allegato. Questi provengono ancora da S3.

Posso sistemarlo!

3 Mi Piace