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

ArtifactsPipelineRunEnableDeepInspection making this field to accept both bool and string #2179

Merged
merged 1 commit into from
Jul 5, 2024
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
8 changes: 4 additions & 4 deletions pkg/apis/operator/v1alpha1/tektonchain_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ type ChainProperties struct {
ArtifactsTaskRunSigner string `json:"artifacts.taskrun.signer,omitempty"`

// pipelinerun artifacts config
ArtifactsPipelineRunFormat string `json:"artifacts.pipelinerun.format,omitempty"`
ArtifactsPipelineRunStorage *string `json:"artifacts.pipelinerun.storage,omitempty"`
ArtifactsPipelineRunSigner string `json:"artifacts.pipelinerun.signer,omitempty"`
ArtifactsPipelineRunEnableDeepInspection *bool `json:"artifacts.pipelinerun.enable-deep-inspection,omitempty"`
ArtifactsPipelineRunFormat string `json:"artifacts.pipelinerun.format,omitempty"`
ArtifactsPipelineRunStorage *string `json:"artifacts.pipelinerun.storage,omitempty"`
ArtifactsPipelineRunSigner string `json:"artifacts.pipelinerun.signer,omitempty"`
ArtifactsPipelineRunEnableDeepInspection BoolValue `json:"artifacts.pipelinerun.enable-deep-inspection,omitempty"`

// oci artifacts config
ArtifactsOCIFormat string `json:"artifacts.oci.format,omitempty"`
Expand Down
19 changes: 12 additions & 7 deletions pkg/apis/operator/v1alpha1/tektonchain_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ import (
)

var (
allowedArtifactsTaskRunFormat = sets.NewString("", "in-toto", "slsa/v1", "slsa/v2alpha2", "slsa/v2alpha3")
allowedArtifactsPipelineRunFormat = sets.NewString("", "in-toto", "slsa/v1", "slsa/v2alpha2", "slsa/v2alpha3")
allowedX509SignerFulcioProvider = sets.NewString("", "google", "spiffe", "github", "filesystem")
allowedTransparencyConfigEnabled = sets.NewString("", "true", "false", "manual")
allowedArtifactsStorage = sets.NewString("", "tekton", "oci", "gcs", "docdb", "grafeas", "kafka")
allowedControllerEnvs = sets.NewString("MONGO_SERVER_URL")
allowedBuildDefinitionType = sets.NewString("", "https://tekton.dev/chains/v2/slsa", "https://tekton.dev/chains/v2/slsa-tekton")
allowedArtifactsTaskRunFormat = sets.NewString("", "in-toto", "slsa/v1", "slsa/v2alpha2", "slsa/v2alpha3")
allowedArtifactsPipelineRunFormat = sets.NewString("", "in-toto", "slsa/v1", "slsa/v2alpha2", "slsa/v2alpha3")
allowedX509SignerFulcioProvider = sets.NewString("", "google", "spiffe", "github", "filesystem")
allowedTransparencyConfigEnabled = sets.NewString("", "true", "false", "manual")
allowedArtifactsPipelineRunEnableDeepInspection = sets.NewString("", "true", "false")
allowedArtifactsStorage = sets.NewString("", "tekton", "oci", "gcs", "docdb", "grafeas", "kafka")
allowedControllerEnvs = sets.NewString("MONGO_SERVER_URL")
allowedBuildDefinitionType = sets.NewString("", "https://tekton.dev/chains/v2/slsa", "https://tekton.dev/chains/v2/slsa-tekton")
)

func (tc *TektonChain) Validate(ctx context.Context) (errs *apis.FieldError) {
Expand Down Expand Up @@ -135,6 +136,10 @@ func (tcs *TektonChainSpec) ValidateChainConfig(path string) (errs *apis.FieldEr
errs = errs.Also(apis.ErrInvalidValue(tcs.TransparencyConfigEnabled, path+".transparency.enabled"))
}

if !allowedArtifactsPipelineRunEnableDeepInspection.Has(string(tcs.ArtifactsPipelineRunEnableDeepInspection)) {
errs = errs.Also(apis.ErrInvalidValue(tcs.ArtifactsPipelineRunEnableDeepInspection, path+".artifacts.pipelinerun.enable-deep-inspection"))
}

if !allowedBuildDefinitionType.Has(tcs.BuildDefinitionBuildType) {
errs = errs.Also(apis.ErrInvalidValue(tcs.BuildDefinitionBuildType, path+".builddefinition.buildtype"))
}
Expand Down
39 changes: 39 additions & 0 deletions pkg/apis/operator/v1alpha1/tektonchain_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,45 @@ func Test_ValidateTektonChain_ConfigPipelineRunStorageValid(t *testing.T) {
}
}

func Test_ValidateTektonChain_ConfigInvalidArtifactsPipelineRunEnableDeepInspection(t *testing.T) {
tc := &TektonChain{
ObjectMeta: metav1.ObjectMeta{
Name: "chain",
Namespace: "namespace",
},
Spec: TektonChainSpec{
CommonSpec: CommonSpec{
TargetNamespace: "namespace",
},
},
}

tc.Spec.Chain.ChainProperties.ArtifactsPipelineRunEnableDeepInspection = "foo"
err := tc.Validate(context.TODO())
assert.Equal(t, "invalid value: foo: spec.artifacts.pipelinerun.enable-deep-inspection", err.Error())
}

func Test_ValidateTektonChain_ConfigArtifactsPipelineRunEnableDeepInspection(t *testing.T) {
tc := &TektonChain{
ObjectMeta: metav1.ObjectMeta{
Name: "chain",
Namespace: "namespace",
},
Spec: TektonChainSpec{
CommonSpec: CommonSpec{
TargetNamespace: "namespace",
},
},
}

tc.Spec.Chain.ChainProperties.ArtifactsPipelineRunEnableDeepInspection = "true"
err := tc.Validate(context.TODO())

if err != nil {
t.Errorf("ValidateTektonChain.Validate() expected no error for the given config, but got one, ValidateTektonChain: %v", err)
}
}

func Test_ValidateTektonChain_ConfigInvalidX509SignerFulcioProvider(t *testing.T) {
tc := &TektonChain{
ObjectMeta: metav1.ObjectMeta{
Expand Down
5 changes: 0 additions & 5 deletions pkg/apis/operator/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.