Skip to content

Commit 8bd230b

Browse files
committed
fix: avoid persisting inline OSS credentials in jindofsx
1 parent 7a06f0f commit 8bd230b

2 files changed

Lines changed: 55 additions & 11 deletions

File tree

pkg/ddc/jindofsx/transform.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -359,14 +359,8 @@ func (e *JindoFSxEngine) transformMaster(runtime *datav1alpha1.JindoRuntime, met
359359
return
360360
}
361361
ossBucketName = rm[2]
362-
if mount.Options["fs.oss.accessKeyId"] != "" {
363-
propertiesFileStore["jindofsx.oss.bucket."+ossBucketName+".accessKeyId"] = mount.Options["fs.oss.accessKeyId"]
364-
}
365-
if mount.Options["fs.oss.accessKeySecret"] != "" {
366-
propertiesFileStore["jindofsx.oss.bucket."+ossBucketName+".accessKeySecret"] = mount.Options["fs.oss.accessKeySecret"]
367-
}
368362
if mount.Options["fs.oss.endpoint"] == "" {
369-
err = fmt.Errorf("oss endpoint can not be null, please check <fs.oss.accessKeySecret> option")
363+
err = fmt.Errorf("oss endpoint can not be null, please check <fs.oss.endpoint> option")
370364
e.Log.Error(err, "oss endpoint can not be null")
371365
return
372366
}
@@ -442,10 +436,10 @@ func (e *JindoFSxEngine) transformMaster(runtime *datav1alpha1.JindoRuntime, met
442436
value.BucketSecretPaths[ossBucketName] = secretURI
443437

444438
itemPath := ""
445-
if key == "fs.oss.accessKeyId" {
439+
switch key {
440+
case "fs.oss.accessKeyId":
446441
itemPath = ossBucketName + "/AccessKeyId"
447-
}
448-
if key == "fs.oss.accessKeySecret" {
442+
case "fs.oss.accessKeySecret":
449443
itemPath = ossBucketName + "/AccessKeySecret"
450444
}
451445
if itemPath != "" {
@@ -460,7 +454,7 @@ func (e *JindoFSxEngine) transformMaster(runtime *datav1alpha1.JindoRuntime, met
460454

461455
secret, err := kubeclient.GetSecret(e.Client, secretKeyRef.Name, e.namespace)
462456
if err != nil {
463-
e.Log.Info("can't get the input secret from dataset", secretKeyRef.Name)
457+
e.Log.Error(err, "can't get the input secret from dataset", "secretName", secretKeyRef.Name)
464458
break
465459
}
466460
secretValue := string(secret.Data[secretKeyRef.Key])

pkg/ddc/jindofsx/transform_master_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,53 @@ func TestJindoFSxEngine_transformMasterWithMultipleOSSEncryptOptions(t *testing.
239239
t.Fatalf("expected bucket-b fuse credentials provider %q, got %q", jindoOSSCredentialsProvider, got)
240240
}
241241
}
242+
243+
func TestJindoFSxEngine_transformMasterDoesNotPersistInlineOSSCredentials(t *testing.T) {
244+
s := runtime.NewScheme()
245+
s.AddKnownTypes(datav1alpha1.GroupVersion, &datav1alpha1.JindoRuntime{}, &datav1alpha1.Dataset{})
246+
_ = corev1.AddToScheme(s)
247+
248+
engine := JindoFSxEngine{
249+
name: "test",
250+
namespace: "fluid",
251+
Client: fake.NewFakeClientWithScheme(s),
252+
Log: fake.NullLogger(),
253+
runtime: &datav1alpha1.JindoRuntime{
254+
Spec: datav1alpha1.JindoRuntimeSpec{
255+
Fuse: datav1alpha1.JindoFuseSpec{},
256+
},
257+
},
258+
}
259+
260+
dataset := &datav1alpha1.Dataset{
261+
Spec: datav1alpha1.DatasetSpec{
262+
Mounts: []datav1alpha1.Mount{{
263+
MountPoint: "oss://bucket-a/data",
264+
Name: "mount-a",
265+
Options: map[string]string{
266+
"fs.oss.endpoint": "oss-cn-shanghai.aliyuncs.com",
267+
"fs.oss.accessKeyId": "inline-ak",
268+
"fs.oss.accessKeySecret": "inline-sk",
269+
},
270+
}},
271+
},
272+
}
273+
274+
value := &Jindo{}
275+
if err := engine.transformMaster(engine.runtime, "/test", value, dataset, true); err != nil {
276+
t.Fatalf("transformMaster() error = %v", err)
277+
}
278+
279+
if got := value.Master.FileStoreProperties["jindofsx.oss.bucket.bucket-a.endpoint"]; got != "oss-cn-shanghai.aliyuncs.com" {
280+
t.Fatalf("expected bucket-a endpoint to be preserved, got %q", got)
281+
}
282+
if _, ok := value.Master.FileStoreProperties["jindofsx.oss.bucket.bucket-a.accessKeyId"]; ok {
283+
t.Fatalf("expected inline bucket-a accessKeyId to stay out of fileStoreProperties")
284+
}
285+
if _, ok := value.Master.FileStoreProperties["jindofsx.oss.bucket.bucket-a.accessKeySecret"]; ok {
286+
t.Fatalf("expected inline bucket-a accessKeySecret to stay out of fileStoreProperties")
287+
}
288+
if len(value.SecretProjections) != 0 {
289+
t.Fatalf("expected no secret projections for inline credentials, got %d", len(value.SecretProjections))
290+
}
291+
}

0 commit comments

Comments
 (0)