sidecar
This commit is contained in:
@@ -10,7 +10,15 @@ metadata:
|
|||||||
policies.kyverno.io/severity: medium
|
policies.kyverno.io/severity: medium
|
||||||
policies.kyverno.io/subject: Pod
|
policies.kyverno.io/subject: Pod
|
||||||
policies.kyverno.io/description: >-
|
policies.kyverno.io/description: >-
|
||||||
Injects an auth sidecar container into Pods annotated with policies.forteapps.io/auth: "true". The sidecar proxies requests through a token-based auth layer. If the auth-tokens Secret does not exist in the namespace, an empty one is created to prevent volume mount failures. Upstream URL and image can be overridden via policies.forteapps.io/auth-upstream-url and policies.forteapps.io/auth-image annotations.
|
Injects an auth sidecar container into Pods annotated with
|
||||||
|
policies.forteapps.io/auth: "true". The sidecar proxies requests through
|
||||||
|
a token-based auth layer and a NetworkPolicy is generated to restrict
|
||||||
|
ingress to the sidecar port only. If the auth-tokens Secret does not
|
||||||
|
exist in the namespace, an empty one is created to prevent volume mount
|
||||||
|
failures. Upstream URL and image can be overridden via
|
||||||
|
policies.forteapps.io/auth-upstream-url and
|
||||||
|
policies.forteapps.io/auth-image annotations. When auth-upstream-url is
|
||||||
|
not set, the first containerPort of the first existing container is used.
|
||||||
spec:
|
spec:
|
||||||
background: false
|
background: false
|
||||||
rules:
|
rules:
|
||||||
@@ -32,6 +40,10 @@ spec:
|
|||||||
- argocd
|
- argocd
|
||||||
- cert-manager
|
- cert-manager
|
||||||
- monitoring
|
- monitoring
|
||||||
|
context:
|
||||||
|
- name: appPort
|
||||||
|
variable:
|
||||||
|
jmesPath: request.object.spec.containers[0].ports[0].containerPort || `3000`
|
||||||
mutate:
|
mutate:
|
||||||
patchStrategicMerge:
|
patchStrategicMerge:
|
||||||
spec:
|
spec:
|
||||||
@@ -46,7 +58,7 @@ spec:
|
|||||||
- name: AUTH_LISTEN_ADDR
|
- name: AUTH_LISTEN_ADDR
|
||||||
value: ":8080"
|
value: ":8080"
|
||||||
- name: AUTH_UPSTREAM_URL
|
- name: AUTH_UPSTREAM_URL
|
||||||
value: "{{ request.object.metadata.annotations.\"policies.forteapps.io/auth-upstream-url\" || 'http://localhost:3000' }}"
|
value: "{{ request.object.metadata.annotations.\"policies.forteapps.io/auth-upstream-url\" || join('', ['http://localhost:', to_string(appPort)]) }}"
|
||||||
- name: AUTH_TOKEN_FILE
|
- name: AUTH_TOKEN_FILE
|
||||||
value: "/etc/auth/tokens"
|
value: "/etc/auth/tokens"
|
||||||
- name: AUTH_MODE
|
- name: AUTH_MODE
|
||||||
@@ -122,3 +134,48 @@ spec:
|
|||||||
app.kubernetes.io/created-by: inject-auth-sidecar
|
app.kubernetes.io/created-by: inject-auth-sidecar
|
||||||
type: Opaque
|
type: Opaque
|
||||||
data: {}
|
data: {}
|
||||||
|
- name: generate-auth-network-policy
|
||||||
|
skipBackgroundRequests: true
|
||||||
|
match:
|
||||||
|
any:
|
||||||
|
- resources:
|
||||||
|
kinds:
|
||||||
|
- Pod
|
||||||
|
annotations:
|
||||||
|
policies.forteapps.io/auth: "true"
|
||||||
|
exclude:
|
||||||
|
any:
|
||||||
|
- resources:
|
||||||
|
namespaces:
|
||||||
|
- kube-system
|
||||||
|
- kyverno
|
||||||
|
- argocd
|
||||||
|
- cert-manager
|
||||||
|
- monitoring
|
||||||
|
preconditions:
|
||||||
|
all:
|
||||||
|
- key: "{{ request.operation }}"
|
||||||
|
operator: In
|
||||||
|
value:
|
||||||
|
- CREATE
|
||||||
|
generate:
|
||||||
|
synchronize: false
|
||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
kind: NetworkPolicy
|
||||||
|
name: "{{ request.object.metadata.name }}-auth-ingress"
|
||||||
|
namespace: "{{ request.namespace }}"
|
||||||
|
data:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/managed-by: kyverno
|
||||||
|
app.kubernetes.io/created-by: inject-auth-sidecar
|
||||||
|
spec:
|
||||||
|
podSelector:
|
||||||
|
matchLabels:
|
||||||
|
"{{ request.object.metadata.labels }}"
|
||||||
|
policyTypes:
|
||||||
|
- Ingress
|
||||||
|
ingress:
|
||||||
|
- ports:
|
||||||
|
- port: 8080
|
||||||
|
protocol: TCP
|
||||||
|
|||||||
Reference in New Issue
Block a user