Skip to content

Commit 5df0737

Browse files
authored
fix: support for anywhere network policies in cilium (#884)
## Description Reference [this doc](https://github.com/cilium/cilium/blob/v1.16.2/Documentation/network/kubernetes/policy.rst#networkpolicy) for the limitations of Cilium with `ipBlock` based netpols. Two changes included to support this behavior: - Modifies the keycloak backchannel policy to include all namespaces instead of using the `Anywhere` generated target. This was intended to be anywhere in cluster anyways (see the deleted TODO comment in the diff). - Modifies `Anywhere` target to include both the `0.0.0.0/0` CIDR and an empty namespace selector. For any non-Cilium CNIs `0.0.0.0/0` would've already covered any in-cluster endpoints, so this only changes the behavior for Cilium. ## Related Issue Fixes #871 ## Type of change - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Other (security config, docs update, etc) ## Checklist before merging - [x] Test, docs, adr added or updated as needed - [x] [Contributor Guide](https://github.com/defenseunicorns/uds-template-capability/blob/main/CONTRIBUTING.md) followed
1 parent 26ea612 commit 5df0737

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

src/keycloak/chart/templates/uds-package.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,12 @@ spec:
2626
app: pepr-uds-core-watcher
2727
port: 8080
2828

29-
# Temp workaround for any cluster pod
30-
# todo: remove this once cluster pods is a remote generated target
3129
- description: "Keycloak backchannel access"
3230
direction: Ingress
3331
selector:
3432
app.kubernetes.io/name: keycloak
35-
remoteGenerated: Anywhere
33+
# Allow access from anything in cluster using an empty namespace selector
34+
remoteNamespace: "*"
3635
port: 8080
3736

3837
# Keycloak OCSP to check certs cannot guarantee a static IP

src/pepr/operator/controllers/network/generate.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { V1NetworkPolicyPeer, V1NetworkPolicyPort } from "@kubernetes/client-nod
33
import { kind } from "pepr";
44

55
import { Allow, RemoteGenerated } from "../../crd";
6-
import { anywhere } from "./generators/anywhere";
6+
import { anywhere, anywhereInCluster } from "./generators/anywhere";
77
import { cloudMetadata } from "./generators/cloudMetadata";
88
import { intraNamespace } from "./generators/intraNamespace";
99
import { kubeAPI } from "./generators/kubeAPI";
@@ -31,7 +31,7 @@ function getPeers(policy: Allow): V1NetworkPolicyPeer[] {
3131
break;
3232

3333
case RemoteGenerated.Anywhere:
34-
peers = [anywhere];
34+
peers = [anywhere, anywhereInCluster];
3535
break;
3636
}
3737
} else if (policy.remoteNamespace !== undefined || policy.remoteSelector !== undefined) {

src/pepr/operator/controllers/network/generators/anywhere.ts

+8
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,11 @@ export const anywhere: V1NetworkPolicyPeer = {
99
except: [META_IP],
1010
},
1111
};
12+
13+
/** Matches any endpoint in cluster
14+
* This is primarily to support Cilium where IP based policies do not match/allow anything in-cluster
15+
* Ref: https://github.com/defenseunicorns/uds-core/issues/871 and https://github.com/cilium/cilium/blob/v1.16.2/Documentation/network/kubernetes/policy.rst#networkpolicy
16+
*/
17+
export const anywhereInCluster: V1NetworkPolicyPeer = {
18+
namespaceSelector: {},
19+
};

0 commit comments

Comments
 (0)