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

Set a default User-Agent if unset #1115

Merged
merged 1 commit into from
Jan 21, 2021
Merged

Conversation

jonjohnsonjr
Copy link
Contributor

@jonjohnsonjr jonjohnsonjr commented Jan 12, 2021

Currently, the User-Agent defaults to a golang default of either:

Go-http-client/1.1
Go-http-client/2.0

This makes it rather difficult to distinguish this client from any other
random golang program in registry logs.

Instead, set the default User-Agent to "containers/$VERSION (github.com/containers/image)".

Context: containers/skopeo#1109

Signed-off-by: Jon Johnson [email protected]

Copy link
Collaborator

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

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

Thanks! This captures the most important part of containers/skopeo#1109 .

LGTM, hoping for a second pair of eyes to review for possible risks we might have missed.

@mtrmac
Copy link
Collaborator

mtrmac commented Jan 13, 2021

I didn't see an obvious place to add tests for this. I'm personally happy not to write any tests for a small change like this, but I'm also more than willing to if you can point me in the right direction 😄

Yeah. I wouldn’t mind a test for newDockerClient, even if it tests only the small aspect of setting the userAgent field based on input; the c/image/docker package has few unit tests and we have to start somewhere.

OTOH the cost/benefit ratio of writing tests for this really is pretty bad — if this will ever be broken, it will probably not be individually broken, but just moved or bypassed in a way that a unit test would not detect. It would make more sense to incorporate a test into something a bit more end-to-end, at least like #254, but that has proven to be a nightmare to maintain and is probably not going to happen in this repo.

@jonjohnsonjr
Copy link
Contributor Author

I've added the simplest test I can imagine (that actually involves sending an http request).

@rhatdan
Copy link
Member

rhatdan commented Jan 20, 2021

LGTM
@mtrmac @vrothberg PTAL

@@ -277,9 +279,15 @@ func newDockerClient(sys *types.SystemContext, registry, reference string) (*doc
}
tlsClientConfig.InsecureSkipVerify = skipVerify

userAgent := "containers-image/" + version.Version
Copy link
Member

Choose a reason for hiding this comment

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

Any chance we can do something like "github.com/containers/image"? Not sure that's allowed but the source would be more explicit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any chance we can do something like "github.com/containers/image"? Not sure that's allowed but the source would be more explicit.

I believe "something like", yes, but not exactly:

       User-Agent     = "User-Agent" ":" 1*( product | comment )

       product         = token ["/" product-version]

       product-version = token

       token          = 1*<any CHAR except CTLs or tspecials>

       tspecials      = "(" | ")" | "<" | ">" | "@"
                      | "," | ";" | ":" | "\" | <">
                      | "/" | "[" | "]" | "?" | "="
                      | "{" | "}" | SP | HT

       comment        = "(" *( ctext | comment ) ")"

       ctext          = <any TEXT excluding "(" and ")">

       TEXT           = <any OCTET except CTLs,
                        but including LWS>

From https://tools.ietf.org/html/rfc1945#section-2.2 and https://tools.ietf.org/html/rfc1945#section-3.7 and https://tools.ietf.org/html/rfc1945#section-10.15

token forbids /, but we could add it to the comment, which can include anything other than (, ), control characters, and newlines.

How about this?

User-Agent: containers/$VERSION (github.com/containers/image)

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for looking into it. I really like it :)

@rhatdan @mtrmac PTAL

@jonjohnsonjr
Copy link
Contributor Author

Updated the PR description and pushed the suggestion of containers/$VERSION (github.com/containers/image).

Let me know if you'd prefer I squash the commits so that the commit message makes more sense.

Currently, the User-Agent defaults to a golang default of either:

Go-http-client/1.1
Go-http-client/2.0

This makes it rather difficult to distinguish this client from any other
random golang program in registry logs.

Instead, set the default User-Agent to:

containers/$VERSION (github.com/containers/image)

Signed-off-by: Jon Johnson <[email protected]>
@rhatdan
Copy link
Member

rhatdan commented Jan 21, 2021

LGTM

@rhatdan rhatdan merged commit 9fba9a7 into containers:master Jan 21, 2021
@jonjohnsonjr jonjohnsonjr deleted the user-agent branch January 22, 2021 00:01
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.

4 participants