-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec6fe0f
commit 56a60b5
Showing
5 changed files
with
246 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,237 @@ | ||
--- | ||
title: "Istio Security" | ||
toc: true | ||
toc_sticky: true | ||
categories: ["Kubernetes", "Istio", "Security"] | ||
excerpt: "`PeerAuthentication`μΌλ‘ Istio μν¬λ‘λμ μ κ·Όλ§ νμ©νκΈ°, `AuthorizationPolicy`λ‘ μλν¬μΈνΈ μ κ·Ό μ μ΄νκΈ°, `Sidecar`λ‘ Envoy Sidecar κ΅¬μ± μ»€μ€ν νκΈ°" | ||
last_modified_at: 2024-03-05 | ||
--- | ||
|
||
![](https://www.asylas.com/wp-content/uploads/2020/12/9-Awareness-Training.jpg){: .align-center } | ||
|
||
λΆμ° μμ€ν μμμ "μλ²½ν" μλΉμ€ λ©μ¬λ₯Ό μ 곡νκΈ° μν΄μ Istioλ "보μ" κ΄λ ¨λ μ¬λ¬ κΈ°λ₯λ€μ μ 곡νλ€!! | ||
|
||
|
||
# `PeerAuthentication` | ||
|
||
μ건 istio μν¬λ‘λμ `mTLS`μ νΈλν½λ§ μ κ·Όλ§ νμ©ν κ²μΈμ§(`STRICT`) μλλ©΄ mTLSκ° μ μ©λμ§ μμ νΈλν½ μ κ·Όλ νμ©ν κ²μΈμ§(`PERMISSIVE`) κ²°μ νλ μ μ± μ΄λ€. | ||
|
||
```yaml | ||
$ kubectl apply -f - <<EOF | ||
apiVersion: security.istio.io/v1beta1 | ||
kind: PeerAuthentication | ||
metadata: | ||
name: only-mtls-allow | ||
namespace: default | ||
spec: | ||
mtls: | ||
mode: STRICT | ||
EOF | ||
``` | ||
|
||
μ΄λ κ² μ€μ ν κ²½μ°, `default` λ€μμ€νμ΄μ€λ‘ ν₯νλ νΈλν½μ λͺ¨λ mTLSλ‘ μνΈν λμ΄μΌ νλ€. κ·Έλ°λ°, mTLS μνΈνκ° λμλ€λ λ§μ΄ 곧 κ·Έ μν¬λ‘λκ° Istio μλΉμ€ λ©μ¬ μμ μλ€λ λ§μ΄κΈ° λλ¬Έμ κ²°κ΅ Istio μλΉμ€ λ©μ¬μ μν¬λ‘λμ μ κ·Όλ§ νμ©νκ² λ€λ κ²μ΄λ€. | ||
|
||
```bash | ||
$ kubectl exec ... -n non-istio -- sh | ||
~# curl helloworld.default:5000/hello | ||
curl: (56) Recv failure: Connection reset by peer | ||
``` | ||
|
||
λ§μ½ istio μν¬λ‘λκ° μλ κ³³μμ μμ²μ 보λΈλ€λ©΄ μ΄λ κ² μ κ·Όμ΄ λΆκ°λ₯νλ€. | ||
|
||
# `AuthorizationPolicy` | ||
|
||
νΉμ Namespaceμ 리μμ€μ λν Call νΈμΆμ μ ν(Deny) νκ±°λ νμ©(Allow) ν λλ‘ μ§μ ν μ μλ 리μμ€μ΄λ€. | ||
|
||
κ°μ₯ κ°λ¨ν `default` λ€μμ€νμ΄μ€μ μν¬λ‘λλ₯Ό `test` λ€μμ€νμ΄μ€λ‘λΆν° 보νΈνλ `AuthorizationPolicy`λΆν° μ΄ν΄λ³΄μ. | ||
|
||
```yaml | ||
$ kubectl apply -f - <<EOF | ||
apiVersion: security.istio.io/v1 | ||
kind: AuthorizationPolicy | ||
metadata: | ||
name: protect-from-test | ||
namespace: default | ||
spec: | ||
action: DENY | ||
rules: | ||
- from: | ||
- source: | ||
namespaces: ["test"] | ||
EOF | ||
``` | ||
|
||
μμ κ°μ AuthPolicyκ° μμ±λμλ€λ©΄, `test` λ€μμ€νμ΄μ€λ μν¬λ‘λμ μ κ·Όνλ €κ³ ν λ, μ΄λ° μλ¬λ₯Ό λ°λλ€. | ||
|
||
```bash | ||
$ kubectl exec -n test ... -- sh | ||
~# curl helloworld.default:5000/hello | ||
RBAC: access denied | ||
``` | ||
|
||
κ·Έλ°λ° μμ AuthPolicyλ `test` λ€μμ€νμ΄μ€μ μ κ·Όμ λ§μμ λΏ λ€λ₯Έ λ€μμ€νμ΄μ€μμμ μ κ·Όμ μ μ΄λ€μ§λ€! | ||
|
||
λ§μ½, λ°λλ‘ νΉμ λ€μμ€νμ΄μ€μ μ κ·Όλ§μ νμ©νκ³ μΆλ€λ©΄ 리μμ€λ₯Ό μ΄λ κ² λ§λ€μ΄λ³΄μ. | ||
|
||
```bash | ||
$ kubectl delete authorizationpolicy -n default protect-from-test | ||
``` | ||
|
||
```yaml | ||
$ kubectl apply -f - <<EOF | ||
apiVersion: security.istio.io/v1 | ||
kind: AuthorizationPolicy | ||
metadata: | ||
name: only-allow-from-test | ||
namespace: default | ||
spec: | ||
action: ALLOW | ||
rules: | ||
- from: | ||
- source: | ||
namespaces: ["test"] | ||
EOF | ||
``` | ||
|
||
μ΄λ κ² νλ©΄, λ°λλ‘ `test` λ€μμ€νμ΄μ€μ μ κ·Όμ νμ©νμ§λ§, λ€λ₯Έ λ€μμ€νμ΄μ€λ‘λΆν°μ μ κ·Όμ κ±°λΆ λλ€. | ||
|
||
λ¨, κ°μ λ€μμ€νμ΄μ€μΈ `default` λ€μμ€νμ΄μ€μ 리μμ€λ€ κ°μ ν΅μ λ κ±°λΆλκΈ° λλ¬Έμ μ£Όμν κ²!! | ||
|
||
λ€μμ€νμ΄μ€ μΈμλ λ€λ₯Έ λͺκ°μ§ 쑰건λ€λ‘ μ κ·Όμ μ μ΄ν μ μλ€. | ||
|
||
νΈλν½μ μΆλ°μ§λ₯Ό κΈ°μ€μΌλ‘ | ||
|
||
- `namespace` | ||
- `ipBlocks` | ||
- `remoteIpBlocks` | ||
|
||
νΈλν½μ΄ λμ°© μ§μ μ κΈ°μ€μΌλ‘ | ||
|
||
- `hosts` | ||
- `ports` | ||
- `methods` | ||
- `paths` | ||
|
||
λ±μ κΈ°μ€μΌλ‘ μ κ·Ό μ μ΄λ₯Ό μνν μ μλ€. | ||
|
||
# `Sidecar` | ||
|
||
Istio μλΉμ€λ©μ¬μμ Envoy SideCarμ λν λ€νΈμν¬ κ΅¬μ±μ λͺ μνλ 리μμ€μ΄λ€. | ||
|
||
## Egress Listener | ||
|
||
μλ₯Ό λ€μ΄, μλμ `Sidecar` 리μμ€λ₯Ό λ§λ€λ©΄, `default` λ€μμ€νμ΄μ€μμ `default`μ `test`μ μν¬λ‘λλ‘λ§ μ κ·Όν μ μλ€. | ||
|
||
```yaml | ||
$ kubectl apply -f - <<EOF | ||
apiVersion: networking.istio.io/v1alpha3 | ||
kind: Sidecar | ||
metadata: | ||
name: default-egress | ||
namespace: default | ||
spec: | ||
egress: | ||
- hosts: | ||
- "default/*" | ||
- "test/*" | ||
EOF | ||
``` | ||
|
||
λ§μ½ λͺ μλμ§ μμ μν¬λ‘λμ `curl` λͺ λ Ήμ λ 리면 μ무 responseλ λ°μ§ λͺ» νκ³ νν°λ§ λλ€. | ||
|
||
μλ κ² `Sidecar`μ `egress` κ·μΉμ νμ©νλ©΄, ν΄λΉ λ€μμ€νμ΄μ€λ μν¬λ‘λμμ μ κ·Ό κ°λ₯ν K8s λλ Istio μλΉμ€ λ©μλ₯Ό μ νν μ μλ€. **μ¦, μ΅μνμ νμλ‘ νλ 보μ μ κ·Όλ§μ νμ©νλ κ²μ΄λ€.** (Zero-Trust Networkμ 쑰건μ μΆ©μ‘±!) | ||
|
||
μ κ·Έλ¦¬κ³ λ§μ½ κ°μ λ€μμ€νμ΄μ€μ μν¬λ‘λλ‘λ§ egress hostλ₯Ό νμ©νλ €λ©΄ μλμ κ°μ΄ μμ±ν μλ μλ€. | ||
|
||
```yaml | ||
... | ||
spec: | ||
egress: | ||
- hosts: | ||
- "./*" | ||
- "./helloworld" | ||
``` | ||
μ΄λ κ² μλκ²½λ‘ ννμ μ²λΌ `./`λ₯Ό μ¬μ©νλ©΄ κ°μ λ€μμ€νμ΄μ€μ μν¬λ‘λλ§ νμ©νκ² λλ€. | ||
|
||
## Ingress Listener | ||
|
||
μ΄λ²μλ λ°λλ‘ μ μν¬λ‘λμ μ κ·Ό κ°λ₯ν portλ₯Ό μ νν΄λ³΄μ. | ||
|
||
```yaml | ||
$ kubectl apply -f - <<EOF | ||
apiVersion: networking.istio.io/v1alpha3 | ||
kind: Sidecar | ||
metadata: | ||
name: default-ingress | ||
namespace: default | ||
spec: | ||
ingress: | ||
- port: 5000 | ||
EOF | ||
``` | ||
|
||
μ΄λ κ² νλ©΄, `default` λ€μμ€νμ΄μ€μ λͺ¨λ μν¬λ‘λμ λν΄μ `5000` ν¬νΈλ§ μ΄λ €μκ² λλ€. | ||
|
||
μ ingressλ portλ₯Ό μ νν κΉ μκ°μ μ’ ν΄λ΄€λλ°... | ||
|
||
λ³΄ν΅ K8sμ μν¬λ‘λμ μ κ·Όνλ €κ³ νλ©΄ K8s Service 리μμ€μ CoreDNS μ£Όμλ‘ μ κ·Ό νλ€. κ·Έλ°λ°, μ΄κ±΄ νΈμλ₯Ό μν΄ μ°λ κ²μ΄κ³ μ¬μ€μ κ° Podμ΄ λΆμ¬ λ°μ Private IPλ‘λ μν¬λ‘λμ μ κ·Όν μ μλ€. | ||
|
||
K8s Serviceλ₯Ό μ κ·Όν λλ K8s Serviceλ₯Ό μ μνλ©΄μ μν¬λ‘λμ μ΄λ€ ν¬νΈλ₯Ό λ ΈμΆν μ§ κ²°μ μ νκ² λμ§λ§, μ΄λ€ ν¬νΈλ K8s Svcλ‘ λ ΈμΆνκ³ μΆμ§ μμ μλ μλ€. | ||
|
||
Istio `Sidecar`λ μ΄λ κ² Native K8sκ° κ°λ μμΉ μλ μν¬λ‘λμ ν¬νΈκ° λ ΈμΆλμ§ μλλ‘ Envoy Sidecar μμ€μμ ingress portλ₯Ό μ ννλ κ² κ°λ€. μ΄λ»κ² 보면, AWS SGμ Ingress Ruleμ²λΌ Inbound ν¬νΈλ₯Ό μ ννλ κ²μΌλ‘ 보μ΄κΈ°λ νλ€. | ||
|
||
## Workload Selector | ||
|
||
μμ `Sidecar` μμλ€μ `metadata.namespace`μ λͺ¨λ Envoy Sidecarμ μ μ©λλ κ·μΉμ΄μλ€. λ§μ½ νΉμ μν¬λ‘λμ Envoy Sidecarμλ§ μ μ©νκ³ μΆλ€λ©΄, μλμ κ°μ΄ `workflowSelector`λ₯Ό ν¬ν¨νλ©΄ λλ€. | ||
|
||
```yaml | ||
$ kubectl apply -f - <<EOF | ||
apiVersion: networking.istio.io/v1alpha3 | ||
kind: Sidecar | ||
metadata: | ||
name: default-egress | ||
namespace: default | ||
spec: | ||
workloadSelector: | ||
labels: | ||
app: helloworld | ||
egress: | ||
- hosts: | ||
- "./*" | ||
EOF | ||
``` | ||
|
||
μμ°! μμ κ°μ΄ `Sidecar`λ₯Ό ꡬμ±νλ©΄ helloworld μν¬λ‘λλ μ€μ§ κ°μ λ€μμ€νμ΄μ€μ μν¬λ‘λλ‘λ§ μ κ·Όν μ μλ€!! | ||
|
||
# Istioμ Zero-trust Network | ||
|
||
Istioλ₯Ό 곡λΆνλ©΄μ "Zero-trust Network"(μ΄ν ZTN)λΌλ μ©μ΄λ₯Ό μ²μ λ³΄κ² λμλ€. λ³ΈμΈμ΄ 보μ μ λ¬Έκ°λ μλλΌμ μ½κ² μ΄ν΄ λμ§λ μμλλ°... | ||
|
||
[ν μ€γ £SLASH 23 - κ³ κ° λΆμμ 0μΌλ‘ λ§λλ ν μ€μ Istio Zero Trust](https://youtu.be/4sJd6PIkP_s?si=FUrtUOR3u_x9jEMK)μ μμμ΄ Istio ZTNλ₯Ό μ΄ν΄νλλ° ν° λμμ΄ λμλ€. | ||
|
||
ν μ€λ μ무λλ κΈμ© κΈ°μ μ΄λ μν¬λ‘λλ₯Ό μ΄μν λ λμ μμ€μ 보μμ μꡬν κ² κ°λ€. Istioλ ν μ€μ K8s ν΄λ¬μ€ν°μ ZTNλ₯Ό μ 곡νλ μ루μ μΌλ‘ μ κΈ°λ₯νλ κ² κ°λ€. | ||
|
||
μ§κΈλΆν°λ μμ μμμ λ΄μ© μμ½μ΄λ€! | ||
|
||
- ν μ€λ λͺ¨λ μν¬λ‘λμ mTLS `STRICT` λͺ¨λμ΄λ€. μ¦, Istio μλΉμ€ λ©μ¬ λ°μμλ μλΉμ€ λ©μ¬λ‘ μ κ·Όν μ μλ€. | ||
- ν μ€λ Istioμ `Sidecar` 리μμ€λ₯Ό μ¬μ©ν΄μ μν¬λ‘λκ° μ κ·Όν μ μλ egress hostλ₯Ό μ ννλ€. λ°λ‘ μ€μ ν΄μ£Όμ§ μμΌλ©΄ μ΄λ€ μν¬λ‘λμλ μ κ·Όν μ μλ€. (Least Privilliage μ¬λ‘) | ||
- ν μ€λ Istioμ `AuthorizationPolicy` 리μμ€λ₯Ό μ€μ νμ¬ μμμΉ λͺ»ν μν¬λ‘λμ μ κ·Όμ λ§κ³ , μν¬λ‘λμ μ κ·Όμ Endpoint λ 벨κΉμ§ μ ννλ€. | ||
|
||
μ¦, μν¬λ‘λ Aκ° μν¬λ‘λ Bμ μ κ·Όνκ³ μ νλ€λ©΄, (1) λλ€ Istio μλΉμ€ λ©μ¬ μμ μμ΄μΌ νκ³ , (2) μν¬λ‘λ Aμ `Sidecar`λ₯Ό μ€μ ν΄μ μν¬λ‘λ Bμ egress ν μ μκ² νμ©ν΄μΌ νκ³ , (3) μλ₯΄μ½λ Bμ `AuthorizationPolicy`λ₯Ό μ€μ ν΄ μν¬λ‘λ Aμ ingress νΈλν½μ νμ©ν΄μ€μΌ νλ€. | ||
|
||
![](/images/development/istio/toss-sidecar-monitoring.png) | ||
|
||
ν μ€μ κ²½μ°, `Sidecar`μ egress host λͺ©λ‘μ΄ λ³κ²½ λλ€κ±°λ, μλ λ±λ‘λμ§ μμ egress hostλ‘ μμ²μ΄ λ°μνλ€λ©΄ Slack λ©μμ§λ μ€λ λ± Istioλ₯Ό μΈλ°νκ² λͺ¨λν°λ§ νκ³ μλ€. (μ΅κ·Ό μ½λ μ»€λ―Έν° λ³΄μ¬μ£Όλ κ²λ μ κΈ°νλ€... π) | ||
|
||
μ²μμλ Istioλ₯Ό μλΉμ€ λ©μ¬? λ€νΈμν¬ νΈλν½μ λͺ¨λν°λ§ νκ³ , λ μΉ΄λ리 λ°°ν¬λ₯Ό ν μ μλ 거ꡬλ~~ λΌκ³ λ§ μκ°νλλ°, λΆμ°μ²λ¦¬ μμ€ν κ³Ό κ·Έκ²μ 보μμ μν΄ μ κ³ μλ μλΉμ€ λ©μ¬λΌλ μκ°μ΄ λ λ€. (μμ CNCF!) | ||
|
||
# μ°Έκ³ μλ£ | ||
|
||
- Istio 곡μ λ¬Έμλ€ | ||
- [`PeerAuthentication`](https://istio.io/latest/docs/reference/config/security/peer_authentication/) | ||
- [`AuthroizationPolicy`](https://istio.io/latest/docs/reference/config/security/authorization-policy/) | ||
- [`Sidecar`](https://istio.io/latest/docs/reference/config/networking/sidecar/) | ||
- Toss Slash 23 | ||
- [ν μ€γ £SLASH 23 - κ³ κ° λΆμμ 0μΌλ‘ λ§λλ ν μ€μ Istio Zero Trust](https://youtu.be/4sJd6PIkP_s?si=FUrtUOR3u_x9jEMK) | ||
- κ·ΈμΈμλ ν μ€μμ Istio κ΄λ ¨ν΄μ λ§μ μ¬λ‘ μΌμ΄μ€λ₯Ό μ μνκ³ μλ€!! (λμ€μ μ λ΄μΌμ§...) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.