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

fix: send auth headers with info requests if missing #392

Merged
merged 4 commits into from
May 8, 2023

Conversation

kruskall
Copy link
Member

@kruskall kruskall commented May 3, 2023

Forward auth headers for info requests. This does not affect data ingestion as we are already forwarding the headers there.

A test has been added to ensure the auth options passed to the lambda extension are correctly forwarded.

Closes #389

@github-actions github-actions bot added the aws-λ-extension AWS Lambda Extension label May 3, 2023
apmproxy/receiver.go Outdated Show resolved Hide resolved
@kruskall kruskall requested a review from lahsivjar May 6, 2023 11:06
apmproxy/receiver.go Outdated Show resolved Hide resolved
@kruskall kruskall enabled auto-merge (squash) May 8, 2023 12:13
@kruskall kruskall merged commit ff89993 into elastic:main May 8, 2023
@kruskall kruskall deleted the fix/apm-server-version branch May 19, 2023 13:28
@lahsivjar lahsivjar self-assigned this Jul 24, 2023
@lahsivjar
Copy link
Contributor

lahsivjar commented Jul 24, 2023

Tested with a custom go lambda function which makes a call to http://127.0.0.1:8200/ and logs the body. The function was configured to use AWS secrets manager (ref) instead of the secret token directly.

Used go lambda function
package main

import (
	"context"
	"fmt"
	"io"
	"net/http"
	"strconv"
	"strings"

	"github.com/aws/aws-lambda-go/events"
	"github.com/aws/aws-lambda-go/lambda"

	_ "go.elastic.co/apm/module/apmlambda/v2"
)

var coldstart = true

func Handle(ctx context.Context, req events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
	var body strings.Builder
	resp, err := http.Get("http://127.0.0.1:8200/")
	if err != nil {
		body.WriteString(fmt.Sprintf("error in info request: %+v", err))
	} else {
		sb, _ := io.ReadAll(resp.Body)
		body.WriteString("body: ")
		body.Write(sb)
		body.WriteString(", ")
		body.WriteString("status_code: ")
		body.WriteString(strconv.Itoa(resp.StatusCode))
		body.WriteString(", ")
		body.WriteString("status: ")
		body.WriteString(resp.Status)
	}
	defer resp.Body.Close()
	response := events.APIGatewayProxyResponse{
		StatusCode: 200,
		Body:       body.String(),
		Headers: map[string]string{
			"coldstart": strconv.FormatBool(coldstart),
		},
	}
	coldstart = false
	return response, nil
}

func main() {
	lambda.Start(Handle)
}
Observed response without this PR
body: , status_code: 200, status: 200 OK
Observed response with this PR
body: {"build_date":"2023-02-13T13:01:54Z","build_sha":"8638b035d700e5e85e376252402b5375e4d4190b","publish_ready":true,"version":"8.6.2"}
, status_code: 200, status: 200 OK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws-λ-extension AWS Lambda Extension
Projects
None yet
Development

Successfully merging this pull request may close these issues.

APM Server health check requests fail when using AWS secret manager
2 participants