Skip to content

Commit

Permalink
Merge pull request #9 from vshn/fix-showing-all-backups
Browse files Browse the repository at this point in the history
Fix leaked backups
  • Loading branch information
zugao authored Oct 30, 2023
2 parents 3549ec8 + 7d2a4e8 commit 65de476
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 11 deletions.
5 changes: 5 additions & 0 deletions pkg/apiserver/vshn/postgres/vshnpostgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ func (k *kubeXVSHNPostgresqlProvider) ListXVSHNPostgreSQL(ctx context.Context, n
err := k.Client.List(ctx, list)
cleanedList := make([]vshnv1.XVSHNPostgreSQL, 0)
for _, p := range list.Items {
// In some cases instance namespaces is missing and as a consequence all backups from the whole cluster
// are being exposed creating a security issue - check APPCAT-563.
if p.Status.InstanceNamespace == "" {
continue
}
if p.Labels[claimNamespaceLabel] == "" || p.Labels[claimNameLabel] == "" {
continue
}
Expand Down
39 changes: 28 additions & 11 deletions pkg/apiserver/vshn/postgres/vshnpostgresql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,41 @@ func Test_ListXVSHNPostgreSQL(t *testing.T) {
namespace: "namespace-prod",
postgresqls: &vshnv1.XVSHNPostgreSQLList{
Items: []vshnv1.XVSHNPostgreSQL{
getInstance("prod", "namespace-prod"),
getInstance("prod-2", "namespace-prod-2"),
getInstance("prod", "namespace-prod", "instance-namespace"),
getInstance("prod-2", "namespace-prod-2", "instance-namespace"),
getInstanceWithoutLabels("prod-3"),
getInstanceWithoutLabels("prod"),
getInstanceWithoutClaimName("prod", "namespace-prod"),
getInstanceWithoutClaimName("prod-3", "namespace-prod-2"),
getInstanceWithoutClaimNamespace("prod"),
getInstanceWithoutClaimNamespace("prod-3"),
getInstance("test", "namespace-test-2"),
getInstance("test", "namespace-prod"),
getInstance("test", "namespace-test-2", "instance-namespace"),
getInstance("test", "namespace-prod", "instance-namespace"),
getInstanceWithoutInstanceNamespace("test", "namespace-prod"),
},
},
expectedPostgresqls: &vshnv1.XVSHNPostgreSQLList{
Items: []vshnv1.XVSHNPostgreSQL{
getInstance("prod", "namespace-prod"),
getInstance("test", "namespace-prod"),
getInstance("prod", "namespace-prod", "instance-namespace"),
getInstance("test", "namespace-prod", "instance-namespace"),
},
},
},
"GivenAListOfPostgreSQLs_ThenFilter_2": {
namespace: "namespace-not-match",
postgresqls: &vshnv1.XVSHNPostgreSQLList{
Items: []vshnv1.XVSHNPostgreSQL{
getInstance("prod", "namespace-prod"),
getInstance("prod-2", "namespace-prod-2"),
getInstance("prod", "namespace-prod", "instance-namespace"),
getInstance("prod", "namespace-prod", "instance-namespace"),
getInstance("prod-2", "namespace-prod-2", "instance-namespace"),
getInstanceWithoutLabels("prod-3"),
getInstanceWithoutLabels("prod"),
getInstanceWithoutClaimName("prod", "namespace-prod"),
getInstanceWithoutClaimName("prod-3", "namespace-prod-2"),
getInstanceWithoutClaimNamespace("prod"),
getInstanceWithoutClaimNamespace("prod-3"),
getInstance("test", "namespace-test-2"),
getInstance("test", "namespace-prod"),
getInstance("test", "namespace-test-2", "instance-namespace"),
getInstance("test", "namespace-prod", "instance-namespace"),
},
},
expectedPostgresqls: &vshnv1.XVSHNPostgreSQLList{
Expand Down Expand Up @@ -118,7 +120,7 @@ func getInstanceWithoutLabels(name string) vshnv1.XVSHNPostgreSQL {
}
}

func getInstance(name, namespace string) vshnv1.XVSHNPostgreSQL {
func getInstanceWithoutInstanceNamespace(name, namespace string) vshnv1.XVSHNPostgreSQL {
return vshnv1.XVSHNPostgreSQL{
ObjectMeta: metav1.ObjectMeta{
Name: name + "-tty",
Expand All @@ -129,3 +131,18 @@ func getInstance(name, namespace string) vshnv1.XVSHNPostgreSQL {
},
}
}

func getInstance(name, namespace, instanceNamespace string) vshnv1.XVSHNPostgreSQL {
return vshnv1.XVSHNPostgreSQL{
ObjectMeta: metav1.ObjectMeta{
Name: name + "-tty",
Labels: map[string]string{
claimNameLabel: name,
claimNamespaceLabel: namespace,
},
},
Status: vshnv1.VSHNPostgreSQLStatus{
InstanceNamespace: instanceNamespace,
},
}
}
11 changes: 11 additions & 0 deletions pkg/apiserver/vshn/redis/vshnredis.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,16 @@ func (c *concreteRedisProvider) ListVSHNRedis(ctx context.Context, namespace str
return nil, err
}

cleanedList := make([]vshnv1.VSHNRedis, 0)
for _, p := range instances.Items {
//
// In some cases instance namespaces is missing and as a consequence all backups from the whole cluster
// are being exposed creating a security issue - check APPCAT-563.
if p.Status.InstanceNamespace != "" {
cleanedList = append(cleanedList, p)
}
}
instances.Items = cleanedList

return instances, nil
}

0 comments on commit 65de476

Please sign in to comment.