Skip to content

Commit 9c207d5

Browse files
authored
feat: brings back local attestation protection (#510)
Signed-off-by: Miguel Martinez Trivino <[email protected]>
1 parent ecd42ad commit 9c207d5

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

app/cli/cmd/attestation_init.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
func newAttestationInitCmd() *cobra.Command {
2828
var (
29+
force bool
2930
contractRevision int
3031
attestationDryRun bool
3132
)
@@ -41,6 +42,7 @@ func newAttestationInitCmd() *cobra.Command {
4142
&action.AttestationInitOpts{
4243
ActionsOpts: actionOpts,
4344
DryRun: attestationDryRun,
45+
Force: force,
4446
},
4547
)
4648
if err != nil {
@@ -76,6 +78,8 @@ func newAttestationInitCmd() *cobra.Command {
7678
},
7779
}
7880

81+
// This option is only useful for local-based attestation states
82+
cmd.Flags().BoolVarP(&force, "replace", "f", false, "replace any existing in-progress attestation")
7983
cmd.Flags().BoolVar(&attestationDryRun, "dry-run", false, "do not record attestation in the control plane, useful for development")
8084
cmd.Flags().IntVar(&contractRevision, "contract-revision", 0, "revision of the contract to retrieve, \"latest\" by default")
8185

app/cli/internal/action/attestation_init.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@ import (
2929
type AttestationInitOpts struct {
3030
*ActionsOpts
3131
DryRun bool
32+
// Force the initialization and override any existing, in-progress ones.
33+
// Note that this is only useful when local-based attestation state is configured
34+
// since it's a protection to make sure you don't override the state by mistake
35+
Force bool
3236
}
3337

3438
type AttestationInit struct {
3539
*ActionsOpts
36-
dryRun bool
37-
c *crafter.Crafter
40+
dryRun, force bool
41+
c *crafter.Crafter
3842
}
3943

4044
// ErrAttestationAlreadyExist means that there is an attestation in progress
@@ -58,6 +62,7 @@ func NewAttestationInit(cfg *AttestationInitOpts) (*AttestationInit, error) {
5862
ActionsOpts: cfg.ActionsOpts,
5963
c: c,
6064
dryRun: cfg.DryRun,
65+
force: cfg.Force,
6166
}, nil
6267
}
6368

@@ -67,6 +72,14 @@ func (action *AttestationInit) Run(ctx context.Context, contractRevision int) (s
6772
return "", errors.New("remote state is not compatible with dry-run mode")
6873
}
6974

75+
// During local initializations we need to make sure if there is already an attestation in progress
76+
// If it is and we are not "forcing" the initialization, we should return an error
77+
if !action.UseAttestationRemoteState && !action.force {
78+
if initialized, _ := action.c.AlreadyInitialized(ctx, ""); initialized {
79+
return "", ErrAttestationAlreadyExist
80+
}
81+
}
82+
7083
action.Logger.Debug().Msg("Retrieving attestation definition")
7184
client := pb.NewAttestationServiceClient(action.ActionsOpts.CPConnection)
7285
// get information of the workflow

0 commit comments

Comments
 (0)