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

Upgrading from 0.11.2 to 0.12.3 breaks anonaddy #150

Closed
yurividal opened this issue Jul 21, 2022 · 33 comments
Closed

Upgrading from 0.11.2 to 0.12.3 breaks anonaddy #150

yurividal opened this issue Jul 21, 2022 · 33 comments

Comments

@yurividal
Copy link

I know this issue was reported when 0.12.2 was released, but even with 0.12.3, anonaddy seems broken. Reverting back to 0.11.2 fixes.
I see errors in the logs:

warning: connect to Milter service inet:127.0.0.1:11332: Connection refused
lost connection after STARTTLS from unknown[10.10.10.1]
Jul 21 12:57:01 anonaddy postfix/smtpd[1042]: disconnect from unknown[10.10.10.1] ehlo=1 starttls=0/1 commands=1/2
Jul 21 12:57:01 anonaddy postfix/smtpd[1042]: connect from unknown[10.10.10.1]
Jul 21 12:57:01 anonaddy postfix/smtpd[1042]: warning: connect to Milter service inet:127.0.0.1:11332: Connection refused
Jul 21 12:57:01 anonaddy postfix/smtpd[1042]: lost connection after STARTTLS from unknown[10.10.10.1]
Jul 21 12:57:01 anonaddy postfix/smtpd[1042]: disconnect from unknown[10.10.10.1] ehlo=1 starttls=0/1 commands=1/2

PS: 10.10.10.1 is my router's LAN address.

My docker-compose file is based on the example one in this repo, and my anonaddy.env file too.

@crazy-max
Copy link
Member

crazy-max commented Jul 21, 2022

@yurividal Hum not sure if Alpine 3.16 bump #131 is responsible for this. Alpine 3.16 install Postfix 3.7.2 and previously we had Postfix 3.6.6. I will push 0.12.3 against Alpine 3.15 ant let you know when the image is available.

might also be linked to #136

@crazy-max
Copy link
Member

@yurividal No PHP 8.1 pks available in Alpine Linux 3.15 unfortunately and AnonAddy 0.12 requires PHP 8.1. Will see if building postfix from source would be a better idea.

@yurividal
Copy link
Author

Has this been fixed on the latest release?

@crazy-max
Copy link
Member

Looking at how packaging for postfix is currently handled in Alpine and patches being applied, it doesn't seem we have a straight forward way to build postfix from source without taking into account aports changes.

As postfix seems to be the culprit here, I will take a look to create a postfix docker image (non-runnable with only bins) to be able to tackle this issue.

@willbrowningme Are you aware of issues with postfix > 3.6?

@willbrowningme
Copy link
Member

Those errors look to me like the issue is an error connecting to Rspamd, as that is the port that Rspamd runs on.

e.g. in /etc/postfix/main.cf:

smtpd_milters = inet:localhost:11332
non_smtpd_milters = $smtpd_milters

@crazy-max
Copy link
Member

@willbrowningme Yes that looks like it but can't repro on my side.

@yurividal Can you post full logs and also your compose file as well as env file if applicable? Thanks.

@yurividal
Copy link
Author

@crazy-max i just upgraded to 0.13.3 (latest) in order to collect the logs for you, and to my surprise, the forwarding worked this time. Something between 0.12.3 and 0.13.3 fixed the issue.

@yurividal
Copy link
Author

here are the logs of the working forward:

Aug 01 14:35:31 anonaddy postfix/smtpd[1035]: connect from mx-relay02-hz5.antispameurope.com[173.45.18.202]
Aug 01 14:35:32 anonaddy postfix/smtpd[1035]: 289984E0CE3: client=mx-relay02-hz5.antispameurope.com[173.45.18.202]
Aug 01 14:35:32 anonaddy postfix/cleanup[1038]: 289984E0CE3: message-id=<[email protected]>
Aug 01 14:35:35 anonaddy postfix/qmgr[1021]: 289984E0CE3: from=<prvs=020525b4a1={removed}>, size=150102, nrcpt=1 (queue active)
Aug 01 14:35:35 anonaddy postfix/smtpd[1035]: disconnect from mx-relay02-hz5.antispameurope.com[173.45.18.202] ehlo=1 mail=1 rcpt=1 data=1 quit=1 commands=5
Aug 01 14:35:36 anonaddy postfix/smtpd[1035]: connect from localhost[127.0.0.1]
Aug 01 14:35:36 anonaddy postfix/smtpd[1035]: 25ADE4E0CF3: client=localhost[127.0.0.1]
Aug 01 14:35:36 anonaddy postfix/cleanup[1038]: 25ADE4E0CF3: message-id=<[email protected]>
Aug 01 14:35:36 anonaddy postfix/qmgr[1021]: 25ADE4E0CF3: from=<[email protected]>, size=147274, nrcpt=1 (queue active)
Aug 01 14:35:36 anonaddy postfix/smtpd[1035]: disconnect from localhost[127.0.0.1] ehlo=1 mail=1 rcpt=1 data=1 quit=1 commands=5
Aug 01 14:35:36 anonaddy postfix/pipe[1039]: 289984E0CE3: to=<[email protected]>, relay=anonaddy, delay=4.6, delays=3.9/0.01/0/0.68, dsn=2.0.0, status=sent (delivered via anonaddy service)
Aug 01 14:35:36 anonaddy postfix/qmgr[1021]: 289984E0CE3: removed

feel free to close this issue if you want.

Only issue i see with this version is the version string not being picked up, but i think a fix for that is on the works

@crazy-max
Copy link
Member

Only issue i see with this version is the version string not being picked up, but i think a fix for that is on the works

Yes indeed: #156 (comment)

@yurividal
Copy link
Author

@crazy-max , sorry. I just realized that after upgrading to 0.13.3, i can no longer execute any actions on the web ui.
image

I know i had to generate a new api token for my app. The app works fine. But, on the web ui, i can't execute any actions. I tells me I am not authenticated.

I have tried different browser and anonymous browser sessions.

@willbrowningme
Copy link
Member

@yurividal thanks for bringing that to my attention, I believe the issue is something to do with this -https://laravel.com/docs/9.x/sanctum#configuring-your-first-party-domains

What is the IP that Docker makes request from, would it be 127.0.0.1:8000?

@willbrowningme
Copy link
Member

The default domains considered stateful by Laravel Sanctum are:

[
  "localhost",
  "localhost:3000",
  "127.0.0.1",
  "127.0.0.1:8000",
  "::1",
  "example.com"
]

As can be seen here, where example.com is the current app URL with port.

@yurividal
Copy link
Author

yurividal commented Aug 1, 2022

What is the IP that Docker makes request from, would it be 127.0.0.1:8000?

I'm not sure I understand your question. Do you mean what is the IP that anonaddy container sees as the source of the request?

@willbrowningme
Copy link
Member

Yes, I believe the issue is that the domain is not being considered stateful by Sanctum which is why it is saying unauthenticated.

@crazy-max
Copy link
Member

@willbrowningme Looking at the code: https://github.com/anonaddy/anonaddy/blob/443d646af6d45e8d0bfa3fa8c984b95cf790292d/config/sanctum.php#L18-L22 I made changes in #158 to take into account SANCTUM_STATEFUL_DOMAINS env var so all anonaddy domains are also part of the stateful api:

SANCTUM_STATEFUL_DOMAINS="\${ANONADDY_ALL_DOMAINS}"

@willbrowningme
Copy link
Member

@crazy-max I'm not sure it needs all domains, I think it only needs the domain that the web application is being run on e.g. on the hosted version this would be app.anonaddy.com.

So it just needs to be whatever domain they are using to access the web application.

@crazy-max
Copy link
Member

@crazy-max I'm not sure it needs all domains, I think it only needs the domain that the web application is being run on e.g. on the hosted version this would be app.anonaddy.com.

So it just needs to be whatever domain they are using to access the web application.

Ok so ANONADDY_DOMAIN would be enough

The default domains considered stateful by Laravel Sanctum are:

[
  "localhost",
  "localhost:3000",
  "127.0.0.1",
  "127.0.0.1:8000",
  "::1",
  "example.com"
]

As can be seen here, where example.com is the current app URL with port.

Otherwise yes web server listening to 127.0.0.1:8000

@crazy-max
Copy link
Member

@crazy-max , sorry. I just realized that after upgrading to 0.13.3, i can no longer execute any actions on the web ui. image

I know i had to generate a new api token for my app. The app works fine. But, on the web ui, i can't execute any actions. I tells me I am not authenticated.

I have tried different browser and anonymous browser sessions.

Can you show your logs? There might be smth useful there.

@yurividal
Copy link
Author

yurividal commented Aug 1, 2022

Can you show your logs? There might be smth useful there.

Browser console logs:

app.js?id=490802ebaa…4a97a58f8f79ec2b0:2 
 DELETE https://anonaddy.mydomain.com/api/v1/active-aliases/aa074f17-2c54-4b03-a079-fcf777412de2 401 (Unauthorized)

Anonaddy Container Logs:

10.10.10.6 - - [01/Aug/2022:16:09:33 +0200] "DELETE /api/v1/active-aliases/3e441479-7394-41d4-9704-7b018817ed70 HTTP/1.0" 401 30 "https://anonaddy.mydomain.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"

As you can see, nothing very useful.

Ps: 10.10.10.6 is the IP of my reverse proxy (nginx). But, when i access anonaddy directly through its IP and port, i also get the same error, (with my PC's ip on the beginning of the line). No, not an nginx issue

@willbrowningme
Copy link
Member

Perhaps 10.10.10.6 needs adding to SANCTUM_STATEFUL_DOMAINS then.

@yurividal
Copy link
Author

Perhaps 10.10.10.6 needs adding to SANCTUM_STATEFUL_DOMAINS then.

I have created an env "SANCTUM_STATEFUL_DOMAINS" and assigned it the IP of my nginx. I verified that anonaddy can echo this variable, but issue still persists.

@crazy-max
Copy link
Member

@yurividal
Copy link
Author

@yurividal https://github.com/anonaddy/docker#define-additional-env-vars

Thanks, but, even after adding the .env file with the variable into the /data folder, the error still persists. Unauthorized.

bash-5.1# cat /data/.env 
SANCTUM_STATEFUL_DOMAINS=10.10.10.6

@willbrowningme
Copy link
Member

What if you set it as:

SANCTUM_STATEFUL_DOMAINS=localhost,localhost:3000,127.0.0.1,127.0.0.1:8000,::1,10.10.10.6,anonaddy.mydomain.com,anonaddy.mydomain.com:8000

Where anonaddy.mydomain.com is the location where you access the web application.

@yurividal
Copy link
Author

yurividal commented Aug 2, 2022

What if you set it as:

SANCTUM_STATEFUL_DOMAINS=localhost,localhost:3000,127.0.0.1,127.0.0.1:8000,::1,10.10.10.6,anonaddy.mydomain.com,anonaddy.mydomain.com:8000

Where anonaddy.mydomain.com is the location where you access the web application.

It worked!
Maybe this solution can be added to the documentation? or is this just a workarround for a future release?

@willbrowningme
Copy link
Member

I suspect the one that worked is either anonaddy.mydomain.com:8000 or anonaddy.mydomain.com.

I could update the app/config/sanctum.php file to look like this by default:

'stateful' => explode(',', env('SANCTUM_STATEFUL_DOMAINS', sprintf(
    '%s%s%s',
    'localhost,localhost:3000,127.0.0.1,127.0.0.1:8000,::1',
    Sanctum::currentApplicationUrlWithPort(),
    ','.config('app.url').':8000'
))),

Then we shouldn't need to set anything for the environment variable SANCTUM_STATEFUL_DOMAINS.

Is your APP_URL environment variable set correctly to anonaddy.mydomain.com?

@yurividal
Copy link
Author

yurividal commented Aug 2, 2022

Is your APP_URL environment variable set correctly to anonaddy.mydomain.com?

Yes, it is. Its set to https://anonaddy.mydomain.com

@willbrowningme
Copy link
Member

Okay, are you able to open up laravel tinker in the command line by running php artisan tinker and then see what the following command returns:

Laravel\Sanctum\Sanctum::currentApplicationUrlWithPort();

I think it will be ,anonaddy.mydomain.com so that means it is adding anonaddy.mydomain.com:8000 that got it working.

@yurividal
Copy link
Author

I think it will be ,anonaddy.mydomain.com so that means it is adding anonaddy.mydomain.com:8000 that got it working.

Exactly:

bash-5.1# php artisan tinker
Psy Shell v0.11.8 (PHP 8.1.8 — cli) by Justin Hileman
>>> Laravel\Sanctum\Sanctum::currentApplicationUrlWithPort();
=> ",anonaddy.mydomain.com"

>>>

@crazy-max
Copy link
Member

I suspect the one that worked is either anonaddy.mydomain.com:8000 or anonaddy.mydomain.com.

I could update the app/config/sanctum.php file to look like this by default:

'stateful' => explode(',', env('SANCTUM_STATEFUL_DOMAINS', sprintf(
    '%s%s%s',
    'localhost,localhost:3000,127.0.0.1,127.0.0.1:8000,::1',
    Sanctum::currentApplicationUrlWithPort(),
    ','.config('app.url').':8000'
))),

Then we shouldn't need to set anything for the environment variable SANCTUM_STATEFUL_DOMAINS.

Is your APP_URL environment variable set correctly to anonaddy.mydomain.com?

@willbrowningme Looking at this, if SANCTUM_STATEFUL_DOMAINS=anonaddy.mydomain.com it will produce:

anonaddy.mydomain.comlocalhost,localhost:3000,127.0.0.1,127.0.0.1:8000,::1

So add a comma :SANCTUM_STATEFUL_DOMAINS=anonaddy.mydomain.com, or maybe I miss smth?

@willbrowningme
Copy link
Member

@crazy-max in Laravel the env() helper method accepts an environment variable as the first argument and then a default value if none is set as the second one, it doesn't append the second argument.

So if you set SANCTUM_STATEFUL_DOMAINS=anonaddy.mydomain.com it would just produce anonaddy.mydomain.com.

The change I just made should mean we don't need to set SANCTUM_STATEFUL_DOMAINS at all.

@crazy-max
Copy link
Member

Looks good thanks, will make the modifications and publish new docker image.

@Nicicalu
Copy link

The latest image (0.13.5) didn't fix the issue for me. From the things you wrote above I thought that you didn't have to add anything to the .env file.
My Anonaddy instance is behind a nginx reverse proxy. I set SANCTUM_STATEFUL_DOMAINS=anonaddy.mydomain.com and it worked.

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

No branches or pull requests

4 participants