Skip to content

Commit 92ef3f3

Browse files
authored
Merge pull request #1477 from iltyty/fix-proxy-mount
Fix proxy mounter empty auth config issue
2 parents 6acf7de + 2130b5c commit 92ef3f3

File tree

5 files changed

+35
-58
lines changed

5 files changed

+35
-58
lines changed

pkg/mounter/cmd_mounter.go

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ package mounter
22

33
import (
44
"context"
5-
"errors"
65
"fmt"
76
"os"
87
"os/exec"
98
"time"
109

11-
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/cloud/metadata"
1210
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/mounter/utils"
1311
"k8s.io/mount-utils"
1412
)
@@ -19,72 +17,33 @@ type OssCmdMounter struct {
1917
mount.Interface
2018
volumeId string
2119
execPath string
22-
metadata metadata.MetadataProvider
2320
}
2421

25-
func NewOssCmdMounter(execPath, volumeId string, metadata metadata.MetadataProvider, inner mount.Interface) Mounter {
22+
func NewOssCmdMounter(execPath, volumeId string, inner mount.Interface) Mounter {
2623
return &OssCmdMounter{
2724
execPath: execPath,
2825
volumeId: volumeId,
2926
Interface: inner,
30-
metadata: metadata,
3127
}
3228
}
3329

34-
func (m *OssCmdMounter) MountWithSecrets(source, target, fstype string, options []string, authCfg *utils.AuthConfig) error {
35-
if authCfg == nil {
36-
return errors.New("empty auth config")
37-
}
38-
30+
func (m *OssCmdMounter) MountWithSecrets(source, target, fstype string, options []string, secrets map[string]string) error {
3931
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(timeout))
4032
defer cancel()
4133

42-
options, err := m.appendAuthOptions(options, target, authCfg)
34+
passwd, err := utils.SaveOssSecretsToFile(secrets)
4335
if err != nil {
4436
return err
4537
}
38+
options = append(options, "passwd_file="+passwd)
4639

4740
args := mount.MakeMountArgs(source, target, "", options)
4841
cmd := exec.CommandContext(ctx, "ossfs", args...)
4942
cmd.Stdout = os.Stdout
5043
cmd.Stderr = os.Stderr
5144

52-
if err = cmd.Run(); err != nil {
45+
if err := cmd.Run(); err != nil {
5346
return fmt.Errorf("failed to execute ossfs: %w", err)
5447
}
5548
return nil
5649
}
57-
58-
func (m *OssCmdMounter) appendAuthOptions(options []string, target string, authCfg *utils.AuthConfig) ([]string, error) {
59-
if authCfg == nil {
60-
return options, nil
61-
}
62-
63-
passwdFile, err := saveOssSecretsToFileIfNeeded(authCfg)
64-
if err != nil {
65-
return nil, err
66-
}
67-
68-
switch authCfg.AuthType {
69-
case "rrsa":
70-
tokenFile, err := m.metadata.Get(metadata.RRSATokenFile)
71-
if err != nil {
72-
return nil, err
73-
}
74-
sessionName := utils.GetRoleSessionName(m.volumeId, target, "ossfs")
75-
options = append(options, fmt.Sprintf("rrsa_oidc_provider_arn=%s", authCfg.RrsaConfig.OidcProviderArn))
76-
options = append(options, fmt.Sprintf("rrsa_role_arn=%s", authCfg.RrsaConfig.RoleArn))
77-
options = append(options, fmt.Sprintf("rrsa_role_session_name=%s", sessionName))
78-
options = append(options, fmt.Sprintf("rrsa_token_file=%s", tokenFile))
79-
default:
80-
options = append(options, "passwd_file="+passwdFile)
81-
}
82-
return options, nil
83-
}
84-
85-
func saveOssSecretsToFileIfNeeded(authCfg *utils.AuthConfig) (string, error) {
86-
if authCfg == nil || authCfg.Secrets == nil {
87-
return "", nil
88-
}
89-
return utils.SaveOssSecretsToFile(authCfg.Secrets)
90-
}

pkg/mounter/mounter.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package mounter
22

33
import (
4-
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/mounter/utils"
54
mountutils "k8s.io/mount-utils"
65
)
76

87
type Mounter interface {
98
mountutils.Interface
10-
MountWithSecrets(source, target, fstype string, options []string, authCfg *utils.AuthConfig) error
9+
MountWithSecrets(source, target, fstype string, options []string, secrets map[string]string) error
1110
}

pkg/mounter/proxy_mounter.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66

77
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/mounter/proxy"
88
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/mounter/proxy/client"
9-
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/mounter/utils"
109
mountutils "k8s.io/mount-utils"
1110
)
1211

@@ -22,18 +21,14 @@ func NewProxyMounter(socketPath string, inner mountutils.Interface) Mounter {
2221
}
2322
}
2423

25-
func (m *ProxyMounter) MountWithSecrets(source, target, fstype string, options []string, authCfg *utils.AuthConfig) error {
26-
if authCfg == nil {
27-
return errors.New("empty auth config")
28-
}
29-
24+
func (m *ProxyMounter) MountWithSecrets(source, target, fstype string, options []string, secrets map[string]string) error {
3025
dclient := client.NewClient(m.socketPath)
3126
resp, err := dclient.Mount(&proxy.MountRequest{
3227
Source: source,
3328
Target: target,
3429
Fstype: fstype,
3530
Options: options,
36-
Secrets: authCfg.Secrets,
31+
Secrets: secrets,
3732
})
3833
if err != nil {
3934
return fmt.Errorf("call mounter daemon: %w", err)

pkg/mounter/utils/helper.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"path/filepath"
1212
"strings"
1313

14+
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/cloud/metadata"
1415
corev1 "k8s.io/api/core/v1"
1516
apierrors "k8s.io/apimachinery/pkg/api/errors"
1617
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -204,3 +205,22 @@ func GetConfigDir(fuseType string) string {
204205
func GetPasswdFileName(fuseType string) string {
205206
return fmt.Sprintf("passwd-%s", fuseType)
206207
}
208+
209+
func AppendRRSAAuthOptions(m metadata.MetadataProvider, options []string, volumeId, target string, authCfg *AuthConfig) ([]string, error) {
210+
if authCfg == nil {
211+
return options, nil
212+
}
213+
214+
if authCfg.AuthType == "rrsa" {
215+
tokenFile, err := m.Get(metadata.RRSATokenFile)
216+
if err != nil {
217+
return nil, err
218+
}
219+
sessionName := GetRoleSessionName(volumeId, target, "ossfs")
220+
options = append(options, fmt.Sprintf("rrsa_oidc_provider_arn=%s", authCfg.RrsaConfig.OidcProviderArn))
221+
options = append(options, fmt.Sprintf("rrsa_role_arn=%s", authCfg.RrsaConfig.RoleArn))
222+
options = append(options, fmt.Sprintf("rrsa_role_session_name=%s", sessionName))
223+
options = append(options, fmt.Sprintf("rrsa_token_file=%s", tokenFile))
224+
}
225+
return options, nil
226+
}

pkg/oss/nodeserver.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
141141
return nil, status.Error(codes.InvalidArgument, err.Error())
142142
}
143143
mountOptions = ns.fusePodManagers[opts.FuseType].AddDefaultMountOptions(mountOptions)
144+
mountOptions, err = mounterutils.AppendRRSAAuthOptions(ns.metadata, mountOptions, req.VolumeId, targetPath, authCfg)
145+
if err != nil {
146+
return nil, status.Error(codes.Internal, err.Error())
147+
}
144148

145149
// rund 3.0 protocol
146150
if features.FunctionalMutableFeatureGate.Enabled(features.RundCSIProtocol3) {
@@ -159,7 +163,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
159163
// Note: In ACK and ACS GPU scenarios, the socket path is provided by publishContext.
160164
var ossfsMounter mounter.Mounter
161165
if socketPath == "" {
162-
ossfsMounter = mounter.NewOssCmdMounter(ossfsExecPath, req.VolumeId, ns.metadata, ns.rawMounter)
166+
ossfsMounter = mounter.NewOssCmdMounter(ossfsExecPath, req.VolumeId, ns.rawMounter)
163167
} else {
164168
ossfsMounter = mounter.NewProxyMounter(socketPath, ns.rawMounter)
165169
}
@@ -169,7 +173,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
169173
if opts.FuseType == OssFsType {
170174
utils.WriteMetricsInfo(metricsPathPrefix, req, opts.MetricsTop, OssFsType, "oss", opts.Bucket)
171175
}
172-
err := ossfsMounter.MountWithSecrets(mountSource, targetPath, opts.FuseType, mountOptions, authCfg)
176+
err := ossfsMounter.MountWithSecrets(mountSource, targetPath, opts.FuseType, mountOptions, authCfg.Secrets)
173177
if err != nil {
174178
return nil, status.Error(codes.Internal, err.Error())
175179
}
@@ -189,7 +193,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
189193
utils.WriteSharedMetricsInfo(metricsPathPrefix, req, OssFsType, "oss", opts.Bucket, attachPath)
190194
}
191195
err := ossfsMounter.MountWithSecrets(
192-
mountSource, attachPath, opts.FuseType, mountOptions, authCfg)
196+
mountSource, attachPath, opts.FuseType, mountOptions, authCfg.Secrets)
193197
if err != nil {
194198
return nil, status.Error(codes.Internal, err.Error())
195199
}

0 commit comments

Comments
 (0)