Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: enforce filename is not a relative path #74

Merged
merged 1 commit into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

All notable changes to secrets-store-csi-driver-provider-gcp will be documented in this file. This file is maintained by humans and is therefore subject to error.

## v0.1.1 (unreleased)
## UNRELEASED

### Fixed

* Cleanup unix domain socket

### Changed

* Validate filenames against regex `[-._a-zA-Z0-9]+` and max length of 253 [#74](https://github.com/GoogleCloudPlatform/secrets-store-csi-driver-provider-gcp/pull/74)

## v0.1.0

Images:
Expand Down
9 changes: 9 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ import (
"fmt"
"log"
"os"
"strings"

"golang.org/x/oauth2"
"golang.org/x/oauth2/google"
"gopkg.in/yaml.v2"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/validation"
)

// Secret holds the parameters of the SecretProviderClass CRD. Links the GCP
Expand Down Expand Up @@ -117,5 +119,12 @@ func Parse(in *MountParams) (*MountConfig, error) {
return nil, fmt.Errorf("failed to unmarshal secrets attribute: %v", err)
}

for i := range out.Secrets {
name := out.Secrets[i].FileName
if errs := validation.IsConfigMapKey(name); len(errs) != 0 {
return nil, fmt.Errorf("%q is not a valid fileName for Secret: %s", name, strings.Join(errs, ";"))
tam7t marked this conversation as resolved.
Show resolved Hide resolved
}
}

return out, nil
}
51 changes: 51 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,57 @@ func TestParseErrors(t *testing.T) {
Permissions: 777,
},
},
{
name: "fileName with path",
in: &MountParams{
Attributes: `
{
"secrets": "- resourceName: \"projects/project/secrets/test/versions/latest\"\n fileName: \"../good1.txt\"\n",
"csi.storage.k8s.io/pod.namespace": "default",
"csi.storage.k8s.io/pod.name": "mypod",
"csi.storage.k8s.io/pod.uid": "123",
"csi.storage.k8s.io/serviceAccount.name": "mysa"
}
`,
KubeSecrets: "{}",
TargetPath: "/tmp/foo",
Permissions: 777,
},
},
{
name: "fileName with filename separator",
in: &MountParams{
Attributes: `
{
"secrets": "- resourceName: \"projects/project/secrets/test/versions/latest\"\n fileName: \"a:good1.txt\"\n",
"csi.storage.k8s.io/pod.namespace": "default",
"csi.storage.k8s.io/pod.name": "mypod",
"csi.storage.k8s.io/pod.uid": "123",
"csi.storage.k8s.io/serviceAccount.name": "mysa"
}
`,
KubeSecrets: "{}",
TargetPath: "/tmp/foo",
Permissions: 777,
},
},
{
name: "fileName with path separator",
in: &MountParams{
Attributes: `
{
"secrets": "- resourceName: \"projects/project/secrets/test/versions/latest\"\n fileName: \"a/good1.txt\"\n",
"csi.storage.k8s.io/pod.namespace": "default",
"csi.storage.k8s.io/pod.name": "mypod",
"csi.storage.k8s.io/pod.uid": "123",
"csi.storage.k8s.io/serviceAccount.name": "mysa"
}
`,
KubeSecrets: "{}",
TargetPath: "/tmp/foo",
Permissions: 777,
},
},
}

for _, tc := range tests {
Expand Down