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

[VC-36032] Set User-Agent header containing the agent version in all HTTP requests #631

Merged
merged 3 commits into from
Nov 29, 2024

Conversation

wallrj
Copy link
Member

@wallrj wallrj commented Nov 29, 2024

In VC-36032 we aim to provide:

Enhanced troubleshooting through improved logging

By adding user-agent headers to all HTTP requests, it will allow the Venafi platform team to know which version of the agent is making requests to the resource and auth APIs, by analysing the request headers among the server logs.

I tried writing tests for this, but the it would have required some significant refactoring of the client code,
for example there's no easy way to intercept the Auth0 client request made by the Jetstack-Secure client in client_oauth.go.
That's a bit of a lame excuse, but I would like to propose that we refactor the Venafi client code in a followup PR and at the same time add tests which verify that all the flavours of Venafi client do include user agent headers.

… with private key authentication

Signed-off-by: Richard Wall <[email protected]>
This will make it easier to diagnose problems by allowing platform teams to
parse HTTP server logs or intermediate HTTP proxy logs and know which version of
the agent has made the request.

Signed-off-by: Richard Wall <[email protected]>
Signed-off-by: Richard Wall <[email protected]>
@@ -265,13 +266,14 @@ func (c *VenafiCloudClient) Post(ctx context.Context, path string, body io.Reade
return nil, err
}

req, err := http.NewRequest(http.MethodPost, fullURL(c.baseURL, path), body)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, fullURL(c.baseURL, path), body)
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 is a drive-by fix. I missed this in #627

@@ -178,7 +178,7 @@ func Test_ValidateAndCombineConfig(t *testing.T) {

// The log line printed by pflag is not captured by the log recorder.
assert.Equal(t, testutil.Undent(`
INFO Using the Jetstack Secure OAuth auth mode since --credentials-file was specified without --venafi-cloud.
INFO Authentication mode mode="Jetstack Secure OAuth" reason="--credentials-file was specified without --venafi-cloud"
Copy link
Member Author

Choose a reason for hiding this comment

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

Another drive-by fix. This test was introduced in #628 but #625 which altered the logging format (and which was merged afterwards) had not been rebased and did not alter the expected log output in this test.

Copy link
Member Author

@wallrj wallrj Nov 29, 2024

Choose a reason for hiding this comment

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

The tests are not being run on the master branch and the green badge on the README file does not reflect the status of the current branch:

Opened an issue about that: #632

@wallrj wallrj changed the title WIP: [VC-36032] Set User-Agent header containing the agent version in all HTTP requests [VC-36032] Set User-Agent header containing the agent version in all HTTP requests Nov 29, 2024
@wallrj wallrj requested a review from maelvls November 29, 2024 15:50
Copy link
Member

@maelvls maelvls 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 fixing this, I wish we had done it sooner. I've realized the importance of the user agent header when responding to last weeks venctl/agent outage.

I haven't tested the PR, but I'm very confident that nothing will break. Nothing in the PR could break anything, I'd say.

@wallrj wallrj merged commit 2d13638 into master Nov 29, 2024
2 checks passed
@wallrj wallrj deleted the VC-36032/http-client-user-agent-header branch November 29, 2024 16:00
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