Skip to content

Commit 62157de

Browse files
authored
Merge pull request #431 from oukoedwin/edwinouko/agc-image-provisioning
Add Azure Storage Blob as an image source
2 parents a7feca9 + 4e9141f commit 62157de

10 files changed

Lines changed: 669 additions & 323 deletions

pkg/redact/redact.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func redactJsonSensitiveField(val reflect.Value) {
152152
return
153153
}
154154

155-
sensitiveKeys := [...]string{"private-key", "sasURI"}
155+
sensitiveKeys := [...]string{"private-key", "sasURI", "endpoint"}
156156

157157
for _, sensitiveKey := range sensitiveKeys {
158158
if _, ok := jsonData[sensitiveKey]; ok {
@@ -256,7 +256,7 @@ func redactErrorJsonSensitiveField(val reflect.Value, errMessage *error) {
256256
if err := json.Unmarshal([]byte(val.String()), &jsonData); err != nil {
257257
return
258258
}
259-
sensitiveKeys := [...]string{"private-key", "sasURI"}
259+
sensitiveKeys := [...]string{"private-key", "sasURI", "endpoint"}
260260

261261
for _, sensitiveKey := range sensitiveKeys {
262262
if strVal, ok := jsonData[sensitiveKey].(string); ok && errMessage != nil && *errMessage != nil && strVal != "" {

pkg/redact/redact_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,19 @@ func TestRedactErrorURL(t *testing.T) {
252252
})
253253
}
254254
}
255+
256+
func TestRedactJsonSensitiveField_Endpoint(t *testing.T) {
257+
endpoint := "https://mystorage.blob.core.windows.net"
258+
jsonStr := fmt.Sprintf(`{"cloud":"AzureCloud","endpoint":"%s","catalogName":"cat"}`, endpoint)
259+
260+
val := reflect.ValueOf(&jsonStr).Elem()
261+
redactJsonSensitiveField(val)
262+
263+
assert.False(t, strings.Contains(val.String(), endpoint),
264+
"endpoint should be redacted, got: %s", val.String())
265+
assert.True(t, strings.Contains(val.String(), RedactedString),
266+
"redacted value should contain placeholder, got: %s", val.String())
267+
// Other fields should remain intact
268+
assert.True(t, strings.Contains(val.String(), "AzureCloud"),
269+
"non-sensitive fields should be preserved, got: %s", val.String())
270+
}

rpc/cloudagent/compute/galleryimage/moc_cloudagent_galleryimage.proto

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ message AzureGalleryImageProperties {
5858
string sasURI = 1 [(sensitive) = true];
5959
string version = 2;
6060
}
61+
message AzureBlobImageProperties {
62+
string catalogName = 1;
63+
string audience = 2;
64+
string version = 3;
65+
string releaseName = 4;
66+
uint32 parts = 5;
67+
string cloud = 6;
68+
string endpoint = 7;
69+
}
6170

6271
message GalleryImage {
6372
string name = 1;

rpc/cloudagent/compute/moc_cloudagent_galleryimage.pb.go

Lines changed: 146 additions & 55 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the Apache v2.0 license.
3+
package compute
4+
5+
import (
6+
"encoding/json"
7+
"testing"
8+
9+
"github.com/stretchr/testify/assert"
10+
"github.com/stretchr/testify/require"
11+
)
12+
13+
// TestAzureBlobImageProperties_JSONKeys locks the exact JSON keys produced by
14+
// the cloudagent AzureBlobImageProperties message. moc-sdk-for-go marshals
15+
// this struct into GalleryImage.sourcePath as the on-the-wire representation
16+
// of AGC (AZURESTORAGEBLOB_SOURCE) image provisioning parameters. Renaming any
17+
// of these proto fields would silently break the encoding agreement with
18+
// wssdagent's parseBlobConfig on the decode side, so this test fails loudly
19+
// if a field name drifts.
20+
func TestAzureBlobImageProperties_JSONKeys(t *testing.T) {
21+
props := AzureBlobImageProperties{
22+
CatalogName: "cat",
23+
Audience: "aud",
24+
Version: "v1",
25+
ReleaseName: "rel",
26+
Parts: 4,
27+
Cloud: "AzureCloud",
28+
Endpoint: "https://example.blob.core.windows.net",
29+
}
30+
raw, err := json.Marshal(&props)
31+
require.NoError(t, err)
32+
33+
var m map[string]any
34+
require.NoError(t, json.Unmarshal(raw, &m))
35+
36+
expected := []string{"catalogName", "audience", "version", "releaseName", "parts", "cloud", "endpoint"}
37+
for _, key := range expected {
38+
_, ok := m[key]
39+
assert.True(t, ok, "missing JSON key %q (renamed proto field?)", key)
40+
}
41+
assert.Len(t, m, len(expected), "unexpected extra/missing JSON keys: %v", m)
42+
}

0 commit comments

Comments
 (0)