Skip to content

Commit f584853

Browse files
authored
Revert "feat(policies): materials in policy groups (#1455)" (#1464)
Signed-off-by: Jose I. Paris <[email protected]>
1 parent 408ced7 commit f584853

17 files changed

+250
-608
lines changed

app/cli/internal/action/attestation_init.go

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@ import (
2222
"strconv"
2323

2424
pb "github.com/chainloop-dev/chainloop/app/controlplane/api/controlplane/v1"
25-
v1 "github.com/chainloop-dev/chainloop/app/controlplane/api/workflowcontract/v1"
2625
"github.com/chainloop-dev/chainloop/pkg/attestation/crafter"
2726
clientAPI "github.com/chainloop-dev/chainloop/pkg/attestation/crafter/api/attestation/v1"
28-
"github.com/chainloop-dev/chainloop/pkg/policies"
29-
"github.com/rs/zerolog"
3027
)
3128

3229
type AttestationInitOpts struct {
@@ -129,12 +126,6 @@ func (action *AttestationInit) Run(ctx context.Context, opts *AttestationInitRun
129126

130127
action.Logger.Debug().Msg("workflow contract and metadata retrieved from the control plane")
131128

132-
// 3. enrich contract with group materials and policies
133-
err = enrichContractMaterials(ctx, contractVersion.GetV1(), client, &action.Logger)
134-
if err != nil {
135-
return "", fmt.Errorf("failed to apply materials from policy groups: %w", err)
136-
}
137-
138129
// Auto discover the runner context and enforce against the one in the contract if needed
139130
discoveredRunner, err := crafter.DiscoverAndEnforceRunner(contractVersion.GetV1().GetRunner().GetType(), action.dryRun, action.Logger)
140131
if err != nil {
@@ -173,8 +164,7 @@ func (action *AttestationInit) Run(ctx context.Context, opts *AttestationInitRun
173164
// NOTE: important to run this initialization here since workflowMeta is populated
174165
// with the workflowRunId that comes from the control plane
175166
initOpts := &crafter.InitOpts{
176-
WfInfo: workflowMeta,
177-
SchemaV1: contractVersion.GetV1(),
167+
WfInfo: workflowMeta, SchemaV1: contractVersion.GetV1(),
178168
DryRun: action.dryRun,
179169
AttestationID: attestationID,
180170
Runner: discoveredRunner,
@@ -196,44 +186,3 @@ func (action *AttestationInit) Run(ctx context.Context, opts *AttestationInitRun
196186

197187
return attestationID, nil
198188
}
199-
200-
func enrichContractMaterials(ctx context.Context, schema *v1.CraftingSchema, client pb.AttestationServiceClient, logger *zerolog.Logger) error {
201-
contractMaterials := schema.GetMaterials()
202-
for _, pgAtt := range schema.GetPolicyGroups() {
203-
group, _, err := policies.LoadPolicyGroup(ctx, pgAtt, &policies.LoadPolicyGroupOptions{
204-
Client: client,
205-
Logger: logger,
206-
})
207-
if err != nil {
208-
return fmt.Errorf("failed to load policy group: %w", err)
209-
}
210-
logger.Debug().Msgf("adding materials from policy group '%s'", group.GetMetadata().GetName())
211-
212-
toAdd := getGroupMaterialsToAdd(group, contractMaterials, logger)
213-
contractMaterials = append(contractMaterials, toAdd...)
214-
}
215-
216-
schema.Materials = contractMaterials
217-
218-
return nil
219-
}
220-
221-
// merge existing materials with group ones, taking the contract's one in case of conflict
222-
func getGroupMaterialsToAdd(group *v1.PolicyGroup, fromContract []*v1.CraftingSchema_Material, logger *zerolog.Logger) []*v1.CraftingSchema_Material {
223-
toAdd := make([]*v1.CraftingSchema_Material, 0)
224-
for _, groupMaterial := range group.GetSpec().GetPolicies().GetMaterials() {
225-
// check if material already exists in the contract and skip it in that case
226-
ignore := false
227-
for _, mat := range fromContract {
228-
if mat.GetName() == groupMaterial.GetName() {
229-
logger.Warn().Msgf("material '%s' from policy group '%s' is also present in the contract and will be ignored", mat.GetName(), group.GetMetadata().GetName())
230-
ignore = true
231-
}
232-
}
233-
if !ignore {
234-
toAdd = append(toAdd, groupMaterial)
235-
}
236-
}
237-
238-
return toAdd
239-
}

app/cli/internal/action/attestation_init_test.go

Lines changed: 0 additions & 101 deletions
This file was deleted.

app/cli/internal/action/testdata/policy_group.yaml

Lines changed: 0 additions & 18 deletions
This file was deleted.

app/controlplane/api/gen/frontend/workflowcontract/v1/crafting_schema.ts

Lines changed: 7 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/api/gen/jsonschema/workflowcontract.v1.CraftingSchema.Material.jsonschema.json

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/api/gen/jsonschema/workflowcontract.v1.CraftingSchema.Material.schema.json

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/api/gen/jsonschema/workflowcontract.v1.PolicyGroup.GroupPolicies.jsonschema.json

Lines changed: 0 additions & 21 deletions
This file was deleted.

app/controlplane/api/gen/jsonschema/workflowcontract.v1.PolicyGroup.GroupPolicies.schema.json

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)