Merge branch '16809-s3-v4-signature'
[arvados.git] / services / keep-web / s3.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package main
6
7 import (
8         "crypto/hmac"
9         "crypto/sha256"
10         "encoding/xml"
11         "errors"
12         "fmt"
13         "hash"
14         "io"
15         "net/http"
16         "net/url"
17         "os"
18         "path/filepath"
19         "sort"
20         "strconv"
21         "strings"
22         "time"
23
24         "git.arvados.org/arvados.git/sdk/go/arvados"
25         "git.arvados.org/arvados.git/sdk/go/ctxlog"
26         "github.com/AdRoll/goamz/s3"
27 )
28
29 const (
30         s3MaxKeys       = 1000
31         s3SignAlgorithm = "AWS4-HMAC-SHA256"
32         s3MaxClockSkew  = 5 * time.Minute
33 )
34
35 func hmacstring(msg string, key []byte) []byte {
36         h := hmac.New(sha256.New, key)
37         io.WriteString(h, msg)
38         return h.Sum(nil)
39 }
40
41 func hashdigest(h hash.Hash, payload string) string {
42         io.WriteString(h, payload)
43         return fmt.Sprintf("%x", h.Sum(nil))
44 }
45
46 // Signing key for given secret key and request attrs.
47 func s3signatureKey(key, datestamp, regionName, serviceName string) []byte {
48         return hmacstring("aws4_request",
49                 hmacstring(serviceName,
50                         hmacstring(regionName,
51                                 hmacstring(datestamp, []byte("AWS4"+key)))))
52 }
53
54 // Canonical query string for S3 V4 signature: sorted keys, spaces
55 // escaped as %20 instead of +, keyvalues joined with &.
56 func s3querystring(u *url.URL) string {
57         keys := make([]string, 0, len(u.Query()))
58         values := make(map[string]string, len(u.Query()))
59         for k, vs := range u.Query() {
60                 k = strings.Replace(url.QueryEscape(k), "+", "%20", -1)
61                 keys = append(keys, k)
62                 for _, v := range vs {
63                         v = strings.Replace(url.QueryEscape(v), "+", "%20", -1)
64                         if values[k] != "" {
65                                 values[k] += "&"
66                         }
67                         values[k] += k + "=" + v
68                 }
69         }
70         sort.Strings(keys)
71         for i, k := range keys {
72                 keys[i] = values[k]
73         }
74         return strings.Join(keys, "&")
75 }
76
77 func s3stringToSign(alg, scope, signedHeaders string, r *http.Request) (string, error) {
78         timefmt, timestr := "20060102T150405Z", r.Header.Get("X-Amz-Date")
79         if timestr == "" {
80                 timefmt, timestr = time.RFC1123, r.Header.Get("Date")
81         }
82         t, err := time.Parse(timefmt, timestr)
83         if err != nil {
84                 return "", fmt.Errorf("invalid timestamp %q: %s", timestr, err)
85         }
86         if skew := time.Now().Sub(t); skew < -s3MaxClockSkew || skew > s3MaxClockSkew {
87                 return "", errors.New("exceeded max clock skew")
88         }
89
90         var canonicalHeaders string
91         for _, h := range strings.Split(signedHeaders, ";") {
92                 if h == "host" {
93                         canonicalHeaders += h + ":" + r.Host + "\n"
94                 } else {
95                         canonicalHeaders += h + ":" + r.Header.Get(h) + "\n"
96                 }
97         }
98
99         canonicalRequest := fmt.Sprintf("%s\n%s\n%s\n%s\n%s\n%s", r.Method, r.URL.EscapedPath(), s3querystring(r.URL), canonicalHeaders, signedHeaders, r.Header.Get("X-Amz-Content-Sha256"))
100         ctxlog.FromContext(r.Context()).Debugf("s3stringToSign: canonicalRequest %s", canonicalRequest)
101         return fmt.Sprintf("%s\n%s\n%s\n%s", alg, r.Header.Get("X-Amz-Date"), scope, hashdigest(sha256.New(), canonicalRequest)), nil
102 }
103
104 func s3signature(secretKey, scope, signedHeaders, stringToSign string) (string, error) {
105         // scope is {datestamp}/{region}/{service}/aws4_request
106         drs := strings.Split(scope, "/")
107         if len(drs) != 4 {
108                 return "", fmt.Errorf("invalid scope %q", scope)
109         }
110         key := s3signatureKey(secretKey, drs[0], drs[1], drs[2])
111         return hashdigest(hmac.New(sha256.New, key), stringToSign), nil
112 }
113
114 // checks3signature verifies the given S3 V4 signature and returns the
115 // Arvados token that corresponds to the given accessKey. An error is
116 // returned if accessKey is not a valid token UUID or the signature
117 // does not match.
118 func (h *handler) checks3signature(r *http.Request) (string, error) {
119         var key, scope, signedHeaders, signature string
120         authstring := strings.TrimPrefix(r.Header.Get("Authorization"), s3SignAlgorithm+" ")
121         for _, cmpt := range strings.Split(authstring, ",") {
122                 cmpt = strings.TrimSpace(cmpt)
123                 split := strings.SplitN(cmpt, "=", 2)
124                 switch {
125                 case len(split) != 2:
126                         // (?) ignore
127                 case split[0] == "Credential":
128                         keyandscope := strings.SplitN(split[1], "/", 2)
129                         if len(keyandscope) == 2 {
130                                 key, scope = keyandscope[0], keyandscope[1]
131                         }
132                 case split[0] == "SignedHeaders":
133                         signedHeaders = split[1]
134                 case split[0] == "Signature":
135                         signature = split[1]
136                 }
137         }
138
139         client := (&arvados.Client{
140                 APIHost:  h.Config.cluster.Services.Controller.ExternalURL.Host,
141                 Insecure: h.Config.cluster.TLS.Insecure,
142         }).WithRequestID(r.Header.Get("X-Request-Id"))
143         var aca arvados.APIClientAuthorization
144         var secret string
145         var err error
146         if len(key) == 27 && key[5:12] == "-gj3su-" {
147                 // Access key is the UUID of an Arvados token, secret
148                 // key is the secret part.
149                 ctx := arvados.ContextWithAuthorization(r.Context(), "Bearer "+h.Config.cluster.SystemRootToken)
150                 err = client.RequestAndDecodeContext(ctx, &aca, "GET", "arvados/v1/api_client_authorizations/"+key, nil, nil)
151                 secret = aca.APIToken
152         } else {
153                 // Access key and secret key are both an entire
154                 // Arvados token or OIDC access token.
155                 ctx := arvados.ContextWithAuthorization(r.Context(), "Bearer "+key)
156                 err = client.RequestAndDecodeContext(ctx, &aca, "GET", "arvados/v1/api_client_authorizations/current", nil, nil)
157                 secret = key
158         }
159         if err != nil {
160                 ctxlog.FromContext(r.Context()).WithError(err).WithField("UUID", key).Info("token lookup failed")
161                 return "", errors.New("invalid access key")
162         }
163         stringToSign, err := s3stringToSign(s3SignAlgorithm, scope, signedHeaders, r)
164         if err != nil {
165                 return "", err
166         }
167         expect, err := s3signature(secret, scope, signedHeaders, stringToSign)
168         if err != nil {
169                 return "", err
170         } else if expect != signature {
171                 return "", fmt.Errorf("signature does not match (scope %q signedHeaders %q stringToSign %q)", scope, signedHeaders, stringToSign)
172         }
173         return secret, nil
174 }
175
176 // serveS3 handles r and returns true if r is a request from an S3
177 // client, otherwise it returns false.
178 func (h *handler) serveS3(w http.ResponseWriter, r *http.Request) bool {
179         var token string
180         if auth := r.Header.Get("Authorization"); strings.HasPrefix(auth, "AWS ") {
181                 split := strings.SplitN(auth[4:], ":", 2)
182                 if len(split) < 2 {
183                         http.Error(w, "malformed Authorization header", http.StatusUnauthorized)
184                         return true
185                 }
186                 token = split[0]
187         } else if strings.HasPrefix(auth, s3SignAlgorithm+" ") {
188                 t, err := h.checks3signature(r)
189                 if err != nil {
190                         http.Error(w, "signature verification failed: "+err.Error(), http.StatusForbidden)
191                         return true
192                 }
193                 token = t
194         } else {
195                 return false
196         }
197
198         _, kc, client, release, err := h.getClients(r.Header.Get("X-Request-Id"), token)
199         if err != nil {
200                 http.Error(w, "Pool failed: "+h.clientPool.Err().Error(), http.StatusInternalServerError)
201                 return true
202         }
203         defer release()
204
205         fs := client.SiteFileSystem(kc)
206         fs.ForwardSlashNameSubstitution(h.Config.cluster.Collections.ForwardSlashNameSubstitution)
207
208         objectNameGiven := strings.Count(strings.TrimSuffix(r.URL.Path, "/"), "/") > 1
209
210         switch {
211         case r.Method == http.MethodGet && !objectNameGiven:
212                 // Path is "/{uuid}" or "/{uuid}/", has no object name
213                 if _, ok := r.URL.Query()["versioning"]; ok {
214                         // GetBucketVersioning
215                         w.Header().Set("Content-Type", "application/xml")
216                         io.WriteString(w, xml.Header)
217                         fmt.Fprintln(w, `<VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"/>`)
218                 } else {
219                         // ListObjects
220                         h.s3list(w, r, fs)
221                 }
222                 return true
223         case r.Method == http.MethodGet || r.Method == http.MethodHead:
224                 fspath := "/by_id" + r.URL.Path
225                 fi, err := fs.Stat(fspath)
226                 if r.Method == "HEAD" && !objectNameGiven {
227                         // HeadBucket
228                         if err == nil && fi.IsDir() {
229                                 w.WriteHeader(http.StatusOK)
230                         } else if os.IsNotExist(err) {
231                                 w.WriteHeader(http.StatusNotFound)
232                         } else {
233                                 http.Error(w, err.Error(), http.StatusBadGateway)
234                         }
235                         return true
236                 }
237                 if err == nil && fi.IsDir() && objectNameGiven && strings.HasSuffix(fspath, "/") && h.Config.cluster.Collections.S3FolderObjects {
238                         w.Header().Set("Content-Type", "application/x-directory")
239                         w.WriteHeader(http.StatusOK)
240                         return true
241                 }
242                 if os.IsNotExist(err) ||
243                         (err != nil && err.Error() == "not a directory") ||
244                         (fi != nil && fi.IsDir()) {
245                         http.Error(w, "not found", http.StatusNotFound)
246                         return true
247                 }
248                 // shallow copy r, and change URL path
249                 r := *r
250                 r.URL.Path = fspath
251                 http.FileServer(fs).ServeHTTP(w, &r)
252                 return true
253         case r.Method == http.MethodPut:
254                 if !objectNameGiven {
255                         http.Error(w, "missing object name in PUT request", http.StatusBadRequest)
256                         return true
257                 }
258                 fspath := "by_id" + r.URL.Path
259                 var objectIsDir bool
260                 if strings.HasSuffix(fspath, "/") {
261                         if !h.Config.cluster.Collections.S3FolderObjects {
262                                 http.Error(w, "invalid object name: trailing slash", http.StatusBadRequest)
263                                 return true
264                         }
265                         n, err := r.Body.Read(make([]byte, 1))
266                         if err != nil && err != io.EOF {
267                                 http.Error(w, fmt.Sprintf("error reading request body: %s", err), http.StatusInternalServerError)
268                                 return true
269                         } else if n > 0 {
270                                 http.Error(w, "cannot create object with trailing '/' char unless content is empty", http.StatusBadRequest)
271                                 return true
272                         } else if strings.SplitN(r.Header.Get("Content-Type"), ";", 2)[0] != "application/x-directory" {
273                                 http.Error(w, "cannot create object with trailing '/' char unless Content-Type is 'application/x-directory'", http.StatusBadRequest)
274                                 return true
275                         }
276                         // Given PUT "foo/bar/", we'll use "foo/bar/."
277                         // in the "ensure parents exist" block below,
278                         // and then we'll be done.
279                         fspath += "."
280                         objectIsDir = true
281                 }
282                 fi, err := fs.Stat(fspath)
283                 if err != nil && err.Error() == "not a directory" {
284                         // requested foo/bar, but foo is a file
285                         http.Error(w, "object name conflicts with existing object", http.StatusBadRequest)
286                         return true
287                 }
288                 if strings.HasSuffix(r.URL.Path, "/") && err == nil && !fi.IsDir() {
289                         // requested foo/bar/, but foo/bar is a file
290                         http.Error(w, "object name conflicts with existing object", http.StatusBadRequest)
291                         return true
292                 }
293                 // create missing parent/intermediate directories, if any
294                 for i, c := range fspath {
295                         if i > 0 && c == '/' {
296                                 dir := fspath[:i]
297                                 if strings.HasSuffix(dir, "/") {
298                                         err = errors.New("invalid object name (consecutive '/' chars)")
299                                         http.Error(w, err.Error(), http.StatusBadRequest)
300                                         return true
301                                 }
302                                 err = fs.Mkdir(dir, 0755)
303                                 if err == arvados.ErrInvalidArgument {
304                                         // Cannot create a directory
305                                         // here.
306                                         err = fmt.Errorf("mkdir %q failed: %w", dir, err)
307                                         http.Error(w, err.Error(), http.StatusBadRequest)
308                                         return true
309                                 } else if err != nil && !os.IsExist(err) {
310                                         err = fmt.Errorf("mkdir %q failed: %w", dir, err)
311                                         http.Error(w, err.Error(), http.StatusInternalServerError)
312                                         return true
313                                 }
314                         }
315                 }
316                 if !objectIsDir {
317                         f, err := fs.OpenFile(fspath, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
318                         if os.IsNotExist(err) {
319                                 f, err = fs.OpenFile(fspath, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
320                         }
321                         if err != nil {
322                                 err = fmt.Errorf("open %q failed: %w", r.URL.Path, err)
323                                 http.Error(w, err.Error(), http.StatusBadRequest)
324                                 return true
325                         }
326                         defer f.Close()
327                         _, err = io.Copy(f, r.Body)
328                         if err != nil {
329                                 err = fmt.Errorf("write to %q failed: %w", r.URL.Path, err)
330                                 http.Error(w, err.Error(), http.StatusBadGateway)
331                                 return true
332                         }
333                         err = f.Close()
334                         if err != nil {
335                                 err = fmt.Errorf("write to %q failed: close: %w", r.URL.Path, err)
336                                 http.Error(w, err.Error(), http.StatusBadGateway)
337                                 return true
338                         }
339                 }
340                 err = fs.Sync()
341                 if err != nil {
342                         err = fmt.Errorf("sync failed: %w", err)
343                         http.Error(w, err.Error(), http.StatusInternalServerError)
344                         return true
345                 }
346                 w.WriteHeader(http.StatusOK)
347                 return true
348         case r.Method == http.MethodDelete:
349                 if !objectNameGiven || r.URL.Path == "/" {
350                         http.Error(w, "missing object name in DELETE request", http.StatusBadRequest)
351                         return true
352                 }
353                 fspath := "by_id" + r.URL.Path
354                 if strings.HasSuffix(fspath, "/") {
355                         fspath = strings.TrimSuffix(fspath, "/")
356                         fi, err := fs.Stat(fspath)
357                         if os.IsNotExist(err) {
358                                 w.WriteHeader(http.StatusNoContent)
359                                 return true
360                         } else if err != nil {
361                                 http.Error(w, err.Error(), http.StatusInternalServerError)
362                                 return true
363                         } else if !fi.IsDir() {
364                                 // if "foo" exists and is a file, then
365                                 // "foo/" doesn't exist, so we say
366                                 // delete was successful.
367                                 w.WriteHeader(http.StatusNoContent)
368                                 return true
369                         }
370                 } else if fi, err := fs.Stat(fspath); err == nil && fi.IsDir() {
371                         // if "foo" is a dir, it is visible via S3
372                         // only as "foo/", not "foo" -- so we leave
373                         // the dir alone and return 204 to indicate
374                         // that "foo" does not exist.
375                         w.WriteHeader(http.StatusNoContent)
376                         return true
377                 }
378                 err = fs.Remove(fspath)
379                 if os.IsNotExist(err) {
380                         w.WriteHeader(http.StatusNoContent)
381                         return true
382                 }
383                 if err != nil {
384                         err = fmt.Errorf("rm failed: %w", err)
385                         http.Error(w, err.Error(), http.StatusBadRequest)
386                         return true
387                 }
388                 err = fs.Sync()
389                 if err != nil {
390                         err = fmt.Errorf("sync failed: %w", err)
391                         http.Error(w, err.Error(), http.StatusInternalServerError)
392                         return true
393                 }
394                 w.WriteHeader(http.StatusNoContent)
395                 return true
396         default:
397                 http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
398                 return true
399         }
400 }
401
402 // Call fn on the given path (directory) and its contents, in
403 // lexicographic order.
404 //
405 // If isRoot==true and path is not a directory, return nil.
406 //
407 // If fn returns filepath.SkipDir when called on a directory, don't
408 // descend into that directory.
409 func walkFS(fs arvados.CustomFileSystem, path string, isRoot bool, fn func(path string, fi os.FileInfo) error) error {
410         if isRoot {
411                 fi, err := fs.Stat(path)
412                 if os.IsNotExist(err) || (err == nil && !fi.IsDir()) {
413                         return nil
414                 } else if err != nil {
415                         return err
416                 }
417                 err = fn(path, fi)
418                 if err == filepath.SkipDir {
419                         return nil
420                 } else if err != nil {
421                         return err
422                 }
423         }
424         f, err := fs.Open(path)
425         if os.IsNotExist(err) && isRoot {
426                 return nil
427         } else if err != nil {
428                 return fmt.Errorf("open %q: %w", path, err)
429         }
430         defer f.Close()
431         if path == "/" {
432                 path = ""
433         }
434         fis, err := f.Readdir(-1)
435         if err != nil {
436                 return err
437         }
438         sort.Slice(fis, func(i, j int) bool { return fis[i].Name() < fis[j].Name() })
439         for _, fi := range fis {
440                 err = fn(path+"/"+fi.Name(), fi)
441                 if err == filepath.SkipDir {
442                         continue
443                 } else if err != nil {
444                         return err
445                 }
446                 if fi.IsDir() {
447                         err = walkFS(fs, path+"/"+fi.Name(), false, fn)
448                         if err != nil {
449                                 return err
450                         }
451                 }
452         }
453         return nil
454 }
455
456 var errDone = errors.New("done")
457
458 func (h *handler) s3list(w http.ResponseWriter, r *http.Request, fs arvados.CustomFileSystem) {
459         var params struct {
460                 bucket    string
461                 delimiter string
462                 marker    string
463                 maxKeys   int
464                 prefix    string
465         }
466         params.bucket = strings.SplitN(r.URL.Path[1:], "/", 2)[0]
467         params.delimiter = r.FormValue("delimiter")
468         params.marker = r.FormValue("marker")
469         if mk, _ := strconv.ParseInt(r.FormValue("max-keys"), 10, 64); mk > 0 && mk < s3MaxKeys {
470                 params.maxKeys = int(mk)
471         } else {
472                 params.maxKeys = s3MaxKeys
473         }
474         params.prefix = r.FormValue("prefix")
475
476         bucketdir := "by_id/" + params.bucket
477         // walkpath is the directory (relative to bucketdir) we need
478         // to walk: the innermost directory that is guaranteed to
479         // contain all paths that have the requested prefix. Examples:
480         // prefix "foo/bar"  => walkpath "foo"
481         // prefix "foo/bar/" => walkpath "foo/bar"
482         // prefix "foo"      => walkpath ""
483         // prefix ""         => walkpath ""
484         walkpath := params.prefix
485         if cut := strings.LastIndex(walkpath, "/"); cut >= 0 {
486                 walkpath = walkpath[:cut]
487         } else {
488                 walkpath = ""
489         }
490
491         type commonPrefix struct {
492                 Prefix string
493         }
494         type listResp struct {
495                 XMLName string `xml:"http://s3.amazonaws.com/doc/2006-03-01/ ListBucketResult"`
496                 s3.ListResp
497                 // s3.ListResp marshals an empty tag when
498                 // CommonPrefixes is nil, which confuses some clients.
499                 // Fix by using this nested struct instead.
500                 CommonPrefixes []commonPrefix
501                 // Similarly, we need omitempty here, because an empty
502                 // tag confuses some clients (e.g.,
503                 // github.com/aws/aws-sdk-net never terminates its
504                 // paging loop).
505                 NextMarker string `xml:"NextMarker,omitempty"`
506                 // ListObjectsV2 has a KeyCount response field.
507                 KeyCount int
508         }
509         resp := listResp{
510                 ListResp: s3.ListResp{
511                         Name:      strings.SplitN(r.URL.Path[1:], "/", 2)[0],
512                         Prefix:    params.prefix,
513                         Delimiter: params.delimiter,
514                         Marker:    params.marker,
515                         MaxKeys:   params.maxKeys,
516                 },
517         }
518         commonPrefixes := map[string]bool{}
519         err := walkFS(fs, strings.TrimSuffix(bucketdir+"/"+walkpath, "/"), true, func(path string, fi os.FileInfo) error {
520                 if path == bucketdir {
521                         return nil
522                 }
523                 path = path[len(bucketdir)+1:]
524                 filesize := fi.Size()
525                 if fi.IsDir() {
526                         path += "/"
527                         filesize = 0
528                 }
529                 if len(path) <= len(params.prefix) {
530                         if path > params.prefix[:len(path)] {
531                                 // with prefix "foobar", walking "fooz" means we're done
532                                 return errDone
533                         }
534                         if path < params.prefix[:len(path)] {
535                                 // with prefix "foobar", walking "foobag" is pointless
536                                 return filepath.SkipDir
537                         }
538                         if fi.IsDir() && !strings.HasPrefix(params.prefix+"/", path) {
539                                 // with prefix "foo/bar", walking "fo"
540                                 // is pointless (but walking "foo" or
541                                 // "foo/bar" is necessary)
542                                 return filepath.SkipDir
543                         }
544                         if len(path) < len(params.prefix) {
545                                 // can't skip anything, and this entry
546                                 // isn't in the results, so just
547                                 // continue descent
548                                 return nil
549                         }
550                 } else {
551                         if path[:len(params.prefix)] > params.prefix {
552                                 // with prefix "foobar", nothing we
553                                 // see after "foozzz" is relevant
554                                 return errDone
555                         }
556                 }
557                 if path < params.marker || path < params.prefix {
558                         return nil
559                 }
560                 if fi.IsDir() && !h.Config.cluster.Collections.S3FolderObjects {
561                         // Note we don't add anything to
562                         // commonPrefixes here even if delimiter is
563                         // "/". We descend into the directory, and
564                         // return a commonPrefix only if we end up
565                         // finding a regular file inside it.
566                         return nil
567                 }
568                 if params.delimiter != "" {
569                         idx := strings.Index(path[len(params.prefix):], params.delimiter)
570                         if idx >= 0 {
571                                 // with prefix "foobar" and delimiter
572                                 // "z", when we hit "foobar/baz", we
573                                 // add "/baz" to commonPrefixes and
574                                 // stop descending.
575                                 commonPrefixes[path[:len(params.prefix)+idx+1]] = true
576                                 return filepath.SkipDir
577                         }
578                 }
579                 if len(resp.Contents)+len(commonPrefixes) >= params.maxKeys {
580                         resp.IsTruncated = true
581                         if params.delimiter != "" {
582                                 resp.NextMarker = path
583                         }
584                         return errDone
585                 }
586                 resp.Contents = append(resp.Contents, s3.Key{
587                         Key:          path,
588                         LastModified: fi.ModTime().UTC().Format("2006-01-02T15:04:05.999") + "Z",
589                         Size:         filesize,
590                 })
591                 return nil
592         })
593         if err != nil && err != errDone {
594                 http.Error(w, err.Error(), http.StatusInternalServerError)
595                 return
596         }
597         if params.delimiter != "" {
598                 resp.CommonPrefixes = make([]commonPrefix, 0, len(commonPrefixes))
599                 for prefix := range commonPrefixes {
600                         resp.CommonPrefixes = append(resp.CommonPrefixes, commonPrefix{prefix})
601                 }
602                 sort.Slice(resp.CommonPrefixes, func(i, j int) bool { return resp.CommonPrefixes[i].Prefix < resp.CommonPrefixes[j].Prefix })
603         }
604         resp.KeyCount = len(resp.Contents)
605         w.Header().Set("Content-Type", "application/xml")
606         io.WriteString(w, xml.Header)
607         if err := xml.NewEncoder(w).Encode(resp); err != nil {
608                 ctxlog.FromContext(r.Context()).WithError(err).Error("error writing xml response")
609         }
610 }