Repository navigation
feat(host): complete profile binding and anomaly coverage #1043
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
Open
matthyx
wants to merge
5
commits into
main
Choose a base branch
from
feat/host-profile-gaps
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2699f39
feat(host): complete profile binding and anomaly coverage
matthyx 84efd74
fix(alerts): address CodeRabbit review 5617280179
matthyx 1e6568a
fix(profiles): address Copilot review 5617666200
matthyx 4f207ac
fix(alerts): address Copilot HTTP attribution review 5617802908
matthyx 36a9a05
fix(processtree): drop cached branch when a tree refresh fails (#1047)
DeathGun44 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # Host profile binding | ||
|
|
||
| In Kubernetes, enable `hostMonitoringEnabled` and | ||
| `applicationProfileServiceEnabled` to learn the host's ContainerProfile. Enable | ||
| `runtimeDetectionEnabled` to evaluate rules against it. Profiles are stored in | ||
| the node-agent deployment namespace. | ||
|
|
||
| To use an authored ContainerProfile for a host, create it in that namespace and | ||
| label the Node running the agent: | ||
|
|
||
| ```sh | ||
| kubectl label node <node-name> kubescape.io/user-defined-profile=<profile-name> --overwrite | ||
| ``` | ||
|
|
||
| The profile cache reads the Node label at registration and on its refresh ticks. | ||
| Changing the label selects a different authored profile; removing it returns to | ||
| the learned profile. A failed Node lookup retains the last observed binding; | ||
| it does not count as label removal. The agent needs `get` permission on Nodes, | ||
| which the test chart already grants. | ||
|
|
||
| Host network observations are learned for the synthetic `host` container. | ||
| Network tracing must also be enabled (`networkServiceEnabled` or | ||
| `runtimeDetectionEnabled`, with `dNetwork` disabled). | ||
| Ordinary Pods using `hostNetwork` remain excluded from network profile learning. | ||
| The test chart enables host context for R0001, R0002, R0003, R0004 and R0040. | ||
| Other rule deployments must opt those rules into `context:host` themselves. | ||
| Required-profile rules remain suppressed while their baseline is unavailable. | ||
|
|
||
| ## Identity and configuration compatibility | ||
|
|
||
| Binding a Node label does not rename existing profiles. The shared host identity | ||
| continues to use the existing synthetic `host` namespace and | ||
| `wlid://cluster-unknown/namespace-host/host-<hostID>`; the Kubernetes storage | ||
| namespace is the agent deployment namespace. See | ||
| [host monitoring completion](host-monitoring-completion.md) for the identity | ||
| builder and learning lifecycle. | ||
|
|
||
| A Node identity with the actual cluster name, node artifact labels and a | ||
| hostname selector would change profile keys and downstream lookup/cleanup | ||
| contracts. Such a migration needs coordinated storage and consumer support, | ||
| plus an explicit policy for existing baselines and node replacement. It should | ||
| not be introduced by changing the builder in place. | ||
|
|
||
| There is no separate `hostProfileServiceEnabled` switch. The existing host | ||
| monitoring and application profiling switches continue to control collection. | ||
| An independent host profiling switch could later provide host/container cost | ||
| control, but its default must preserve existing host learning, and disabling | ||
| learning must have defined behavior for bound profiles and required rules. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package containerprofilemanager | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/armosec/armoapi-go/armotypes" | ||
| "github.com/inspektor-gadget/inspektor-gadget/pkg/types" | ||
| "github.com/kubescape/node-agent/pkg/utils" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestReportNetworkEventHostNetwork(t *testing.T) { | ||
| for _, tc := range []struct { | ||
| name string | ||
| containerID string | ||
| hostNetwork bool | ||
| pktType string | ||
| podHostIP string | ||
| wantStored bool | ||
| }{ | ||
| {name: "host egress", containerID: armotypes.HostContainerID, hostNetwork: true, pktType: utils.OutgoingPktType, wantStored: true}, | ||
| {name: "host ingress", containerID: armotypes.HostContainerID, hostNetwork: true, pktType: utils.HostPktType, wantStored: true}, | ||
| {name: "hostNetwork pod egress", containerID: "hostnet-pod", hostNetwork: true, pktType: utils.OutgoingPktType}, | ||
| {name: "hostNetwork pod ingress", containerID: "hostnet-pod", hostNetwork: true, pktType: utils.HostPktType}, | ||
| {name: "ordinary pod", containerID: "pod", pktType: utils.OutgoingPktType, wantStored: true}, | ||
| {name: "host unknown packet type", containerID: armotypes.HostContainerID, hostNetwork: true, pktType: "UNKNOWN"}, | ||
| {name: "host localhost ingress", containerID: armotypes.HostContainerID, hostNetwork: true, pktType: utils.HostPktType, podHostIP: "10.0.0.5"}, | ||
| } { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| cpm, entry := newTestManager(t, tc.containerID) | ||
| event := &utils.StructEvent{ | ||
| DstEndpoint: types.L3Endpoint{Addr: "10.0.0.5"}, | ||
| DstPort: 8080, | ||
| Proto: "tcp", | ||
| PktType: tc.pktType, | ||
| PodHostIP: tc.podHostIP, | ||
| HostNetwork: tc.hostNetwork, | ||
| } | ||
|
|
||
| cpm.ReportNetworkEvent(tc.containerID, event) | ||
|
|
||
| if !tc.wantStored { | ||
| assert.Nil(t, entry.data.networks) | ||
| assert.Zero(t, entry.data.size.Load()) | ||
| return | ||
| } | ||
| require.NotNil(t, entry.data.networks) | ||
| require.Equal(t, 1, entry.data.networks.Cardinality()) | ||
| assert.True(t, entry.data.networks.Contains(NetworkEvent{ | ||
| Port: 8080, | ||
| Protocol: "tcp", | ||
| PktType: tc.pktType, | ||
| Destination: Destination{IPAddress: "10.0.0.5"}, | ||
| })) | ||
| assert.Positive(t, entry.data.size.Load()) | ||
|
|
||
| // Accepted host observations must reach the same flush set as pod observations. | ||
| assert.Equal(t, entry.data.networks, entry.data.networkEventsForFlush(false)) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.