Skip to content

Commit 207848e

Browse files
committed
ARO-17482 resolve copilot comments
1 parent a532656 commit 207848e

File tree

5 files changed

+22
-12
lines changed

5 files changed

+22
-12
lines changed

admin/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This prefix is abbreviated as `{resourceId}` below.
1818
|--------|------|-------------|
1919
| `PUT` | `/admin/v1/hcp{resourceId}/breakglass?group=...&ttl=...` | Create a breakglass session ([details](breakglass.md)) |
2020
| `GET` | `/admin/v1/hcp{resourceId}/breakglass/{sessionName}/kubeconfig` | Get kubeconfig for a breakglass session ([details](breakglass.md)) |
21-
| `GET` | `/admin/v1/hcp{resourceId}/serialconsole?vmName=...` | Retrieve serial console logs for a VM ([details](serialconsole.md)) |
21+
| `GET` | `/admin/v1/hcp{resourceId}/serialconsole?vmName=...` | Retrieve serial console logs for a VM |
2222
| `GET` | `/admin/v1/hcp{resourceId}/cosmosdump` | Cosmos DB dump for a cluster |
2323
| `GET` | `/admin/v1/hcp{resourceId}/helloworld` | HCP hello world (dev/test) |
2424
| `GET` | `/admin/helloworld` | Hello world (dev/test) |

admin/server/go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ require (
5858
github.com/google/uuid v1.6.0 // indirect
5959
github.com/gorilla/css v1.0.1 // indirect
6060
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3 // indirect
61-
github.com/hashicorp/go-version v1.7.0 // indirect
6261
github.com/inconshreveable/mousetrap v1.1.0 // indirect
6362
github.com/jedib0t/go-pretty/v6 v6.6.7 // indirect
6463
github.com/josharian/intern v1.0.0 // indirect

admin/server/go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8=
106106
github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A3b0=
107107
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3 h1:NmZ1PKzSTQbuGHw9DGPFomqkkLWMC+vZCkfs+FHv1Vg=
108108
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3/go.mod h1:zQrxl1YP88HQlA6i9c63DSVPFklWpGX4OWAc9bFuaH4=
109-
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
110-
github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
111109
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
112110
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
113111
github.com/itchyny/gojq v0.12.7 h1:hYPTpeWfrJ1OT+2j6cvBScbhl0TkdwGM4bc66onUSOQ=

admin/server/handlers/hcp/serialconsole.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"fmt"
1919
"io"
2020
"net/http"
21+
"time"
2122

2223
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5"
2324

@@ -158,8 +159,10 @@ func (h *HCPSerialConsoleHandler) ServeHTTP(writer http.ResponseWriter, request
158159
return fmt.Errorf("failed to create blob request: %w", err)
159160
}
160161

161-
// download blob content
162-
httpClient := &http.Client{}
162+
// download blob content with timeout to avoid stuck handlers on slow blob endpoints
163+
httpClient := &http.Client{
164+
Timeout: 30 * time.Second,
165+
}
163166
blobResp, err := httpClient.Do(blobReq)
164167
if err != nil {
165168
return fmt.Errorf("failed to download serial console log: %w", err)
@@ -170,13 +173,19 @@ func (h *HCPSerialConsoleHandler) ServeHTTP(writer http.ResponseWriter, request
170173
return fmt.Errorf("failed to download serial console log: unexpected status %d", blobResp.StatusCode)
171174
}
172175

173-
// stream response as text/plain
176+
// stream response as text/plain and prevent caching of potentially sensitive console output
174177
writer.Header().Set("Content-Type", "text/plain; charset=utf-8")
178+
writer.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
179+
writer.Header().Set("Pragma", "no-cache")
180+
writer.Header().Set("Expires", "0")
175181
writer.WriteHeader(http.StatusOK)
176182
_, err = io.Copy(writer, blobResp.Body)
177183
if err != nil {
178-
// If we fail during streaming, log it
179-
return fmt.Errorf("failed to stream serial console log: %w", err)
184+
// After headers are sent, we cannot return an error response
185+
// Log the error and return nil to avoid panic
186+
logger := utils.LoggerFromContext(request.Context())
187+
logger.Error(err, "failed to stream serial console log", "vmName", vmName)
188+
return nil
180189
}
181190

182191
return nil

test/util/framework/admin_api_helpers.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,18 +409,22 @@ func (tc *perItOrDescribeTestContext) GetSerialConsoleLogs(ctx context.Context,
409409

410410
adminAPIEndpoint := tc.perBinaryInvocationTestContext.adminAPIAddress
411411

412-
serialConsoleEndpoint := fmt.Sprintf("%s/admin/v1/hcp%s/serialconsole?vmName=%s",
412+
serialConsoleEndpoint := fmt.Sprintf("%s/admin/v1/hcp%s/serialconsole",
413413
adminAPIEndpoint,
414414
resourceID,
415-
vmName,
416415
)
417416

418-
By(fmt.Sprintf("reaching out to the admin API to retrieve serial console logs for VM %s: %s", vmName, serialConsoleEndpoint))
417+
By(fmt.Sprintf("reaching out to the admin API to retrieve serial console logs for VM %s", vmName))
419418
req, err := http.NewRequestWithContext(ctx, http.MethodGet, serialConsoleEndpoint, nil)
420419
if err != nil {
421420
return "", fmt.Errorf("failed to create request: %w", err)
422421
}
423422

423+
// Add query parameter with proper encoding
424+
q := req.URL.Query()
425+
q.Add("vmName", vmName)
426+
req.URL.RawQuery = q.Encode()
427+
424428
resp, err := httpClient.Do(req)
425429
if err != nil {
426430
return "", fmt.Errorf("failed to send request: %w", err)

0 commit comments

Comments
 (0)