Goals
As an admin or maintainer (global or team), I want to create a new policy with a proprietary query that is owned by the policy so that my policy query is distinct and separate from other queries.
Overview
As part of #2711, policies will now be distinct entities with their own name, description and proprietary queries. Policies will no longer be associated with general queries. We need to create the supporting UI by adding new "Create Policy" and "Edit Policy" flows.
Figma
Add the ability to create and edit detailed policies and associated proprietary queries: https://www.figma.com/file/hdALBDsrti77QuDNSzLdkx/?node-id=2897%3A73534
Tasks
1

2

3
Parameters:
- query - The SQL query that is used to create the policy’s query (required). query cannot be specified if
query_id is - specified
- name - The name that is used to create the policy’s query (required)
- description - The description that is used to create the policy’s query
- query_id -
query_id cannot be specified if query is specified
Request:
{
“query”: “SELECT 1 FROM gatekeeper WHERE assessments_enabled = 1”,
“name”: “Is Gatekeeper enabled on macOS devices?”,
“description”: “Checks to make sure that the Gatekeeper feature is enabled on macOS devices. This feature enforces code signing and verifies downloaded applications before allowing them to run, thereby reducing the likelihood of inadvertently executing malware.”
}
Endpoint Description: Creates a new policy and associated proprietary query.
Response:
{
"policy": {
“query”: “SELECT 1 FROM gatekeeper WHERE assessments_enabled = 1”,
"name": "Is Gatekeeper enabled on macOS devices?",
“description”: “Checks to make sure that the Gatekeeper feature is enabled on macOS devices. This feature enforces code signing and verifies downloaded applications before allowing them to run, thereby reducing the likelihood of inadvertently executing malware.”
"resolution": "Some resolution steps",
"passing_host_count": 0,
"failing_host_count": 0
}
}
4

5
6
Endpoint Description: Modifies the policy and the query that the policy owns.
Parameters:
- query - the SQL query that is used to create the policy’s query
- name - the name that is used to create the policy’s query
- description - the description that is used to create the policy’s query
- resolution - the steps to resolve a policy
Request:
{
“name”: “Is Gatekeeper enabled?”,
}
Response:
{
"policy": {
"id": 2,
“query”: “SELECT 1 FROM gatekeeper WHERE assessments_enabled = 1”,
"name": "Is Gatekeeper enabled?",
“description”: “Checks to make sure that the Gatekeeper feature is enabled on macOS devices. This feature enforces code signing and verifies downloaded applications before allowing them to run, thereby reducing the likelihood of inadvertently executing malware.”
“resolution”: "Some resolution steps",
"passing_host_count": 0,
"failing_host_count": 0
}
}
7

8

Backend notes
As can be assumed from the API changes, the idea behind this is to reflect the query, description, and any other policy attribute in the policies table directly, just like we do with labels.
As part of this work, we need to migrate away from the previous setup and copy the queries and so on into the new table.
Here's a longer conversation about this #2711
Goals
As an admin or maintainer (global or team), I want to create a new policy with a proprietary query that is owned by the policy so that my policy query is distinct and separate from other queries.
Overview
As part of #2711, policies will now be distinct entities with their own name, description and proprietary queries. Policies will no longer be associated with general queries. We need to create the supporting UI by adding new "Create Policy" and "Edit Policy" flows.
Figma
Add the ability to create and edit detailed policies and associated proprietary queries: https://www.figma.com/file/hdALBDsrti77QuDNSzLdkx/?node-id=2897%3A73534
Tasks
1
/policies/newSELECT 1 FROM osquery_info WHERE start_time > 1;2
3
POST /api/v1/fleet/global/policiesPOST /api/v1/fleet/teams/{teamId}/policies/policies/{policyId}Parameters:
query_idis - specifiedquery_idcannot be specified if query is specifiedRequest:
Endpoint Description: Creates a new policy and associated proprietary query.
Response:
4
/policies/{policyId}5
/query/{queryId6
PATCH /api/v1/fleet/policies/1PATCH /api/v1/fleet/teams/{teamId}/policiesEndpoint Description: Modifies the policy and the query that the policy owns.
Parameters:
Request:
Response:
7
8
Backend notes
As can be assumed from the API changes, the idea behind this is to reflect the query, description, and any other policy attribute in the
policiestable directly, just like we do withlabels.As part of this work, we need to migrate away from the previous setup and copy the queries and so on into the new table.
Here's a longer conversation about this #2711