Agent risk assessments and evidence¶
In the following examples, client is an AgentManagementClient created as described in The main AgentManagementClient class. Managing an assessment requires the appropriate agent risk-management rights.
Reading an assessment¶
agent = client.get_agent("production", "support-agent")
assessment = agent.get_risk_assessment()
for association in assessment.raw["assessment"]["associatedRisks"]:
print(association["riskId"], association["likelihood"], association["impact"])
Risk and control IDs must exist in the current taxonomy. This example lists the available agent risks and controls.
taxonomy = client.get_risk_taxonomy().raw["taxonomy"]
for category in taxonomy["agentCategories"]:
for risk in category["risks"]:
print(risk["id"], risk["title"])
for control in risk["controls"]:
print(" ", control["id"], control["description"])
Associating a risk and updating ratings¶
Replace risk-id-from-taxonomy with an ID from the preceding listing. Preserve other associations and controls when updating one risk.
risk_id = "risk-id-from-taxonomy"
assessment = agent.get_risk_assessment()
associations = assessment.raw["assessment"]["associatedRisks"]
association = next(
(item for item in associations if item["riskId"] == risk_id),
None,
)
if association is None:
association = {"riskId": risk_id, "controls": {}}
associations.append(association)
association["likelihood"] = 3
association["impact"] = 4
assessment.save()
Ratings range from 0 to 5; 0 represents an intentionally unscored risk. Saving checks the retrieved fetchedRevision to detect concurrent changes.
Adding control evidence¶
Choose a control belonging to the selected risk. The following example marks it implemented and attaches a comment. Evidence IDs must be unique within the assessment.
from uuid import uuid4
control_id = "control-id-from-that-risk"
assessment = agent.get_risk_assessment()
association = next(
item for item in assessment.raw["assessment"]["associatedRisks"]
if item["riskId"] == risk_id
)
control = association["controls"].setdefault(
control_id, {"implemented": False, "evidences": []}
)
control["implemented"] = True
control["evidences"].append({
"id": uuid4().hex,
"type": "COMMENT",
"title": "Access review",
"comment": "Reviewed the agent's access to customer data.",
})
assessment.save()
For a link, use type="LINK" and an url field. Evidence belongs to an implemented control; evidence attached to an unimplemented control is cleared when saving.
Uploading a document¶
The document evidence must be present in the assessment, and the key in documents must match its evidence ID. This example continues with the implemented control from the preceding example.
assessment = agent.get_risk_assessment()
association = next(
item for item in assessment.raw["assessment"]["associatedRisks"]
if item["riskId"] == risk_id
)
control = association["controls"][control_id]
evidence_id = uuid4().hex
control["evidences"].append({
"id": evidence_id,
"type": "DOCUMENT",
"title": "Access review report",
})
with open("access-review.pdf", "rb") as document:
assessment.save(documents={evidence_id: ("access-review.pdf", document)})
saved_association = next(
item for item in assessment.raw["assessment"]["associatedRisks"]
if item["riskId"] == risk_id
)
evidence_id = saved_association["controls"][control_id]["evidences"][-1]["id"]
The server assigns a new ID to each new evidence entry. After saving, read this ID from the updated assessment. The example selects the document just added to the control.
Downloading a document¶
with assessment.get_risk_evidence_content(evidence_id) as response:
with open("downloaded-access-review.pdf", "wb") as output:
for chunk in response.iter_content(chunk_size=65536):
output.write(chunk)
Signing off an assessment¶
Signing off an assessment records that a user has validated it. Use authentication with an associated user, such as a personal API key, to record who signs off the assessment.
assessment = agent.set_risk_assessment_signed_off(True)
print(assessment.raw["assessment"].get("signOff"))
# Remove the validation:
assessment = agent.set_risk_assessment_signed_off(False)
For taxonomy administration and aggregated exposure, see Risk taxonomy and overall exposure.
Reference documentation¶
Classes¶
The risk assessment of a monitored agent, including its evidence documents. |
Functions¶
|
Returns a handle to an agent. |
Returns the risk assessment of this agent. |
|
|
Downloads the content of a document attached as evidence in this assessment. |
Returns the Agent Management risk taxonomy settings. |
|
|
Saves the risk assessment and optionally uploads document evidence. |
|
Sets whether the current risk assessment is validated. |
