-
Notifications
You must be signed in to change notification settings - Fork 47
feat(policies): allow gate=false to override org-wide blocking #2777
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
9dc5598
eb1a13a
12d2b0f
c97c54c
3253d09
706b2e9
0af9bb8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -728,7 +728,14 @@ func (c *Crafter) addMaterial(ctx context.Context, m *schemaapi.CraftingSchema_M | |
| return i.MaterialName == m.Name | ||
| }) | ||
|
|
||
| pgv := policies.NewPolicyGroupVerifier(c.CraftingState.GetPolicyGroups(), c.CraftingState.GetPolicies(), c.attClient, c.Logger, policies.WithAllowedHostnames(c.CraftingState.Attestation.PoliciesAllowedHostnames...)) | ||
| pgv := policies.NewPolicyGroupVerifier( | ||
| c.CraftingState.GetPolicyGroups(), | ||
| c.CraftingState.GetPolicies(), | ||
| c.attClient, | ||
| c.Logger, | ||
| policies.WithAllowedHostnames(c.CraftingState.Attestation.PoliciesAllowedHostnames...), | ||
| policies.WithDefaultGate(c.CraftingState.Attestation.GetBlockOnPolicyViolation()), | ||
| ) | ||
| policyGroupResults, err := pgv.VerifyMaterial(ctx, mt, value) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("error applying policy groups to material: %w", err) | ||
|
|
@@ -739,7 +746,13 @@ func (c *Crafter) addMaterial(ctx context.Context, m *schemaapi.CraftingSchema_M | |
| policies.LogPolicyEvaluations(policyGroupResults, c.Logger) | ||
|
|
||
| // Validate policies | ||
| pv := policies.NewPolicyVerifier(c.CraftingState.GetPolicies(), c.attClient, c.Logger, policies.WithAllowedHostnames(c.CraftingState.Attestation.PoliciesAllowedHostnames...)) | ||
| pv := policies.NewPolicyVerifier( | ||
| c.CraftingState.GetPolicies(), | ||
| c.attClient, | ||
| c.Logger, | ||
| policies.WithAllowedHostnames(c.CraftingState.Attestation.PoliciesAllowedHostnames...), | ||
| policies.WithDefaultGate(c.CraftingState.Attestation.GetBlockOnPolicyViolation()), | ||
|
Member
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. Very elegant, thanks. |
||
| ) | ||
| policyResults, err := pv.VerifyMaterial(ctx, mt, value) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("error applying policies to material: %w", err) | ||
|
|
@@ -772,6 +785,7 @@ func (c *Crafter) EvaluateAttestationPolicies(ctx context.Context, attestationID | |
| // evaluate attestation-level policies | ||
| pv := policies.NewPolicyVerifier(c.CraftingState.GetPolicies(), c.attClient, c.Logger, | ||
| policies.WithAllowedHostnames(c.CraftingState.Attestation.PoliciesAllowedHostnames...), | ||
| policies.WithDefaultGate(c.CraftingState.Attestation.GetBlockOnPolicyViolation()), | ||
| policies.WithEvalPhase(phase), | ||
| ) | ||
| policyEvaluations, err := pv.VerifyStatement(ctx, statement) | ||
|
|
@@ -781,6 +795,7 @@ func (c *Crafter) EvaluateAttestationPolicies(ctx context.Context, attestationID | |
|
|
||
| pgv := policies.NewPolicyGroupVerifier(c.CraftingState.GetPolicyGroups(), c.CraftingState.GetPolicies(), c.attClient, c.Logger, | ||
| policies.WithAllowedHostnames(c.CraftingState.Attestation.PoliciesAllowedHostnames...), | ||
| policies.WithDefaultGate(c.CraftingState.Attestation.GetBlockOnPolicyViolation()), | ||
| policies.WithEvalPhase(phase), | ||
| ) | ||
| policyGroupResults, err := pgv.VerifyStatement(ctx, statement) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,6 +78,7 @@ type PolicyVerifier struct { | |
| client v13.AttestationServiceClient | ||
| grpcConn *grpc.ClientConn | ||
| allowedHostnames []string | ||
| defaultGate bool | ||
| includeRawData bool | ||
| enablePrint bool | ||
| evalPhase EvalPhase | ||
|
|
@@ -87,6 +88,7 @@ var _ Verifier = (*PolicyVerifier)(nil) | |
|
|
||
| type PolicyVerifierOptions struct { | ||
| AllowedHostnames []string | ||
| DefaultGate bool | ||
| IncludeRawData bool | ||
| EnablePrint bool | ||
| GRPCConn *grpc.ClientConn | ||
|
|
@@ -101,6 +103,12 @@ func WithAllowedHostnames(hostnames ...string) PolicyVerifierOption { | |
| } | ||
| } | ||
|
|
||
| func WithDefaultGate(defaultGate bool) PolicyVerifierOption { | ||
| return func(o *PolicyVerifierOptions) { | ||
| o.DefaultGate = defaultGate | ||
| } | ||
| } | ||
|
|
||
| func WithIncludeRawData(include bool) PolicyVerifierOption { | ||
| return func(o *PolicyVerifierOptions) { | ||
| o.IncludeRawData = include | ||
|
|
@@ -137,6 +145,7 @@ func NewPolicyVerifier(policies *v1.Policies, client v13.AttestationServiceClien | |
| logger: logger, | ||
| grpcConn: options.GRPCConn, | ||
| allowedHostnames: options.AllowedHostnames, | ||
| defaultGate: options.DefaultGate, | ||
| includeRawData: options.IncludeRawData, | ||
| enablePrint: options.EnablePrint, | ||
| evalPhase: options.EvalPhase, | ||
|
|
@@ -336,10 +345,22 @@ func (pv *PolicyVerifier) evaluatePolicyAttachment(ctx context.Context, attachme | |
| SkipReasons: reasons, | ||
| Requirements: attachment.Requirements, | ||
| RawResults: engineRawResultsToAPIRawResults(rawResults), | ||
| Gate: attachment.GetGate(), | ||
| Gate: policyAttachmentGate(attachment, pv.defaultGate), | ||
|
Member
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. ok, so before the default gate was outside the context of policy verifier and now you are bringing both in?
Contributor
Author
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. Right, The efective gate is now resolved inside
|
||
| }, nil | ||
| } | ||
|
|
||
| func policyAttachmentGate(attachment *v1.PolicyAttachment, defaultGate bool) bool { | ||
| if attachment == nil { | ||
| return defaultGate | ||
| } | ||
|
|
||
| if attachment.Gate != nil { | ||
| return attachment.GetGate() | ||
| } | ||
|
|
||
| return defaultGate | ||
| } | ||
|
|
||
| // ComputeArguments takes a list of arguments, and matches it against the expected inputs. It also applies a set of interpolations if needed. | ||
| func ComputeArguments(name string, inputs []*v1.PolicyInput, args map[string]string, bindings map[string]string, logger *zerolog.Logger) (map[string]string, error) { | ||
| result := make(map[string]string) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure we want to disable this globally but instead you coudl add an annotation in your specific case?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that breaking change detection doesn't support inline comment ignores.
Also exceptions are only per file/directory level.
Given that we control the gRPC clients/servers that use these messages and that the
booltooptional booldoesn't imply a wire format change in PB, it should be safe to regenerate the bindings and update any other parts of the code that use this message.Also
buf breakingalways compares to latestmain. If this PR lands (with or without the exceptions, which we can also leave out), a subsequent PR won't raise a breaking change error - cc @jiparisThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, unfortunately
buf breakingdoesn't support inline ignores asbuf lintdoes. To be honest, I'm wondering how this is the first time we are facing this issue. Did we update buf recently?The only solution is adding this top level
exceptoption. The change tooptionalis safe, as it only affects to generated code. Wired bytes are exactly the same (although with different semantics from now on).