Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/cli/cmd/organization_describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package cmd

import (
"fmt"
"strings"

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

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

gt.AppendRow(table.Row{"Organization", orgInfo})
}

backend := config.CurrentCASBackend
Expand Down
14 changes: 9 additions & 5 deletions app/cli/cmd/organization_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@
package cmd

import (
"context"

"github.com/chainloop-dev/chainloop/app/cli/internal/action"
"github.com/spf13/cobra"
)

func newOrganizationUpdateCmd() *cobra.Command {
var (
orgName string
blockOnPolicyViolation bool
orgName string
blockOnPolicyViolation bool
policiesAllowedHostnames []string
)

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

_, err := action.NewOrgUpdate(actionOpts).Run(context.Background(), orgName, opts)
if cmd.Flags().Changed("policies-allowed-hostnames") {
opts.PoliciesAllowedHostnames = &policiesAllowedHostnames
}

_, err := action.NewOrgUpdate(actionOpts).Run(cmd.Context(), orgName, opts)
if err != nil {
return err
}
Expand All @@ -52,5 +55,6 @@ func newOrganizationUpdateCmd() *cobra.Command {
cobra.CheckErr(err)

cmd.Flags().BoolVar(&blockOnPolicyViolation, "block", false, "set the default policy violation blocking strategy")
cmd.Flags().StringSliceVar(&policiesAllowedHostnames, "policies-allowed-hostnames", []string{}, "set the allowed hostnames for the policy engine")
return cmd
}
7 changes: 4 additions & 3 deletions app/cli/documentation/cli-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2710,9 +2710,10 @@ chainloop organization update [flags]
Options

```
--block set the default policy violation blocking strategy
-h, --help help for update
--name string organization name
--block set the default policy violation blocking strategy
-h, --help help for update
--name string organization name
--policies-allowed-hostnames strings set the allowed hostnames for the policy engine
```

Options inherited from parent commands
Expand Down
2 changes: 1 addition & 1 deletion app/cli/internal/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func newCrafter(stateOpts *newCrafterStateOpts, conn *grpc.ClientConn, opts ...c
attestationStatePath = path
}

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

Expand Down
37 changes: 22 additions & 15 deletions app/cli/internal/action/attestation_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,9 @@ func (action *AttestationInit) Run(ctx context.Context, opts *AttestationInitRun

var (
// Identifier of this attestation instance
attestationID string
blockOnPolicyViolation bool
attestationID string
blockOnPolicyViolation bool
policiesAllowedHostnames []string
// Timestamp Authority URL for new attestations
timestampAuthorityURL, signingCAName string
)
Expand All @@ -197,14 +198,18 @@ func (action *AttestationInit) Run(ctx context.Context, opts *AttestationInitRun
return "", err
}

workflowRun := runResp.GetResult().GetWorkflowRun()
result := runResp.GetResult()
workflowRun := result.GetWorkflowRun()
workflowMeta.WorkflowRunId = workflowRun.GetId()
workflowMeta.Organization = runResp.GetResult().GetOrganization()
blockOnPolicyViolation = runResp.GetResult().GetBlockOnPolicyViolation()
timestampAuthorityURL = runResp.GetResult().GetSigningOptions().GetTimestampAuthorityUrl()
signingCAName = runResp.GetResult().GetSigningOptions().GetSigningCa()
if v := workflowMeta.Version; v != nil {
workflowMeta.Version.Prerelease = runResp.GetResult().GetWorkflowRun().Version.GetPrerelease()
workflowMeta.Organization = result.GetOrganization()
blockOnPolicyViolation = result.GetBlockOnPolicyViolation()
policiesAllowedHostnames = result.GetPoliciesAllowedHostnames()
signingOpts := result.GetSigningOptions()
timestampAuthorityURL = signingOpts.GetTimestampAuthorityUrl()
signingCAName = signingOpts.GetSigningCa()

if v := workflowMeta.Version; v != nil && workflowRun.GetVersion() != nil {
v.Prerelease = workflowRun.GetVersion().GetPrerelease()
}

action.Logger.Debug().Str("workflow-run-id", workflowRun.GetId()).Msg("attestation initialized in the control plane")
Expand All @@ -224,12 +229,14 @@ func (action *AttestationInit) Run(ctx context.Context, opts *AttestationInitRun
// NOTE: important to run this initialization here since workflowMeta is populated
// with the workflowRunId that comes from the control plane
initOpts := &crafter.InitOpts{
WfInfo: workflowMeta,
SchemaV1: contractVersion.GetV1(),
DryRun: action.dryRun,
AttestationID: attestationID,
Runner: discoveredRunner,
BlockOnPolicyViolation: blockOnPolicyViolation,
WfInfo: workflowMeta,
//nolint:staticcheck // TODO: Migrate to new contract version API
SchemaV1: contractVersion.GetV1(),
DryRun: action.dryRun,
AttestationID: attestationID,
Runner: discoveredRunner,
BlockOnPolicyViolation: blockOnPolicyViolation,
PoliciesAllowedHostnames: policiesAllowedHostnames,
SigningOptions: &crafter.SigningOpts{
TimestampAuthorityURL: timestampAuthorityURL,
SigningCAName: signingCAName,
Expand Down
8 changes: 5 additions & 3 deletions app/cli/internal/action/membership_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type OrgItem struct {
ID, Name string
CreatedAt *time.Time
PolicyViolationBlockingStrategy string
PolicyAllowedHostnames []string `json:"policyAllowedHostnames,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accidental annotation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope really, I wanted to hide this option if the default is set

}

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

func pbOrgItemToAction(in *pb.OrgItem) *OrgItem {
i := &OrgItem{
ID: in.Id,
Name: in.Name,
CreatedAt: toTimePtr(in.CreatedAt.AsTime()),
ID: in.Id,
Name: in.Name,
CreatedAt: toTimePtr(in.CreatedAt.AsTime()),
PolicyAllowedHostnames: in.PolicyAllowedHostnames,
}

if in.DefaultPolicyViolationStrategy == pb.OrgItem_POLICY_VIOLATION_BLOCKING_STRATEGY_BLOCK {
Expand Down
18 changes: 14 additions & 4 deletions app/cli/internal/action/org_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,24 @@ func NewOrgUpdate(cfg *ActionsOpts) *OrgUpdate {
}

type NewOrgUpdateOpts struct {
BlockOnPolicyViolation *bool
BlockOnPolicyViolation *bool
PoliciesAllowedHostnames *[]string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks a bit weird. Slices are pointers already and are nil if no initialized. No need to create a pointer to a pointer. Just keep in mind that len([]string(nil)) is 0

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checking, thanks

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated the pointer situation to leverage instead the duality of empty slice vs nil slice.

}

func (action *OrgUpdate) Run(ctx context.Context, name string, opts *NewOrgUpdateOpts) (*OrgItem, error) {
client := pb.NewOrganizationServiceClient(action.cfg.CPConnection)
resp, err := client.Update(ctx, &pb.OrganizationServiceUpdateRequest{
Name: name, BlockOnPolicyViolation: opts.BlockOnPolicyViolation,
})

payload := &pb.OrganizationServiceUpdateRequest{
Name: name,
BlockOnPolicyViolation: opts.BlockOnPolicyViolation,
}

if opts.PoliciesAllowedHostnames != nil {
payload.PoliciesAllowedHostnames = *opts.PoliciesAllowedHostnames
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what I mean, *variable shouldn't be needed for slices, since they are pointers anyways.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is about making sure we can detect when we want to update the value vs empty it. In any case I've implemented the same by using slices

payload.UpdatePoliciesAllowedHostnames = true
}

resp, err := client.Update(ctx, payload)
if err != nil {
return nil, err
}
Expand Down
Loading
Loading