Skip to content

Commit e0d32ff

Browse files
authored
feat: support storage and use of custom rego engine hostnames (#2315)
Signed-off-by: Miguel Martinez <[email protected]>
1 parent 971be38 commit e0d32ff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1547
-862
lines changed

app/cli/cmd/organization_describe.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package cmd
1717

1818
import (
1919
"fmt"
20+
"strings"
2021

2122
"github.com/chainloop-dev/chainloop/app/cli/internal/action"
2223
"github.com/jedib0t/go-pretty/v6/table"
@@ -48,7 +49,12 @@ func contextTableOutput(config *action.ConfigContextItem) error {
4849
gt.AppendSeparator()
4950

5051
if m := config.CurrentMembership; m != nil {
51-
gt.AppendRow(table.Row{"Organization", fmt.Sprintf("%s (role=%s)\nPolicy strategy=%s", m.Org.Name, m.Role, m.Org.PolicyViolationBlockingStrategy)})
52+
orgInfo := fmt.Sprintf("%s (role=%s)\nPolicy strategy=%s", m.Org.Name, m.Role, m.Org.PolicyViolationBlockingStrategy)
53+
if len(m.Org.PolicyAllowedHostnames) > 0 {
54+
orgInfo += fmt.Sprintf("\nPolicy allowed hostnames: %v", strings.Join(m.Org.PolicyAllowedHostnames, ", "))
55+
}
56+
57+
gt.AppendRow(table.Row{"Organization", orgInfo})
5258
}
5359

5460
backend := config.CurrentCASBackend

app/cli/cmd/organization_update.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@
1616
package cmd
1717

1818
import (
19-
"context"
20-
2119
"github.com/chainloop-dev/chainloop/app/cli/internal/action"
2220
"github.com/spf13/cobra"
2321
)
2422

2523
func newOrganizationUpdateCmd() *cobra.Command {
2624
var (
27-
orgName string
28-
blockOnPolicyViolation bool
25+
orgName string
26+
blockOnPolicyViolation bool
27+
policiesAllowedHostnames []string
2928
)
3029

3130
cmd := &cobra.Command{
@@ -37,7 +36,11 @@ func newOrganizationUpdateCmd() *cobra.Command {
3736
opts.BlockOnPolicyViolation = &blockOnPolicyViolation
3837
}
3938

40-
_, err := action.NewOrgUpdate(actionOpts).Run(context.Background(), orgName, opts)
39+
if cmd.Flags().Changed("policies-allowed-hostnames") {
40+
opts.PoliciesAllowedHostnames = &policiesAllowedHostnames
41+
}
42+
43+
_, err := action.NewOrgUpdate(actionOpts).Run(cmd.Context(), orgName, opts)
4144
if err != nil {
4245
return err
4346
}
@@ -52,5 +55,6 @@ func newOrganizationUpdateCmd() *cobra.Command {
5255
cobra.CheckErr(err)
5356

5457
cmd.Flags().BoolVar(&blockOnPolicyViolation, "block", false, "set the default policy violation blocking strategy")
58+
cmd.Flags().StringSliceVar(&policiesAllowedHostnames, "policies-allowed-hostnames", []string{}, "set the allowed hostnames for the policy engine")
5559
return cmd
5660
}

app/cli/documentation/cli-reference.mdx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2710,9 +2710,10 @@ chainloop organization update [flags]
27102710
Options
27112711

27122712
```
2713-
--block set the default policy violation blocking strategy
2714-
-h, --help help for update
2715-
--name string organization name
2713+
--block set the default policy violation blocking strategy
2714+
-h, --help help for update
2715+
--name string organization name
2716+
--policies-allowed-hostnames strings set the allowed hostnames for the policy engine
27162717
```
27172718

27182719
Options inherited from parent commands

app/cli/internal/action/action.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func newCrafter(stateOpts *newCrafterStateOpts, conn *grpc.ClientConn, opts ...c
8181
attestationStatePath = path
8282
}
8383

84-
c.Logger.Debug().Str("path", attestationStatePath).Msg("using local state")
84+
c.Logger.Debug().Str("path", fmt.Sprintf("file:%s", attestationStatePath)).Msg("using local state")
8585
stateManager, err = filesystem.New(attestationStatePath)
8686
}
8787

app/cli/internal/action/attestation_init.go

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,9 @@ func (action *AttestationInit) Run(ctx context.Context, opts *AttestationInitRun
173173

174174
var (
175175
// Identifier of this attestation instance
176-
attestationID string
177-
blockOnPolicyViolation bool
176+
attestationID string
177+
blockOnPolicyViolation bool
178+
policiesAllowedHostnames []string
178179
// Timestamp Authority URL for new attestations
179180
timestampAuthorityURL, signingCAName string
180181
)
@@ -197,14 +198,18 @@ func (action *AttestationInit) Run(ctx context.Context, opts *AttestationInitRun
197198
return "", err
198199
}
199200

200-
workflowRun := runResp.GetResult().GetWorkflowRun()
201+
result := runResp.GetResult()
202+
workflowRun := result.GetWorkflowRun()
201203
workflowMeta.WorkflowRunId = workflowRun.GetId()
202-
workflowMeta.Organization = runResp.GetResult().GetOrganization()
203-
blockOnPolicyViolation = runResp.GetResult().GetBlockOnPolicyViolation()
204-
timestampAuthorityURL = runResp.GetResult().GetSigningOptions().GetTimestampAuthorityUrl()
205-
signingCAName = runResp.GetResult().GetSigningOptions().GetSigningCa()
206-
if v := workflowMeta.Version; v != nil {
207-
workflowMeta.Version.Prerelease = runResp.GetResult().GetWorkflowRun().Version.GetPrerelease()
204+
workflowMeta.Organization = result.GetOrganization()
205+
blockOnPolicyViolation = result.GetBlockOnPolicyViolation()
206+
policiesAllowedHostnames = result.GetPoliciesAllowedHostnames()
207+
signingOpts := result.GetSigningOptions()
208+
timestampAuthorityURL = signingOpts.GetTimestampAuthorityUrl()
209+
signingCAName = signingOpts.GetSigningCa()
210+
211+
if v := workflowMeta.Version; v != nil && workflowRun.GetVersion() != nil {
212+
v.Prerelease = workflowRun.GetVersion().GetPrerelease()
208213
}
209214

210215
action.Logger.Debug().Str("workflow-run-id", workflowRun.GetId()).Msg("attestation initialized in the control plane")
@@ -224,12 +229,14 @@ func (action *AttestationInit) Run(ctx context.Context, opts *AttestationInitRun
224229
// NOTE: important to run this initialization here since workflowMeta is populated
225230
// with the workflowRunId that comes from the control plane
226231
initOpts := &crafter.InitOpts{
227-
WfInfo: workflowMeta,
228-
SchemaV1: contractVersion.GetV1(),
229-
DryRun: action.dryRun,
230-
AttestationID: attestationID,
231-
Runner: discoveredRunner,
232-
BlockOnPolicyViolation: blockOnPolicyViolation,
232+
WfInfo: workflowMeta,
233+
//nolint:staticcheck // TODO: Migrate to new contract version API
234+
SchemaV1: contractVersion.GetV1(),
235+
DryRun: action.dryRun,
236+
AttestationID: attestationID,
237+
Runner: discoveredRunner,
238+
BlockOnPolicyViolation: blockOnPolicyViolation,
239+
PoliciesAllowedHostnames: policiesAllowedHostnames,
233240
SigningOptions: &crafter.SigningOpts{
234241
TimestampAuthorityURL: timestampAuthorityURL,
235242
SigningCAName: signingCAName,

app/cli/internal/action/membership_list.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type OrgItem struct {
3232
ID, Name string
3333
CreatedAt *time.Time
3434
PolicyViolationBlockingStrategy string
35+
PolicyAllowedHostnames []string `json:"policyAllowedHostnames,omitempty"`
3536
}
3637

3738
type MembershipItem struct {
@@ -129,9 +130,10 @@ func (action *MembershipList) ListMembers(ctx context.Context, page int, pageSiz
129130

130131
func pbOrgItemToAction(in *pb.OrgItem) *OrgItem {
131132
i := &OrgItem{
132-
ID: in.Id,
133-
Name: in.Name,
134-
CreatedAt: toTimePtr(in.CreatedAt.AsTime()),
133+
ID: in.Id,
134+
Name: in.Name,
135+
CreatedAt: toTimePtr(in.CreatedAt.AsTime()),
136+
PolicyAllowedHostnames: in.PolicyAllowedHostnames,
135137
}
136138

137139
if in.DefaultPolicyViolationStrategy == pb.OrgItem_POLICY_VIOLATION_BLOCKING_STRATEGY_BLOCK {

app/cli/internal/action/org_update.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,24 @@ func NewOrgUpdate(cfg *ActionsOpts) *OrgUpdate {
3030
}
3131

3232
type NewOrgUpdateOpts struct {
33-
BlockOnPolicyViolation *bool
33+
BlockOnPolicyViolation *bool
34+
PoliciesAllowedHostnames *[]string
3435
}
3536

3637
func (action *OrgUpdate) Run(ctx context.Context, name string, opts *NewOrgUpdateOpts) (*OrgItem, error) {
3738
client := pb.NewOrganizationServiceClient(action.cfg.CPConnection)
38-
resp, err := client.Update(ctx, &pb.OrganizationServiceUpdateRequest{
39-
Name: name, BlockOnPolicyViolation: opts.BlockOnPolicyViolation,
40-
})
39+
40+
payload := &pb.OrganizationServiceUpdateRequest{
41+
Name: name,
42+
BlockOnPolicyViolation: opts.BlockOnPolicyViolation,
43+
}
44+
45+
if opts.PoliciesAllowedHostnames != nil {
46+
payload.PoliciesAllowedHostnames = *opts.PoliciesAllowedHostnames
47+
payload.UpdatePoliciesAllowedHostnames = true
48+
}
49+
50+
resp, err := client.Update(ctx, payload)
4151
if err != nil {
4252
return nil, err
4353
}

0 commit comments

Comments
 (0)