@@ -34,10 +34,29 @@ own and can obtain certificates for.
34
34
1 . Install Go version 1.10 or higher. Optionally, set
35
35
[ $GOPATH] ( https://github.com/golang/go/wiki/GOPATH ) to something (default
36
36
is ` ~/go ` ) and/or add ` $GOPATH/bin ` to ` $PATH ` .
37
- 2 . ` go get -u -mod=vendor github.com/ampproject/amppackager/cmd/amppkg `
38
-
39
- Optionally, move the built ` ~/go/bin/amppkg ` wherever you like.
40
- 3 . Create a file ` amppkg.toml ` . A minimal config looks like this:
37
+ 1 . Get amppackager.
38
+
39
+ Check your Go version by running ` go version ` .
40
+
41
+ For Go 1.14 and higher versions run:
42
+
43
+ ```
44
+ go get -u github.com/ampproject/amppackager/cmd/amppkg
45
+ ```
46
+
47
+ For Go 1.13 and earlier versions run:
48
+
49
+ ```
50
+ go get -u -mod=vendor github.com/ampproject/amppackager/cmd/amppkg
51
+ ```
52
+
53
+ 1 . Optionally, move the built ` ~/go/bin/amppkg ` wherever you like.
54
+ 1 . Prepare a temporary certificate and private key pair to use for signing the
55
+ exchange when testing your config. Follow WICG
56
+ [ instructions] ( https://github.com/WICG/webpackage/tree/master/go/signedexchange#creating-our-first-signed-exchange )
57
+ to ensure compliance with the [ WICG certificate
58
+ requirements] ( https://wicg.github.io/webpackage/draft-yasskin-httpbis-origin-signed-exchanges-impl.html#cross-origin-cert-req ) .
59
+ 1 . Create a file ` amppkg.toml ` . A minimal config looks like this:
41
60
```
42
61
LocalOnly = true
43
62
CertFile = 'path/to/fullchain.pem'
@@ -49,7 +68,7 @@ own and can obtain certificates for.
49
68
Domain = "amppackageexample.com"
50
69
```
51
70
More details can be found in [amppkg.example.toml](amppkg.example.toml).
52
- 4 . `amppkg -development`
71
+ 1 . `amppkg -development`
53
72
54
73
If `amppkg.toml` is not in the current working directory, pass
55
74
`-config=/path/to/amppkg.toml`.
@@ -61,12 +80,17 @@ container.
61
80
62
81
#### Test your config
63
82
64
- 1. Run Chrome with the following commandline flags:
83
+ 1. Run Chrome with the following command line flags:
65
84
```
66
- --user-data-dir=/tmp/udd
67
- --ignore-certificate-errors-spki-list=$(openssl x509 -pubkey -noout -in path/to/fullchain.pem | openssl pkey -pubin -outform der | openssl dgst -sha256 -binary | base64)
68
- --enable-features=SignedHTTPExchange
69
- 'data:text/html,<a href="https://localhost:8080/priv/doc/https://amppackageexample.com/">click me'
85
+ alias chrome = [FULL PATH TO CHROME BINARY]
86
+ PATH_TO_FULLCHAIN_PEM = [FULL PATH TO fullchain.pem]
87
+ chrome --user-data-dir=/tmp/udd\
88
+ --ignore-certificate-errors-spki-list=$(\
89
+ openssl x509 -pubkey -noout -in $PATH_TO_FULLCHAIN_PEM |\
90
+ openssl pkey -pubin -outform der |\
91
+ openssl dgst -sha256 -binary | base64)\
92
+ --enable-features=SignedHTTPExchange\
93
+ 'data:text/html,<a href="https://localhost:8080/priv/doc/https://amppackageexample.com/">click me'
70
94
```
71
95
2. Open DevTools. Check 'Preserve log'.
72
96
3. Click the `click me` link.
@@ -148,13 +172,15 @@ You may also want to:
148
172
before publication, or with a regular audit of a sample of documents. The
149
173
[transforms](transformer/) are designed to work on valid AMP pages, and
150
174
may break invalid AMP in small ways.
175
+ 4. Setup
176
+ [monitoring](#monitoring-amppackager-in-production-via-its-prometheus-endpoints)
177
+ of `amppackager` and related requests to AMP document server.
151
178
152
179
Once you've done the above, you should be able to test by launching Chrome
153
- without any comamndline flags; just make sure
154
- chrome://flags/#enable-signed-http-exchange is enabled. To test by visiting the
155
- packager URL directly, first add a Chrome extension to send an
156
- `AMP-Cache-Transform: any` request header. Otherwise, follow the above
157
- "Demonstrate privacy-preserving prefetch" instructions.
180
+ without any command line flags. To test by visiting the packager URL directly,
181
+ first add a Chrome extension to send an `AMP-Cache-Transform: any` request
182
+ header. Otherwise, follow the above "Demonstrate privacy-preserving prefetch"
183
+ instructions.
158
184
159
185
##### Security Considerations
160
186
@@ -175,8 +201,9 @@ that:
175
201
176
202
It is possible to test an otherwise fully production configuration without
177
203
obtaining a certificate with the `CanSignHttpExchanges` extension. `amppkg`
178
- still needs to perform OCSP verification, so the Issuer CA must be valid (i.e. no
179
- self-signed certificates). e.g. You can use a certificate from [Let's Encrypt](https://letsencrypt.org/).
204
+ still needs to perform OCSP verification, so the Issuer CA must be valid (i.e.
205
+ no self-signed certificates). e.g. You can use a certificate from [Let's
206
+ Encrypt](https://letsencrypt.org/).
180
207
181
208
Running `amppkg` with the `-invalidcert` flag will skip the check for
182
209
`CanSignHttpExchanges`. This flag is not necessary when using the
@@ -204,8 +231,9 @@ eligible for use in the AMP viewer in other browsers.
204
231
205
232
### Limitations
206
233
207
- Currently, the packager will refuse to sign any AMP documents larger than 4 MB.
208
- Patches that allow for streamed signing are welcome.
234
+ Currently, the packager will refuse to sign any AMP documents that hit the size
235
+ limit of 4MB. You can [monitor](monitoring.md#available-metrics) the size of
236
+ your documents that have been signed, to see how close you are to the limit.
209
237
210
238
The packager refuses to sign any URL that results in a redirect. This is by
211
239
design, as neither the original URL nor the final URL makes sense as the signed
@@ -225,6 +253,65 @@ amp-install-serviceworker will still succeed in the unsigned AMP viewer case,
225
253
and crawlers may reuse the contents of the signed exchange when displaying an
226
254
AMP viewer to browser versions that don't support SXG.
227
255
256
+ #### `<amp-script>`
257
+
258
+ If you have any inline `<amp-script>`s (those with a `script` attribute), then
259
+ the expiration of the SXG will be set based on the minimum `max-age` of those
260
+ `<amp-script>`s, minus one day (due to
261
+ [backdating](https://github.com/ampproject/amppackager/issues/397)). If
262
+ possible, prefer external `<amp-script>`s (those with a `src` attribute), which
263
+ do not have this limitation.
264
+
265
+ If inline is necessary, you will need to weigh the [security
266
+ risks](https://wicg.github.io/webpackage/draft-yasskin-http-origin-signed-responses.html#seccons-downgrades)
267
+ against the [AMP Cache requirement](docs/cache_requirements.md) for a minimum
268
+ `max-age` of `345600` (4 days). For SXGs shorter than that, the Google AMP Cache
269
+ will treat them as if unsigned (by showing an AMP Viewer).
270
+
271
+ #### How does `amppackager` process a document it cannot sign?
272
+
273
+ Packager will respond to every request with either a signed document, an
274
+ unsigned document, or an error.
275
+
276
+ It will sign every document it can. It may, however, decide not to,
277
+ for a number of reasons: the certificate may be invalid, the page may not be a
278
+ valid AMP page, the page may not be an AMP page at all, the page may be 4MB or
279
+ larger, etc.
280
+
281
+ If packager cannot sign the document but can fetch it, it will proxy the
282
+ document unsigned.
283
+
284
+ If there was a problem with the gateway fetch request, or with the original
285
+ request, packager will respond with an HTTP error, and log the problem to
286
+ stdout.
287
+
288
+ You can monitor the packager's error rates, as well as the rates of signed
289
+ vs unsigned documents, via the tools discussed in the next section.
290
+
291
+ Specifically, you can monitor the requests that resulted in a signed or an
292
+ unsigned document via `documents_signed_vs_unsigned` metric, and the ones that
293
+ resulted in an error - via `total_requests_by_code_and_url` metric.
294
+
295
+ #### Monitoring `amppackager` in production via its Prometheus endpoints
296
+
297
+ Once you've run the `amppackager` server in production, you may want to
298
+ [monitor](monitoring.md) its health and performance. You may also monitor the
299
+ performance of the underlying requests to the AMP document server. You can
300
+ monitor both servers via the [Prometheus](https://prometheus.io/) endpoints
301
+ provided by `amppackager`. A few examples of questions you can answer:
302
+
303
+ * Is `amppackager` up and running?
304
+ * How many requests has it processed since it's been up?
305
+ * What was the 0.9 percentile latency of handling those request?
306
+ * How many of those requests have triggered a gateway request to the
307
+ AMP document server?
308
+ * For those gateway requests, what was the 0.9 percentile latency of
309
+ the AMP document server?
310
+
311
+ You can perform one-off manual health inspections, visualize the real-time
312
+ stats, set up alerts, and more. To learn what are all the things you can
313
+ monitor, and how to do it, check the [monitoring manual](monitoring.md).
314
+
228
315
## Local Transformer
229
316
230
317
The local transformer is a library within the AMP Packager that transforms AMP
0 commit comments