From e8f198684b75662a2c0f0433c852a466d24f54fa Mon Sep 17 00:00:00 2001 From: Matheus Pimenta Date: Sun, 15 Oct 2023 01:25:34 +0100 Subject: [PATCH] Add CLI flag for OCIRepo verify secret Signed-off-by: Matheus Pimenta --- cmd/flux/create_source_oci.go | 38 ++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/cmd/flux/create_source_oci.go b/cmd/flux/create_source_oci.go index 5d6a5f95f2..bdb79f6de5 100644 --- a/cmd/flux/create_source_oci.go +++ b/cmd/flux/create_source_oci.go @@ -51,16 +51,18 @@ var createSourceOCIRepositoryCmd = &cobra.Command{ } type sourceOCIRepositoryFlags struct { - url string - tag string - semver string - digest string - secretRef string - serviceAccount string - certSecretRef string - ignorePaths []string - provider flags.SourceOCIProvider - insecure bool + url string + tag string + semver string + digest string + secretRef string + serviceAccount string + certSecretRef string + verifyProvider string + verifySecretRef string + ignorePaths []string + provider flags.SourceOCIProvider + insecure bool } var sourceOCIRepositoryArgs = newSourceOCIFlags() @@ -80,6 +82,8 @@ func init() { createSourceOCIRepositoryCmd.Flags().StringVar(&sourceOCIRepositoryArgs.secretRef, "secret-ref", "", "the name of the Kubernetes image pull secret (type 'kubernetes.io/dockerconfigjson')") createSourceOCIRepositoryCmd.Flags().StringVar(&sourceOCIRepositoryArgs.serviceAccount, "service-account", "", "the name of the Kubernetes service account that refers to an image pull secret") createSourceOCIRepositoryCmd.Flags().StringVar(&sourceOCIRepositoryArgs.certSecretRef, "cert-ref", "", "the name of a secret to use for TLS certificates") + createSourceOCIRepositoryCmd.Flags().StringVar(&sourceOCIRepositoryArgs.verifyProvider, "verify-provider", "", "the provider to use for signture verification") + createSourceOCIRepositoryCmd.Flags().StringVar(&sourceOCIRepositoryArgs.verifySecretRef, "verify-secret-ref", "", "the name of a secret to use for signture verification") createSourceOCIRepositoryCmd.Flags().StringSliceVar(&sourceOCIRepositoryArgs.ignorePaths, "ignore-paths", nil, "set paths to ignore resources (can specify multiple paths with commas: path1,path2)") createSourceOCIRepositoryCmd.Flags().BoolVar(&sourceOCIRepositoryArgs.insecure, "insecure", false, "for when connecting to a non-TLS registries over plain HTTP") @@ -156,6 +160,20 @@ func createSourceOCIRepositoryCmdRun(cmd *cobra.Command, args []string) error { } } + if secretName := sourceOCIRepositoryArgs.verifySecretRef; secretName != "" { + provider := sourceOCIRepositoryArgs.verifyProvider + if provider == "" { + return fmt.Errorf("a provider must be specified for signature verification") + } + + repository.Spec.Verify = &sourcev1.OCIRepositoryVerification{ + Provider: provider, + SecretRef: &meta.LocalObjectReference{ + Name: secretName, + }, + } + } + if createArgs.export { return printExport(exportOCIRepository(repository)) }