Skip to content

Commit 476fd15

Browse files
author
Jeremi Piotrowski
committed
azure: Switch to managed boot diagnostics for console
This does not require that the user have RBAC permissions to a storage account to fetch, because it uses SAS keys behind the scenes. The previous approach used a kola created storage account has Shared Key Access disabled for security reasons. Signed-off-by: Jeremi Piotrowski <jpiotrowski@microsoft.com>
1 parent 6335d15 commit 476fd15

1 file changed

Lines changed: 10 additions & 33 deletions

File tree

platform/api/azure/instance.go

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"encoding/base64"
2020
"fmt"
2121
"io"
22-
"regexp"
22+
"net/http"
2323
"time"
2424

2525
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
@@ -148,8 +148,7 @@ func (a *API) getVMParameters(name, sshkey, storageAccountURI string, userdata *
148148
},
149149
DiagnosticsProfile: &armcompute.DiagnosticsProfile{
150150
BootDiagnostics: &armcompute.BootDiagnostics{
151-
Enabled: to.Ptr(true),
152-
StorageURI: &storageAccountURI,
151+
Enabled: to.Ptr(true),
153152
},
154153
},
155154
},
@@ -303,46 +302,24 @@ func (a *API) TerminateInstance(machine *Machine, resourceGroup string) error {
303302

304303
func (a *API) GetConsoleOutput(name, resourceGroup, storageAccount string) ([]byte, error) {
305304
vmResourceGroup := a.getVMRG(resourceGroup)
306-
vm, err := a.compClient.Get(context.TODO(), vmResourceGroup, name, &armcompute.VirtualMachinesClientGetOptions{
307-
Expand: to.Ptr(armcompute.InstanceViewTypesInstanceView),
308-
})
305+
param := &armcompute.VirtualMachinesClientRetrieveBootDiagnosticsDataOptions{
306+
SasURIExpirationTimeInMinutes: to.Ptr[int32](5),
307+
}
308+
resp, err := a.compClient.RetrieveBootDiagnosticsData(context.TODO(), vmResourceGroup, name, param)
309309
if err != nil {
310310
return nil, fmt.Errorf("could not get VM: %v", err)
311311
}
312-
313-
consoleURI := vm.Properties.InstanceView.BootDiagnostics.SerialConsoleLogBlobURI
314-
if consoleURI == nil {
312+
if resp.SerialConsoleLogBlobURI == nil {
315313
return nil, fmt.Errorf("serial console URI is nil")
316314
}
317315

318-
// Only the full URI to the logs are present in the virtual machine
319-
// properties. Parse out the container & file name to use the GetBlob
320-
// API call directly.
321-
uri := []byte(*consoleURI)
322-
containerPat := regexp.MustCompile(`bootdiagnostics-[a-z0-9\-]+`)
323-
container := string(containerPat.Find(uri))
324-
if container == "" {
325-
return nil, fmt.Errorf("could not find container name in URI: %q", *consoleURI)
326-
}
327-
namePat := regexp.MustCompile(`[a-z0-9\-\.]+.serialconsole.log`)
328-
blobname := string(namePat.Find(uri))
329-
if blobname == "" {
330-
return nil, fmt.Errorf("could not find blob name in URI: %q", *consoleURI)
331-
}
332-
333-
client, err := a.GetBlobServiceClient(storageAccount)
334-
if err != nil {
335-
return nil, err
336-
}
337316
var data io.ReadCloser
338317
err = util.Retry(6, 10*time.Second, func() error {
339-
data, err = GetBlob(client, container, blobname)
318+
reply, err := http.Get(*resp.SerialConsoleLogBlobURI)
340319
if err != nil {
341-
return fmt.Errorf("could not get blob for container %q, blobname %q: %v", container, blobname, err)
342-
}
343-
if data == nil {
344-
return fmt.Errorf("empty data while getting blob for container %q, blobname %q", container, blobname)
320+
return fmt.Errorf("could not GET console output: %v", err)
345321
}
322+
data = reply.Body
346323
return nil
347324
})
348325
if err != nil {

0 commit comments

Comments
 (0)