-
Notifications
You must be signed in to change notification settings - Fork 0
/
plan.go
361 lines (305 loc) · 13.8 KB
/
plan.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
package domain
import (
"errors"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// Plan An assessment plan, such as those provided by a FedRAMP assessor.
// Here are some real-world examples for Assets, Platforms, Subjects and Inventory Items within an OSCAL Assessment Plan:
// 1. Assets: This could be something like a customer database within a retail company. It's an asset because it's crucial to the business operation, storing all the essential customer details such as addresses, contact information, and purchase history.
// 2. Platforms: This could be the retail company's online E-commerce platform which hosts their online store, and where transactions occur. The platform might involve web servers, database servers, or a cloud environment.
// 3. Subjects: If the company is performing a security assessment, the subject could be the encryption method or security protocols used to protect the customer data while in transit or at rest in the database.
// 4. Inventory Items: These could be the individual servers or workstations used within the company. Inventory workstations are the physical machines or software applications used by employees that may have vulnerabilities or exposure to risk that need to be tracked and mitigated.
//
// Relation between Tasks, Activities and Steps:
//
// Scenario: Conducting a cybersecurity assessment of an organization's systems.
//
// 1. Task: The major task could be "Conduct vulnerability scanning on servers."
// 2. Activity: Within this task, an activity could be "Prepare servers for vulnerability scan."
// 3. Step: The steps that make up this activity could be things like:
// - "Identify all servers"
// - "Ensure necessary permissions are in place for scanning"
// - "Check that scanning software is properly installed and updated."
//
// Another activity under the same task could be "Execute vulnerability scanning," and steps for that activity might include:
//
// 1. "Begin scanning process through scanning software."
// 2. "Monitor progress of scan."
// 3. "Document any issues or vulnerabilities identified."
//
// The process would continue like this with tasks broken down into activities, and activities broken down into steps.
//
// These concepts still apply in the context of automated tools or systems. In fact, the OSCAL model is designed to support both manual and automated processes.
// 1. Task: The major task could be “Automated Compliance Checking”
// 2. Activity: This task could have multiple activities such as:
// ▪ “Configure Automated Tool with necessary parameters”
// ▪ “Run Compliance Check”
// ▪ “Collect and Analyze Compliance Data”
// 3. Step: In each of these activities, there are several subprocesses or actions (Steps). For example, under “Configure Automated Tool with necessary parameters”, the steps could be:
// ▪ “Define the criteria based on selected standards”
// ▪ “Set the scope or target systems for the assessment”
// ▪ “Specify the output (report) format”
// In context of an automated compliance check, the description of Task, Activity, and Step provides a systematic plan or procedure that the tool is expected to follow. This breakdown of tasks, activities, and steps could also supply useful context and explain the tool’s operation and results to system admins, auditors or other stakeholders. It also allows for easier troubleshooting in the event of problems.
type Plan struct {
Id primitive.ObjectID `bson:"_id,omitempty" json:"id"`
// Status The status of the assessment plan, such as "active" or "inactive".
// These statuses are subject to change.
Status string `json:"status,omitempty"`
// We might switch to struct embedding for fields like Metadata, Props, etc.
Metadata Metadata `json:"metadata"`
// Tasks Represents a scheduled event or milestone, which may be associated with a series of assessment actions.
Tasks []Task `json:"tasks"`
// Title A name given to the assessment plan. OSCAL doesn't have this, but we need it for our use case.
Title string `json:"title,omitempty"`
// The following fields are part of the OSCAL spec, but we don't use them yet.
// Assets Identifies the assets used to perform this assessment, such as the assessment team, scanning tools, and assumptions. Mostly CF in our case.
Assets Assets `json:"assets"`
// BackMatter A collection of resources that may be referenced from within the OSCAL document instance.
BackMatter BackMatter `json:"backMatter"`
// Reference to a System Security Plan
ImportSSP string `json:"importSSP"`
// LocalDefinitions Used to define data objects that are used in the assessment plan, that do not appear in the referenced SSP.
// Reference to LocalDefinition
LocalDefinitions LocalDefinition `json:"localDefinitions"`
// ReviewedControls Identifies the controls being assessed and their control objectives.
ReviewedControls []ControlsAndObjectives `json:"reviewedControls"`
// TermsAndConditions Used to define various terms and conditions under which an assessment, described by the plan, can be performed. Each child part defines a different type of term or condition.
TermsAndConditions []Part `json:"termsAndConditions"`
Results []Result `json:"results"`
}
func NewPlan() *Plan {
revision := NewRevision("Initial version", "Initial version", "")
metadata := Metadata{
Revisions: []Revision{revision},
Actions: []Action{
{
Id: primitive.NewObjectID(),
Title: "Create",
},
},
}
return &Plan{
Metadata: metadata,
Tasks: []Task{},
Assets: Assets{
Components: []primitive.ObjectID{},
Platforms: []primitive.ObjectID{},
},
Status: "inactive",
Results: make([]Result, 0),
}
}
func (p *Plan) AddAsset(assetId string, assetType string) error {
oid, err := primitive.ObjectIDFromHex(assetId)
if err != nil {
return err
}
if assetType == "component" {
p.Assets.Components = append(p.Assets.Components, oid)
} else if assetType == "platform" {
p.Assets.Platforms = append(p.Assets.Components, oid)
}
return nil
}
func (p *Plan) GetTask(id string) *Task {
oid, err := primitive.ObjectIDFromHex(id)
if err != nil {
return nil
}
for _, task := range p.Tasks {
if task.Id == oid {
return &task
}
}
return nil
}
func (p *Plan) Ready() bool {
// If there are no Tasks then there's nothing to run.
if len(p.Tasks) == 0 {
return false
}
// Check if the tasks have at least one activity and all activities have valid subjects.
for _, task := range p.Tasks {
if len(task.Activities) == 0 {
return false
}
for _, activity := range task.Activities {
if !activity.Subjects.Valid() {
return false
}
}
}
return true
}
func (p *Plan) JobSpecification() JobSpecification {
// TODO: We need to send component and control ids as well
jobSpec := JobSpecification{
Id: p.Id.Hex(),
ControlId: NewUuid().String(),
ComponentId: NewUuid().String(),
Title: p.Title,
PlanId: p.Id.Hex(),
}
for _, task := range p.Tasks {
taskInfo := TaskInformation{
Id: task.Id.Hex(),
Title: task.Title,
Schedule: task.Schedule,
}
for _, activity := range task.Activities {
activityInfo := ActivityInformation{
Id: activity.Id.Hex(),
Title: activity.Title,
Provider: activity.Provider,
Selector: activity.Subjects,
}
taskInfo.Activities = append(taskInfo.Activities, activityInfo)
}
jobSpec.Tasks = append(jobSpec.Tasks, taskInfo)
}
return jobSpec
}
type TaskType string
const (
TaskTypeMilestone TaskType = "milestone"
TaskTypeAction TaskType = "action"
)
type Task struct {
Id primitive.ObjectID `json:"id"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Props []Property `json:"props,omitempty"`
Links []Link `json:"links,omitempty"`
Remarks string `json:"remarks,omitempty"`
Type TaskType `json:"type"`
Activities []Activity `json:"activities"`
Dependencies []TaskDependency `json:"dependencies"`
ResponsibleRoles []Uuid `json:"responsibleRoles"`
// Subjects hold all the subjects that the activities act upon.
Subjects []primitive.ObjectID `json:"subjects"`
Tasks []Uuid `json:"tasks"`
Schedule string `json:"schedule"`
}
func (t *Task) AddActivity(activity Activity) error {
// Validate the activity
if activity.Title == "" {
return errors.New("activity title cannot be empty")
}
// Add the activity to the Activities slice
t.Activities = append(t.Activities, activity)
return nil
}
type TaskDependency struct {
TaskId primitive.ObjectID `json:"taskUuid"`
Remarks string `json:"remarks"`
}
// Assets Identifies the assets used to perform this assessment, such as the assessment team, scanning tools, and assumptions.
type Assets struct {
// Reference to component.Component
Components []primitive.ObjectID `json:"components"`
// Used to represent the toolset used to perform aspects of the assessment.
Platforms []primitive.ObjectID `json:"platforms"`
}
type Platform struct {
Id primitive.ObjectID `json:"id"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Props []Property `json:"props,omitempty"`
Links []Link `json:"links,omitempty"`
Remarks string `json:"remarks,omitempty"`
// Reference to component.Component
UsesComponents []string `json:"usesComponents"`
}
type ControlsAndObjectives struct {
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Props []Property `json:"props,omitempty"`
Links []Link `json:"links,omitempty"`
Remarks string `json:"remarks,omitempty"`
Objectives []ObjectiveSelection `json:"objectives"`
ControlSelections Selection `json:"controlSelections"`
}
type ObjectiveSelection struct {
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Props []Property `json:"props,omitempty"`
Links []Link `json:"links,omitempty"`
Remarks string `json:"remarks,omitempty"`
IncludeAll bool `json:"includeAll"`
Exclude []string `json:"exclude"`
Include []string `json:"include"`
}
type LocalDefinition struct {
Remarks string `json:"remarks,omitempty"`
// Reference to Activity
Activities []string `json:"activities"`
// Reference to component.Component
Components []primitive.ObjectID `json:"components"`
// Reference to ssp.InventoryItem
InventoryItems []primitive.ObjectID `json:"inventoryItems"`
Objectives []Objective `json:"objectives"`
// Reference to identity.User
Users []primitive.ObjectID `json:"users"`
}
// Objective A local objective is a security control or requirement that is specific to the system or organization under assessment.
type Objective struct {
Id primitive.ObjectID `json:"id"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Props []Property `json:"props,omitempty"`
Links []Link `json:"links,omitempty"`
Remarks string `json:"remarks,omitempty"`
Parts []Part `json:"parts,omitempty"`
Control primitive.ObjectID `json:"control"`
}
type SubjectType string
const (
SubjectTypeComponent SubjectType = "component"
SubjectTypeInventoryItem SubjectType = "inventoryItem"
SubjectTypeLocation SubjectType = "location"
SubjectTypeParty SubjectType = "party"
SubjectTypeUser SubjectType = "user"
)
// Subject Identifies system elements being assessed, such as components, inventory items, and locations.
// In the assessment plan, this identifies a planned assessment subject.
// In the assessment results this is an actual assessment subject, and reflects any changes from the plan. exactly what will be the focus of this assessment.
type Subject struct {
Id primitive.ObjectID `json:"id"`
SubjectId string `json:"subjectId"`
Type SubjectType `json:"type"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Props []Property `json:"props,omitempty"`
Links []Link `json:"links,omitempty"`
Remarks string `json:"remarks,omitempty"`
}
// SubjectSelection Identifies system elements being assessed, such as components, inventory items, and locations by specifying a selection criteria.
// We do not directly store SubjectIds as we might not know the actual subjects before running the assessment.
// The assessment runtime evaluates the selection by running the providers and returns back with subject ids.
type SubjectSelection struct {
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Query string `json:"query,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Expressions []SubjectMatchExpression `json:"expressions,omitempty"`
Ids []string `json:"ids,omitempty"`
}
func (s *SubjectSelection) Valid() bool {
return s.Query != "" || len(s.Labels) > 0 || len(s.Expressions) > 0 || len(s.Ids) > 0
}
type SubjectMatchExpression struct {
Key string `json:"key"`
Operator string `json:"operator"`
Values []string `json:"values"`
}
type Activity struct {
Id primitive.ObjectID `json:"id"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Props []Property `json:"props,omitempty"`
Links []Link `json:"links,omitempty"`
Remarks string `json:"remarks,omitempty"`
ResponsibleRoles []string `json:"responsibleRoles"`
Subjects SubjectSelection `json:"subjects"`
Provider Provider `json:"provider"`
}