Skip to content

Added anchors to cluster asset regex for security #190

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

Merged
merged 1 commit into from
Aug 3, 2023
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
2 changes: 1 addition & 1 deletion internal/gke/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func filterMapSeachResults(results []*assetpb.ResourceSearchResult) []string {

// getIDFromName returns cluster identifier from full cluster asset name.
func getIDFromName(name string) (string, error) {
r := regexp.MustCompile(`//container\.googleapis\.com/(projects/.+/(locations|zones)/.+/clusters/.+)`)
r := regexp.MustCompile(`^//container\.googleapis\.com/(projects/.+/(locations|zones)/.+/clusters/.+$)`)
if !r.MatchString(name) {
return "", fmt.Errorf("given name %q does not match GKE cluster name pattern", name)
}
Expand Down
1 change: 1 addition & 0 deletions internal/gke/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ func TestGetIDFromName_negative(t *testing.T) {
inputs := []string{
"projects/my-project/locations/europe-west2/clusters/my-cluster",
"//container.googleapis.com/project/test/locations/europe/my-cluster",
"malicious//container.googleapis.com/projects/my-project/locations/europe-west2/clusters/other-cluster/code",
}
for _, input := range inputs {
if _, err := getIDFromName(input); err == nil {
Expand Down