Skip to content

Multi-tenancy with custom domains #2668

Open

Description

@Gargron

More technical look at #897

Idea: Let users point DNS records to an existing instance, configure specific user to be served as-if from that domain.

What parts must work correctly for this:

  • Separate field for storing whether an account is remote or local rather than relying on domain being null - store custom domain in that column?
  • All functions that check whether an account is local must check the custom domain as well as the "local domain" of the instance
  • Webfinger must answer queries for the faux-remote account
  • Other accounts must not be served from that custom domain. Accessing the website through the custom domain should be limited to only public content from the owner of the domain.

Concerns:

  • Switching instances while keeping the same domain will present the same problem as erasing/reinstalling an old instance on the same domain - other servers will remember data that you don't, any numeric IDs may reset and overlap (but generated string URIs include not just numeric ID, but also timestamp of creation, so that's not a big concern)
  • Might be the first credible case for exporting/importing data verbatim, e.g. including all small details. Just like with local users having a custom domain, statuses should be amended to be local and able to have verbatim URIs like remote ones

Activity

  1. ZiiX commented on May 1, 2017

    @ZiiX
    SponsorContributor

    Great option to consider! You know I'm for it. With this feature, I'm thinking it would be also awesome to consider personal file/media settings as an option with this. WebDAV, S3, Dropbox, Amazon, Google, etc - this allows their media hierarchy to follow them too.

  2. ramsey commented on May 1, 2017

    @ramsey

    I feel like there are a lot of security/identity concerns to consider, especially with importing data verbatim. I could forge an import and pretend to be someone else, replaying all their posts into the new server. There’s no mechanism for signing posts and asserting one’s identity.

  3. saper commented on May 1, 2017

    @saper
    Contributor

    @Gargron what about having a separate domain table and foreign key to that.

    Also I think the primary domain should be treated just like all those tenants. Do you have a reason to have it "special"?

  4. Gargron commented on May 1, 2017

    @Gargron
    MemberAuthor

    @saper Initial design decision was:

    • Your domain could be adjusted (even just only at the very start when you're setting up/troubleshooting)
    • Don't want to have 20.000 copies of the same string in the db if it can be avoided by making it null and generating local URIs on the fly
    • Simple distinction for local vs remote content - remote content has a non-null URI

    Of course right now we're exploring a use case where, perhaps, that design should be replaced... At the same time, you're right, we could have a separate domain table, then there wouldn't be 20.000 copies of the same string. Though you'd need to join the accounts and domains table on basically every single query.

  5. saper commented on May 1, 2017

    @saper
    Contributor
  6. jeremyBanks commented on May 1, 2017

    @jeremyBanks

    Will it be possible to point to a different user name? If you need to use the same name across instances, that could limit your ability to migrate.

  7. ClearlyClaire commented on May 1, 2017

    @ClearlyClaire
    Contributor

    Off the top of my head:

    • Some of this is already handled with the distinction between LOCAL_DOMAIN and WEB_DOMAIN, except that you'd need to use a custom user-specific domain if not null instead of LOCAL_DOMAIN, which is easy when generating something, but can get messy when looking up an user. Also, Mastodon still makes some assumptions that are broken when WEB_DOMAIN is different from the user's domain (see OStatus URIs and Mastodon handles #2012 and OStatus user URI verification/disambiguation #2032), although until now, this can be worked around, but…
    • What about username conflicts? Should user@redirected and user@local conflict or not? If not, the workaround for misdirected webfinger queries (y0t4@46555ce) can't work in this setting, as it would need to disambiguate.
    • Further, should the URIs of redirected accounts follow the same template as local ones? If so, and user@redirected and user@local are different users, how to disambiguate? The easiest way to handle that is probably to have https://web_domain/@user@redirected and https://web_domain/users/user@redirected etc.
    • With that in place, using a remote Mastodon instance for your domain seems easy: just redirect (or proxy, but Using WEB_DOMAIN wrong URL is returned in Webfinger for atom, salmon #2375) /.well-known/host-meta (and possibly /.well-known/webfinger), or use a CNAME RR for your domain, if it's to be only used for Mastodon.
    • Migration probably will be a bit tricky: in OStatus, users are not identified by their acct: (user@redirected) URIs but by their ActivityStream actor URI (which is so far an URL to the user's web profile, and will thus reference the “backend” Mastodon instance). The easiest way to migrate seem to just point to another backend, however, your actor URI will most probably change as a result. I'm not sure how bad a thing that is. Also, it won't be immediate, as remote instances having your account details will need to refresh it from webfinger to switch to the new instance, and that's currently only done in a few situations, and at most once a day.
  8. semarie commented on May 1, 2017

    @semarie

    having this kind of configuration at DNS level would be great. But isn't more simple to have it at webserver level ? it would mean having a minimal code on remote webserver side (could be done with simple PHP script and/or webserver redirection).

    As example, considere user@mastodon.social who want to use user@my.domain

    On the remote side (my.domain):

    • /.well-known/host_meta : reply with LRDD link to webfinger on my.domain
    • /.well-known/webfinger : get information (mostly magic-public-key) from mastodon.social, and build a reply with acct:user@my.domain. Use local URL for atom, salmon, ...
    • for URL entries points (atom, salmon, ...), use HTTP redirection (Location HTTP Header) to point to mastodon.social

    On mastodon side (mastodon.social):

    • permit the user to config is account as user@my.domain
    • use acct:user@my.domain in replies
  9. russss commented on May 1, 2017

    @russss

    I'm keen on @semarie's proposal, and in fact I started looking into the feasibility of it a while ago. The advantages as I see it are:

    • You don't need a separate hostname purely for this - which means (for example) my username could be the same as my email address.
    • Multiple users on the same domain could be housed on different Mastodon instances.

    This would be similar to how OpenID works, and it feels like a more "federated" situation than pointing domain names around.

    It also seems that in the original proposal, the host Mastodon instance would have to obtain an SSL certificate for each domain (or serve them unsecured which is annoying). Even with LetsEncrypt this is fiddly.

  10. saper commented on May 1, 2017

    @saper
    Contributor

    here is what I understand under domain multi-tenancy:

    Ability to point multiple A and AAAA DNS entries, add a new domain to the certificate and make sure the domains do not get mixed up.

    1. Different domain names are treated like independent instances.

    1a the simplest implementation would be just to reuse the code base and point to different databases on request. This is probably achievable now with a web server configuration. I think this should be tested prior to proceeding further (how to talk to redis, store media for multiple instances, mail support etc.).

    Every instance is completely independent, has its own member namespace and they federate independently. They only get upgraded at the same time. You have to run db:migrate multiple times, with a new RUBY_ENV for ever domain in the loop.

    I think there must be some folk trying this right now?

    MediaWiki has an interesting hack that allows sharing only some database tables between such instances, not sure it would be helpful here.

    A dedicated asset domain could be another thing, but it should be made in a way that does not break the possibility to export the domain to a fully standalone instance.

    1b accept multiple WEB_DOMAINS and issues and hacks related to that. This is more tricky in the implementation as it might require a new domain table, new queries etc. This provides little more benefit to 1a but it carries more of the development effort. The web server/PostgreSQL configuration is simplified compared to (1a)and every domain lives independently in the webspace, with its own member namespace.

    Interesting questions appear here, like should those instances automatically be federated or not?
    (I think not, they should feel independent).

    There is a possibility to shortcut the traffic between the domains internally for performance reasons (maybe not necessary).

    1c Accept multiple domains under one certificate - basically it is the scheme used by Google multi-tenant Apps. Everything is under google.com/a/domainname/restoftheurl

    The problem here is the initial redirect - how to securely redirect domain.fluffy to mastodon.social/a/domain.fluffy on the web? In case of SMTP it works because nobody validates SMTP domains in certs and we have MX records.

    One solution could be to have some custom SRV record that is universally accepted (haven't checked the spec yet). StatusNet, bot frameworks etc should also use it.

    A quick check with the WebFinger RFC tells me it only supports HTTP redirect to a different domain and not a well known URL but you still need to be able to accept initial request securely.

    And here comes another variant:

    2a. Some fluffy form of "user@domain" as an identity alias on mastodon.social without DNS entries. I don't know how would that possibly work, except for the user being mrserious@mastodn.socialvall the time on the protocol level and just bring presented as @pinky@fluffyanimal.farm on mastodon.social only.

    2b. A variant of (2a) could be considered where mastodon.social tries to convince other instances that mrserious wants to be presented as @pinky@fluffyanimal.farm, which opens a whole can of worms (misrepresentation).

    May be this use case should be further elaborated (maybe it is a separate issue).

    I think there is a natural development progression to go from 1a via 1b maybe to 1c.

    it would be good to refer to one of those variants as we speak (or define additional ones)

  11. s-leroux commented on May 1, 2017

    @s-leroux

    Great idea. But let me rephrase to see if I understand the typical use case:

    Someone connects to me as @sylvain@yesik.it

    First we query the yesik.it DNS for the _mastodon TXT record.
    If not found, "yesik.it" is assumed to run its own Mastodon instance.
    Otherwise, the TXT record (CNAME?) holds my current instance. Say its "mastodon.social"

    So, on the background, Mastodon will understand the physical account name is @sylvain@mastodon.social
    But in the UI and for all user interactions, only my logical account name is used @sylvain@yesik.it

    Basically we add here a new layer of indirection. Or did I missed the point?


    Several remarks:

    1. It doesn't help if someone bookmarked my account URL (https://mastodon.social/@YesIKnowIT). Or does it?
    2. What if several members of the same domain have accounts on different instances?
    3. What if I actually made several domains point toward the same account (aka, @sylvain@chicoree.fr, @sylvain@yesik.it ... being different alias to the same account -- just like I can do it for my email).
  12. saper commented on May 2, 2017

    @saper
    Contributor

    @s-leroux so what you mean is something like federated alias.

    Basically one more assumption had to be broken - not all users from @Domain are hosted on a single instance.

    That is another piece of complexity, basically "domain" server would need to provide redirects/pointers,
    but I understand that the trouble is for the target host to accept user@otherdomain stuff and somehow treat it's as own

    Not sure it's multi-tenant domain handling, though

  13. alexgleason commented on May 3, 2017

    @alexgleason
    Contributor

    I like this idea a lot, but not sure the benefits outweigh the costs.

    I think the goal is to give users more control. The easiest way to do that now is to run your own instance. That's hard though for non-tech users, while setting some DNS values is easy given a tutorial.

    Would it be better to make it easy to start your own instance? I feel like a 1-click install on a web host would be ideal. I think IndieHosters is supporting Mastodon, maybe they'd be willing to set something up like this. @pierreozoux

    Basically I'm wondering what the goals actually are and how to best reach those goals. I can definitely see the benefits of supporting remote domain names, but running your own instance is more beneficial: you own/control your data, there's no reason to migrate, and it produces no technical debt to the project itself. The paradigm currently in place makes sense: if you're part of a server, you're part of that community and you take their name. If you're remote, you have a remote name. This is intuitive.

    On the other hand, email has some similar paradigms and any service can send emails from your domain name with the proper authentication (eg Postmark). But this is usually a generic service and to my knowledge is not built into any email providers themselves.

  14. pierreozoux commented on May 3, 2017

    @pierreozoux
    Contributor

    I think it is a tricky discussion.

    In one hand, with one postfix, I can host various domains, and it is convenient.
    As a user, I can migrate from one hoster to another, it is a bit painful, but it is doable.

    On the other hand, on the web, one domain name means the control over your own piece of land, your rules, your design, so it also makes sense to have your own instance (from the indieweb principles).

    It is not that hard to host a mastodon instance, or pay somebody to do it. And then, it is easy to just transfer from one server to another, or from one hoster to another. And the change that has to be made to add this feature are quiet heavy I guess. Then, they also have to be maintained.

    I think that multitenancy, is always a headache for developers, and it is never really well done, so even if I have the option, as a hoster, I never choose that. It is always easier to migrate people with their own instances.
    (All the options I hear, DNS, running a small app server will touch 0.01% of our user base IMHO)

    I'm probably not the best judge to help here, but I think the discussion has to evolve around cost/benefit for the software in itself. I'm a fan of unix philosophy, and I think the effort can serve a lot better in other areas :)

    And to conclude, I also think that the discussion should happen at the standard itsefl, at ostatus level.

  15. jeremyBanks commented on May 3, 2017

    @jeremyBanks

    "It's not hard to host a Mastodon instance", said one engineer to the next.

    Dozens of projects have told themselves this, but the reality of self-hosting applications like this is that it does not happen for a non-trivial number of users, despite great efforts like Sandstorm. One-click install for end-users is not a responsible solution, unless you also have automatic fast and secure updating on multiple levels. We might get there one day, but don't let that ideal get in the way of a realistic solution.

    Configuring DNS entries as a one-time (or at least rare) action is something that a moderately tech-competent person can handle. It will at least get Mastodon on par with email in terms of identifier portability, and is probably the most viable mid-term solution (assuming the current identifier scheme is preserved instead of moving to something cryptographic).

  16. 58 remaining items

  17. filipesaraiva commented on Jan 25, 2025

    @filipesaraiva

    Just a doubt, is this feature in roadmap?

  18. dogshapedangel commented on Mar 10, 2025

    @dogshapedangel

    I am also curious on whether this will see any movement given Bluesky's custom domain handle functionality and the apparent demand for a feature like this. I've gotten complaints for years about how folks are concerned about my unchangeable domain name "yiff.life" and while I still think it's funny, it would be very cool to allow people to actually use our alternate aliased SFW domains for their handles, even if it is still just masking yiff.life.

    But now the idea may be a bit different with the advent of what Bluesky implemented. I still prefer the original multi-tenant idea.

  19. flamingsnowflake commented on Mar 10, 2025

    @flamingsnowflake

    as tempting as it is, I don't think it's a good idea to compare Mastodon to Bluesky or Discord

    those are user problems, not server problems

    I totally get that we need three or more accounts per person and people want fancy URLs.
    but it's a lot more important to separate those from each other... not everybody is cool enough to post pony porn or luigi memes with the same account that they use to apply for a job.

    some people want their private life to remain private. If you run the server, you will be responsible for this. do you want this responsibility? not for you, for your users.

    maybe it's time to think about single user Mastodon instances with multiple domain names and multiple identities?
    then the isolation is no longer a problem. because it is the same user and the same database on the same machine but it only has to look different to the outside world.

    I'm not a developer but these are the things that prevent me from using Mastodon. I don't want to run three instances for one person with multiple identities.

    I also don't want to become a member on somebody else's server.

    we are all spoiled by Discord and Bluesky.

  20. saschanaz commented on Mar 10, 2025

    @saschanaz

    maybe it's time to think about single user Mastodon instances with multiple domain names and multiple identities? then the isolation is no longer a problem. because it is the same user and the same database on the same machine but it only has to look different to the outside world.

    I'm not a developer but these are the things that prevent me from using Mastodon. I don't want to run three instances for one person with multiple identities.

    I also don't want to become a member on somebody else's server.

    we are all spoiled by Discord and Bluesky.

    Perhaps you are looking for Hollo than Mastodon in that case.

  21. dogshapedangel commented on Mar 10, 2025

    @dogshapedangel

    as tempting as it is, I don't think it's a good idea to compare Mastodon to Bluesky or Discord

    I am not sure where DIscord comes into this, but Bluesky is another decentralized social media platform that is at least somewhat similar to Mastodon and ActivityPub. While I would not advocate Mastodon directly replicate what Bluesky is doing, this feature request is older than Bluesky's creation, and I absolutely think it is worth noting when another platform implements a somewhat similar idea with great success.

    There are a few ways this would be beneficial to users:

    • Alternate domains offered by admins
    • User domains for vanity URLs

    I could also see it potentially causing confusion depending on how it is implemented.

    My inquiry is mostly just to understand whether this is still on the roadmap in some form or another, and it looks like some work was done in 2024 (#32724) to move away from using usernames as immutable IDs and instead use numeric generated IDs, which would be a huge step in the direction of supporting this.

  22. nileshtrivedi commented on Mar 11, 2025

    @nileshtrivedi

    Bluesky is another decentralized social media platform

    It looks centralized to me. Most users are on the central server. This has been called out by others as well.

  23. dogshapedangel commented on Mar 17, 2025

    @dogshapedangel

    Bluesky is another decentralized social media platform

    It looks centralized to me. Most users are on the central server. This has been called out by others as well.

    I agree with your correction here but I do not believe that detracts from my belief that the feature would see high demand in both Bluesky's form (as a verified handle) and as originally proposed in this issue in multi-tenancy format.

  24. Exagone313 commented on Mar 17, 2025

    @Exagone313
    Contributor

    I had a quick look at how Bluesky/atproto is dealing with handles. If you add a TXT record to a _atproto subdomain or if you configure your HTTPS server for your domain name to answer /.well-known/atproto-did, you can return a did:plc identifier. This identifier is then queried on https://plc.directory (then comes some cryptography stuff).

    With ActivityPub (actually, WebFinger), you need to configure your HTTPS server for your domain to answer /.well-known/webfinger?resource=acct:username@yourdomain.example (for identifying accounts, to keep it simple).

    So, to summarize:

    • with atproto, you rely on a centralized entity (plc.directory)
    • with ActivityPub, each domain is independent from each other, there is not a centralized entity

    For Mastodon to support multiple domains, it needs to handle WebFinger (and other stuff) on multiple origins. There are multiple ways to consider this.

  25. corobin commented on Mar 17, 2025

    @corobin

    I am one of those people who use BlueSky's custom handles and found this thread because I was looking for the same with Mastodon.

    I just want to chime in with a use-case:

    The BlueSky custom handle is very convenient because it makes my domain a universal identifier that does not depend on the instance's domain. it's also very easy to set up just with verifying the domain ownership. there's no need for me to spin up my own web server or run my own instance of the platform just to use my domain as a handle. lots of people would not want to run their own for a variety of reasons, such as limited technical ability, not wanting to spend the maintenance time or effort, or monetary cost of running a web server, but a DNS record is relatively trivial to set up and does not incur any marginal cost to do.

    The BlueSky custom handle is also a bit different at the front end than - say - running your own instance. Your BlueSky username is simply example.com whereas with your own instance it would currently be something like myname@example.com or me@example.com. the user-part is just unnecessary for many many use cases, particularly where it's a single-person personal domain.

    another benefit for the way BlueSky does it is that it makes it very pretty to set my domain as my handle, and also setup a redirect from my domain to my profile. it's very elegant for anyone who doesn't care to have a separate landing page. you can go directly to example.com to get to my bluesky profile, whose handle is also @example.com. without the redirect even though my handle is @example.com you won't actually get to my profile if you just typed in example.com. this kind of symmetry becomes ugly if you have to have an additional username before the domain part.

    to sum up: at the very basic level, supporting bluesky-style domain handles would be a very useful feature for people who have their own domains and want that persistent identity, but for whatever reason want to use an established server (which is a lot of people).

    in terms of the technical implementation:

    With ActivityPub (actually, WebFinger), you need to configure your HTTPS server for your domain to answer /.well-known/webfinger?resource=acct:username@yourdomain.example (for identifying accounts, to keep it simple).

    this is going to be of relatively low value because it still requires an https web server, which already creates a huge barrier to entry.

    however, there are many potential methods to use only DNS to verify ownership of the domain while using somebody else's service and still be decentralized.

    one obvious and simplistic example is just to craft your txt record to contain 2 pieces of information:

    1. a way to identify the server that you want to authorize to claim to represent your domain
    2. an authorization token so that server knows you admin the domain

    e.g. mast:mastodon.social=random_id would tell the world that the legitimate user account claiming to be example.com would be the one that's hosted at mastodon.social (the 1st part) , and would tell mastodon.social that you are authorized to claim that domain (the 2nd part)

    you can also do it cryptographically

    there are two real-world systems that are in wide use that do both in a highly decentralized environment - in emails:

    SPF - just a list of authorized servers who can send on the domain's behalf - so kind of like the 1st example

    DKIM - cryptographic validation that that specific server is authorized to send on the domain's behalf. the domain publishes the public key in DNS and any authorized servers will sign outgoing emails with the corresponding private key.

    they have proven very effective and does not rely on a centralized register at all.

  26. Exagone313 commented on Mar 17, 2025

    @Exagone313
    Contributor

    Disclaimer: I have not read the full specifications, I am only writing this after quick reading and research.


    Mastodon and other software implement existing specifications (like WebFinger). Adding new ways to identify accounts would not be supported by other software. I think it is too late to change these choices, or it could fragment the ecosystem.

    To move an account to another instance, you would need to download the secret key for your account, upload it to the new instance and then the new instance would need to rotate the key for security reasons. From my understanding, if the instance disappears or bans you, or if you loose the secret key, your existing account handle won't be usable anymore, unless existing instances forget you.

    It is not as easy as changing a DNS record.


    I think that adding the support of multiple domains for accounts in a single Mastodon instance is a first step and the main feature request discussed here. Adding the ability to move a domain to another instance could only come later.

    EDIT: To your specific need of using your domain name for other stuff while delegating WebFinger to another server, you can have an HTTP server that redirects the /.well-known/webfinger location on your domain name.

  27. andypiper commented on Mar 19, 2025

    @andypiper
    SponsorContributor

    The discussion of DID vs WebFinger, ATProto vs / and-or ActivityPub etc goes significantly outside of this issue. ActivityPub account portability is under discussion in working groups at the W3C. You'll need to explore other communities (W3C, activitypub.rocks, etc) to go deeper into those conversations as this issue isn't the right place to do so.

    There's no current/immediate plan to implement multi-tenancy with custom domains in Mastodon itself (and it is somewhat complicated by the need to remove support for Redis namespaces in an upcoming version). We'll certainly keep the issue open as a suggestion for now.

  28. jazmichaelking commented on Mar 25, 2025

    @jazmichaelking

    Just to add a use case here: I have multiple domains registered for a bilingual instance, eg toot.wales and toot.cymru, mastodon.wales and mastodon.cymru

    Community members may wish to represent themselves as being more focused on Cymraeg (Welsh) than English. Being able to use member@toot.cymru instead of member@toot.wales would be of great benefit to them in how they want to represent themselves on the social web.

    Secondly, while I am personally a huge fan of "toot" as a branded moniker, I understand that some accounts may prefer a less frivolous-sounding handle for their activities. Being able to offer serious.domain and fun.domain as options would greatly improve my ability to market and advocate for the Fediverse generally.

    I am reminded of the proliferation of custom domain free email services that preceded everyone having an email account on one of five or so domains. At sign-up, I could choose from a list of domains available to me from the service. Those were fun services that allowed millions of people to express themselves with a domain that best suited them, without having to go through the cost and hassle of registering their own domain. There are fewer than 400 million domain names registered, for 5.5 billion Internet users. Not everyone has or wants their own domain.

    I believe expanding and adding detail to the existing ALTERNATE_DOMAINS functionality would be incredibly helpful for those of us who simply want to offer multiple domains (even if the login / account name is always tied to the primary domain). If I knew this to be a robust, functional, supported feature I would be offering multiple domains today. And - if it were to be detailed - I can see how this could lead to future conversations and enhancements that might allow for monetising additional custom/personal domains to help cover operating costs, as well as potentials for account portability, although I think both of those options are for a later discussion.

    I leave it to more-informed commenters to ponder whether or not the user account would/should/could be discoverable by domains other than their chosen preference (I would hope not).

  29. michaelhofer commented on Dec 9, 2025

    @michaelhofer

    Another use case where this might be useful is for further customisation and idividualisation of accounts. There are different projects and sites I support where a custom handle is wanted (similar to BlueSky's offering), but only a single account per domain is required (like myproject.com).

    The solution with ALTERNATE_DOMAINS does not seem to help in this scenario, since users would still see the xyz@myserver.tld handle.

  30. Exagone313 commented on Sep 2, 2026

    @Exagone313
    Contributor

    As registries are holding domain names for political reasons, it could be interesting to explore this topic again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    deploymentRelated to runtime configuration, production setups

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions