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

Dev environment #41

Merged
merged 4 commits into from
Sep 20, 2024
Merged

Dev environment #41

merged 4 commits into from
Sep 20, 2024

Conversation

allouis
Copy link
Collaborator

@allouis allouis commented Sep 18, 2024

Added a script to allow populating the local db with 5k followers

This also sets the groundwork for adding more scripts to run against our dev environment

Comment on lines 3 to 8
if ($http_x_forwarded_proto = "https") {
set $real_scheme https;
}
if ($http_x_forwarded_proto = "") {
set $real_scheme http;
}
Copy link
Member

Choose a reason for hiding this comment

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

Not a blocker - I think we could use a map directive and dry this up:

map $http_x_forwarded_proto $real_scheme {
    default http;
    https https;
}

I think it might have to go at the http level though 🤔

http {
   map $http_x_forwarded_proto $real_scheme {
       default http;
       https https;
   }

   server {
       location /.ghost/activitypub {
           proxy_set_header Host $host;
           proxy_set_header X-Real-IP $remote_addr;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
           proxy_set_header X-Forwarded-Proto $real_scheme;

           proxy_pass http://activitypub:8080;
       }

       
       ...
   }
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah this is nice - I'll try it and update

Comment on lines +13 to +15
- NODE_ENV=testing
- ALLOW_PRIVATE_ADDRESS=true
- SKIP_SIGNATURE_VERIFICATION=true
Copy link
Member

Choose a reason for hiding this comment

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

Should we make a note here (comment) or / and track (in linear task) that we need to come back to this once the signature stuff has been sorted (or maybe make a note on the task for that if we have one?)

Comment on lines 153 to 177
# Define variables
PRIVATE_KEY="private.pem"
KEY_ID="http://fake-mastodon:8080/user/john#main-key"

BODY=$(echo "{\"@context\": \"https://www.w3.org/ns/activitystreams\", \"id\": \"http://fake-mastodon:8080/activity/$RANDOM\", \"type\": \"Follow\", \"actor\": \"http://fake-mastodon:8080/user/john\", \"object\": \"http://activitypub:8080/.ghost/activitypub/users/index\", \"to\": [\"http://activitypub:8080/.ghost/activitypub/users/index\"], \"cc\": [\"http://fake-mastodon:8080/user/john/following\"]}" | jq -c .)

DIGEST=$(echo -n "$BODY" | openssl dgst -sha256 -binary | openssl base64)
REQUEST_TARGET="post /.ghost/activitypub/inbox/index"
HOST="activitypub"
DATE=$(date -R)
SIGN_STRING="(request-target): $REQUEST_TARGET\nhost: $HOST\ndate: $DATE\ndigest: SHA-256=$DIGEST"

# Sign the string
SIGNATURE=$(echo -n "$SIGN_STRING" | openssl dgst -sha256 -sign $PRIVATE_KEY | openssl base64 -A)

# Construct the Authorization header
AUTH_HEADER="keyId=\"$KEY_ID\",algorithm=\"rsa-sha256\",headers=\"(request-target) host date digest\",signature=\"$SIGNATURE\""

# Make the request
curl -v -X POST http://activitypub:8080/.ghost/activitypub/inbox/index \
-H "Host: $HOST" \
-H "Date: $DATE" \
-H "Digest: SHA-256=$DIGEST" \
-H "Signature: $AUTH_HEADER" \
-d "$BODY"
Copy link
Member

Choose a reason for hiding this comment

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

This a left over? (occurs after the script has exited)

@@ -0,0 +1,177 @@
#!/usr/bin/env bash
Copy link
Member

Choose a reason for hiding this comment

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

Not a blocker - Kudos on persevering with raw bash here, the script is easy / clear to follow and grok 👌

Thoughts on using https://github.com/google/zx for stuff like this (not suggesting you change anything here 👍)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oooh I remember seeing this before, still not tried it! I'm happy to give it a go!

PRIVATE_KEY="private.pem"

# Loop 5000 times
for i in $(seq 1 5000); do
Copy link
Member

Choose a reason for hiding this comment

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

Should we make it so the 5000 can be passed into the script?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yessss

This was causing issues when trying to hit activitypub over http as the origins
would not match. Instead should forward the X-Forwarded-Proto header if it's
present, which will allow us to continue working with Tailscale funnel, whilst
keeping basic local development working.
This is going to make things easier when running scripts against our service
Once we've solved signatures, we can re-enable the signature verification, but
we need to allow local addresses if we want to work with wiremock.
@allouis allouis merged commit 9e9321f into main Sep 20, 2024
1 check passed
@allouis allouis deleted the dev-environment branch September 20, 2024 04:40
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.

2 participants