Skip to content

Commit 19c4ddc

Browse files
committed
Mounted cloud credentials should not be world-readable
Signed-off-by: Scott Seago <sseago@redhat.com>
1 parent 8d0d15d commit 19c4ddc

4 files changed

Lines changed: 11 additions & 3 deletions

File tree

changelogs/unreleased/8919-sseago

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Mounted cloud credentials should not be world-readable

internal/credentials/file_store.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ func (n *namespacedFileStore) Path(selector *corev1api.SecretKeySelector) (strin
7171

7272
keyFilePath := filepath.Join(n.fsRoot, fmt.Sprintf("%s-%s", selector.Name, selector.Key))
7373

74-
file, err := n.fs.OpenFile(keyFilePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
74+
// owner RW perms, group R perms, no public perms
75+
file, err := n.fs.OpenFile(keyFilePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0640)
7576
if err != nil {
7677
return "", errors.Wrap(err, "unable to open credentials file for writing")
7778
}

pkg/install/daemonset.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
appsv1api "k8s.io/api/apps/v1"
2424
corev1api "k8s.io/api/core/v1"
2525
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26+
"k8s.io/utils/ptr"
2627

2728
"github.com/vmware-tanzu/velero/internal/velero"
2829
)
@@ -177,7 +178,9 @@ func DaemonSet(namespace string, opts ...podTemplateOption) *appsv1api.DaemonSet
177178
Name: "cloud-credentials",
178179
VolumeSource: corev1api.VolumeSource{
179180
Secret: &corev1api.SecretVolumeSource{
180-
SecretName: "cloud-credentials",
181+
// read-only for Owner and Group; no permission for Public
182+
DefaultMode: ptr.To(int32(0440)),
183+
SecretName: "cloud-credentials",
181184
},
182185
},
183186
},

pkg/install/deployment.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
appsv1api "k8s.io/api/apps/v1"
2525
corev1api "k8s.io/api/core/v1"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27+
"k8s.io/utils/ptr"
2728

2829
"github.com/vmware-tanzu/velero/internal/velero"
2930
"github.com/vmware-tanzu/velero/pkg/builder"
@@ -404,7 +405,9 @@ func Deployment(namespace string, opts ...podTemplateOption) *appsv1api.Deployme
404405
Name: "cloud-credentials",
405406
VolumeSource: corev1api.VolumeSource{
406407
Secret: &corev1api.SecretVolumeSource{
407-
SecretName: "cloud-credentials",
408+
// read-only for Owner and Group; no permission for Public
409+
DefaultMode: ptr.To(int32(0440)),
410+
SecretName: "cloud-credentials",
408411
},
409412
},
410413
},

0 commit comments

Comments
 (0)