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

Integrate Endpoints for Posture Checks #1432

Merged
merged 37 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
1921499
wip: add posture checks structs
bcmmbaga Dec 28, 2023
1afdf2e
add netbird version check
bcmmbaga Dec 28, 2023
1ad959b
Refactor posture checks and add version checks
bcmmbaga Jan 3, 2024
f3568f4
Implement posture and version checks in API models
bcmmbaga Jan 3, 2024
75b42ad
Refactor API models and enhance posture check functionality
bcmmbaga Jan 3, 2024
ec06af2
wip: add posture checks endpoints
bcmmbaga Jan 3, 2024
aeae4cb
go mod tidy
bcmmbaga Jan 3, 2024
fb22d6b
Reference the posture checks by id's in policy
bcmmbaga Jan 3, 2024
2a5991c
Add posture checks management to server
bcmmbaga Jan 4, 2024
8709ff1
Add posture checks management mocks
bcmmbaga Jan 4, 2024
11ee123
implement posture checks handlers
bcmmbaga Jan 4, 2024
86bbb38
Add posture checks to account copy and fix tests
bcmmbaga Jan 4, 2024
d3e59d5
Refactor posture checks validation
bcmmbaga Jan 4, 2024
ce9e9ec
wip: Add posture checks handler tests
bcmmbaga Jan 4, 2024
9a6f2cf
Add JSON encoding support to posture checks
bcmmbaga Jan 5, 2024
3dd35ad
Encode posture checks to correct api response object
bcmmbaga Jan 5, 2024
ad744d3
Refactored posture checks implementation to align with the new API sc…
bcmmbaga Jan 5, 2024
930e461
Refactor structure of `Checks` from slice to map
bcmmbaga Jan 8, 2024
df4d43b
Cleanup
bcmmbaga Jan 8, 2024
373b79a
Add posture check activities (#1445)
bcmmbaga Jan 8, 2024
1169b13
Revert map to use list of checks
bcmmbaga Jan 8, 2024
d07e3bd
Add posture check activity events
bcmmbaga Jan 8, 2024
328314f
Refactor posture check initialization in account test
bcmmbaga Jan 8, 2024
41a695a
Improve the handling of version range in posture check
bcmmbaga Jan 9, 2024
cbbba6e
Fix tests and linter
bcmmbaga Jan 9, 2024
5152750
Remove max_version from NBVersionCheck
bcmmbaga Jan 9, 2024
03e7317
Added unit tests for NBVersionCheck
bcmmbaga Jan 9, 2024
d64beaa
go mod tidy
bcmmbaga Jan 9, 2024
ad877c0
Merge branch 'feature/posture-checks' into feature/posture-checks-end…
bcmmbaga Jan 9, 2024
b308f34
Extend policy endpoint with posture checks (#1450)
bcmmbaga Jan 9, 2024
16c4bf5
Merge remote-tracking branch 'origin/feature/posture-checks-endpoints…
bcmmbaga Jan 9, 2024
e138aa2
Add validation for non-existing posture checks
bcmmbaga Jan 9, 2024
feaefd8
fix unit tests
bcmmbaga Jan 10, 2024
6d272bb
use Wt version
bcmmbaga Jan 10, 2024
dcaaacd
Remove the enabled field, as posture check will now automatically be …
bcmmbaga Jan 11, 2024
35b744c
Merge branch 'main' into feature/posture-checks-endpoints
bcmmbaga Jan 11, 2024
41c348d
Merge branch 'feature/posture-checks' into feature/posture-checks-end…
bcmmbaga Jan 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -996,4 +996,4 @@ rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
12 changes: 12 additions & 0 deletions management/server/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/netbirdio/netbird/management/server/idp"
"github.com/netbirdio/netbird/management/server/jwtclaims"
nbpeer "github.com/netbirdio/netbird/management/server/peer"
"github.com/netbirdio/netbird/management/server/posture"
"github.com/netbirdio/netbird/management/server/status"
"github.com/netbirdio/netbird/route"
)
Expand Down Expand Up @@ -118,6 +119,10 @@ type AccountManager interface {
GetAllConnectedPeers() (map[string]struct{}, error)
HasConnectedChannel(peerID string) bool
GetExternalCacheManager() ExternalCacheManager
GetPostureChecks(accountID, postureChecksID, userID string) (*posture.Checks, error)
SavePostureChecks(accountID, userID string, postureChecks *posture.Checks) error
DeletePostureChecks(accountID, postureChecksID, userID string) error
ListPostureChecks(accountID, userID string) ([]*posture.Checks, error)
}

type DefaultAccountManager struct {
Expand Down Expand Up @@ -216,6 +221,7 @@ type Account struct {
NameServerGroups map[string]*nbdns.NameServerGroup `gorm:"-"`
NameServerGroupsG []nbdns.NameServerGroup `json:"-" gorm:"foreignKey:AccountID;references:id"`
DNSSettings DNSSettings `gorm:"embedded;embeddedPrefix:dns_settings_"`
PostureChecks []*posture.Checks `gorm:"foreignKey:AccountID;references:id"`
// Settings is a dictionary of Account settings
Settings *Settings `gorm:"embedded;embeddedPrefix:settings_"`
}
Expand Down Expand Up @@ -661,6 +667,11 @@ func (a *Account) Copy() *Account {
settings = a.Settings.Copy()
}

postureChecks := []*posture.Checks{}
for _, postureCheck := range a.PostureChecks {
postureChecks = append(postureChecks, postureCheck.Copy())
}

return &Account{
Id: a.Id,
CreatedBy: a.CreatedBy,
Expand All @@ -677,6 +688,7 @@ func (a *Account) Copy() *Account {
Routes: routes,
NameServerGroups: nsGroups,
DNSSettings: dnsSettings,
PostureChecks: postureChecks,
Settings: settings,
}
}
Expand Down
16 changes: 12 additions & 4 deletions management/server/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
nbdns "github.com/netbirdio/netbird/dns"
"github.com/netbirdio/netbird/management/server/activity"
nbpeer "github.com/netbirdio/netbird/management/server/peer"
"github.com/netbirdio/netbird/management/server/posture"
"github.com/netbirdio/netbird/route"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -1537,9 +1538,10 @@ func TestAccount_Copy(t *testing.T) {
},
Policies: []*Policy{
{
ID: "policy1",
Enabled: true,
Rules: make([]*PolicyRule, 0),
ID: "policy1",
Enabled: true,
Rules: make([]*PolicyRule, 0),
SourcePostureChecks: make([]string, 0),
},
},
Routes: map[string]*route.Route{
Expand All @@ -1558,7 +1560,13 @@ func TestAccount_Copy(t *testing.T) {
},
},
DNSSettings: DNSSettings{DisabledManagementGroups: []string{}},
Settings: &Settings{},
PostureChecks: []*posture.Checks{
{
ID: "posture Checks1",
Checks: make([]posture.Check, 0),
},
},
Settings: &Settings{},
}
err := hasNilField(account)
if err != nil {
Expand Down
202 changes: 202 additions & 0 deletions management/server/http/api/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,12 @@ components:
- $ref: '#/components/schemas/PolicyMinimum'
- type: object
properties:
source_posture_checks:
description: Posture checks ID's applied to policy source groups
type: array
items:
type: string
example: "chacdk86lnnboviihd70"
rules:
description: Policy rule object for policy UI editor
type: array
Expand All @@ -791,13 +797,73 @@ components:
- $ref: '#/components/schemas/PolicyMinimum'
- type: object
properties:
source_posture_checks:
description: Posture checks ID's applied to policy source groups
type: array
items:
type: string
example: "chacdk86lnnboviihd70"
rules:
description: Policy rule object for policy UI editor
type: array
items:
$ref: '#/components/schemas/PolicyRule'
required:
- rules
- source_posture_checks
PostureCheck:
type: object
properties:
id:
description: Posture check ID
type: string
example: ch8i4ug6lnn4g9hqv7mg
name:
description: Posture check name identifier
type: string
example: Default
description:
description: Posture check friendly description
type: string
example: This checks if the peer is running required NetBird's version
checks:
$ref: '#/components/schemas/Checks'
required:
- id
- name
- checks
Checks:
description: List of objects that perform the actual checks
type: object
properties:
nb_version_check:
$ref: '#/components/schemas/NBVersionCheck'
NBVersionCheck:
description: Posture check for the version of NetBird
type: object
properties:
min_version:
description: Minimum acceptable NetBird version
type: string
example: "0.25.0"
required:
- min_version
PostureCheckUpdate:
type: object
properties:
name:
description: Posture check name identifier
type: string
example: Default
description:
description: Posture check friendly description
type: string
example: This checks if the peer is running required NetBird's version
checks:
$ref: '#/components/schemas/Checks'
required:
- name
- description
RouteRequest:
type: object
properties:
Expand Down Expand Up @@ -2464,3 +2530,139 @@ paths:
"$ref": "#/components/responses/forbidden"
'500':
"$ref": "#/components/responses/internal_error"
/api/posture-checks:
get:
summary: List all Posture Checks
description: Returns a list of all posture checks
tags: [ Posture Checks ]
security:
- BearerAuth: [ ]
- TokenAuth: [ ]
responses:
'200':
description: A JSON Array of posture checks
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/PostureCheck'
'400':
"$ref": "#/components/responses/bad_request"
'401':
"$ref": "#/components/responses/requires_authentication"
'403':
"$ref": "#/components/responses/forbidden"
'500':
"$ref": "#/components/responses/internal_error"
post:
summary: Create a Posture Check
description: Creates a posture check
tags: [ Posture Checks ]
security:
- BearerAuth: [ ]
- TokenAuth: [ ]
requestBody:
description: New posture check request
content:
'application/json':
schema:
$ref: '#/components/schemas/PostureCheckUpdate'
responses:
'200':
description: A posture check Object
content:
application/json:
schema:
$ref: '#/components/schemas/PostureCheck'
/api/posture-checks/{postureCheckId}:
get:
summary: Retrieve a Posture Check
description: Get information about a posture check
tags: [ Posture Checks ]
security:
- BearerAuth: [ ]
- TokenAuth: [ ]
parameters:
- in: path
name: postureCheckId
required: true
schema:
type: string
description: The unique identifier of a posture check
responses:
'200':
description: A posture check object
content:
application/json:
schema:
$ref: '#/components/schemas/PostureCheck'
'400':
"$ref": "#/components/responses/bad_request"
'401':
"$ref": "#/components/responses/requires_authentication"
'403':
"$ref": "#/components/responses/forbidden"
'500':
"$ref": "#/components/responses/internal_error"
put:
summary: Update a Posture Check
description: Update/Replace a posture check
tags: [ Posture Checks ]
security:
- BearerAuth: [ ]
- TokenAuth: [ ]
parameters:
- in: path
name: postureCheckId
required: true
schema:
type: string
description: The unique identifier of a posture check
requestBody:
description: Update Rule request
content:
'application/json':
schema:
$ref: '#/components/schemas/PostureCheckUpdate'
responses:
'200':
description: A posture check object
content:
application/json:
schema:
$ref: '#/components/schemas/PostureCheck'
'400':
"$ref": "#/components/responses/bad_request"
'401':
"$ref": "#/components/responses/requires_authentication"
'403':
"$ref": "#/components/responses/forbidden"
'500':
"$ref": "#/components/responses/internal_error"
delete:
summary: Delete a Posture Check
description: Delete a posture check
tags: [ Posture Checks ]
security:
- BearerAuth: [ ]
- TokenAuth: [ ]
parameters:
- in: path
name: postureCheckId
required: true
schema:
type: string
description: The unique identifier of a posture check
responses:
'200':
description: Delete status code
content: { }
'400':
"$ref": "#/components/responses/bad_request"
'401':
"$ref": "#/components/responses/requires_authentication"
'403':
"$ref": "#/components/responses/forbidden"
'500':
"$ref": "#/components/responses/internal_error"
Loading
Loading