Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable communication with "authorized_fetch" Mastodon servers #2613

Merged
merged 19 commits into from
Jan 26, 2023

Conversation

hughrun
Copy link
Contributor

@hughrun hughrun commented Jan 20, 2023

This builds on the initial work of @renatolond in #427 and resolves a number of bugs preventing that PR moving forward.

In short, this PR should allow communication between Bookwyrm instances and Mastodon instances that use "secure mode" aka AUTHORIZED_FETCH.

I have run tests and also tested this manually against accounts running on both "secure mode" and non "secure mode" Mastodon instances, as well as between 2 Bookwyrm instances, and it appears to work, but I definitely want at least one other person to test it independently in case I missed something.

New settings

There is a new value in settings.py:

  • INSTANCE_ACTOR_USERNAME - defaults to the instance domain name bookwyrm.instance.actor, so that the instance actor (required to sign requests to "secure mode" Mastodon servers) will have a username like @[email protected]
    * INSTANCE_ACTOR_EMAIL - defaults to representative@DOMAIN so that instance actors will have a registered email like [email protected]

The new instance actor will have an email address registered as bookwyrm@localhost.

resolves #1179
closes #427

renatolond and others added 13 commits January 5, 2022 15:46
When mastodon is in authorized fetch mode any request has to be signed
or it fails with 401. This adds the needed signature to the requests
made to discover the actor when receiving something from mastodon (such
as a follow request)
If no digest value is passed to make_signature and Exception was thrown.
Since digest is added to the signature headers if it is not None anyway, there is no need to assign the digest value before that check.
When signing a request _as the server_ for Mastodon's AUTHORIZED_FETCH there is no need to include a digest.
ERROR HANDLING FIXES

- use raise_for_status() to pass through response code
- handle exceptions where no response object is passed through

INSTANCE ACTOR

- models.User.objects.create_user function cannot take an ID
- allow instance admins to determine username and email for instance actor in settings.py
Makes exception handling more precise, only raising status for 401s.

Also fixes a string pylint was complaining about.
@hughrun hughrun marked this pull request as ready for review January 20, 2023 09:15
@renatolond
Copy link
Contributor

Thanks for picking this up 🙏🏼

bookwyrm/settings.py Outdated Show resolved Hide resolved
- when using raise_for_status we need to catch an HTTPError, not a ConnectionError
- simplify instance actor - use internal email address since it will never be used anyway, and make default username less likely to already be in use.
Copy link
Member

@jaschaurbach jaschaurbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very good to me.

I recommend to add INSTANCE_ACTOR_USERNAME to the documentation that admins know what this does, that they could change it but there is most time no need to change it.

I can't even tell what it thinks it did, but Black likes to complain.
@hughrun hughrun removed the request for review from mouse-reeve January 26, 2023 06:33
@hughrun
Copy link
Contributor Author

hughrun commented Jan 26, 2023

@mouse-reeve if you're happy with @jaschaurbach's review, then this is ready to go. The only change I made since that review was to add a more verbose note in the settings.py file.

@mouse-reeve
Copy link
Member

Seems to work to me!

@mouse-reeve mouse-reeve merged commit 62d1c54 into bookwyrm-social:main Jan 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot interact with mastodon instances that have activated 'secure mode'
4 participants