mariusor / brutalinks

Link aggregator inspired by (old)reddit using ActivityPub federation. (mirror repository)
https://brutalinks.tech
MIT License
259 stars 12 forks source link

Issue getting littr and fedbox to communicate with each other correctly #37

Closed jhert0 closed 4 years ago

jhert0 commented 4 years ago

Here is what is in my .env for littr

# HOSTNAME is used as the base for the absolute URLs in the site
HOSTNAME=littr.local
# LISTEN_PORT is the port number that the application will listen on for connections
LISTEN_PORT=3000
# LISTEN_HOST is the host/ip that the application will listen on for connections
LISTEN_HOST=localhost
# ENV the environment type sets different configuration settings, valid are: DEV, QA, STAGING, PROD
ENV=dev
# API_URL is the url of the fedbox instance that provides our C2S ActivityPub API
API_URL=http://fedbox.local
# SESS_AUTH_KEY is used for encrypting the session data
SESS_AUTH_KEY=16_chars_enc_key=
# SESS_ENC_KEY
SESS_ENC_KEY=16_chars_enc_key+
# OAUTH2_KEY the default OAuth2 key used by the frontend to connect to the C2S ActivityPub end-points
OAUTH2_KEY=1e2ba133-f4a5-4182-8540-309646e9ea59
# OAUTH2_SECRET the default OAuth2 secret used by the frontend
OAUTH2_SECRET=littr
# SESSIONS_BACKEND the backend to use for session storage, valid: cookie, fs
SESSIONS_BACKEND=fs
# DISABLE_SESSIONS setting this to true, makes the instance essentially read only, by disallowing user logins
DISABLE_SESSIONS=false
# DISABLE_DOWNVOTING disables allowing Dislike activities
DISABLE_DOWNVOTING=false
# DISABLE_VOTING disables all Like/Dislike activities
DISABLE_VOTING=false

Here is what is in my fedbox .env

HOSTNAME=fedbox.local
LISTEN=localhost:4000
ENV=dev
STORAGE=fs
STORAGE_PATH=.

I have littr.local and fedbox.local setup in /etc/hosts. I also have both littr and fedbox running behind a reverse proxy using nginx.

I ran these commands for setting up fedbox:

./bin/ctl bootstrap
./bin/ctl ap actor add admin
./bin/ctl oauth client add --redirectUri http://littr.local/auth/fedbox/callback

This is what I get when I go to littr.local

2020-07-13-210544_1915x957_scrot

In the littr log I get this:

ERRO[0000] http://fedbox.local/actors/1e2ba133-f4a5-4182-8540-309646e9ea59: Unable to load from the AP end point: invalid status 404
ERRO[0000] Failed to load actor: Unable to load Actor: http://fedbox.local/actors/1e2ba133-f4a5-4182-8540-309646e9ea59
ERRO[0000] oauth2: cannot fetch token: 403 Forbidden
mariusor commented 4 years ago

OK, I see. From what I can see you have two issues.

  1. The session can not be saved - if you're on a linux machine /tmp/fedbox.local should be writable by the user that runs the application - this is the error in the screenshot "Failed to save session". I guess I'll add a followup task to make session path more configurable, or use the STORAGE_PATH.
  2. The second issue, is that the application can't load the generated OAuth2 application that you configured in the settings. Can you please access the url from the error: http://fedbox.local/actors/1e2ba133-f4a5-4182-8540-309646e9ea59 and paste the log from fedbox, with maybe a screenshot of the result?
jhert0 commented 4 years ago

On the vm running littr I have /tmp/littr.local folder and the user running littr can write to it.

Log from fedbox:

ERRO[0003] Not Found addr="127.0.0.1:36538" elapsed=1.47849ms id=fedbox/sxsPfDPG0z-000001 len=6640 method=GET proto=HTTP/1.0 scheme=http status=404 ts="Tue, 14 Jul 2020 17:00:30 UTC" ua="Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0" uri="http://localhost:4000/actors/1e2ba133-f4a5-4182-8540-309646e9ea59"

Error from going to that url:

{
  "@context": "http://localhost:4000/ns#errors",
  "errors": [
    {
      "status": 404,
      "message": "1e2ba133-f4a5-4182-8540-309646e9ea59 not found in actors",
      "trace": [
        {
          "file": "github.com/go-ap/errors@v0.0.0-20200610194301-39b7d0cbba26/errors.go",
          "line": 79,
          "calee": "github.com/go-ap/errors.wrap(0x0, 0x0, 0xc4a318, 0xd, 0xc0000cf7e0, 0x2, 0x2, 0x0, 0x0, 0x0, ...)"
        },
        {
          "file": "github.com/go-ap/errors@v0.0.0-20200610194301-39b7d0cbba26/errors.go",
          "line": 42,
          "calee": "github.com/go-ap/errors.Annotatef(...)"
        },
        {
          "file": "github.com/go-ap/errors@v0.0.0-20200610194301-39b7d0cbba26/http.go",
          "line": 54,
          "calee": "github.com/go-ap/errors.wrapErr(0x0, 0x0, 0xc4a318, 0xd, 0xc0000cf7e0, 0x2, 0x2, 0x0, 0x0, 0x0, ...)"
        },
        {
          "file": "github.com/go-ap/errors@v0.0.0-20200610194301-39b7d0cbba26/http.go",
          "line": 109,
          "calee": "github.com/go-ap/errors.NotFoundf(...)"
        },
        {
          "file": "github.com/go-ap/fedbox@/app/handlers.go",
          "line": 238,
          "calee": "github.com/go-ap/fedbox/app.HandleItem.func1(0xc0000c2c00, 0x7f1d22af7368, 0xc000137f20, 0xc000137f20, 0x0, 0x0, 0xc000186960)"
        },
        {
          "file": "github.com/go-ap/handlers@v0.0.0-20200630121116-d3d7a2315572/handlers.go",
          "line": 225,
          "calee": "github.com/go-ap/handlers.ItemHandlerFn.ServeHTTP(0xc78f48, 0x7f1d22af7338, 0xc000195400, 0xc0000c2c00)"
        },
        {
          "file": "github.com/go-chi/chi@v4.1.2+incompatible/mux.go",
          "line": 431,
          "calee": "github.com/go-chi/chi.(*Mux).routeHTTP(0xc000057ec0, 0x7f1d22af7338, 0xc000195400, 0xc0000c2c00)"
        },
        {
          "file": "net/http/server.go",
          "line": 2007,
          "calee": "net/http.HandlerFunc.ServeHTTP(0xc00015c660, 0x7f1d22af7338, 0xc000195400, 0xc0000c2c00)"
        },
        {
          "file": "github.com/go-chi/chi@v4.1.2+incompatible/mux.go",
          "line": 70,
          "calee": "github.com/go-chi/chi.(*Mux).ServeHTTP(0xc000057ec0, 0x7f1d22af7338, 0xc000195400, 0xc0000c2c00)"
        },
        {
          "file": "github.com/go-chi/chi@v4.1.2+incompatible/mux.go",
          "line": 298,
          "calee": "github.com/go-chi/chi.(*Mux).Mount.func1(0x7f1d22af7338, 0xc000195400, 0xc0000c2c00)"
        },
        {
          "file": "net/http/server.go",
          "line": 2007,
          "calee": "net/http.HandlerFunc.ServeHTTP(0xc00015b360, 0x7f1d22af7338, 0xc000195400, 0xc0000c2c00)"
        },
        {
          "file": "github.com/go-chi/chi@v4.1.2+incompatible/chain.go",
          "line": 31,
          "calee": "github.com/go-chi/chi.(*ChainHandler).ServeHTTP(0xc000191100, 0x7f1d22af7338, 0xc000195400, 0xc0000c2c00)"
        },
        {
          "file": "github.com/go-chi/chi@v4.1.2+incompatible/mux.go",
          "line": 431,
          "calee": "github.com/go-chi/chi.(*Mux).routeHTTP(0xc000057da0, 0x7f1d22af7338, 0xc000195400, 0xc0000c2c00)"
        },
        {
          "file": "net/http/server.go",
          "line": 2007,
          "calee": "net/http.HandlerFunc.ServeHTTP(0xc00015c630, 0x7f1d22af7338, 0xc000195400, 0xc0000c2c00)"
        },
        {
          "file": "github.com/go-chi/chi@v4.1.2+incompatible/mux.go",
          "line": 70,
          "calee": "github.com/go-chi/chi.(*Mux).ServeHTTP(0xc000057da0, 0x7f1d22af7338, 0xc000195400, 0xc0000c2c00)"
        },
        {
          "file": "github.com/go-chi/chi@v4.1.2+incompatible/mux.go",
          "line": 298,
          "calee": "github.com/go-chi/chi.(*Mux).Mount.func1(0x7f1d22af7338, 0xc000195400, 0xc0000c2c00)"
        },
        {
          "file": "net/http/server.go",
          "line": 2007,
          "calee": "net/http.HandlerFunc.ServeHTTP(0xc00015b400, 0x7f1d22af7338, 0xc000195400, 0xc0000c2c00)"
        },
        {
          "file": "github.com/go-chi/chi@v4.1.2+incompatible/mux.go",
          "line": 431,
          "calee": "github.com/go-chi/chi.(*Mux).routeHTTP(0xc000057d40, 0x7f1d22af7338, 0xc000195400, 0xc0000c2c00)"
        },
        {
          "file": "net/http/server.go",
          "line": 2007,
          "calee": "net/http.HandlerFunc.ServeHTTP(0xc00015c620, 0x7f1d22af7338, 0xc000195400, 0xc0000c2c00)"
        },
        {
          "file": "github.com/go-ap/fedbox@/app/middleware.go",
          "line": 61,
          "calee": "github.com/go-ap/fedbox/app.ActorFromAuthHeader.func1.1(0x7f1d22af7338, 0xc000195400, 0xc0000c2b00)"
        },
        {
          "file": "net/http/server.go",
          "line": 2007,
          "calee": "net/http.HandlerFunc.ServeHTTP(0xc000061cc0, 0x7f1d22af7338, 0xc000195400, 0xc0000c2b00)"
        },
        {
          "file": "github.com/go-chi/chi@v4.1.2+incompatible/middleware/get_head.go",
          "line": 37,
          "calee": "github.com/go-chi/chi/middleware.GetHead.func1(0x7f1d22af7338, 0xc000195400, 0xc0000c2b00)"
        },
        {
          "file": "net/http/server.go",
          "line": 2007,
          "calee": "net/http.HandlerFunc.ServeHTTP(0xc00015b040, 0x7f1d22af7338, 0xc000195400, 0xc0000c2b00)"
        },
        {
          "file": "github.com/go-chi/chi@v4.1.2+incompatible/middleware/realip.go",
          "line": 34,
          "calee": "github.com/go-chi/chi/middleware.RealIP.func1(0x7f1d22af7338, 0xc000195400, 0xc0000c2b00)"
        },
        {
          "file": "net/http/server.go",
          "line": 2007,
          "calee": "net/http.HandlerFunc.ServeHTTP(0xc00015b060, 0x7f1d22af7338, 0xc000195400, 0xc0000c2b00)"
        },
        {
          "file": "github.com/go-chi/chi@v4.1.2+incompatible/mux.go",
          "line": 70,
          "calee": "github.com/go-chi/chi.(*Mux).ServeHTTP(0xc000057d40, 0x7f1d22af7338, 0xc000195400, 0xc0000c2b00)"
        },
        {
          "file": "github.com/go-chi/chi@v4.1.2+incompatible/mux.go",
          "line": 298,
          "calee": "github.com/go-chi/chi.(*Mux).Mount.func1(0x7f1d22af7338, 0xc000195400, 0xc0000c2b00)"
        },
        {
          "file": "net/http/server.go",
          "line": 2007,
          "calee": "net/http.HandlerFunc.ServeHTTP(0xc00015b640, 0x7f1d22af7338, 0xc000195400, 0xc0000c2b00)"
        },
        {
          "file": "github.com/go-chi/chi@v4.1.2+incompatible/mux.go",
          "line": 431,
          "calee": "github.com/go-chi/chi.(*Mux).routeHTTP(0xc000057740, 0x7f1d22af7338, 0xc000195400, 0xc0000c2b00)"
        },
        {
          "file": "net/http/server.go",
          "line": 2007,
          "calee": "net/http.HandlerFunc.ServeHTTP(0xc00015c910, 0x7f1d22af7338, 0xc000195400, 0xc0000c2b00)"
        },
        {
          "file": "github.com/go-chi/chi@v4.1.2+incompatible/middleware/logger.go",
          "line": 46,
          "calee": "github.com/go-chi/chi/middleware.RequestLogger.func1.1(0xd67ca0, 0xc0001a20e0, 0xc0000c2a00)"
        },
        {
          "file": "net/http/server.go",
          "line": 2007,
          "calee": "net/http.HandlerFunc.ServeHTTP(0xc00018d320, 0xd67ca0, 0xc0001a20e0, 0xc0000c2a00)"
        },
        {
          "file": "github.com/go-chi/chi@v4.1.2+incompatible/middleware/request_id.go",
          "line": 76,
          "calee": "github.com/go-chi/chi/middleware.RequestID.func1(0xd67ca0, 0xc0001a20e0, 0xc0000c2900)"
        },
        {
          "file": "net/http/server.go",
          "line": 2007,
          "calee": "net/http.HandlerFunc.ServeHTTP(0xc00015b660, 0xd67ca0, 0xc0001a20e0, 0xc0000c2900)"
        },
        {
          "file": "github.com/go-ap/fedbox@/app/middleware.go",
          "line": 21,
          "calee": "github.com/go-ap/fedbox/app.Repo.func1.1(0xd67ca0, 0xc0001a20e0, 0xc0000c2800)"
        },
        {
          "file": "net/http/server.go",
          "line": 2007,
          "calee": "net/http.HandlerFunc.ServeHTTP(0xc00018d350, 0xd67ca0, 0xc0001a20e0, 0xc0000c2800)"
        },
        {
          "file": "github.com/go-chi/chi@v4.1.2+incompatible/mux.go",
          "line": 86,
          "calee": "github.com/go-chi/chi.(*Mux).ServeHTTP(0xc000057740, 0xd67ca0, 0xc0001a20e0, 0xc0000c2700)"
        },
        {
          "file": "net/http/server.go",
          "line": 2802,
          "calee": "net/http.serverHandler.ServeHTTP(0xc0001a2000, 0xd67ca0, 0xc0001a20e0, 0xc0000c2700)"
        },
        {
          "file": "net/http/server.go",
          "line": 1890,
          "calee": "net/http.(*conn).serve(0xc000187ea0, 0xd6c260, 0xc000195240)"
        },
        {
          "file": "net/http/server.go",
          "line": 2928,
          "calee": "created by net/http.(*Server).Serve"
        }
      ],
      "location": "github.com/go-ap/errors@v0.0.0-20200610194301-39b7d0cbba26/http.go:54"
    }
  ]
}
mariusor commented 4 years ago

I suspect that this issue might be related to #38. I'll come back with a followup when I find a fix for it.

mariusor commented 4 years ago

Hey @endoffile78 I think I fixed the issue by fixing the bootstrap command for fedbox. Can you please give it a spin and let me know if it fixes this issue too?

jhert0 commented 4 years ago

On the homepage I now get this:

2020-07-14-125937_1917x951_scrot

I get the same error as before on the other pages.

My littr .env is

# HOSTNAME is used as the base for the absolute URLs in the site
HOSTNAME=littr.local
# LISTEN_PORT is the port number that the application will listen on for connections
LISTEN_PORT=3000
# LISTEN_HOSTNAME is the host/ip that the application will listen on for connections
LISTEN_HOSTNAME=localhost
# ENV the environment type sets different configuration settings, valid are: DEV, QA, STAGING, PROD
ENV=dev
# API_URL is the url of the fedbox instance that provides our C2S ActivityPub API
API_URL=http://fedbox.local
# SESS_AUTH_KEY is used for encrypting the session data
SESS_AUTH_KEY=16_chars_enc_key=
# SESS_ENC_KEY
SESS_ENC_KEY=16_chars_enc_key+
# OAUTH2_KEY the default OAuth2 key used by the frontend to connect to the C2S ActivityPub end-points
OAUTH2_KEY=e13d5e23-1c62-4c92-b248-23aa8d213423
# OAUTH2_SECRET the default OAuth2 secret used by the frontend
OAUTH2_SECRET=littr
# SESSIONS_BACKEND the backend to use for session storage, valid: cookie, fs
SESSIONS_BACKEND=fs
# DISABLE_SESSIONS setting this to true, makes the instance essentially read only, by disallowing user logins
DISABLE_SESSIONS=false
# DISABLE_DOWNVOTING disables allowing Dislike activities
DISABLE_DOWNVOTING=false
# DISABLE_VOTING disables all Like/Dislike activities
DISABLE_VOTING=false        

My fedbox .env is

HOSTNAME=fedbox.local
LISTEN=localhost:4000
ENV=dev
STORAGE=fs
STORAGE_PATH=.

In the fedbox log I get:

RRO[0008] Not Found addr="127.0.0.1:38116" elapsed=1.410219ms id=fedbox/dssr5P9R44-000001 len=6640 method=GET proto=HTTP/1.0 scheme=http status=404 ts="Tue, 14 Jul 2020 18:09:44 UTC" ua=littr.local-b1a72a7 uri="http://localhost:4000/actors/e13d5e23-1c62-4c92-b248-23aa8d213423"ERRO[0008] Invalid username or password                 
ERRO[0008] Unauthorized addr="127.0.0.1:38120" elapsed=1.07406ms id=fedbox/dssr5P9R44-000002 len=1005 method=POST proto=HTTP/1.0 scheme=http status=401 ts="Tue, 14 Jul 2020 18:09:44 UTC" ua=Go-http-client/1.1 uri="http://localhost:4000/oauth/token"
ERRO[0008] Forbidden addr="127.0.0.1:38122" elapsed="782.275_s" id=fedbox/dssr5P9R44-000003 len=6155 method=POST proto=HTTP/1.0 scheme=http status=403 ts="Tue, 14 Jul 2020 18:09:44 UTC" ua=Go-http-client/1.1 uri="http://localhost:4000/oauth/token"
ERRO[0008] Not Found addr="127.0.0.1:38124" elapsed="873.234_s" id=fedbox/dssr5P9R44-000004 len=6613 method=GET proto=HTTP/1.0 scheme=http status=404 ts="Tue, 14 Jul 2020 18:09:44 UTC" ua=littr.local-b1a72a7 uri="http://localhost:4000/actors?type=Person&type=Service&type=Group&type=Application&type=Organization"
ERRO[0008] Not Found addr="127.0.0.1:38128" elapsed="888.457_s" id=fedbox/dssr5P9R44-000005 len=6614 method=GET proto=HTTP/1.0 scheme=http status=404 ts="Tue, 14 Jul 2020 18:09:44 UTC" ua=littr.local-b1a72a7 uri="http://localhost:4000/objects?context=-&type=Article&type=Note&type=Link&type=Page&type=Document&type=Video&type=Audio"
ERRO[0008] Not Found addr="127.0.0.1:38132" elapsed="890.822_s" id=fedbox/dssr5P9R44-000006 len=6614 method=GET proto=HTTP/1.0 scheme=http status=404 ts="Tue, 14 Jul 2020 18:09:44 UTC" ua=littr.local-b1a72a7 uri="http://localhost:4000/objects?type=Article&type=Note&type=Link&type=Page&type=Document&type=Video&type=Audio"
ERRO[0017] Not Found   addr="127.0.0.1:38146" elapsed=1.057821ms id=fedbox/dssr5P9R44-000007 len=6612 method=GET proto=HTTP/1.0 scheme=http status=404 ts="Tue, 14 Jul 2020 18:09:53 UTC" ua=littr.local-b1a72a7 uri="http://localhost:4000/inbox?maxItems=25&object.context=-&object.type=Article&object.type=Note&object.type=Link&object.type=Page&object.type=Document&object.type=Video&object.type=Audio&type=Create"

Using thunder this what I get for the client information

{"Id":"e13d5e23-1c62-4c92-b248-23aa8d213423","Secret":"littr","RedirectUri":"http://littr.local/auth/fedbox/callback","Extra":"bnVsbA=="}
mariusor commented 4 years ago

Hey @endoffile78 can you test again ? I did some improvements to bootstrapping/initial run in for issue #38, and I want to know if it fixes your problem too. Let me know please. :)

jhert0 commented 4 years ago

No, I'm still having some problems, the one I described in https://github.com/go-ap/fedbox/issues/6 seems to be fixed.

When starting littr I get:

ERRO[0000] http://fedbox.local/objects?context=-&type=Article&type=Note&type=Link&type=Page&type=Document&type=Video&type=Audio: Unable to load from the AP end point: invalid status 404 
ERRO[0000] http://fedbox.local/objects?type=Article&type=Note&type=Link&type=Page&type=Document&type=Video&type=Audio: Unable to load from the AP end point: invalid status 404 

I get this on the littr homepage: 2020-07-29-225203_1916x959_scrot

mariusor commented 4 years ago

Those are not fatal issues.

The error in the screenshot is related to the browser sending a session cookie to go-littr, but no session exists for it.

The 404 errors from fedbox are there just because the fedbox.local/objects collection doesn't exist until you save something in it. As soon as you add a submission they will be gone.