-
Notifications
You must be signed in to change notification settings - Fork 61
fix(EC-1993): reject past --effective-time values by default #3424
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,15 +26,17 @@ import ( | |
| "github.com/spf13/cobra" | ||
| "sigs.k8s.io/yaml" | ||
|
|
||
| "github.com/conforma/cli/internal/policy" | ||
| "github.com/conforma/cli/internal/policy/equivalence" | ||
| ) | ||
|
|
||
| var ( | ||
| effectiveTime string | ||
| imageDigest string | ||
| imageRef string | ||
| imageURL string | ||
| outputFormat string | ||
| effectiveTime string | ||
| allowPastEffectiveTime bool | ||
| imageDigest string | ||
| imageRef string | ||
| imageURL string | ||
| outputFormat string | ||
| ) | ||
|
|
||
| var CompareCmd *cobra.Command | ||
|
|
@@ -73,7 +75,8 @@ Examples: | |
| RunE: runCompare, | ||
| } | ||
|
|
||
| compareCmd.Flags().StringVar(&effectiveTime, "effective-time", "now", "Effective time for policy evaluation (RFC3339 format, 'now')") | ||
| compareCmd.Flags().StringVar(&effectiveTime, "effective-time", "now", "Effective time for policy evaluation ('now', 'attestation', or RFC3339 format, e.g. 2022-11-18T00:00:00Z)") | ||
| compareCmd.Flags().BoolVar(&allowPastEffectiveTime, "allow-past-effective-time", false, "Allow setting --effective-time to a date in the past. By default, dates more than 5 minutes in the past are rejected.") | ||
| compareCmd.Flags().StringVar(&imageDigest, "image-digest", "", "Image digest for volatile config matching") | ||
| compareCmd.Flags().StringVar(&imageRef, "image-ref", "", "Image reference for volatile config matching") | ||
| compareCmd.Flags().StringVar(&imageURL, "image-url", "", "Image URL for volatile config matching") | ||
|
|
@@ -84,20 +87,12 @@ Examples: | |
|
|
||
| func runCompare(cmd *cobra.Command, args []string) error { | ||
|
|
||
|
cuipinghuo marked this conversation as resolved.
|
||
| // Parse effective time | ||
| var effectiveTimeValue time.Time | ||
| switch effectiveTime { | ||
| case "now": | ||
| effectiveTimeValue = time.Now().UTC() | ||
| case "attestation": | ||
| // For now, use current time as default for attestation time | ||
| effectiveTimeValue, err := policy.ParseEffectiveTime(effectiveTime, allowPastEffectiveTime) | ||
| if err != nil { | ||
| return err | ||
|
cuipinghuo marked this conversation as resolved.
|
||
| } | ||
| if effectiveTimeValue.IsZero() { | ||
| effectiveTimeValue = time.Now().UTC() | ||
| default: | ||
| var err error | ||
| effectiveTimeValue, err = time.Parse(time.RFC3339, effectiveTime) | ||
| if err != nil { | ||
| return fmt.Errorf("invalid effective time format: %w", err) | ||
| } | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [low] edge-case When --effective-time=attestation is used with compare, ParseEffectiveTime returns a zero time.Time and the IsZero() check falls back to time.Now().UTC(). Pre-existing behavior preserved by this PR. |
||
|
|
||
| // Create image info if provided | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,20 +43,21 @@ type InputValidationFunc func(context.Context, string, policy.Policy, bool) (*ou | |
|
|
||
| func validateInputCmd(validate InputValidationFunc) *cobra.Command { | ||
| data := struct { | ||
| effectiveTime string | ||
| filePaths []string | ||
| forceColor bool | ||
| info bool | ||
| namespaces []string | ||
| noColor bool | ||
| output []string | ||
| policy policy.Policy | ||
| policyConfiguration string | ||
| strict bool | ||
| workers int | ||
| serverMode bool | ||
| serverAddress string | ||
| serverPort int | ||
| effectiveTime string | ||
| allowPastEffectiveTime bool | ||
| filePaths []string | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [low] code-organization allowPastEffectiveTime field placement differs between input.go (grouped with effectiveTime) and image.go (alphabetical). Inconsistent ordering convention. |
||
| forceColor bool | ||
| info bool | ||
| namespaces []string | ||
| noColor bool | ||
| output []string | ||
| policy policy.Policy | ||
| policyConfiguration string | ||
| strict bool | ||
| workers int | ||
| serverMode bool | ||
| serverAddress string | ||
| serverPort int | ||
| }{ | ||
| strict: true, | ||
| workers: 5, | ||
|
|
@@ -168,7 +169,7 @@ func validateInputCmd(validate InputValidationFunc) *cobra.Command { | |
| } | ||
| data.policyConfiguration = policyConfiguration | ||
|
|
||
| if p, err := policy.NewInputPolicy(cmd.Context(), data.policyConfiguration, data.effectiveTime); err != nil { | ||
| if p, err := policy.NewInputPolicy(cmd.Context(), data.policyConfiguration, data.effectiveTime, data.allowPastEffectiveTime); err != nil { | ||
| allErrors = errors.Join(allErrors, err) | ||
| } else { | ||
| data.policy = p | ||
|
|
@@ -349,6 +350,10 @@ func validateInputCmd(validate InputValidationFunc) *cobra.Command { | |
| effective dates in the future. The value can be "now" (default) - for | ||
| current time, or a RFC3339 formatted value, e.g. 2022-11-18T00:00:00Z.`)) | ||
|
|
||
| cmd.Flags().BoolVar(&data.allowPastEffectiveTime, "allow-past-effective-time", false, hd.Doc(` | ||
| Allow setting --effective-time to a date in the past. By default, dates | ||
| more than 5 minutes in the past are rejected.`)) | ||
|
|
||
| cmd.Flags().BoolVar(&data.info, "info", data.info, hd.Doc(` | ||
| Include additional information on the failures. For instance for policy | ||
| violations, include the title and the description of the failed policy | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.