Граф коммитов

305 Коммитов

Автор SHA1 Сообщение Дата
Hunter Gregory 17ed0b83fa
feat: [NPM] ipset save before restoring and fix grep UTs (#1085)
* use ipset save to update members and update error handling logic for ipsets to skip previously run lines. Also update some logging for iptables chain management

* remove unused code

* add comment block describing high level ipset restore logic

* fix bug in piping to grep. need to add pipe errors for fexec UTs so that we dont revert on dataplane UTs

* grep for npm sets working for ipsets save, but this breaks DP UTs

* VerifyCalls method for mock ioshim

* add ability to unit test piped commands

* update logging

* UTs for piping a command to grep

* grep for npm sets in ipset save, verify number of calls in UTs, and update ApplyIPSets test calls for dataplane UTs

* update comments based on PR suggestions

* addressing comments

* remove out-of-scope policy changes for this PR

* rename restore file creator files

* FIXME: setting v2 controllers toggle to true to create an image in pipeline

* Revert "FIXME: setting v2 controllers toggle to true to create an image in pipeline"

This reverts commit 31148c3034.

* wrap errors
2021-11-15 17:47:05 -08:00
JungukCho d7dcc64f93
refactor: [NPM] General translation logic for egress and ingress (#1106)
* Generallize function for ingress and egress

* Use function to support both ingress and egress and update UTs

* Simplify UTs and correct comments

* Add more comments and correct policies.MatchType

* Reorganize codes to better understand and simplify UTs

* Addresses comments (e.g., fix typo and correct wrong comments)

* Address comments (e.g., srcList and dstList) and correct MatchType values

* Address comments (fromRulesExists -> peerRuleExists)
2021-11-15 17:38:08 -08:00
JungukCho 0d2e1dc573
refactor: [NPM] General translation logic (mainly clean-up codes and correct bugs) (#1105)
* Delete unneeded codes for podSelector and update UTs

* Delete unneeded codes for nameSpaceSelector and UTs

* Delete unneeded codes in parseSelector

* Use nil slices instead of zero slices for TranslatedIPSet from namespaceSelector

* Use Variadic functions in NewTranslatedIPSet to use nil slice instead of empty slice and update UTs accordingly

* Use right settype for all-namespaces

* no export for flattenNameSpaceSelector function in parseSelector (vamsi's comments)
2021-11-12 13:46:50 -08:00
JungukCho 6835b8630f
refactor: [NPM] parsing label selector for general translation logic (#1077)
* Add comments for package and functions

* Handle namespaceSelector in simple way and remove unnecessary code for ipBlock field

* Translate podSelector in a simple way and update its UTs.

* Use parsedSelectors struct to reduce duplicated codes and update comments

* Address lint errors and add missing comments

* Correct comments

* Addressed comments

* Use correct settype for all-namespaces

* Address comments

* Addressed comments
2021-11-12 12:05:15 -08:00
JungukCho 76e7531a08
feat: [NPM] Support pod grace period for v2 (#1095)
* Use official k8s equals functions for label instead of our own implementation

* Update v2 pod controller to support graceful shutdown of pod
2021-11-10 16:01:21 -08:00
JungukCho cc68c342fa
feat: [NPM] Support graceful shutdown in pod (#1083)
* Support graceful shutdown in pod

* Update detailed comments and cleaning up codes

* Add Unit tests

* Address lint errors

* Address comments

* Addressed comment and add UTs
2021-11-09 17:24:42 -08:00
Vamsi Kalapala 08df7f7429
feat: [NPM] NPM v2 network policy controller and UTs for all v2 controllers (#1082)
* adding a legacy build command

* Adding all v2 controller test files

* v2 podcontroller changes

* completing all pod v2 controllers uts

* Adding netpol v2 controller UTs

* Removing unused make file command

* Fixing lints and correcting a test case

* Fixing an error in expected values

* dealing with flaky tests

* Fixing an issue with HCN vendor, until we wait for the fix to be rolled out

* Addressing some comments

* Removing addPolicy call and relying on updatepolicy

* Saving only spec of netpol and not whole object

* changing name of rawNPMap to rawNPSpecMap

* changing name of rawNPMap to rawNPSpecMap

* Deep equal type for spec was not equal corrected the pointers

* Deep equal type for spec was not equal corrected the pointers
2021-11-09 15:29:17 -08:00
Mathew Merrick fa8f665ab5
ci: add windows build pool and NPM windows dockerfile (#1073)
* build pool windows
2021-11-05 10:30:09 -07:00
Vamsi Kalapala cb866ef956
[NPM] Moving v1 netpol controller into its new location (#1081)
* Mocing v1 netpol controller into its new location

* fixing lints

* Addressing some comments

* Changing var to const
2021-11-03 15:09:24 -07:00
JungukCho 8434e139d1
[NPM] General translation logic for linux and windows (#1055)
* Create generic translation struct and start using it networkPolicyController

* Update ipsm to get more information from NPMCache

* Working on translateIngress part and its UTs

* Done functions of Translate ingress rule (need to add UTs to test its functions and clean up codes)

* Use function for repeated codes

* Cleanup UTs

* Remove all unused codes in this PR except for ingress rules

* Create functions to make codes concise and reorganize ipsets for better readability

* Remove duplicated data for targetPod information in every ACL

* Move translation logics to /pkg/controlplane/translation dir

* Remove redundant codes and resolved some of lint errors

* Resolve lint errors and remove unused codes in parseSelector and its UTs

* Use unique id for acl policy among network policies and add UTs for port rules

* Addresses some comments (will resolve more later)

* Complete namespaceSelector UTs and correct some logics for handling namespaceSelector

* Use consistent variables and variable for flexibility in UTs

* Add more UTs for allowAll and defaultDrop rules and clean-up codes

* Remove unused codes

* Resolve lint errors

* Clean-up and reorganize codes

* Revert "Update ipsm to get more information from NPMCache"

This reverts commit 477bbaf43d56a6535f5cc035dfe15d5b6035647a.

* Address comments

* Resolve part of lint errors

* Add comments for todo things in next PR

* Delete unused file and clean-up code

* Fix Uts

* Remove unnecessary code
2021-11-01 09:03:16 -07:00
Vamsi Kalapala 66453dd20b
[NPM] Fixing a windows NPM build issue (#1074)
* [NPM] Fixing a windows NPM build issue

* building npm windows

* ignore building npm windows
2021-10-29 14:50:33 -07:00
Hunter Gregory 5490a9fa1f
NPM: Linux Policy Manager (#1069)
* feat: policy manager for linux

* remove composer from this PR (saving progress on my local machine)

* redesign iptables, rework/complete UTs

* use strings instead of constants in UTs

* fixed go lints

* fixed bug found in integration testing

* added integration tests for policymanager (should replace with dataplane interface calls later)

* rearrange UTs, add extra coverage for chain management, and fix bug for reporting error on chain destroy failures

* rename variable

* fixed lint (removed newline)

* update errors in policymanager and add an error in linux pMgr if we cant delete jump rules from ingress/egress chain to policy chain

* fix tiny lint

* address comments, update UTs in dataplane_test.go, update error wrapping, add windows UT files

* address more feedback and fix DP UTs by commenting out pMgr init/reset for now

* add comment
2021-10-29 13:57:19 -07:00
Vamsi Kalapala 9850758e4b
[NPM] Windows Policy Manager changes for OS22 (#1062)
* [NPM] Windows Policy Manager changes for OS22

* Adding new NPM ACLSettings with ID

* first pass on both add and remove policies

* fixing a merge issue

* Working 1st level Setpolicy CRUD operations

* have NPMACl to HNSACL conversion logic ready

* updating policy endpoints only after adding policy to an endpoint

* updating policy endpoints only after adding policy to an endpoint

* fixing a build issue

* fixing issue in linux files

* Addressing some comments and also completing some integrations with V2 control plane

* Updating policy ID logic and update pod

* Updating policy ID logic and update pod

* Addressing some comments

* adding basic reset bits

* fixnig build issue in linux

* Fixing the _linux_test.go build failures

* fix lints

* Addressing some comments and correcting windows logic to apply set policies in order

* cleaning up logic for calculating set policies

* Applying some feedback.

* fixing a failing test and panic
2021-10-28 08:50:41 -07:00
Hunter Gregory 5a8931bc55
make exported testutils for ipsets (#1067) 2021-10-21 10:50:45 -07:00
Mathew Merrick 60820006e1
refactor: move existing npm controllers to v1 (#1040)
* put v2 behind toggle
2021-10-20 13:03:12 -07:00
Hunter Gregory e692542c0c
NPM v2 Linux IPSet Manager (#1029)
* add note in comment

* fix ipset metrics, add TODO comments, and add delete cache

* linux ipsetmanager

* Revert "add note in comment"

This reverts commit b20c486cfa.

* update comments and add stub for destroyNPMIPsets() func

* move restore file logic to external package

* remove existence check in updateDirtyCache()

* rearranging stuff and updates for old version of new ipsetmanager

* update ipsetmanager to version in master (from ipsetmanager-update PR)

* updates to ipsetmanager linux test

* revamped file creator for retry logic (for ipset and iptables restore)

* renaming variables and moving code around

* completed logic for retrying (generic and for ipset restore)

* addressing sectionID comment and including a call to errorHandler Callback

* remove obsolete struct fields

* Revert "remove obsolete struct fields"

This reverts commit b53af2c2d7.

* unit tests and some changes/reordering of code for file-creator

* file creator unit tests (forgot to add in last commit)

* refactored file creator for external testing of error handling

* added missing argument to fucntion

* first pass at unit testing for ipsetmanager_linux

* fix file creator a bit (use ioshim, etc.) and finish basic UTs for ipsetmanager linux

* implemented ApplyAll mode

* update error messages

* full UT coverage for file creator

* update comments, var names, and remove debug code

* full UT coverage for ipsetmanager linux

* resolvee golint problems with function literals

* resolve golint problems with function literals v2

* rename variable

* added reboot function to generic ipsetmanager

* added caveat about ApplyAll mode

* initialize metrics in dataplane constructor

* fix go lints and update error messages in file creator

* add basic integration testing file

* addressing comments

* fix unit tests

* fix lints in integration test file

* fixed bad function name in windows ipsetmanager
2021-10-15 16:55:35 -07:00
Vamsi Kalapala 0eff6a789f
[NPM] Adjusting datastructures for Control Plane needs (#1054)
* [NPM] Adjusting datastructures for Control Plane needs

* Addressing some comments
2021-10-12 20:55:00 -07:00
Vamsi Kalapala dfc70acbd9
[NPM] Adding prefixes to IPSets in dataplane (#1047)
* [NPM] Adding prefixes to IPSets in dataplane

* Correcting a linting issue

* Using the correct case for metadata

* Adding IOShim for both windows and linux

* splitting ioshim for each os

* correcting a import error

* correcting some mistakes

* Adding tests for policies in Dp

* fixing a testname

* Updating the dataplane mock file

* removing dataplane mocks from dataplane tests as their scope is controllers
2021-10-11 13:11:45 -07:00
Mathew Merrick 70d78387f7
chore: add dataplane interface for npm tests (#1048)
* generic dataplane

* gomock for dpi
2021-10-11 10:14:27 -07:00
JungukCho 9db8386634
[NPM] chore: add NPM cmd UTs (#1015)
* Add uts for parseiptable.go

Co-authored-by: Hunter Gregory <hgregory@microsoft.com>

* test commit

* deleted file from test commit

* added a UT for convertiptable and moved shared UT functionality to a new file. also renamed some command constants to avoid confusion with real commands

* removing print statements from when I was debugging

* Add UTs for start.go

* Add simple UT for start.go

* make it clear that cache file and iptables save file need to be used together

* remove unnecessary wantEmptyOutput field in test struct

* Refactor cobra command and adjust unit tests

* UT for gettuples cmd

* comment out test without cache file and refactor args

* Delete unnecessary comments and commeted codes

* Remove lint errors

* Use correct files and expected values in UTs

Co-authored-by: Hunter Gregory <hgregory@microsoft.com>
Co-authored-by: Hunter Gregory <hunterlgregory@gmail.com>
2021-10-08 13:52:38 -07:00
Vamsi Kalapala 779e965965
[NPM] generic Policy Manager and some windows specific policy updates (#1045)
* removing some redundant info

* Adding some policy related changes

* initial pass on some update pod dependencies

* adding update pod logic

* cleaning up some unused code

* Adding some basic test cases

* Correcting some test cases

* fixing a testcase

* correcting some golints

* fixing a test

* Fixing some golints:

* Addressing a comment
2021-10-06 17:27:53 -07:00
Hunter Gregory 6c947e2039
Ipsetmanager-update (#1034)
* add new npm errors

* add logic for adding/removing sets to kernel in ipsetmanager, update usage of prometheus metrics, and update dataplane API to not use IPSets

* update to a pointer return value for NewPolicyManager

* fix go lints

* renamed count to kernelReferCount

* fix a bug with kernel logic, rearrange code, rename things, and update comments

* rearrange functions

* removed checkIfExists, consolidated AddReference and DeleteReference with a special type, and fixed go lints

* moved logic for different reference types to ipset.go

* remove file with just notes on it

* remove redundant boolean calculation that is always true

* add clarifying comment

* fix ipset  metrics to be for all of NPM (not necessarily in kernel), and write TODOs for kernel-based metrics

* update based on code review

* var name change

* update unit test to use DeleteIPSet

* moved internal functions to the bottom
2021-09-29 11:33:28 -07:00
Paul Johnston 3f97a3040f
Arm64 docker (#1030)
* chore: making docker images arch agnostic through docker buildx
2021-09-28 14:17:25 -07:00
Vamsi Kalapala 95882de142
[NPM] Modifying destroy ipsets logic (#1032)
* [NPM] Modifying destroy ipsets logic

* [NPM] Modifying destroy ipsets logic

* removing the metrics additions and correcting UT fake exec order
2021-09-24 15:10:03 -07:00
Hunter Gregory d00aa2e9b1
NPM Prometheus Unit Tests (#1016)
* fixed bug in NumIPSetsIsPositive()

* moved code for getting metric values to a new file

* renamed file

* unit tests for prometheus metrics

* fix go lints

* use fexec for TestDestroyNpmIpsets()
2021-09-21 10:02:58 -07:00
tamilmani1989 2bd3c74811
Netlink package interfacing and adding a fake (#996) (#1025)
* Initial pass at Netlink interface

* changing some netlink and epc

* Resolcing all dependencies on netlink package

* first pass at adding a netlinkinterface

* windows working now

* feat: update cns client (#992)

* fix debug commands

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* fix: update cns client

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* add ctx to debug calls

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* repackage cns client

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* add ctx to all methods and preinit all route urls

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* down-scope cns client interface and move to consumer packages

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* no unkeyed struct literals

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* trace updated client method signatures out through windows paths

* delint

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* fix windows build

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* delint

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>

* windows working now

* Some golints checks

* commenting a flaky NPM UT and adding some golint checks

* renaming fakenetlink to mocknetlink

* removing a mock netlink usage

* fixing more golints and a test fix

* fixing more go lints

* Adding in netlink from higher level as input

* adding netlinkinterface to windows endpoint impl

* removing netlink name confusion

Co-authored-by: Evan Baker <rbtr@users.noreply.github.com>

Co-authored-by: Vamsi Kalapala <vakr@microsoft.com>
Co-authored-by: Evan Baker <rbtr@users.noreply.github.com>
2021-09-20 13:57:12 -05:00
JungukCho c74c49745f
[NPM] refactor: npmcache json marshaling (#993)
* wip

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>
Co-authored-by: JungukCho <jungukcho@microsoft.com>

* wip

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>
Co-authored-by: JungukCho <jungukcho@microsoft.com>

* Add unit tests

* Use correct parameters

* Check nil value of ipsMgr before calling marshal function and add UT

* Resolve lint errors

* Resolve all lint errors

* Define error

* Use a right file for UT and resolve lint error

* Use better directory name for managing testfiles
2021-09-17 16:19:51 -07:00
Hunter Gregory fe23878507
Remove test coverage (#1007)
* removed test/ and testutil/ from code coverage

* remove promutil from coverage

* removed tools/ from code coverage

* removed crd/ from code coverage and updated multitenantnetworkcontainer's manifest

* switch to !ignore_NAME syntax for test and cli tags

* add coverage back to crd (besides autogenerated files)

* rename ignore_test and ignore_cli tags to ignore_uncovered

* make cns/fakes/ uncovered

* mark go files in crd api folders as uncovered again

* add main.go back for nnsmock server
2021-09-17 15:29:40 -07:00
JungukCho 3817a98350
Remove dead codes in NPM-related metrics from telemetry and NPM (#999) 2021-09-14 09:38:58 -07:00
Vamsi Kalapala 01c12d8f40
[NPM] Generic Dataplane interface for windows and linux (#984)
* adding initial dataplane interface

* adding some skeleton code for crud functions

* adding dirty cache initial support for ipset manager

* correcting some go lints

* Adding some skeleton around os specific files

* removing interface and adding some network logic

* adding apply ipsets logic

* Addressing some comments and also adding comments to code

* Fixing some golints

* addressing some comments

* adding some golint checks

* Adding a new field setProperty and also adding structure for policies

* applying some comments

* correcting a condition

* Adding some comments

* Adding some test cases

* Addressing some comments

* Addressing more comments

* resolving some comments

* resolving some comments

* fixing some comments

* removing lock on policymap

* fixing some golints

* merging with master

* fixingsome wrap checks

* fixing lints
2021-09-12 19:43:31 -07:00
Hunter Gregory 0dd10e4e89
NPM Prometheus Update (#986)
* made prometheus exec time metrics for ipsets and iptables in line with those for network policies (exec time recorded even for failures). Also made prometheus timer variable names clearer.

* fixed faulty prometheus handler test looking for a node metric name when testing the cluster metric handler

* add clarity in comments related to the IPSetInventory metric

* Include prometheus metrics for lists and in DestroyNPMIpsets(). Only make metric updates when there's no error

* refactor prometheus testing and include metric tests for lists and NPMDestroyIpsets()

* better check for empty response to ipset list in DestroyNpmIpsets()

* remove unused clientset from controllers

* replace function for setting ipset inventory with function for removing ipset for better readability. updating comments too

* reset ipset inventory before each unit test

* added unit test for adding to set with pod cache

* remove unused cluster state function and clientset from np manager

* fix build problems: remove clientset from calls to npm.NewNetworkPolicyManager()

* fix logic for destroy ipsets for situation when destroy is called while num ipsets is 0

* delete commented out function

* encapsulated prometheus metrics, refactored prometheus testing for iptm and netpol controller, and removed clientset from controller creation in test files (fixing build error)

* update test for DestroyNpmIpsets() to always use a new Exec
2021-09-10 15:53:58 -07:00
Evan Baker 96bec09d41
chore: appease the linter (3/?), the big gofumpt (#987)
* gofumpt -w -s .

* small addtl cleanups after gofumpt

* rerun after rebase
2021-09-02 16:33:18 -05:00
Evan Baker 1087201b28
chore: appease the linter, pt 2 of ? (#925) 2021-09-01 18:28:17 -05:00
Mathew Merrick 836ee3810e
feat: [NPM] Add config file and feature toggles (#979)
* package case

* package restructure

* add default config and toggles

* lint
2021-09-01 09:03:24 -07:00
JungukCho 83b6240933
[NPM] Make each controller in npm independent (#949)
* Locate key data structure in each controller and remove locks in each controller if possible and lower lock location into ipset manager

* Create npmNameSpaceCache to manage shared namespace objects and mutex

* Encapsulate listMap and setMap in ipset manager struct not to expose them to other packages.
Remove unnecessary codes and clean-up initialization codes.

* Encapsulate methods and members to avoid unintentional access to variables and manage better shared resource. Correct UTs and Clean-up codes

* Update expected values in UTs according to architectural change and clean-up code (remove unnecessary comment and duplicated logging)

* Add comments and clean-up codes (removing redundant codes, etc)

* Remove threadness variable to avoid unintentional increase in the number of workers in each controller without safe synchronization

* Handle errors and return values in right ways based on lint hints

* Remove error handling codes in initializing iptables and ipset when NPM starts

* Call a correct function to avoid UT failure

* Resolve comments

* Locate key data structure in each controller and remove locks in each controller if possible and lower lock location into ipset manager

* Create npmNameSpaceCache to manage shared namespace objects and mutex

* Encapsulate listMap and setMap in ipset manager struct not to expose them to other packages.
Remove unnecessary codes and clean-up initialization codes.

* Encapsulate methods and members to avoid unintentional access to variables and manage better shared resource. Correct UTs and Clean-up codes

* Update expected values in UTs according to architectural change and clean-up code (remove unnecessary comment and duplicated logging)

* Add comments and clean-up codes (removing redundant codes, etc)

* Remove threadness variable to avoid unintentional increase in the number of workers in each controller without safe synchronization

* Handle errors and return values in right ways based on lint hints

* Remove error handling codes in initializing iptables and ipset when NPM starts

* Call a correct function to avoid UT failure

* Resolve comments

* Correct lint's complaint

* Correct chain order

* resolved llc lint warnings and renamed variables

* Resolved lint warnings if possible

* Removed unnecessary variables and codes

* Locate key data structure in each controller and remove locks in each controller if possible and lower lock location into ipset manager

Encapsulate listMap and setMap in ipset manager struct not to expose them to other packages.
Remove unnecessary codes and clean-up initialization codes.

Encapsulate methods and members to avoid unintentional access to variables and manage better shared resource. Correct UTs and Clean-up codes

Update expected values in UTs according to architectural change and clean-up code (remove unnecessary comment and duplicated logging)

Add comments and clean-up codes (removing redundant codes, etc)

Handle errors and return values in right ways based on lint hints

Remove error handling codes in initializing iptables and ipset when NPM starts

Call a correct function to avoid UT failure

Resolve comments

Correct lint's complaint

Correct chain order

* Add custom encoding and decoding logic for NPMCache

* Revise UT case in server_test.go and resolve lint warning

* Add npm cache file which was revised based on custom encoding and revise corresponding UTs

* Add unit test for npmCache (need to remove redundancy in server_test.go)

* Resolve lint warnings
2021-08-27 16:05:40 -07:00
Quang Nguyen 91695d85f0
[NPM] NPM Debug CLI (#971)
* CLI functions

* fix whitespace bug in CIDRmatch + go lint issue

* update main.go from master

* addressed CR comments

* addressed Matt's comments

* make config flag to be a root cmd flag  only

* make config flag to be a root cmd flag  only
2021-08-17 19:29:27 -04:00
Quang Nguyen 25daa48b30
[NPM] Dataplane Parser + Dataplane Converter + Traffic Analyzer (#907)
* organized iptable parser code

* print functions for iptable object + comments and testing template for parser

* add converter package + code refractoring parser

* fix bug where the program throws an error when the length of an option's value is 1 in parser

* add tests for parseTarget and parseModule + code refactoring for parser

* add ConvertIptablesObject func

* tests for parser

* add converter UT

* experimenting with protobuff

* used constructors, getters and setters for iptables' struct

* export GrapIptableLock

* add parser for negation in npm rules + add SetInfo obj for converter + update protobuf

* move folder into npm + changes to converter

* change hack folder name + move within npm

* make changes to converter

* change gitignore

* temporarily remove http folder

* converter ut

* fix converter tests + partial tests for tupleProcessor

* fix go lint issue with json unmarshal

* changed npmcache.exec type to interface to pass tests in converter

* change back policy file

* add conditions to get npm cache and iptable-save from node

* Update const.go

* Update converter.go

* Update converter_test.go

* Changes to return error statements in converter.go

* Update converter_test.go

* Change import path

* Update iptables strings method

* Update parser.go

* Update parser_test.go

* Update networkTupleProcessor.go

* update tupleProcessor_test.go

* Delete main.go

* resolve golint issue

* fix returning errors in tupleProcessor

* changed unit tests so they are more aligned with guidelines + add cidrblocks set type placeholder

* pull updates from master

* move everything to the datplane package

* refactoring code

* fix golint issues

* java style is not the way to Go ;)

* add more comments to the parseLine function

* fix more golint issues

* fix line length linting issues

* fix more linting issues

* add parse CIDR Block functionality

* minor bug fixes + more test coverage

* fix remaining lint issues

* minor linting issue

* fix the final linting issus this time for real

* for real

* remove todos

* addressed some CR reviews

* moved parser and iptables to their own package

* change package name

* minor comments

* change package name

* addressed more CR comments

* minor linting issue

* rename tupleProcessor to trafficAnalyzer

* remove a test that used exec

* fix parse iptable logic + re adding the previous test
2021-08-12 12:34:01 -04:00
JungukCho 47461d03ef
[NPM] Print running NPM version in stdout. (#958)
* Print running NPM version in stdout which helps debugging purpose.
Replace log with klog.

* Correct formatting error
2021-08-04 17:12:37 -07:00
JungukCho 6502e78952
[NPM] Remove unused codes to save and restore ipset and iptables (#952)
* Fix save and restore function to work properly with real exec

* Delete unused save and restore codes

* Clean-up deadcodes (i.e., save and restore) for ipset

* Remove an unused variable
2021-08-03 14:29:03 -07:00
JungukCho 161a5c7ff6
Remove duplicate namedports in slices to avoid unnecessary CreateSet calls in network policy controller (#953) 2021-07-26 12:40:21 -07:00
Mathew Merrick 9b24dbd95a
test: [NPM] Use fakeexec for ipsm and iptm tests (#868)
* iptmgr

* more iptm testing

* grep call

* progress

* progress

* ipsm

* ioshim

* update tests

* package restructure

* fix broken test and delint

* reduce scope of ioshim

* reduce scope of ioshim

* ioshim scope

* require no error, retrigger ci

* ut return multiple results

* fix tests from master changes

* unexport ioshim

* update ut

* fix tests

* vendor

* test fix

* go version

* go version

* pipeline fixes

* fix tests
2021-07-14 12:53:45 -07:00
Vamsi Kalapala a9c2430f54
[NPM] [bug] Adding sort in iptable comment for deterministic behavior in Flake UT (#924)
* Adding sort in comment for deterministic behavior

* Fixing some other UTs' comments

* addressing some comments
2021-07-08 12:00:39 -07:00
Evan Baker 45f3668401
chore: appease the linter, pt 1 of ? (#922) 2021-07-08 13:30:59 -05:00
Vamsi Kalapala a0e322d23d
[NPM] Add a protocol flag to namedport (#904)
* NPM today does not adhere to the protocol attached to a named port

* fixing a UT

* expanding ports to test
2021-07-07 14:21:17 -07:00
Vamsi Kalapala b76bbcf360
[NPM] [Bug] Fixing the looping issue in backup and reconcile chains (#923)
* Fixing the looping issue in backup and reconcile chains

* fixing a golint

* addressing some comments
2021-07-07 10:48:20 -07:00
Vamsi Kalapala a1b487af8b
[NPM] [BUG] Supporting multiple values under label selector MatchExpr (#863)
* basic scenario and investigation

* adding some basic imcrements to yaml

* First pass at adding 2nd level ipsets for multi value selector expressions

* resolving some references for drop match fields

* Adding some fixes around nil checks

* ignoring 1 value expr to be added to list mems

* not adding lists to the setMap

* correcting some UTs

* Correcting UTs.

* fixing all UTs

* Adding and cleaning some comments

* basic scenario and investigation

* adding some basic imcrements to yaml

* First pass at adding 2nd level ipsets for multi value selector expressions

* resolving some references for drop match fields

* Adding some fixes around nil checks

* ignoring 1 value expr to be added to list mems

* not adding lists to the setMap

* correcting some UTs

* Correcting UTs.

* fixing all UTs

* Adding and cleaning some comments

* fixing ns- prefixes for some lists and adding sort for comment

* fixing nsSlectors, flattening nsSelectors, since list of lists is not allowed in ipset

* correcting some UTs for nsselectors

* putting back removed testcase to resolve conflicts

* addressing some comments

* Addressing some comments regarding policy translation

* fixing some test after the merge

* addressing a potential nil deference issue

* adding a test case for some corner cases in flattenNS

* adding a TODO to clean up stale code if not used in next iteration

* Fixing some golint

* Fixing a sed in github actions
2021-07-07 09:05:24 -07:00
Mathew Merrick f90739e813
ci: bump Cyclonus version (#921)
* bump cyclonus version
2021-07-06 11:03:47 -07:00
Vamsi Kalapala c2b2db1042
[NPM] RETURN early on MARK in DROP chains (#881)
* Returning in DROP chains

* adding a comment about future cleanup of chains:

* Removing duplicate rules in PORT chains of TO/FROM and DROP chain jumps

* Adding a image of new chains behavior

* Addressing comments

* addressing some comments

* Correcting some UTs to not have the jump rules

* removing jump flag
2021-06-15 10:06:37 -07:00
Mathew Merrick b09ca83ef7
[CNI] Add GET_ENDPOINT_STATE command to dump CNI state to stdout (#891)
* inital dump state and ipam interface update

* add reconcile command to CNI

* add integration test

* pass endpoint id on add

* address some feedback

* fix test path and linting

* address feedback and logging

* remove return and rename to PodEndpointID
2021-06-11 14:01:42 -07:00
Mathew Merrick 1fa243e5f5
CI: Add golint-ci (#888)
* add golint-ci

* add gofmt

* enable linters

* uncap count

* fix linting/fmt issues
2021-06-01 16:58:56 -07:00
JungukCho 92165d8b11
[NPM] Fix recent unit test failures from each controller (#880)
* Use sharedInformer for only local storage to cache resource to make deterministic unit tests

* add comments in the codes

* add comments for future enhancement for unit tests
2021-05-26 13:10:12 -07:00
Mathew Merrick 6312309d61
[NPM] Use utilexec for IPSet calls and fakeexec in podcontroller tests (#861)
* use utilexec for IPSet syscalls
2021-05-06 12:08:26 -07:00
Mathew Merrick 3bc1a1f00e
[CI] Add Cyclonus to merge validation (#860) 2021-05-04 23:51:45 -07:00
JungukCho 8648739307
[NPM] fix incorrect NsMap local cache management between nameSpaceController and PodController (#866)
* fix incorrect NsMap local cache management between nameSpaceController and podcontroller

* Correct comment

* PodController adds list in ipset and npm-namespace into NsMap local cache
2021-05-04 17:46:51 -07:00
JungukCho da7f2c7e6d
fix management of deletefinalstateUnknown object on deletion event in each controller. Add Unit test for them. Correct log messages. (#856) 2021-04-23 11:51:45 -07:00
Vamsi Kalapala 53e45c8cf2
[NPM] better error handling and cache building (#848)
* [NPM] better error handling and cache building

* using const for label operations

* tests correction to discard non-exists delete op

* cleaning up some stale code

* fixing some port issues

* Addressing some comments

* Addressing some comments

* Addressing some comments

* fixing a missed ns- prefix while deleting from ns ipset

* fixing a missed ns- prefix while deleting from ns ipset

* resducing complexity when pod ip changes

* Adding some test validations

* Adding some test validations

* Adding some test validations

* removing more unsed fields

* removing redundant checks

* Adding improvement of podinformer

* removing the deepcopy logic

* streamlining some redudant log messages

* moving a comment
2021-04-14 12:20:24 -07:00
JungukCho d8169318f1
[NPM] support network policy controller and its unit tests (#849)
* first version of network policy controller and its unit tests

* update reconcile and deleteNetworkPolicy function to correctly install and uninstall default Azure NPM chain.

* To explicitly manage default Azure NPM chain in deleteNetworkPolicy function

* correct comments and delete unused variable

* fix missed returing errors in codes

* Correct to check DeletionTimestamp and DeletionGracePeriodSeconds variables

* removed placeholder functions in network policy controoler and added more test cases (e.g., update and adding multiple network policies)

* - applied comments (use explict names, locating lock in a better place)

* add two methods to save and restore iptables in unit test

* comment out unused function

* early filter in updateNetworkPolicy function if they are the same network policies. Update unit tests to test more network policies events

* - start using klog package instead of log package

* remove unneeded defer for lock

* Locate of adding and deleting network policy object from our network policy cache in a right place. Correct prometheus metric code.

* use cached network policy key instead of network policy object as method parameter in cleanUpNetworkPolicy

* remove redundant check

* Remove ns- prefix as key in RawNpMap. Update UT to check prometheus metrics. Applied better naming and removed redundancy codes.

* minor update for varialbe names

* remove dependency between UT by re-initializing metrics. Correct message.
2021-04-14 10:35:36 -07:00
Mathew Merrick a4b844aa8f
chore: Update NPM limits (#845) 2021-04-09 11:14:52 -07:00
Mathew Merrick 85cd950a1c
[NPM] Add NPM Error structs (#840)
* add NPM tests structs

* remove codecov annotations
2021-03-31 18:43:55 -07:00
Vamsi Kalapala 0b1086b5ca
Fixing a regression with integration of two controllers (#842) 2021-03-31 18:41:49 -07:00
JungukCho a7b5202209
[NPM] Support pod controller and unit test to improve reliability (#836)
* Junguk cho pod controller support (#1)

* code layout to support pod controller in npm

* filter events if they do not need to handle and clean up business logic

* put lock when it needs to access shared resource
use namespace/name as key
clean up functions

* - use pod key instead of uid.
- remove unnecessary error check

* use namespace prefix in pod namespace. add log messages to know what events happens.

* move event logs with more contexts in needsync func

* Put returning an error in a right place

* Return if the RV of both pod obj are the same. Proactively start cleaning up pod when the pod is deleted.

* first version of podController UT

* add ipset management in pod controller unit test

* Make methods flexible for ipset store and restore operation

* clean up functions and variables

Co-authored-by: Junguk Cho <jungukcho@microsoft.com>

* correct and clean functions and error messages. Return errors from appendNamedPortIpsets function to retry syncPod operation

* Check npmPod exists in cleanUpDeletedPod function. Use GetIPSetListFromLabels in syncAddedPod and cleanUpDeletedPod functions. Correct error messages, functions, etc

* Clean up podController code. Make podController UT more flexible.

* clean up appendNamedPortIpsets to improve readibility

* minor update (v1 -> corev1) for consistency

* clean up syncPod code to compare last applied states and new pod's states

* add validation for casting old pod. correct log message

* delete unneeded codes

* minor fix: correct comments and removed unneeded variables

* add pre-filter codes to avoid unnecessary reconcile process in updatePod event

* correct a comment

* check workqueue length to validate case where it does not need to reconcile in unit test
2021-03-31 16:23:19 -07:00
Vamsi Kalapala 45c2fca54c
[NPM] NameSpace resource controller changes (#839)
* Upgrading Namespace to use NSController

* Unit tests for namespace controller

* correcting testcases

* correcting testcases

* correcting testcases

* Adding in more testcases

* adding threadness to NS

* minor imporvements wrt RV

* minor imporvements wrt RV

* minor imporvements wrt RV

* Cleaning up some stale code

* resolving comments

* Addressing some comments

* Addressing some comments

* Adding missing newcontroller

* Addressing more comments

* Addressing more comments
2021-03-31 16:16:34 -07:00
Vamsi Kalapala 9efd8a7869
[NPM] Remove non-fatal error which is causing early bail out (#834)
* Remove non-fatal error which is causing early bail out

* removing the function

* removing the function

* removing the function
2021-03-25 13:58:19 -07:00
Mathew Merrick a0c36fe50b
[fix] IPset fail if set doesn't exist when attempting to add to list (#828)
* ipset fail if set doesn't exist when attempting to add to list

* bail out on add to set when ip is empty

* check set type when adding to list

* revert checking nil value

* fix test build issues

* additional ip check

* ip check with parseip

* prometheus count

* delete from set checks

* delete from set checks

* log on skipping pod

* logging pipeline

* npm logs ci
2021-03-24 10:50:52 -07:00
Vamsi Kalapala 4df65da71d
[NPM] pushing Netpol cache update below errors (#826)
* [NPM] pushing Netpol cache update below errors

* removing some non critical err returns

* Revert "removing some non critical err returns"

This reverts commit 46d5ab46ec.
2021-03-19 20:34:47 -07:00
Vamsi Kalapala 37993588e4
[NPM] Clearing NPM MARKs on packets before accepting them (#823)
* First pass at creating a new chain to accept and clear marks npm added

* Adding rules to defualt chains
2021-03-18 16:16:00 -07:00
Vamsi Kalapala 455f5cb9f0
[NPM] Decoupling resource cache maps from NSmap (#820)
* first pass at decoupling resource maps

* First pass on decoupling resource maps

* Adding telemetry capabilities to resource CRUD events

* Initializing new maps in nprMgr for tests

* Initializing new maps in nprMgr for tests

* Adding artifact for Npm logs

* Addressing comments

* Addressing comments
2021-03-15 16:08:42 -07:00
Mathew Merrick d169929048
Npm debug tools (#817)
* add inital debug tools

* export member variables for debug api

* add dependencies

* update metrics and tests

* remove refactor artifacts
2021-03-11 11:47:34 -08:00
Vamsi Kalapala ba8394046d
[NPM] Caching ability for Pods and NS (#814)
* First pass at implementing pod cache

* handling namedports in case of pod update

* Correcting print error

* Cleaning up pod cache update event. moving pod cache to nsMAP

* Correcting namespace prefix

* Adding in checks on protlists and Podips

* changing some variable names

* changing some variable names

* Adding resource versions checks for Pod, NS and netpols

* fixing some tests

* changing ResourceVersion to uint64 and cleaning up oldpodobj references

* rearranging hostneptol and correcting a UT failure

* Fixing the hostnet pod UT

* Addressing comments

* fixing UT

* Fixing UTs

* correcting pod delete failure bug

* Fixing clean up bug

* Handling hostnet pods in Delete pod

* Addressing comments and ficing a panic error
2021-03-08 10:19:22 -08:00
Mathew Merrick bfbd945917
perf: NPM only writes to stdout instead of file (#811) 2021-03-05 11:08:58 -08:00
Vamsi Kalapala 1e26d075c5
Revert "[NPM] Caching Pod information to compare against desired state (#780)" (#810)
This reverts commit b93e4cca54.
2021-03-02 10:02:17 -08:00
Vamsi Kalapala b93e4cca54
[NPM] Caching Pod information to compare against desired state (#780)
* First pass at implementing pod cache

* handling namedports in case of pod update

* Correcting print error

* Cleaning up pod cache update event. moving pod cache to nsMAP

* Correcting namespace prefix

* Adding in checks on protlists and Podips

* changing some variable names

* changing some variable names

* Adding resource versions checks for Pod, NS and netpols

* fixing some tests

* changing ResourceVersion to uint64 and cleaning up oldpodobj references

* rearranging hostneptol and correcting a UT failure

* Fixing the hostnet pod UT

* Addressing comments

* fixing UT

* Fixing UTs

* correcting pod delete failure bug
2021-03-01 19:43:55 -08:00
Vamsi Kalapala 08f0006dda
[NPM] Default-Deny all bug fix with design change (#799)
* Changed init NPM chains with new chains

* Rearranging target sets

* Fixing UTs

* Fixing UTs

* Fixing UTs
2021-02-26 15:43:12 -08:00
Vamsi Kalapala c4f007e709
Reducing resync time to 15 mins (#789) 2021-02-24 12:45:51 -08:00
Vamsi Kalapala effc4294d3
[NPM] Consolidating default chains and rules for easier readability (#796)
* Consolidating default chains and rules for easier readability

* Adding tests and checks for allchainsandrules

* [build] Update pipeline and enable debug symbols in bins (#793)

* add symbols, add gcflags, update timeouts, only show azure core errors

Co-authored-by: Mathew Merrick <matmerr@users.noreply.github.com>
2021-02-23 17:14:29 -08:00
Vamsi Kalapala 55f53d5abc
[NPM] Periodic Reconciliation of NPM Chain ordering in FORWARD table (#787)
* merge conflict

* Adding in wait to get mitigate defunct process

* Adding error handling and addressing comments

* Addressing some comments

* Adding a testcase for GetlineNumber

* Adding error message in failures

* Adding error message in failures

* correcting the name for Kubeservices chain
2021-02-18 21:10:37 -08:00
Vamsi Kalapala f63d8ca79a
[NPM] DeletedFinalStateUnknown check missed delete events (#785)
* adding better delete watch function logic
2021-02-17 16:01:40 -08:00
Vamsi Kalapala 230122f2cc
[NPM] Fixing log noise and removing GetClusterState (#784) (#786)
* Fixing log noise for hotnet pods

* Removing GetClusterState usage
2021-02-16 16:56:01 -08:00
Vamsi Kalapala 599ea8fb4b
[NPM] Supporting Namespace label updates (#773)
* Supporting Namespace label updates

* first pass at saving NS labels in nsmap

* Strengthing testcases
2021-02-05 08:55:47 -08:00
Vamsi Kalapala 899c3a34e1
[NPM] Ignoring hostnetwork pods from being added into Ipsets (#776)
* Ignoring hostnetwork pods from being added into Ipsets

* generalizing the check on hostnetwork pod

* Adding tests for add, update and delete hostnetwork pods
2021-02-02 14:05:11 -08:00
Vamsi Kalapala 2bc809e17c
Changing src.dst check in egress named port to dst,dst (#768) 2021-01-26 08:33:50 -08:00
Vamsi Kalapala a1f13a8eea
NPM adhering to both ingress and egress rules (#765)
This change will help evaluate both INGRESS and EGRESS rules before accepting/taking a decision on a packet. NPM will now MARK a packet for ingress/egress and RETURN the MARK'ed packet. Then packet will be accepted in the main chain after all the ingress and egress rules are processed.

* first pass trying to return instead of accept

* Adding initial marking capability

* Adding accept on ingress and egress marks

* Correcting an ingress marker

* Correcting unit test cases to show the appropriate markers

* Correcting a comment

* Addressing comments
2021-01-25 12:33:26 -08:00
shchen 0835cae2d1
Change AI log and metrics sending function name in NPM. (#737) 2020-11-23 23:14:31 -08:00
Vamsi Kalapala 8ae7b8ad41
[NPM] 🐞 {fix} error creating IPsets when same string for ports and labels is used (#734)
* Adding port_ format for named ports

* Cleaning existing ipsets incase of a upgrade

* Changing the delimiter for port prefix

* Some basic formatting

* Adding fixes to testcases

* Addressing comments

* Adding mitigation for empty string in named port

* Changing port nil behavior. NPM does partial rule handling in port nil case

* removing exists check, as setmap is not accessible from this test

* Adding support to delete only azure-npm ipsets

* Adding support to delete only azure-npm ipsets

* Addressing comments

* Changing azure-npm to const flag and cleaning up un wanted error log

* Changing the make entries to 0
2020-11-19 23:48:58 -08:00
shchen 61fb84d11e
fix: Resolve flaky TestDestroy ipset unit test (#671)
* fix: Improve TestDestroy unit test validation to make it not flaky.
2020-11-06 16:27:20 -08:00
Mathew Merrick 323b048843
Update NPM Dockerfile (#699) 2020-10-22 11:00:14 -07:00
Shufang f04a9183e5 Change variable name from IP6tables back to Ip6tables. 2020-09-04 12:12:24 -07:00
shchen 1330e4aa3b
Add error log and metrics to AI telemetry. (#656)
* Accelerate metrics report from every 30 mins to every 5 mins.

* Add errCountTest metric.

* Refactor SendAiMetrics. AI initialization is in main routine while send metrics is in another go routine.

* Add aiMetadata config.

* Add SendErrorMetrics function in ai utils.

* Going to push error log to AI telemetry.

* Add error log to AI telemetry.

* Change error message format.

* Add error log and metrics to AI telemetry.

* Remove unnecessary const.

* Change heartbeat back to every 30 mins.

* Seperate send log from SendErrorMetric function for better reuse.

* Change a unit test set name to avoid kernel conflict.

* Address comments. Make error log and metrics sending more generic.

* Fix typo.

* Fix indentation.

* Fix AI initialize issue.

* Remove unnecessary log.

* Use break in if condition.
2020-09-04 10:57:37 -07:00
shchen dc76670115
Add list deletion and validation in unit test. (#659) 2020-08-18 20:11:45 -07:00
shchen e3659a7c2f
Add checking kernel logic in unit test for TestDeleteFromList. (#641) 2020-08-07 15:02:40 -07:00
Hunter Gregory 74c0521de4
Efficient prometheus (#629)
* made ipset inventory metric more efficient for container insights scraping. Added metric for total ipset entries

* updated comment for GetVecValue

* changed prometheus metrics port number from 8000 to 10091 to be next to the node port used in CNS

* added cluster service for NPM Prometheus metrics (lets a scraper only scrape this service for node redundant metrics)

* separated node and cluster metrics into separate registries and HTTP endpoints

* separated functionality for getting IPSetInventory labels and made public

* updated initialization of IPSetInventory to have hash set label and changed ipsm tests to mirror this

* added two yaml options for configuring a prometheus server to scrape NPM efficiently. Removed generic prometheus annotations on NPM pod to prevent default scraping of NPM for a helm prometheus server, and added a specific annotation for the alternative prometheus server config

Co-authored-by: Hunter Gregory <t-hugreg@microsoft.com>
2020-08-05 11:21:29 -04:00
shchen d5694ad088
Simplify AddToSet logic and fix an inconsistency set type creation. (#625)
* Simplify AddToSet logic and fix an inconsistency set type creation.

* Address the comment for checking whether specific set exists.
2020-07-27 12:44:38 -07:00
Hunter Gregory 88ea3c2acd
Prometheus metrics (#590)
* prometheus additions to testmain (commented out right now)

* home of the npm prometheus metrics and tools for updating them, testing them

* add/remove policy metrics

* add/remove iptables rule metric measurements

* add/remove ipset metric measurements

* testing for gauges. want to soon remove the boolean for including prometheus in unit testing

* run http server that exposes prometheus from main

* cleaner test additions with less code

* removed incorrect instance of AddSet in the TestDeleteSet test

* added prometheus annotations to pod templates

* deleted unused file

* much more organized initialization of metrics now. now includes map from metric to metric name

* add ability to get summary count value. now getting gauge values and this new count value are done by passing the metric itself as a param instead of a string

* condenses prometheus testing code base by condensing all prometheus error messages into a function

* added testing for summary counts, condensed prometheus error handling code, and updated calls to use new form for getting metric values

* update based on variable spelling change in metrics package

* Added comments for functions and moved http handler code to the http file

* fixed problem of registering same metric name for different metrics, and passing in the wrong param type for testing

* made prometheus testing folder with interactive testing file. moved old random metric flux testing function over from ipsm_test

* moved testing around again

* fixed spelling mistake

* counting mistake in unit test

* handler variable ws in wrong file. Changed stdout printing to logging

* fixed parameter errors and counting error in a test

* moved utilities for testing prometheus metrics to npm/util. Updated StartHTTP to have an additional parameter for waiting after starting the server

* updated uses of StartHTTP to have the extra parameter

* updated GetValue and GetCountValue uses to use the prometheus features of the util package, which is now moved to a promutil package within npm/metrics/

* removed unnecessary comments, removed print statement, and added quantiles to all summary metrics

* fixed problem of double registering metrics

* wait longer for http server to start

* moved tool in test-util.go to promutil/util.go

* fixed timer to be in milliseconds and updated metric descriptions to mention units

* removed unnecessary comments

* http server always started in a go routine now. Added comment justifying the use of an http server

* debugging http connection refused in pipeline

* fixed syntax error

* removed debugging wrapper around http service

* sleep so that the testing metrics endpoint can be pinged

* redesigned GetValue and GetCountValue so that they don't use http calls

* removed random but helpful testing file - will write about quick testing in a wiki page

* milliseconds were being truncated. now they have decimals

* use direct Prometheus metric commands instead of wrapping them

* removed code used when testing was done through http server. Moved registering to metric creation functions

* added createGaugeVec, updated comments, made all help strings constants

* added metric that counts number of entries in each ipset. still need to add tests

* fixed creation of GaugeVecs, and use explicit labeling instead of order-based labeling now

* updated GetVecValue method signature

* added set to metrics on creation and wrote unit tests for CreateSet, AddToSet, DeleteFromSet, DeleteSet

* use custom registry to limit content that Container Insights scrapes. Also log the start of http server

* wrote TODO item comments for Restore and Destroy (currently these functions are only used in testing)

* NPM won't crash if a Prometheus metric fails to register now (unlikely). Added logging for metric registration/creation, and explicit public function to initialize metrics so that we can finish log config first

* initialize metrics in unit tests

* renamed util.go to test-util.go

Co-authored-by: Hunter Gregory <t-hugreg@microsoft.com>
2020-07-14 19:41:02 -04:00
shchen b92d8c6757
Update NPM logs to use Logf instead of Printf. (#610) 2020-07-14 11:11:25 -07:00
shchen a537df1f45
Add nil pointer checker when reading port value to avoid panic. (#606) 2020-07-10 14:20:36 -07:00
neaggarwMS 508a2bb9c7
Changes for caching pod ip (#600)
* Changes for cahing pod ip

* Test fix for API changes

* added test

* Fixed merge conflicts

* Add tests for pod cache

* Add one more check to validate the cache

* Incorporated the comment

Co-authored-by: neaggarw <neaggarwMS@users.noreply.github.com>
2020-07-10 12:49:18 -07:00
shchen 14e8a980cc
Add logic to hanle different order between namespace selectoer, pod selector, ip block rules. (#604) 2020-07-08 11:08:39 -07:00
shchen d96246eae0
Move ipset deletion condition check from DeleteSet to DeleteFromSet. (#602) 2020-07-08 11:00:36 -07:00
shchen ea5c9a7c21
Add logic to deal with 0.0.0.0/0 which ipset not support. (#599)
* Add logic to deal with 0.0.0.0/0 which ipset not support.

* Add unit test for checking 0.0.0.0/0 ipset entry logic.
2020-07-08 10:00:38 -07:00
neaggarwMS cf25cd318a
Update NPM logs to use Logf instead of Printf (#601) 2020-07-06 10:57:44 -07:00
Mathew Merrick 9f82c3f526
Fix NPM image libgnutls vulnerability (#589)
* lock npm image back to ubuntu 18 for libgnutls vulnerability
2020-06-23 20:52:53 -07:00
shchen 19fb3e6ed5
Move Cidr translation from iptable to ipset. (#582)
* Move Cidr translation from iptable to ipset.

* Move Cidr translation from iptable to ipset.

* Move Cidr translation from iptable to ipset.
2020-06-22 14:35:29 -07:00
shchen 7b3a71fd2a
Update to latest image version for azure-npm.yaml file. (#580) 2020-06-16 14:03:21 -07:00
Jaeryn d3db72e1f7
Re-order NPM IpTable Chains/Rules (#572)
* Move AZURE-NPM chain under KUBE-SERVICES chain; Move default allow CONNECTED/RELATED entry to the end of AZURE-NPM chain.

* Find index of KUBE-SERVICES chain.
2020-06-02 15:45:46 -07:00
Jaeryn 6542186694
Prevent multiple deletions of pods (#563)
* Prevent multiple deletions of pods

* fix deduct policy test
2020-05-20 10:30:35 -07:00
Jaeryn 933e5be2cd
Ignore namespace and pod updates that we have not action items on. (#556) 2020-05-05 16:48:23 -07:00
Jaeryn 6712d8b9b6
Making a fix to prevent NPM from deleting ipsets on delete network policies. (#555) 2020-05-05 11:39:17 -07:00
Jaeryn 5e26843be6
Named Ports Support (#553)
* Initial changes to support named ports.

* add support for named ports via ipset ip+port hash

* fixing a couple of operational bugs

* adding simple test to validate named port parsing
2020-05-01 11:42:05 -07:00
Mathew Merrick 26569aa10d
Update NPM base image to 20.04 (#552) 2020-04-30 11:27:44 -07:00
Jaeryn ef14c8d186
Fix a bug that created a random egress entry when deleting from ingress-centric policy group. Also added a check to add multiple default entries to prevent deletion of once policy to affect another. (#551) 2020-04-29 14:32:22 -07:00
Jaeryn 8162a2bc45
Check Processed NP Map & Add Update Pod Conditions (#546)
* Check raw and processed network policy maps separately in add operation.

* Remove failed & succeeded pods from ipset
2020-04-14 11:19:32 -07:00
Jaeryn 5bcce3b1ac
Revising add and update network policy logic in npm (#544) 2020-04-13 12:35:10 -07:00
Jaeryn e98b789916
Fix NPM Bugs (#542)
* Remove old npm chains which were causing errors on uninit

* Utilize rawNpMap and refrain from updating policies with no change.

* redacted

* add added policy to processedNpMap
2020-04-10 17:54:24 -07:00
Jaeryn 38dc38e898
Move NPM from dep to go mod (#539)
* Moving NPM to use gomod

* Vendoring via go mod

* add more npm tests

* remove go dep specific commands

* adding pipeline changes
2020-04-06 16:18:17 -07:00
Jaeryn 2427888550
Lock update operations to prevent race in between updates. (#536)
* Lock update operations to prevent race in between updates.

* fixing tests

* fixing nwpolicy files
2020-04-03 13:31:02 -07:00
Mathew Merrick d2ba9bb2f3
IPv6 Node IPAM (#532)
* switch to go mod

* pull node spec from apiserver

* carve v6 addresses

* address pool

* update go mod vendor

* build image

* build image

* build image

* separate go mod for npm

* add manager ipv6 ipam test

* added comments and addressed feedback

* address comments

* address comments

* address comments

* check if loaded

* address comments

* update pipeline

* update pipeline

* update test message

Co-authored-by: Ubuntu <azureuser@k8s-agentpool1-23761303-0.2w0jm2xwiahebmp33klngrlq1d.xx.internal.cloudapp.net>
2020-04-02 11:01:05 -07:00
shchen b69f72ea3f
Update npm image version to use the latest v1.0.33 (#521) 2020-03-06 13:22:52 -08:00
Mathew Merrick 358736681c
Upgrade packages at image build time (#504)
* upgrade packages at image build time

* update pipeline to use MCR

* use mcr

* use mcr

* use mcr

* use mcr

* use mcr

* use mcr

* env

* env

* update pipeline

* update pipeline

* update pipeline

* update pipeline

* update pipeline

* update pipeline

* update pipeline

* update pipeline

* update pipeline

* update pipeline

* update pipelines

* update pipelines

* update pipelines
2020-02-21 13:38:14 -08:00
Jaeryn 0576688c57
copy kube-proxy tolerations NPM may run on customer tainted nodes (#493) 2020-02-07 11:53:22 -08:00
Jaeryn 2378d37546
NPM Version Validation (#498)
* The value of minor was incorrectly assumed to be e.g. 14.8-hotfix.20191113 instead of 14+

* adding Jonathan Chauncey's test

* addressing Robbie's comments
2020-02-07 11:49:22 -08:00
Ashvin Deodhar ca00635a6b
Fix CNS regression (#489)
log.SetTarget creates the log file under log directory using golang os package. Whenever code sets the log directory, it needed to call SetTarget to create the actual log file under that directory. In the recent logger changes, InitLogger by default set the log directory to the current folder. This created the log file in the current folder. The code then set the log directory to a different location without a subsequent call to log.SetTarget. This resulted into the logger to not find the actual log file in the set log directory.

This fix updates the logger InitLogger function to accept the log directory to create the file in correct log directory. To avoid having such issue, this fix also combines the function calls to set log directory and set target into a single function. This prevents any out of order calls resulting into such issue.
2020-01-30 09:33:35 -08:00
Jaeryn 21888133e9
Limit NPM AI Telemetry Handle Retrievals (#488)
* let npm loop 30 min (1 heartbeat interval) for AI telemetry handle

* fix cns dockerfile so that it may resolve it's ip via env var
2020-01-29 15:01:56 -08:00
Jaeryn dd1777c776
Network Policy Namespace Leak (#479)
* add changes to contain rule application within policy namespace

* fix slice leak

* fixing pod and namespace selector combination bug
2020-01-24 16:23:08 -08:00
Jaeryn df012bcd1f
Adding AI metrics for NPM (#475)
* Adding AI metrics for NPM

* addressing tamilmani's comments
2020-01-23 13:52:30 -08:00
Mathew Merrick 94759f579b Azure NPM UT Test Refactor (#467)
* add policy yamls for test scenarios

* fix policy names

* fix jump entry
2020-01-02 18:16:31 -08:00
Jaeryn e6c4e77476
append jump ipt entries and prepend the rest (#468) 2020-01-02 16:19:58 -08:00
Jaeryn d272578994
We need to allow external instead of all-namespaces when ingress/egress rules only contain {} (#466) 2020-01-02 14:26:27 -08:00
jaer-tsun 570f9b0920
Prevent Namespace Race (#463)
* poll api-server version for a minute before panicking

* always add namespace set, when adding nw policy

* create the ns set in add pod, if add namespace has not been called yet
2019-12-19 21:38:57 -08:00
jaer-tsun 43746bc677
apply policies in a way where the network policy may seem order agnostic (#462) 2019-12-18 16:28:08 -08:00
jaer-tsun 8ae2c0a3a2
Merge NPM Port Rules Properly (#456)
* Fix NPM port rules

* Add port entry logic for ipblock, namespace, and pod selector; Fix tests.

* removing unnecessary hops between chains
2019-12-17 15:45:28 -08:00
jaer-tsun 61ccd6f387
Fix NPM Regression & Remove TelemetryBuffer Sidecar (#449)
* give precedence to drop rules (over allow)

* - Moving kube-system-chain above target-sets-chain
- Add drop entry at the end of Ingress-From and Egress-To chains when there are non Allow-All* entries

* write logs to stdout (and log file) so that we can see logs via kubectl

* removing kube-system chain and fixing tests

* removing telemetry buffer
2019-12-05 13:58:11 -08:00
jaer-tsun d27696bb9b
K8s Version Comparison Fix (#437)
* Modifying the way we compare k8s version so that we don't fail versions with hotfix / pre-release tag

* cleaning build directory
2019-11-14 18:25:17 -08:00
Mathew Merrick 2c0ae6d723 Allow egress all and ingress all without target set (#435)
* allow all egress and ingress without drop

* remove comment breaks

* update test

* remove sleep and socket cleanup

* address feedback

* all namespaces

* fix tests

* update npm test

* aks-engine

* aks-engine

* pipeline

* pipeline

* pipeline

* pipeline

* remove comment breaks

* remove comment breaks

* remove comment breaks

* remove comment breaks

* pipeline

* pipeline

* pipeline

* pipeline

* pipeline

* pipeline

* pipeline

* pipeline

* pipeline

* pipeline

* pipeline

* pipeline

* pipeline
2019-11-14 11:11:11 -08:00
jaer-tsun ca99852ac1
Pull azure-vnet-telemetry image from MCR (#416) 2019-10-01 12:28:23 -04:00
jaer-tsun 2e8d6f556e
Update npm yaml to version v1.0.28 (#414) 2019-09-30 20:39:19 -04:00
Yongli Chen ff7b9c0801 clear stale states on creation (#411)
* clear stale states on creation

* log first UninitNpmChains() call

* adding kube system namespace after reboot
2019-09-30 19:09:49 -04:00
jaer-tsun f2c8c38903 Adding tests to verify that allow policies should take precedence over deny (#405) 2019-09-25 17:45:22 -07:00
Yongli Chen d2b3f58cef
Update azure-npm.yaml (#404) 2019-09-25 11:32:29 -07:00
Mathew Merrick c44e775344
NPM test fixes + Azure Pipelines (#402)
Initial Azure Pipelines config, run pipeline tests in container, CNM and NPM fixes
2019-09-20 16:15:08 -07:00
jaer-tsun 3ad49688d9 Fix default drop entries (#398)
* Retrieve and append the appropriate default drop entries based on policy type.

* Modifying translate_policy unit tests that use getDefaultDropEntries.

* Address Yongli's comments
2019-09-16 13:56:37 -07:00
Yongli Chen 36f188cfc9
Merge policies (#390) 2019-08-30 14:02:45 -07:00
Yongli Chen d1d8d95ace
update base image to ubuntu:19.10 (#378) 2019-07-19 15:41:07 -07:00
Yongli Chen f6bff8e3af
change telemetry to message queue and add npm (#366)
* change telemetry to message queue and add npm

* remove [Azure-NPM] prefix

* remove npmreport url

* fair scheduling

* holds up to 1k reports for each type

* fix cap on reports
2019-06-19 14:08:35 -07:00
tamilmani1989 313878e8c3
added default wait timeot to 60 seconds to get iptable lock (#343) 2019-04-24 16:34:58 -07:00
tamilmani1989 9cfec88252
add following support: (#342)
1. ip6table cmd support
2. wiat falg with timeout
2019-04-24 16:04:37 -07:00
Yongli Chen cc49b45924
Add azure-npm documentation (#329)
* add azure-npm documentation

* address comment
2019-04-11 12:38:53 -07:00
Yongli Chen ea70592862
Handle failover scenarios (#320) 2019-03-27 11:23:54 -07:00
Yongli Chen 97d3ddc13c
Honoring xtables lock (#315) 2019-03-20 14:25:53 -07:00
Yongli Chen d8d848fe24
Support new network policy definition since Kubernetes version 1.11 (#307) 2019-03-01 15:46:17 -08:00
jaer-tsun e5f6b0d03c
Update host machine ip (#300)
* Limiting the size of our buffered payload to ~2MB

* Changing IPs for calls to host machines from 169.254.169.254 to 168.63.129.16.
2019-02-26 16:03:29 -08:00
Tamilmani Manoharan d05cabc9cd removed calling gethostmetadata from npm as it will called by telemetry process 2019-02-01 17:22:04 -08:00
Tamilmani Manoharan 55dbf50359 fixed compilation issue in npm 2019-02-01 17:10:18 -08:00
Yongli Chen 434ddf768f
LIFO order for network policies (#258)
* reverseOrder

* add npm to circleCI
2018-10-12 15:40:45 -07:00
jaer-tsun 45914be23d
Adding telemetry report functions for DNC. (#216)
* Adding telemetry report functions for DNC.

* Addressing Yongli's suggestions.

* commit to switch branches

* Adding some changes to npm due to telemetry change.

* Modifying tests for interface reports...
2018-08-16 14:12:58 -07:00
Yongli Chen 6a0f9ff207
Add Azure-npm to provide k8s network policy support (#173)
* address comments

* make azure-npm versiona consistent with main version

* Npm telemetry (#12)

* azure-npm

* set logging file

* parameterize telemetry API

* avoid null ptr derefence

* add telemetry to npm

* address comments

* add descriptive comments

* add copyright info

* returns on err
2018-07-19 14:23:11 -07:00