SSOと外部アバター

When using SSO with sso overrides avatar: true, Discourse seems to download the avatar and always serve it locally instead of linking directly to the URL provided.

Would it make more sense to allow avatars to serve directly from the avatar_url provided? As is, for each avatar shown it hits Discourse backend somewhat needlessly. Perhaps this could be a SSO option?

If the concern is that avatars may go missing, that could be handled with the image onerror event that fallback’s src to the locally downloaded copy (or show a default one). What I don’t know is if too large avatars images can be constrained with CSS alone.

「いいね!」 1

I believe disabling download_remote_images_to_local should solve your issue, although this will also serve images within posts remotely instead of locally.

That seems to be only for images in posts — or perhaps for local avatar too, when they are not overwritten by SSO.

「いいね!」 1

Interesting. I know that the OIDC Plugin allows you to override email on every login, maybe something like this would be possible for avatar’s being overwritten by SSO as well.

If the SSO avatar is in the format of https://central.avatar.service/<username> you can use the external_system_avatars_url site setting to get this feature.

It’s not in our case (they are served from S3) — and it’s unlikely to usually be in that format so that it can be efficiently cached.

数年後にフォローアップします。以前は何かを誤解していたと思いますが、パフォーマンスの簡単な改善策がまだあると考えています。

以前は、アバターがローカル(Discourseサーバー自体)に保存されていると考えており、なぜSSO外部アバターURLから直接提供されず、Discourseにヒットするのか疑問に思っていました。しかし、いくつか調べてみると、SSOから外部アバターはすでにオブジェクトストレージ(例:S3)にアップロードされ、必要な複数のサイズになっていることがわかりました。

したがって、私の理解が正しければ、現在Discourseはオブジェクトストレージからクライアントにアバターをプロキシしています。しかし、この動作はSSO外部アバターを使用する場合に特有のようです。なぜなら、ここメタのアバターは(CDN化された)オブジェクトストレージから直接提供されているからです。しかし、SSOで外部URLを使用する場合、アバターURLは次の形式になります。

https://discourse-host/user_avatar/discourse-host/{username}/{size}/{uploadid}_{version}.png

ここで、クライアントによってキャッシュされる前に、すべてのアバター表示でrailsにヒットします。

コードを理解している限り、プロキシの代わりにリダイレクトを許可する設定さえありますが、その時点ですでにrailsにヒットしており、リダイレクトはクライアントのロード時間に時間を追加するだけです。

アバターをオブジェクトストレージ(潜在的にはCDNから提供)に直接リンクし、同時にrailsリソースを解放する方が速いのではないでしょうか? /cc @Falco

そうではありません。デフォルトでは、Discourseはアバターのリクエストをプロキシします。これは、あなたのサイトで見られるとおりです。

しかし、昨年、ここで見られる動作をトリガーするために、ENV DISCOURSE_REDIRECT_AVATAR_REQUESTS=1 を介して有効にできる設定を導入しました。

「いいね!」 1