diff --git a/cmd/compose/c2pcr.yaml b/cmd/compose/c2pcr.yaml index 1948e7c..2c1bc45 100644 --- a/cmd/compose/c2pcr.yaml +++ b/cmd/compose/c2pcr.yaml @@ -8,6 +8,8 @@ compliance: url: ./pkg/composer/testdata/oscal/component-definition.json policyResources: url: ./pkg/composer/testdata/policies +policyResults: + url: a/b/c clusterGroups: - name: cluster-nist-high # name of clusterGroup matchLabels: @@ -17,4 +19,4 @@ binding: clusterGroups: - cluster-nist-high # clusterGroup name target: - namespace: compliance-high # namespace to which C2P deploys generated resources \ No newline at end of file + namespace: "" # namespace to which C2P deploys generated resources \ No newline at end of file diff --git a/pkg/composer/composer.go b/pkg/composer/composer.go index 2cd760a..1a4bbdc 100644 --- a/pkg/composer/composer.go +++ b/pkg/composer/composer.go @@ -38,6 +38,8 @@ import ( var logger *zap.Logger = pkg.GetLogger("composer") +var DummyNamespace string = "dummy-namespace-c2p" + type Composer struct { policiesDir string tempDir pkg.TempDirectory @@ -176,6 +178,9 @@ func (c *Composer) Compose(namespace string, componentObjects []oscal.ComponentO }, } + if policySetGeneratorManifest.PolicyDefaults.Namespace == "" { + policySetGeneratorManifest.PolicyDefaults.Namespace = DummyNamespace + } if err := pkg.WriteObjToYamlFileByGoYaml(c.tempDir.GetTempDir()+"/policy-generator.yaml", policySetGeneratorManifest); err != nil { return err } @@ -225,6 +230,14 @@ func (c *Composer) GeneratePolicySet() (*resmap.ResMap, error) { logger.Sugar().Error(err, "failed to run kustomize") return nil, err } + // TODO: Workaround to allow to run PolicyGenerator with empty namespace. + for _, resource := range generatedManifests.Resources() { + if resource.GetNamespace() == DummyNamespace { + if err := resource.SetNamespace(""); err != nil { + return nil, err + } + } + } return &generatedManifests, nil } diff --git a/pkg/composer/composer_test.go b/pkg/composer/composer_test.go index b8b89e2..5dc8aed 100644 --- a/pkg/composer/composer_test.go +++ b/pkg/composer/composer_test.go @@ -68,7 +68,7 @@ func TestComposer(t *testing.T) { ClusterGroups: []string{"test-group"}, }, Target: typec2pcr.Target{ - Namespace: "test", + Namespace: "", }, } c2pcrParser := c2pcr.NewParser(gitUtils)