|
| 1 | +# cyclonus analyze |
| 2 | + |
| 3 | +The `analyze` command provides a suite of tools for understanding and poking network policies, |
| 4 | +without the need for a working kubernetes cluster or CNI. |
| 5 | + |
| 6 | +It provides several modes which can be activated by a `--mode $MODE` flag. Multiple `--mode` |
| 7 | +flags may be provided in a single invocation. |
| 8 | + |
| 9 | +## Supported flags |
| 10 | + |
| 11 | +```bash |
| 12 | +cyclonus analyze -h |
| 13 | +analyze network policies |
| 14 | + |
| 15 | +Usage: |
| 16 | + cyclonus analyze [flags] |
| 17 | + |
| 18 | +Flags: |
| 19 | + -A, --all-namespaces reads kube resources from all namespaces; same as kubectl's '--all-namespaces'/'-A' flag |
| 20 | + --context string selects kube context to read policies from; only reads from kube if one or more namespaces or all namespaces are specified |
| 21 | + -h, --help help for analyze |
| 22 | + --mode strings analysis modes to run; allowed values are parse,explain,lint,query-traffic,query-target,probe (default [explain]) |
| 23 | + -n, --namespace strings namespaces to read kube resources from; similar to kubectl's '--namespace'/'-n' flag, except that multiple namespaces may be passed in and is empty if not set explicitly (instead of 'default' as in kubectl) |
| 24 | + --policy-path string may be a file or a directory; if set, will attempt to read policies from the path |
| 25 | + --probe-path string path to json model file for synthetic probe |
| 26 | + --simplify-policies if true, reduce policies to simpler form while preserving semantics (default true) |
| 27 | + --target-pod-path string path to json target pod file -- json array of dicts |
| 28 | + --traffic-path string path to json traffic file, containing of a list of traffic objects |
| 29 | + --use-example-policies if true, reads example policies |
| 30 | + |
| 31 | +Global Flags: |
| 32 | + -v, --verbosity string log level; one of [info, debug, trace, warn, error, fatal, panic] (default "info") |
| 33 | +``` |
| 34 | +
|
| 35 | +## Mode examples |
| 36 | +
|
| 37 | +### `--mode explain`: explains network policies |
| 38 | +
|
| 39 | +Groups policies by target, divides rules into egress and ingress, and gives a basic explanation of the combined |
| 40 | +policies. This clarifies the interactions between "denies" and "allows" from multiple policies. |
| 41 | +
|
| 42 | +``` |
| 43 | +cyclonus analyze \ |
| 44 | + --mode explain \ |
| 45 | + --policy-path ./networkpolicies/simple-example/ |
| 46 | + |
| 47 | ++---------+---------------+------------------------+---------------------+--------------------------+ |
| 48 | +| TYPE | TARGET | SOURCE RULES | PEER | PORT/PROTOCOL | |
| 49 | ++---------+---------------+------------------------+---------------------+--------------------------+ |
| 50 | +| Ingress | namespace: y | y/allow-label-to-label | no ips | no ports, no protocols | |
| 51 | +| | Match labels: | y/deny-all-for-label | | | |
| 52 | +| | pod: a | | | | |
| 53 | ++ + + +---------------------+--------------------------+ |
| 54 | +| | | | namespace: y | all ports, all protocols | |
| 55 | +| | | | pods: Match labels: | | |
| 56 | +| | | | pod: c | | |
| 57 | ++ +---------------+------------------------+---------------------+ + |
| 58 | +| | namespace: y | y/allow-all-for-label | all pods, all ips | | |
| 59 | +| | Match labels: | | | | |
| 60 | +| | pod: b | | | | |
| 61 | ++ +---------------+------------------------+---------------------+--------------------------+ |
| 62 | +| | namespace: y | y/allow-by-ip | ports for all IPs | no ports, no protocols | |
| 63 | +| | Match labels: | | | | |
| 64 | +| | pod: c | | | | |
| 65 | ++ + + +---------------------+--------------------------+ |
| 66 | +| | | | 0.0.0.0/24 | all ports, all protocols | |
| 67 | +| | | | except [] | | |
| 68 | +| | | | | | |
| 69 | ++ + + +---------------------+--------------------------+ |
| 70 | +| | | | no pods | no ports, no protocols | |
| 71 | +| | | | | | |
| 72 | +| | | | | | |
| 73 | ++ +---------------+------------------------+---------------------+ + |
| 74 | +| | namespace: y | y/deny-all | no pods, no ips | | |
| 75 | +| | all pods | | | | |
| 76 | ++---------+---------------+------------------------+---------------------+--------------------------+ |
| 77 | +``` |
| 78 | +
|
| 79 | +### `--mode query-target`: which policy rules apply to a pod? |
| 80 | +
|
| 81 | +This takes the previous command a step further: it combines the rules from all the targets that apply |
| 82 | +to a pod. |
| 83 | +
|
| 84 | +``` |
| 85 | +cyclonus analyze \ |
| 86 | + --mode query-target \ |
| 87 | + --policy-path ./networkpolicies/simple-example/ \ |
| 88 | + --target-pod-path ./examples/targets.json |
| 89 | + |
| 90 | +pod in ns y with labels map[pod:a]: |
| 91 | ++---------+---------------+-----------------------------+---------------------+--------------------------+ |
| 92 | +| TYPE | TARGET | SOURCE RULES | PEER | PORT/PROTOCOL | |
| 93 | ++---------+---------------+-----------------------------+---------------------+--------------------------+ |
| 94 | +| Ingress | namespace: y | y/allow-label-to-label | no ips | no ports, no protocols | |
| 95 | +| | Match labels: | y/deny-all-for-label | | | |
| 96 | +| | pod: a | y/deny-all | | | |
| 97 | ++ + + +---------------------+--------------------------+ |
| 98 | +| | | | namespace: y | all ports, all protocols | |
| 99 | +| | | | pods: Match labels: | | |
| 100 | +| | | | pod: c | | |
| 101 | ++---------+---------------+-----------------------------+---------------------+--------------------------+ |
| 102 | +| | | | | | |
| 103 | ++---------+---------------+-----------------------------+---------------------+--------------------------+ |
| 104 | +| Egress | namespace: y | y/deny-all-egress | all pods, all ips | all ports, all protocols | |
| 105 | +| | Match labels: | y/allow-all-egress-by-label | | | |
| 106 | +| | pod: a | | | | |
| 107 | ++---------+---------------+-----------------------------+---------------------+--------------------------+ |
| 108 | +``` |
| 109 | +
|
| 110 | +
|
| 111 | +### `--mode query-traffic`: will policies allow or block traffic? |
| 112 | +
|
| 113 | +Given arbitrary traffic examples (from a source to a destination, including labels, over a port and protocol), |
| 114 | +this command parses network policies and determines if the traffic is allowed or not. |
| 115 | +
|
| 116 | +``` |
| 117 | +cyclonus analyze \ |
| 118 | + --mode query-traffic \ |
| 119 | + --policy-path ./networkpolicies/simple-example/ \ |
| 120 | + --traffic-path ./examples/traffic.json |
| 121 | +
|
| 122 | +Traffic: |
| 123 | ++--------------------------+-------------+---------------+-----------+-----------+------------+ |
| 124 | +| PORT/PROTOCOL | SOURCE/DEST | POD IP | NAMESPACE | NS LABELS | POD LABELS | |
| 125 | ++--------------------------+-------------+---------------+-----------+-----------+------------+ |
| 126 | +| 80 (serve-80-tcp) on TCP | source | 192.168.1.99 | y | ns: y | app: c | |
| 127 | ++ +-------------+---------------+ + +------------+ |
| 128 | +| | destination | 192.168.1.100 | | | pod: b | |
| 129 | ++--------------------------+-------------+---------------+-----------+-----------+------------+ |
| 130 | +
|
| 131 | +Is traffic allowed? |
| 132 | ++-------------+--------+---------------+ |
| 133 | +| TYPE | ACTION | TARGET | |
| 134 | ++-------------+--------+---------------+ |
| 135 | +| Ingress | Allow | namespace: y | |
| 136 | +| | | Match labels: | |
| 137 | +| | | pod: b | |
| 138 | ++ +--------+---------------+ |
| 139 | +| | Deny | namespace: y | |
| 140 | +| | | all pods | |
| 141 | ++-------------+--------+---------------+ |
| 142 | +| | | | |
| 143 | ++-------------+--------+---------------+ |
| 144 | +| Egress | Deny | namespace: y | |
| 145 | +| | | all pods | |
| 146 | ++-------------+--------+---------------+ |
| 147 | +| IS ALLOWED? | FALSE | |
| 148 | ++-------------+--------+---------------+ |
| 149 | +``` |
| 150 | +
|
| 151 | +### `--mode probe`: simulates a connectivity probe |
| 152 | +
|
| 153 | +Runs a simulated connectivity probe against a set of network policies, without using a kubernetes cluster. |
| 154 | +
|
| 155 | +``` |
| 156 | +cyclonus analyze \ |
| 157 | + --mode probe \ |
| 158 | + --policy-path ./networkpolicies/simple-example/ \ |
| 159 | + --probe-path ./examples/probe.json |
| 160 | +
|
| 161 | +Combined: |
| 162 | ++-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+ |
| 163 | +| | X/A | X/B | X/C | Y/A | Y/B | Y/C | Z/A | Z/B | Z/C | |
| 164 | ++-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+ |
| 165 | +| x/a | . | . | . | X | . | X | . | . | . | |
| 166 | +| x/b | . | . | . | X | . | X | . | . | . | |
| 167 | +| x/c | . | . | . | X | . | X | . | . | . | |
| 168 | +| y/a | . | . | . | X | . | X | . | . | . | |
| 169 | +| y/b | . | . | . | X | . | X | . | . | . | |
| 170 | +| y/c | X | X | X | X | X | X | X | X | X | |
| 171 | +| z/a | . | . | . | X | . | X | . | . | . | |
| 172 | +| z/b | . | . | . | X | . | X | . | . | . | |
| 173 | +| z/c | . | . | . | X | . | X | . | . | . | |
| 174 | ++-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+ |
| 175 | +``` |
| 176 | +
|
| 177 | +### `--mode lint`: lints network policies |
| 178 | +
|
| 179 | +Checks network policies for common problems. |
| 180 | +
|
| 181 | +``` |
| 182 | +cyclonus analyze \ |
| 183 | + --mode lint \ |
| 184 | + --policy-path ./networkpolicies/simple-example |
| 185 | +
|
| 186 | ++-----------------+------------------------------+-------------------+-----------------------------+ |
| 187 | +| SOURCE/RESOLVED | TYPE | TARGET | SOURCE POLICIES | |
| 188 | ++-----------------+------------------------------+-------------------+-----------------------------+ |
| 189 | +| Resolved | CheckTargetAllEgressAllowed | namespace: y | y/allow-all-egress-by-label | |
| 190 | +| | | | | |
| 191 | +| | | pod selector: | | |
| 192 | +| | | matchExpressions: | | |
| 193 | +| | | - key: pod | | |
| 194 | +| | | operator: In | | |
| 195 | +| | | values: | | |
| 196 | +| | | - a | | |
| 197 | +| | | - b | | |
| 198 | +| | | | | |
| 199 | ++-----------------+------------------------------+-------------------+-----------------------------+ |
| 200 | +| Resolved | CheckDNSBlockedOnTCP | namespace: y | y/deny-all-egress | |
| 201 | +| | | | | |
| 202 | +| | | pod selector: | | |
| 203 | +| | | {} | | |
| 204 | +| | | | | |
| 205 | ++-----------------+------------------------------+-------------------+-----------------------------+ |
| 206 | +| Resolved | CheckDNSBlockedOnUDP | namespace: y | y/deny-all-egress | |
| 207 | +| | | | | |
| 208 | +| | | pod selector: | | |
| 209 | +| | | {} | | |
| 210 | +| | | | | |
| 211 | ++-----------------+------------------------------+-------------------+-----------------------------+ |
| 212 | +``` |
0 commit comments