kanidm / webauthn-rs

An implementation of webauthn components for Rustlang servers
Mozilla Public License 2.0
488 stars 80 forks source link

Application stops without any error message in build phase when running in docker container #387

Closed RzaIs closed 10 months ago

RzaIs commented 10 months ago

I did this

write super simple app:

main.rs

use webauthn_rs::prelude::{Url, Uuid};
use webauthn_rs::WebauthnBuilder;

fn main() {

    let rp_id = "rza.is";
    let rp_origin = "https://passkit.rza.is";

    let rp_origin = &Url::parse(rp_origin)
        .expect("Url::parse");

    println!("rp_origin = Url::parse success");

    let webauthn_builder = WebauthnBuilder::new(rp_id, rp_origin)
        .map(|b| b.rp_name("passkit"))
        .expect("WebauthnBuilder::new");

    println!("webauthn_builder = WebauthnBuilder::new success");

    let webauthn = webauthn_builder.build().expect("webauthn_builder.build");

    println!("webauthn = webauthn_builder.build success");

    let user_uuid = Uuid::new_v4();

    _ = webauthn.start_passkey_registration(
        user_uuid,
        "rzais",
        "Rza Ismayilov",
        None
    ).expect("webauthn.start_passkey_registration");

    println!("webauthn.start_passkey_registration success");
}

Cargo.toml

[package]
name = "passkit"
version = "0.1.0"
edition = "2021"

[dependencies]
webauthn-rs-core = "0.4.8"
webauthn-rs = { version = "0.4.8", features = ["danger-allow-state-serialisation"]}

Dockerfile

FROM rust:1.70-alpine3.17 as builder

RUN apk update
RUN apk update && apk add pkgconfig openssl openssl-dev musl-dev

RUN rustup target add x86_64-unknown-linux-musl

WORKDIR /rust/src

COPY . .

RUN cargo build --target x86_64-unknown-linux-musl --release

######## Start a new stage from scratch #######
FROM alpine:3.13

COPY --from=builder /rust/src/target/x86_64-unknown-linux-musl/release/passkit /

CMD [ "./passkit" ]

I expected the following

printing all debug messages shown in main functions

What actually happened

application exits when running webauthn_builder.build() without any error panic message, just stops.

Version (and git commit)

Operating System / Version

main machine is macbook pro m1 pro but docker container is linux/x86_64

Any other comment

Application works fine on local machine but fails in docker container

yaleman commented 10 months ago

To save having to copy-paste and do the thing, have you got the app in a repo somewhere we can clone?

My first idea would be to ensure you're running the container with --platform set to linux/x86_64 or trying it without musl.

Firstyear commented 10 months ago

@RzaIs We support tracing, so consider setting that up to see what's occuring.

RzaIs commented 10 months ago

To save having to copy-paste and do the thing, have you got the app in a repo somewhere we can clone?

My first idea would be to ensure you're running the container with --platform set to linux/x86_64 or trying it without musl.

Here is the repo: https://github.com/RzaIs/passkit-rs

As in the compose file I made sure of it. I didn't tested it without musl but it is necessary fir me working without any dynamic linking. I need a pure binary which can run in the alpine linux without any dependency

RzaIs commented 10 months ago

@RzaIs We support tracing, so consider setting that up to see what's occuring.

Would you please assist a little more about how to set it up

Firstyear commented 10 months ago

https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/index.html#usage

RzaIs commented 10 months ago

I have noticed the program is exited with 139 which is segfault signal. I believe it is coming from a linked C code. How can I trace it back?

Firstyear commented 10 months ago

I think this is an environmental issue in how you are setting up and using the code in your container. I don't know how you would approach debugging this, but it's clear the issue is not in webauthn-rs at this point.

The best advice I can give is to change CMD to /bin/bash and then go from there, install something like lldb, and then do lldb ./passkey

I'm going to close this now though, because it's not a fault in webauthn-rs.

yaleman commented 10 months ago

this works on my mac laptop

$ docker build --platform linux/x86_64 -t passkit-rs .
<snip stuff>
$ docker run --rm -it --platform linux/x86_64 passkit-rs
rp_origin = Url::parse success
webauthn_builder = WebauthnBuilder::new success

You need to build it on the right architecture, that's what's causing the segfault.

RzaIs commented 10 months ago

this works on my mac laptop

$ docker build --platform linux/x86_64 -t passkit-rs .
<snip stuff>
$ docker run --rm -it --platform linux/x86_64 passkit-rs
rp_origin = Url::parse success
webauthn_builder = WebauthnBuilder::new success

You need to build it on the right architecture, that's what's causing the segfault.

My compose file already have the platform property as linux/x86_64

Additionally when I looked at your log I noticed you actually had the same issue. Your execution also stops after WebauthnBuilder::new success but there is more process supposed to happen after it if you at the main.rs

RzaIs commented 10 months ago

I think this is an environmental issue in how you are setting up and using the code in your container. I don't know how you would approach debugging this, but it's clear the issue is not in webauthn-rs at this point.

The best advice I can give is to change CMD to /bin/bash and then go from there, install something like lldb, and then do lldb ./passkey

I'm going to close this now though, because it's not a fault in webauthn-rs.

I am not sure if this is the right thing to do. It appears your library is not platform agnostic. If it what the issue is you should have a list of condition that needs to be satisfied in order to use the lib in a documentation.

yaleman commented 10 months ago

Apologies, my shell masked the error code at the time.

Looks like an issue exists with alpine/musl and some openssl crate linking problem.

I updated your Dockerfile and this seems to run. Note:

FROM rust:1.70-alpine3.17 as builder

RUN apk update
RUN apk update && apk add pkgconfig openssl openssl-dev musl-dev

RUN rustup target add x86_64-unknown-linux-musl

WORKDIR /rust/src

COPY . .

RUN RUSTFLAGS="-C target-feature=-crt-static" cargo build --target x86_64-unknown-linux-musl --release

######## Start a new stage from scratch #######
FROM alpine:3.17
COPY --from=builder /rust/src/target/x86_64-unknown-linux-musl/release /

RUN apk update && apk add libgcc

CMD [ "/passkit" ]

output:

11:10:55 ➜ docker build --platform linux/x86_64 -t passkit-rs . && \
docker run --rm -it --platform linux/x86_64 passkit-rs && \
echo "Finished OK"
[+] Building 56.4s (16/16) FINISHED                                                                                                             docker:orbstack
 => [internal] load build definition from Dockerfile                                                                                                       0.0s
 => => transferring dockerfile: 533B                                                                                                                       0.0s
 => [internal] load .dockerignore                                                                                                                          0.0s
 => => transferring context: 2B                                                                                                                            0.0s
 => [internal] load metadata for docker.io/library/alpine:3.17                                                                                             0.0s
 => [internal] load metadata for docker.io/library/rust:1.70-alpine3.17                                                                                    1.0s
 => [builder 1/7] FROM docker.io/library/rust:1.70-alpine3.17@sha256:c41756ff1f9db067b47f48ee816aec9665b7242e40d6fdea85de3b5ee002c7d5                      0.0s
 => [internal] load build context                                                                                                                          0.0s
 => => transferring context: 73.65kB                                                                                                                       0.0s
 => [stage-1 1/3] FROM docker.io/library/alpine:3.17                                                                                                       0.0s
 => CACHED [builder 2/7] RUN apk update                                                                                                                    0.0s
 => CACHED [builder 3/7] RUN apk update && apk add pkgconfig openssl openssl-dev musl-dev                                                                  0.0s
 => CACHED [builder 4/7] RUN rustup target add x86_64-unknown-linux-musl                                                                                   0.0s
 => CACHED [builder 5/7] WORKDIR /rust/src                                                                                                                 0.0s
 => [builder 6/7] COPY . .                                                                                                                                 0.1s
 => [builder 7/7] RUN RUSTFLAGS="-C target-feature=-crt-static" cargo build --target x86_64-unknown-linux-musl --release                                  55.1s
 => CACHED [stage-1 2/3] COPY --from=builder /rust/src/target/x86_64-unknown-linux-musl/release /                                                          0.0s
 => CACHED [stage-1 3/3] RUN apk update && apk add libgcc                                                                                                  0.0s
 => exporting to image                                                                                                                                     0.0s
 => => exporting layers                                                                                                                                    0.0s
 => => writing image sha256:fb54b0e9703e12e8a050e854b9826a2796a77206f6025c8dc5bb546f62c087d5                                                               0.0s
 => => naming to docker.io/library/passkit-rs                                                                                                              0.0s
rp_origin = Url::parse success
webauthn_builder = WebauthnBuilder::new success
webauthn = webauthn_builder.build success
webauthn.start_passkey_registration success
Finished OK
Firstyear commented 10 months ago

I am not sure if this is the right thing to do. It appears your library is not platform agnostic. If it what the issue is you should have a list of condition that needs to be satisfied in order to use the lib in a documentation.

No. This is flatly incorrect, and you should not come into a project and make such accusations.

We have directed you on precise instructions on how to proceed with your investigation, we have told you in no uncertain terms that the issue is in your environment. @yaleman has gone above and beyond and even investigated this for you, when you showed no interest in conducting your own investigation.

It is not up to us to hand-hold you as your use our library. You need to take ownership of your own problems and your mistakes, and investigate them yourself before making accusations like this.

We will no longer be responding to this issue.