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

Support new -invalidcert flag #278

Merged
merged 5 commits into from
Apr 10, 2019
Merged

Support new -invalidcert flag #278

merged 5 commits into from
Apr 10, 2019

Conversation

mattwomple
Copy link
Member

Run amppackager in production mode with known invalid SSL certificates.
Useful to emulate an otherwise fully production environment without
having to pay the sole provider of SSL certificates with
CanSignHttpExchanges extension.

Run amppackager in production mode with known invalid SSL certificates.
Useful to emulate an otherwise fully production environment without
having to pay the sole provider of SSL certificates with
CanSignHttpExchanges extension.
@mattwomple
Copy link
Member Author

@Gregable I'm not normally in the camp of we need more flags!, but this feature would have been very useful to me while I was initially testing amppackager. Not a problem if you would rather implement this differently; I just hope it can inspire thoughts about making first-time use of amppackager easier.

@twifkak
Copy link
Member

twifkak commented Apr 10, 2019

Thanks! I'm generally in the same camp as you, but I'm okay with flags for things that signal this isn't a production instance. (It's easier to accidentally leave something in a config file than to accidentally paste it into your init script.)

FYI there's a similar FR at #188. That one addresses a different stage: I've got a production SXG cert from a CA, but I want to test it before intercepting production requests. I think your PR can coexist with that one—they probably should be separate flags—but I wanted to point it out in case you had ideas.

Use form !(A || B) rather than !A && !B for invalidcert and development
flags.
Copy link
Member

@twifkak twifkak left a comment

Choose a reason for hiding this comment

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

Sorry for not catching this the first time.

@@ -91,7 +91,7 @@ func main() {
if certs == nil || len(certs) == 0 {
die(fmt.Sprintf("no cert found in %s", config.CertFile))
}
if (!*flagDevelopment && !*flagInvalidCert) && !util.CanSignHttpExchanges(certs[0]) {
if !(*flagDevelopment || *flagInvalidCert) && !util.CanSignHttpExchanges(certs[0]) {
Copy link
Member

Choose a reason for hiding this comment

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

Oops, actually it reads even better if you De Morgan again:
!(*flagDevelopment || *flagInvalidCert || util.CanSignHttpExchanges(certs[0]))

But that's outside the scope of your change, so feel free to ignore.

Copy link
Member Author

Choose a reason for hiding this comment

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

Resolved in commit 79453d9

@@ -127,7 +127,7 @@ func main() {
}

packager, err := signer.New(certs[0], key, config.URLSet, rtvCache, certCache.IsHealthy,
overrideBaseURL, /*requireHeaders=*/!*flagDevelopment && !*flagInvalidCert)
overrideBaseURL, /*requireHeaders=*/!(*flagDevelopment || *flagInvalidCert))
Copy link
Member

Choose a reason for hiding this comment

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

Actually, on further consideration, are you sure flagInvalidCert belongs here? requireHeaders seems unrelated to the invalid cert:

if this.requireHeaders {
header_value := GetJoined(req.Header, "AMP-Cache-Transform")
var act string
act, transformVersion = amp_cache_transform.ShouldSendSXG(header_value)
if act == "" {
log.Println("Not packaging because AMP-Cache-Transform request header is invalid:", header_value)
proxy(resp, fetchResp, nil)
return
}
resp.Header().Set("AMP-Cache-Transform", act)
} else {

For testing one can use curl, amppkg_dl_sxg, or something like ModHeader or Requestly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for looking at this closer. You're correct. The -invalidcert flag is meant to be "otherwise production", so yes, we should expect a valid AMP-Cache-Transform header.

Copy link
Member Author

Choose a reason for hiding this comment

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

I verified commit 97f8a38 works as intended when sending values nothing and any for header AMP-Cache-Transform.

Use form !(A || B) rather than !A && !B
Restore the requirement that the AMP-Cache-Transform header should be
present and valid when determining whether to respond with an SXG.
Copy link
Member

@twifkak twifkak left a comment

Choose a reason for hiding this comment

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

Thanks! Merging. (Once Travis is happy.)

@twifkak twifkak merged commit e73a104 into ampproject:master Apr 10, 2019
@mattwomple mattwomple deleted the patch-1 branch April 10, 2019 22:06
@twifkak
Copy link
Member

twifkak commented Apr 10, 2019

Done. Note this is master while the default branch is releases, so go get won't pick this up until we do a release. Can git clone -b in the meantime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants