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

Swap out iframely #1706

Merged
merged 11 commits into from
Aug 19, 2021
Merged

Swap out iframely #1706

merged 11 commits into from
Aug 19, 2021

Conversation

dessalines
Copy link
Member

@dessalines dessalines commented Aug 16, 2021

This is obviously missing embed codes, IE embed_html in our DB, but I greatly doubt they were used much anyway (and they're a security risk).

@dessalines dessalines marked this pull request as draft August 16, 2021 16:47
@dessalines dessalines marked this pull request as ready for review August 16, 2021 17:05
src/main.rs Outdated
// Required because docker installs try to use TLS, which is disabled as a reqwest feature flag
let client = reqwest::ClientBuilder::new()
.danger_accept_invalid_certs(true)
.build()?;
Copy link
Member

Choose a reason for hiding this comment

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

We should only use this for testing, not in prod.

Copy link
Member Author

Choose a reason for hiding this comment

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

This fails for both dev and prod. The only way to not do this would be to turn on an SSL feature flag of reqwest.

Copy link
Member

@Nutomic Nutomic Aug 16, 2021

Choose a reason for hiding this comment

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

And thats enabled by default. Its also required by activitypub, so its impossible to disable it. Not to mention that it would be a security vulnerability for open graph fetching as well.

So I really dont understand why you think it is necessary to accept invalid certs.

Copy link
Member Author

Choose a reason for hiding this comment

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

It took me a while to find the ssl bug, but the docker post creates will fail without this flag. I'll redo it then post the error.

Copy link
Member Author

@dessalines dessalines Aug 17, 2021

Choose a reason for hiding this comment

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

Yep, just tested removing it, and it gets this error every time:

error sending request for url (https://www.marxists.org/archive/lenin/works/1921/apr/21.htm): error trying to connect: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed:../ssl/statem/statem_clnt.c:1913: (unable to get local issuer certificate)

http://localhost:8536/api/v3/post/site_metadata?url=https://www.marxists.org/archive/lenin/works/1921/apr/21.htm

I remember googling it, its due to SSL not being correctly installed on the system that uses reqwest, IE using the native SSL.

Copy link
Member Author

@dessalines dessalines Aug 17, 2021

Choose a reason for hiding this comment

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

If we merge this without using .danger_accept_invalid_certs(true), all post creates with a URL will be broken, and this feature won't work on any official install.

Copy link
Member

Choose a reason for hiding this comment

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

But the SSL problem doesnt happen in prod, otherwise federation wouldnt work either.

Copy link
Member Author

@dessalines dessalines Aug 17, 2021

Choose a reason for hiding this comment

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

Ohhh okay I can maybe guess the issue. We never use or generate self-signed certs (which apparently reqwest needs ) , we use letsencrypt for the ansible deploys, which docker is somehow smart enough to be able to insert into from the system into our docker container, which rust can then use. I have no idea how it does this without any configuring, because we haven't touched a thing or passed these forward in any way.

The best way would be to check if it exists using openssl_probe: https://docs.rs/openssl-probe/0.1.4/openssl_probe/fn.has_ssl_cert_env_vars.html , and use the dangerous flag if there are no certs, and output a warning in the console on lemmy startup.

Reqwest works in our system unit tests by using the local system generated certs, but our docker images don't do this.

Copy link
Member

Choose a reason for hiding this comment

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

Reqwest as http client doesnt need access to website certificates, those are sent by the server. All it needs are the CA certificates in order to verify the tls certificate. Did you try apt-get install ca-certificates and checking CURL_CA_BUNDLE env var as described in my link above?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah that appeared to do it, I forgot that the volume_mount uses a different DockerFile.

I wonder why this doesn't need to be done with the musl images.

@dessalines dessalines marked this pull request as draft August 17, 2021 19:05
@dessalines dessalines marked this pull request as ready for review August 18, 2021 00:35
}
}

pub async fn fetch_iframely_and_pictrs_data(
/// Both are options, since the URL might be either an html page, or an image
pub async fn fetch_site_metadata_and_pictrs_data(
Copy link
Member

Choose a reason for hiding this comment

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

Imo the thumbnail is also part of metadata, so no need to mention pictrs explicitly here. This method should definitely log errors (under verbose). A more detailed description of what it does would also be nice.

Copy link
Member Author

Choose a reason for hiding this comment

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

There's already a fetch_site_metadata function, which refers specifically to this SiteMetadata struct I just added. I can change the name to fetch_site_data tho.

context: &Data<LemmyContext>,
_websocket_id: Option<ConnectionId>,
) -> Result<GetSiteMetadataResponse, LemmyError> {
let data: &Self = self;
Copy link
Member

Choose a reason for hiding this comment

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

Why do you rename self in every API method? For me its quite confusing, because it doesnt actually do anything.

Copy link
Member Author

Choose a reason for hiding this comment

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

Just history, these used to be very different impls. If someone wanted to go through and change all these to self, it wouldn't hurt anything, but data to me is more clear as its describing that its the Form data.

@Nutomic Nutomic merged commit 6af7549 into main Aug 19, 2021
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