Skip to content

Add Invoice skip list #176

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

Merged
merged 3 commits into from
May 15, 2025
Merged

Conversation

sputn1ck
Copy link
Member

@sputn1ck sputn1ck commented May 14, 2025

This PR adds a new list for the config which will allow skipping the creation of invoices on these specific calls.
This is useful for streaming rpcs, as we can't handle the l402 handshake there (yet?).

@sputn1ck sputn1ck force-pushed the invoice_skip_list branch from 86ddf38 to 0b5dd11 Compare May 14, 2025 16:34
proxy/service.go Outdated
// given request.
func (s *Service) SkipInvoiceCreation(r *http.Request) bool {
for _, pathRegexp := range s.AuthSkipInvoiceCreationPaths {
pathRegexp := regexp.MustCompile(pathRegexp)
Copy link
Member

@bhandras bhandras May 14, 2025

Choose a reason for hiding this comment

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

Perhaps this could be precompiled for better performance, see:

func MustCompile(str string) *Regexp {
	regexp, err := Compile(str)
	if err != nil {
		panic(`regexp: Compile(` + quote(str) + `): ` + err.Error())
	}
	return regexp
}

Copy link
Member

Choose a reason for hiding this comment

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

Can probably rebase this on the other PR and then use pre-compiled patterns here too.

@bhandras bhandras requested a review from guggero May 14, 2025 16:44
proxy/proxy.go Outdated
@@ -182,6 +183,14 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// resources.
acceptAuth := p.authenticator.Accept(&r.Header, resourceName)
if !acceptAuth {
if skipInvoiceCreation {
addCorsHeaders(w.Header())
sendDirectResponse(w, r, http.StatusUnauthorized,
Copy link
Member

Choose a reason for hiding this comment

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

nit: formatting

@sputn1ck sputn1ck force-pushed the invoice_skip_list branch 2 times, most recently from e9ab581 to 1cda069 Compare May 14, 2025 16:55
Copy link
Member

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Nice, LGTM 🎉

@@ -135,6 +135,12 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

// If the request is a gRPC request, we need to set the Content-Type
// header to application/grpc.
if strings.HasPrefix(r.Header.Get(hdrContentType), hdrTypeGrpc) {
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, this might fix a long-standing error that we see sometimes. I just hope it doesn't introduce any side effects (I remember the whole header handling for gRPC being super brittle with many weird behaviors).

proxy/service.go Outdated
// given request.
func (s *Service) SkipInvoiceCreation(r *http.Request) bool {
for _, pathRegexp := range s.AuthSkipInvoiceCreationPaths {
pathRegexp := regexp.MustCompile(pathRegexp)
Copy link
Member

Choose a reason for hiding this comment

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

Can probably rebase this on the other PR and then use pre-compiled patterns here too.

Prior we would not set the Content-Type header for
grpc request, which on failure events would cause
the response to be invalid gRPC responses, as the
grpc code path in sendDirectResponse expects the
Content-Type header to be set.

This change fixes the problem by setting the
Content-Type header to application/grpc for gRPC
requests.
@sputn1ck sputn1ck force-pushed the invoice_skip_list branch from 1cda069 to 9023abc Compare May 14, 2025 20:25
@sputn1ck sputn1ck requested a review from bhandras May 14, 2025 20:56
Copy link
Member

@bhandras bhandras left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

@sputn1ck sputn1ck force-pushed the invoice_skip_list branch from 9023abc to b1b0dc5 Compare May 15, 2025 06:41
@bhandras bhandras merged commit ab83de2 into lightninglabs:master May 15, 2025
5 checks passed
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.

None yet

3 participants