Skip to content

Commit b3c673e

Browse files
authored
feat(plugins): add experimental pktmon plugin for Windows (#235)
# Description This is the first of many commits to add Windows flow support via pktmon in the form of a Retina plugin. ## Related Issue If this pull request is related to any issue, please mention it here. Additionally, make sure that the issue is assigned to you before submitting this pull request. ## Checklist - [x] I have read the [contributing documentation](https://retina.sh/docs/contributing). - [x] I signed and signed-off the commits (`git commit -S -s ...`). See [this documentation](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification) on signing commits. - [x] I have correctly attributed the author(s) of the code. - [x] I have tested the changes locally. - [x] I have followed the project's style guidelines. - [ ] I have updated the documentation, if necessary. - [ ] I have added tests, if applicable. ## Screenshots (if applicable) or Testing Completed Please add any relevant screenshots or GIFs to showcase the changes made. ## Additional Notes Add any additional notes or context about the pull request here. This is an experimental build, and in the current form remains half present. Omitting Windows cgo for the time being. --- Please refer to the [CONTRIBUTING.md](../CONTRIBUTING.md) file for more information on how to contribute to this project. --------- Signed-off-by: Mathew Merrick <[email protected]>
1 parent e9f8064 commit b3c673e

16 files changed

+1392
-87
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ dist/
3737
bin/
3838

3939
image-metadata-*.json
40+
*packetmonitorsupport*/

.golangci.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@ issues:
22
max-same-issues: 0
33
max-issues-per-linter: 0
44
new-from-rev: origin/main
5+
exclude-rules:
6+
# some type names are caps/underscore to map OS primitive types
7+
- path: pkg/metrics/types_windows.go
8+
linters:
9+
- revive
10+
- gomnd
11+
- var-naming
12+
- path: pkg/metrics/types_linux.go
13+
linters:
14+
- revive
15+
- gomnd
16+
- var-naming
517
linters:
618
presets:
719
- bugs

.pipelines/cg-pipeline.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ stages:
189189
targetType: "inline"
190190
script: |
191191
Import-Module -Name "$(Build.SourcesDirectory)\windows\docker\DockerBuildModule.psm1" -Force
192-
Build-RetinaAgentImage -fullBuilderImageName $(WINDOWS_BUILDER_IMAGE) -registry $(BUILD_REGISTRY)
192+
Build-RetinaAgentImage -fullBuilderImageName $(WINDOWS_BUILDER_IMAGE) -registry $(BUILD_REGISTRY) -appInsightsID $(PROD_AI)
193193
Save-Image -imageName retina-agent -registry $(BUILD_REGISTRY)
194194
195195
- task: PublishBuildArtifacts@1

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ helm-install-advanced-local-context: manifests
458458
helm-install-hubble:
459459
helm upgrade --install retina ./deploy/hubble/manifests/controller/helm/retina/ \
460460
--namespace kube-system \
461+
--set os.windows=true \
461462
--set operator.enabled=true \
462463
--set operator.repository=$(IMAGE_REGISTRY)/$(RETINA_OPERATOR_IMAGE) \
463464
--set operator.tag=$(HELM_IMAGE_TAG) \
@@ -533,4 +534,3 @@ quick-deploy-hubble:
533534
.PHONY: simplify-dashboards
534535
simplify-dashboards:
535536
cd deploy/legacy/grafana/dashboards && go test . -tags=dashboard,simplifydashboard -v && cd $(REPO_ROOT)
536-

controller/Dockerfile.windows-2022

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
FROM --platform=linux/amd64 mcr.microsoft.com/oss/go/microsoft/golang:1.21 as builder
2-
3-
# Build args
42
ARG VERSION
53
ARG APP_INSIGHTS_ID
64

@@ -15,7 +13,7 @@ RUN --mount=type=cache,target="/root/.cache/go-build" go build -v -o /usr/bin/co
1513
RUN --mount=type=cache,target="/root/.cache/go-build" go build -v -o /usr/bin/captureworkload.exe ./captureworkload/
1614

1715
# Copy into final image
18-
FROM mcr.microsoft.com/windows/servercore:ltsc2022 as final
16+
FROM --platform=windows/amd64 mcr.microsoft.com/windows/servercore:ltsc2022 as final
1917
COPY --from=builder /usr/src/retina/windows/kubeconfigtemplate.yaml kubeconfigtemplate.yaml
2018
COPY --from=builder /usr/src/retina/windows/setkubeconfigpath.ps1 setkubeconfigpath.ps1
2119
COPY --from=builder /usr/bin/controller.exe controller.exe

controller/Dockerfile.windows-native

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,31 @@
22
# It can't be placed in the other Windows Dockerfile, as those use
33
# buildx targets, and this one requires legacy build.
44
# Maybe one day: https://github.com/moby/buildkit/issues/616
5-
65
ARG BUILDER_IMAGE
7-
FROM --platform=windows/amd64 ${BUILDER_IMAGE} as builder
8-
# Build args
6+
FROM --platform=windows/amd64 mcr.microsoft.com/oss/go/microsoft/golang:1.22-windowsservercore-ltsc2022 as builder
97
WORKDIR C:\\retina
10-
RUN gcc.exe --version
11-
RUN go version
128
COPY go.mod .
139
COPY go.sum .
1410
ENV CGO_ENABLED=1
1511
RUN go mod download
1612
RUN go mod verify
1713
ADD . .
18-
RUN cp -r c:/pktmon/ pkg/plugin/windows/pktmon/packetmonitorsupport/
19-
RUN ls pkg/plugin/windows/pktmon/packetmonitorsupport/
2014
ARG VERSION
2115
ARG APP_INSIGHTS_ID
2216
SHELL ["cmd", "/S", "/C"]
2317
ENV VERSION=$VERSION
24-
ENV APP_INSIGHTS_ID=$APP_INSIGHTS_ID
2518

19+
ENV APP_INSIGHTS_ID=$APP_INSIGHTS_ID
2620
RUN go build -v -o controller.exe -ldflags="-X main.version=%VERSION% -X main.applicationInsightsID=%APP_INSIGHTS_ID%" .\controller
2721
RUN go build -v -o captureworkload.exe -ldflags="-X main.version=%VERSION% -X main.applicationInsightsID=%APP_INSIGHTS_ID%" .\captureworkload
2822

23+
FROM --platform=windows/amd64 ${BUILDER_IMAGE} as pktmon-builder
24+
WORKDIR C:\\retina
2925

3026
FROM --platform=windows/amd64 mcr.microsoft.com/windows/nanoserver:ltsc2022 as final
3127
ADD https://github.com/microsoft/etl2pcapng/releases/download/v1.10.0/etl2pcapng.exe /etl2pcapng.exe
3228
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'Continue';"]
3329
COPY --from=builder C:\\retina\\controller.exe controller.exe
30+
COPY --from=pktmon-builder C:\\pktmon\\controller-pktmon.exe controller-pktmon.exe
3431
COPY --from=builder C:\\retina\\captureworkload.exe captureworkload.exe
3532
CMD ["controller.exe"]
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
pkg/plugin/windows/pktmon/packetmonitorsupport/*
2-
*.tar
1+
pkg/plugin/windows/pktmon/packetmonitorsupport/*
2+
*.tar

pkg/metrics/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,5 @@ func ToPrometheusType(metric interface{}) prometheus.Collector {
109109
return nil
110110
}
111111
}
112+
113+
type DropReasonType uint32

pkg/metrics/types_linux.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
package metrics
4+
5+
import "github.com/cilium/cilium/api/v1/flow"
6+
7+
// Alert: this ordering should match the drop_reason_t enum ordering
8+
// in dropreason.h of DropReason plugin
9+
const (
10+
IPTABLE_RULE_DROP DropReasonType = iota
11+
IPTABLE_NAT_DROP
12+
TCP_CONNECT_BASIC
13+
TCP_ACCEPT_BASIC
14+
TCP_CLOSE_BASIC
15+
CONNTRACK_ADD_DROP
16+
UNKNOWN_DROP
17+
)
18+
19+
func GetDropType(value uint32) DropReasonType {
20+
switch value {
21+
case 0:
22+
return IPTABLE_RULE_DROP
23+
case 1:
24+
return IPTABLE_NAT_DROP
25+
case 2:
26+
return TCP_CONNECT_BASIC
27+
case 3:
28+
return TCP_ACCEPT_BASIC
29+
case 4:
30+
return TCP_CLOSE_BASIC
31+
case 5:
32+
return CONNTRACK_ADD_DROP
33+
default:
34+
return UNKNOWN_DROP
35+
}
36+
}
37+
38+
func GetDropTypeFlowDropReason(dr flow.DropReason) string {
39+
return GetDropType(uint32(dr)).String()
40+
}
41+
42+
func (d DropReasonType) String() string {
43+
switch d {
44+
case IPTABLE_RULE_DROP:
45+
return "IPTABLE_RULE_DROP"
46+
case IPTABLE_NAT_DROP:
47+
return "IPTABLE_NAT_DROP"
48+
case TCP_CONNECT_BASIC:
49+
return "TCP_CONNECT_BASIC"
50+
case TCP_ACCEPT_BASIC:
51+
return "TCP_ACCEPT_BASIC"
52+
case TCP_CLOSE_BASIC:
53+
return "TCP_CLOSE_BASIC"
54+
case CONNTRACK_ADD_DROP:
55+
return "CONNTRACK_ADD_DROP"
56+
case UNKNOWN_DROP:
57+
return "UNKNOWN_DROP"
58+
default:
59+
return "UNKNOWN_DROP"
60+
}
61+
}

0 commit comments

Comments
 (0)