Skip to content
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

Feature/272 manual step api implementation #275

Open
wants to merge 63 commits into
base: development
Choose a base branch
from

Conversation

lucamrgs
Copy link
Collaborator

@lucamrgs lucamrgs commented Dec 4, 2024

No description provided.

@lucamrgs lucamrgs linked an issue Dec 4, 2024 that may be closed by this pull request
Copy link

github-actions bot commented Dec 4, 2024

Sigrid maintainability feedback

✅ You wrote maintainable code and achieved your objective of 3.8 stars

Show details

Sigrid compared your code against the baseline of 2025-01-16.

👍 What went well?

You fixed or improved 0 refactoring candidates.

👎 What could be better?

Unfortunately, 21 refactoring candidates were introduced or got worse.

Risk System property Location
🔴 Duplication
(Introduced)
pkg/models/cacao/cacao.go (lines 282-294)
pkg/models/decoder/decoder.go (lines 50-62)
🔴 Duplication
(Introduced)
pkg/core/capability/fin/controller/controller.go (lines 104-110)
pkg/core/capability/fin/controller/controller.go (lines 132-138)
🟠 Unit Size
(Worsened)
internal/controller/controller.go
initializeCore(app *gin.Engine)
🟠 Unit Size
(Introduced)
pkg/api/manual/manual_api.go
ManualHandler.PostContinue(g *gin.Context)
🟡 Unit Size
(Introduced)
pkg/api/manual/manual_api.go
ManualHandler.parseCommandInfoToResponse(commandInfo manual.CommandInfo)
🟡 Unit Size
(Introduced)
pkg/api/manual/manual_api.go
ManualHandler.GetPendingCommands(g *gin.Context)
🟡 Unit Size
(Introduced)
pkg/api/manual/manual_api.go
ManualHandler.parseManualResponseToInteractionResponse(response api.ManualOutArgsUpdatePayload)
🟡 Unit Size
(Introduced)
pkg/api/manual/manual_api.go
ManualHandler.GetPendingCommand(g *gin.Context)
⚫️ + 13 more

📚 Remaining technical debt

9 refactoring candidates didn't get better or worse, but are still present in the code you touched.

View this system in Sigrid** to explore your technical debt

⭐️ Sigrid ratings

System property System on 2025-01-16 Before changes New/changed code
Volume 5.4 N/A N/A
Duplication 4.4 5.1 4.9
Unit Size 2.6 2.8 2.5
Unit Complexity 3.0 2.4 2.9
Unit Interfacing 3.1 5.1 5.3
Module Coupling 3.8 5.5 5.5
Component Independence 0.5 N/A N/A
Component Entanglement 2.5 N/A N/A
Maintainability 3.2 4.0 4.1

💬 Did you find this feedback helpful?

We would like to know your thoughts to make Sigrid better.
Your username will remain confidential throughout the process.


View this system in Sigrid

@lucamrgs
Copy link
Collaborator Author

lucamrgs commented Dec 4, 2024

Documentation needs to be adapted to these changes

@MaartendeKruijf MaartendeKruijf force-pushed the feature/272-manual-step-api-implementation branch 2 times, most recently from b077d25 to bc0953a Compare December 11, 2024 16:03
@MaartendeKruijf MaartendeKruijf force-pushed the feature/272-manual-step-api-implementation branch from a2429cf to b84ef03 Compare December 20, 2024 10:31
@lucamrgs
Copy link
Collaborator Author

Thanks @MaartendeKruijf for rebasing in the middle of my edits on the draft pull request

@lucamrgs
Copy link
Collaborator Author

I think we need to fix a couple things trough the way that out args would be passed down to the manual command capability

@lucamrgs lucamrgs marked this pull request as ready for review December 23, 2024 13:14
@lucamrgs lucamrgs marked this pull request as draft December 23, 2024 13:16
@lucamrgs
Copy link
Collaborator Author

Next on todo is connect manual capability / interaction objects to initialisation controller, and test the APIs

@lucamrgs lucamrgs marked this pull request as ready for review January 10, 2025 08:58
@@ -153,8 +154,8 @@ None
404/Not found with payload:
General error

#### POST `/manual/continue`
Respond to manual command pending in SOARCA, if out_args are defined they must be filled in and returned in the payload body. Only value is required in the response of the variable. You can however return the entire object. Of the object does not match the original out_arg the call we be considered as failed.
#### PATCH `/manual/<execution-id>/<step-id>`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this changed to PATCH and has a different route

@@ -45,7 +46,7 @@ None
|step_id |UUID |string |The id of the step executed by the execution
|description |description of the step|string |The description from the workflow step
|command |command |string |The command for the agent either command
|command_is_base64 |true \| false |bool |Indicate the command is in base 64
Copy link
Collaborator

Choose a reason for hiding this comment

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

Revert this to the bool

@@ -45,7 +46,7 @@ None
|step_id |UUID |string |The id of the step executed by the execution
|description |description of the step|string |The description from the workflow step
|command |command |string |The command for the agent either command
|command_is_base64 |true \| false |bool |Indicate the command is in base 64
Copy link
Collaborator

Choose a reason for hiding this comment

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

Revert this to the bool

|response_status |enum |string |Can be either `success` or `failed`
|response_out_args |cacao variables |dictionary |Map of [cacao variables](https://docs.oasis-open.org/cacao/security-playbooks/v2.0/cs01/security-playbooks-v2.0-cs01.html#_Toc152256555) handled in the step out args with current values and definitions

|response_status |true / false |string |`true` indicates successfull fulfilment of the manual request. `false` indicates failed satisfaction of request
Copy link
Collaborator

Choose a reason for hiding this comment

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

revert

control "ThirdPartyManualIntegration" as 3ptool


manual -> interaction : Queue(command, capabilityChannel)
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe move the native implementation sequence to be the first


metadata, err := manualController.makeExecutionMetadataFromPayload(result)
if err != nil {
return http.StatusBadRequest, err
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove the http details from here check for it in the api

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added some custom errors in the manual model, and now checking for those types on the API side. Let me know what you think about it this way.

// then warn if any value outside "value" has changed
if pending, ok := pendingEntry.CommandData.OutVariables[varName]; ok {
if variable.Constant != pending.Constant {
log.Warningf("provided out arg %s is attempting to change 'Constant' property", varName)
Copy link
Collaborator

Choose a reason for hiding this comment

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

also include into the message the attempted action is not effectuated

Comment on lines 115 to 110
// Check register for pending manual command
metadata, err := manualController.makeExecutionMetadataFromPayload(result.Payload)
if err != nil {
log.Error(err)
manualComms.Channel <- manual.InteractionResponse{
ResponseError: err,
Payload: cacao.Variables{},
}
return
}
// Remove interaction from pending ones
err = manualController.removeInteractionFromPending(metadata)
if err != nil {
// If it was not there, was already resolved
log.Warning(err)
// Captured if channel not yet closed
log.Warning("manual command not found among pending ones. should be already resolved")
manualComms.Channel <- manual.InteractionResponse{
ResponseError: err,
Payload: cacao.Variables{},
}
return
}

// Copy result and conversion back to interactionResponse format
returnedVars := manualController.copyOutArgsToVars(result.Payload.ResponseOutArgs)

interactionResponse := manual.InteractionResponse{
ResponseError: result.ResponseError,
Payload: returnedVars,
}

manualComms.Channel <- interactionResponse
return
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move to separate function

for {
select {
case <-manualComms.TimeoutContext.Done():
log.Info("context canceled due to response or timeout. exiting goroutine")
Copy link
Collaborator

Choose a reason for hiding this comment

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

call removeInteractionFromPending

Comment on lines 10 to 14
// ################################################################################
// Data structures for native SOARCA manual command handling
// ################################################################################

// Object stored in interaction storage and provided back from the API
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move the api models to the api folder

Comment on lines 365 to 366
3ptool --> interaction : integrationChannel <- InteractionIntegrationResponse
interaction --> manual : capabilityChannel <- InteractionResponse
Copy link
Collaborator

Choose a reason for hiding this comment

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

Merge intergration and interaction channel into one

@lucamrgs lucamrgs marked this pull request as draft January 17, 2025 16:29
@lucamrgs lucamrgs force-pushed the feature/272-manual-step-api-implementation branch from d7fafe1 to 5a4f8af Compare January 20, 2025 13:50
@lucamrgs lucamrgs marked this pull request as ready for review January 20, 2025 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

manual step api implementation
2 participants