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

caddyhttp: Placeholder for client cert in DER + base64 format #4241

Merged
merged 3 commits into from
Oct 1, 2021

Conversation

musinit
Copy link
Contributor

@musinit musinit commented Jul 10, 2021

Fixes #3767

Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. I think it needs to be changed though, as it doesn't really make sense as-is.

modules/caddyhttp/replacer.go Outdated Show resolved Hide resolved
modules/caddyhttp/replacer.go Outdated Show resolved Hide resolved
@musinit musinit requested a review from mholt July 12, 2021 12:19
@francislavoie
Copy link
Member

francislavoie commented Jul 12, 2021

It's not PEM if it's raw bytes base64 encoded; that's DER base64 encoded.

PEM is specifically DER base64 encoded then with ASCII armor added and newlines at every 64 chars.

Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

Yeah these changes aren't quite what was suggested... try something like this instead.

modules/caddyhttp/replacer.go Outdated Show resolved Hide resolved
@musinit musinit requested a review from mholt July 13, 2021 09:50
@mholt
Copy link
Member

mholt commented Jul 13, 2021

Cool, does this serve the intended purpose @musinit @mc0239 @ramzec?

@mholt mholt added the under review 🧐 Review is pending before merging label Jul 13, 2021
@mholt mholt added this to the 2.x milestone Jul 13, 2021
@mholt
Copy link
Member

mholt commented Aug 16, 2021

Someone with an actual need for this will need to verify it works and fulfills the need before this will get merged, otherwise we will have to close this for inactivity.

@mholt
Copy link
Member

mholt commented Aug 24, 2021

Closing due to inactivity. Can reopen if needed.

@mholt mholt closed this Aug 24, 2021
@cschmatzler
Copy link

cschmatzler commented Oct 1, 2021

Hey @mholt!

Not one of the people that originally wanted this, but stumbled upon it half an hour ago and can report that this change does indeed work and allows me to use Caddy in front of the Syncthing Discovery service with

tls {
    client_auth {
        mode require
    }
}

reverse_proxy /* syncthing-discovery:8443 {
    header_up X-Real-IP {http.request.remote.host}
    header_up X-Client-Port {http.request.remote.port}
    header_up X-SSL-Cert {http.request.tls.client.certificate_der_base64}
}

That said, I'd appreciate you reopening and merging this PR.

Thanks!

@francislavoie
Copy link
Member

Interesting, thanks @cschmatzler, for ref, X-SSL-Cert is documented here: https://docs.syncthing.net/users/stdiscosrv.html#requirements

@francislavoie francislavoie reopened this Oct 1, 2021
@francislavoie francislavoie force-pushed the certificate-pem-base64 branch from c36860f to 3b49a2d Compare October 1, 2021 21:22
@francislavoie francislavoie modified the milestones: 2.x, v2.4.6 Oct 1, 2021
@francislavoie francislavoie changed the title client.certificate_pem_encoded in base64 format caddyhttp: Placeholder for client cert in DER + base64 format Oct 1, 2021
@francislavoie
Copy link
Member

I went ahead and rebased the branch, fixing some merge conflicts.

@mholt I think this is ready to go 👍

Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

As this has an actual (but niche) use case, I guess we can merge this. Thank you for verifying!

@mholt mholt merged commit cbb045a into caddyserver:master Oct 1, 2021
@mholt mholt removed the under review 🧐 Review is pending before merging label Jan 6, 2022
@aoxiangtianji
Copy link

aoxiangtianji commented Jul 30, 2022

This doesn't work on my machine.
I'm running a syncthing discovery server container and a caddy container as reverse proxy via podman rootless.
But the discovery server still reports no certificates.

This is my Caddyfile:

{
    debug
}

sync.example.com:10443 {
    tls {
        dns cloudflare ***
        client_auth {
            mode request
        }
    }

    reverse_proxy /* syncthing-discovery:8443 {
        header_up X-Forwarded-For {http.request.remote.host}
        header_up X-Client-Port {http.request.remote.port}
        header_up X-SSL-Cert {http.request.tls.client.certificate_der_base64}
    }
}

And the log of caddy:

{"level":"debug","ts":1659198997.878383,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"syncthing-discovery:8443","duration":0.004028418,"request":{"remote_ip":"10.89.1.15","remote_port":"55602","proto":"HTTP/1.1","method":"POST","host":"sync.aoxtj.cyou:10443","uri":"/","headers":{"X-Forwarded-Proto":["https"],"X-Forwarded-Host":["sync.aoxtj.cyou:10443"],"Content-Type":["application/json"],"Accept-Encoding":["gzip"],"X-Forwarded-For":["10.89.1.15"],"X-Client-Port":["55602"],"X-Ssl-Cert":["MIICH********************37OvaXi2w=="],"User-Agent":["Go-http-client/1.1"],"Content-Length":["133"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"","server_name":"sync.aoxtj.cyou","client_common_name":"syncthing","client_serial":"6081856432655817123"}},"headers":{"Retry-After":["1500"],"X-Content-Type-Options":["nosniff"],"Date":["Sat, 30 Jul 2022 16:36:37 GMT"],"Content-Length":["10"],"Content-Type":["text/plain; charset=utf-8"]},"status":403}

Is there something wrong?

@francislavoie
Copy link
Member

The headers look correct. It's not an issue with Caddy, you'll need to figure out why your upstream app doesn't accept it.

@Rirmach
Copy link

Rirmach commented Nov 27, 2022

@aoxiangtianji Just change

header_up X-SSL-Cert {http.request.tls.client.certificate_der_base64}

to

header_up X-Tls-Client-Cert-Der-Base64 {http.request.tls.client.certificate_der_base64}

They fixed this but do not update the document, remember to build using the latest commit.

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.

"invalid header field value" when including http.request.tls.client.certificate_pem placeholder in a header
6 participants