Skip to content

Commit c093a40

Browse files
authored
Add kubectl ate proxy actor command. (#3191)
Allow a user to land traffic on an actor from a dev machine. The `kubectl-ate` CLI now authenticates to `atenet` by minting a certificate (via `PodCertificateRequest`) for `spiffe://cluster.local/ns/ate-system/sa/atenet-client`. Ideally, atenet should support JWT based auth and there would be no need for a certificate minting. But that support is not in place yet. The `kubectl ate proxy actor` command also improves local dev ergonomics as it attachjes the actor header so clients don't need to be "substrate-aware". For example, a web browser can just point to the local proxy. Fixed #3194 and #3187 --------- Signed-off-by: Julian Gutierrez Oschmann <[email protected]>
1 parent b5d7201 commit c093a40

44 files changed

Lines changed: 1569 additions & 684 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README.md‎

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,15 @@ To quickly set up the complete environment:
115115

116116
2. Run the following steps:
117117
```shell
118-
# create cluster and local registry (IPv4; IP_FAMILY=dual|ipv6 overrides)
118+
# create cluster and local registry
119119
hack/create-kind-cluster.sh
120120

121-
# install ate, PostgreSQL, rustfs
122-
hack/install-ate-kind.sh deploy ate-system --credential-provider='{"name":"k8s.io"}'
121+
# install Substrate
122+
hack/install-ate-kind.sh deploy ate-system --credential-provider='{"name":"k8s.io"}' \
123+
--ingress-allowed-spiffe-ids=spiffe://cluster.local/ns/ate-system/sa/atenet-client
123124

124125
# install counter demo
125-
hack/install-ate-kind.sh deploy demo-counter
126+
hack/install-ate-kind.sh deploy demo counter
126127

127128
# install kubectl-ate
128129
go install ./cmd/kubectl-ate
@@ -131,8 +132,9 @@ go install ./cmd/kubectl-ate
131132
# actor template, resolved in the actor's atespace)
132133
kubectl ate create actor my-counter-1 -a ate-demo-counter --template counter
133134

134-
# port-forward the network router to bind to local port `8000`
135-
kubectl port-forward -n ate-system svc/atenet-router 8000:80
135+
# serve a local proxy on port 8000 that sends requests to the actor through the
136+
# network router
137+
kubectl ate proxy actor my-counter-1 -a ate-demo-counter
136138
```
137139

138140
> [!IMPORTANT]
@@ -143,9 +145,7 @@ kubectl port-forward -n ate-system svc/atenet-router 8000:80
143145
144146
3. In a **separate terminal**, send an HTTP request to increment the counter:
145147
```shell
146-
curl -X POST \
147-
-H "ate-target-actor: ate-demo-counter/my-counter-1" \
148-
-i http://localhost:8000/
148+
curl -X POST -i http://localhost:8000/
149149
```
150150

151151
### GKE Quickstart (Development)
@@ -179,9 +179,15 @@ curl -X POST \
179179

180180
4. Deploy the Agent Substrate system to your cluster:
181181
```bash
182-
go run ./cmd/ate-setup deploy ate-system --credential-provider='{"name":"k8s.io"}'
182+
go run ./cmd/ate-setup deploy ate-system --credential-provider='{"name":"k8s.io"}' \
183+
--ingress-allowed-spiffe-ids=spiffe://cluster.local/ns/ate-system/sa/atenet-client
183184
```
184185

186+
`--ingress-allowed-spiffe-ids` lists the clients the router lets reach
187+
actors. The ID above is the one `kubectl ate proxy actor` presents. Without
188+
the flag no client reaches actors. See
189+
[Ingress to actors](docs/operator-install.md#ingress-to-actors).
190+
185191
`--credential-provider` is required. `{"name":"k8s.io"}` also deploys the
186192
bundled Kubernetes Secrets provider, with a NetworkPolicy that admits only
187193
the egress gateway; `{"enabled":false}` turns egress credential injection off
@@ -195,7 +201,7 @@ curl -X POST \
195201

196202
5. You can then deploy the sample applications. See [demos/counter/README.md](demos/counter/README.md) or [demos/sandbox/README.md](demos/sandbox/README.md) for detailed walkthroughs.
197203
```bash
198-
go run ./cmd/ate-setup deploy demo demo-counter
204+
go run ./cmd/ate-setup deploy demo counter
199205
```
200206

201207
#### Custom Setup and Deployment

‎cmd/ate-setup/commands.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ a pre-scan pass, so they may appear anywhere on its command line.
3131
| `--ateapi-postgres-storage-class NAME` | `ATE_API_POSTGRES_STORAGE_CLASS=NAME` | StorageClass for the bundled PostgreSQL volume instead of the cluster default, such as `dynamic-rwo` on GKE so C4 and N4 nodes can attach it. An existing install must delete the postgres StatefulSet and its claim first |
3232
| `--cordon-system-infra-components` | `--cordon-system-infra-components` | Keep the system infra components, such as ate-api-server, atenet-router, atenet-egress and postgres, off the worker nodes. Assumes a small shared pool labeled and tainted `ate.dev/workloadType=ate-system-infra:NoSchedule`, across which each workload's replicas are spread, and a one-node pool labeled and tainted `ate.dev/workloadType=ate-postgres:NoSchedule` for postgres alone. `ATE_INSTALL_CORDON_SYSTEM_INFRA_COMPONENTS=true` when the flag is absent |
3333
| `--fake-data-plane` | `--fake-data-plane` | Install the fake data plane for control-plane benchmarks: fake-atelet takes atelet's place in its DaemonSet, taking its objectstore-plugin's storage settings, ate-controller is scaled to zero, and fake-workersync honors every WorkerPool with fake Workers on the fake-atelet nodes. Reaches `deploy ate-system`, `deploy atelet`, and `deploy ate-controller`; only `deploy ate-system` switches a cluster between the real and fake data planes, and the other two refuse a data plane other than the installed one. `deploy ate-system --fake-data-plane` refuses a cluster whose WorkerPools have worker pods. fake-atelet runs with its defaults; a benchmark tunes it through the optional `fake-atelet-tuning` ConfigMap, whose `FAKE_ATELET_*` variables set its flags, and which no install creates or resets. Actors do not exist; never use it on a cluster that serves real actors. `ATE_INSTALL_FAKE_DATA_PLANE=true` when the flag is absent |
34-
| `--ingress-allowed-spiffe-ids IDS` | `--ingress-allowed-spiffe-ids IDS`, or `ATE_INGRESS_ALLOWED_SPIFFE_IDS=IDS` | Required by `deploy ate-system` and `deploy atenet` for both dataplanes. Comma-separated SPIFFE IDs (exact match) of the clients the ingress router lets reach actors; any listed client may reach any actor. Both dataplanes require a Pod Identity CA client certificate on HTTPS and TLS CONNECT. The SPIFFE URI SAN allowlist may be checked during or after TLS, including after CONNECT acceptance, but unlisted clients must be denied before actor routing. The podidentity signer issues `spiffe://cluster.local/ns/<namespace>/sa/<service-account>` |
34+
| `--ingress-allowed-spiffe-ids IDS` | `--ingress-allowed-spiffe-ids IDS`, or `ATE_INGRESS_ALLOWED_SPIFFE_IDS=IDS` | Comma-separated SPIFFE IDs (exact match) of the clients the ingress router lets reach actors; any listed client may reach any actor. Unset, no client may reach actors through the router. Both dataplanes require a Pod Identity CA client certificate on HTTPS and TLS CONNECT. The SPIFFE URI SAN allowlist may be checked during or after TLS, including after CONNECT acceptance, but unlisted clients must be denied before actor routing. The podidentity signer issues `spiffe://cluster.local/ns/<namespace>/sa/<service-account>` |
3535
| `--experimental-additional-egress-extproc-service NS/SVC:PORT` | `--experimental-additional-egress-extproc-service NS/SVC:PORT` | External processor authorization filter |
3636
| `--credential-provider JSON` | `--credential-provider JSON`, or `ATE_CREDENTIAL_PROVIDER` | Required by `deploy ate-system` and `deploy atenet`. A JSON object: `{"name":"k8s.io"}` deploys and uses the bundled Kubernetes Secrets provider, with a NetworkPolicy that admits only the egress gateway; `{"enabled":false}` turns egress credential injection off; `{"name":"<provider>","address":"<host>:<port>"}` uses a provider you deploy yourself. See [`docs/egress-credential-injection.md`](../../docs/egress-credential-injection.md) |
3737
| `--ateapi-log-level LEVEL` | `--ateapi-log-level LEVEL`, or `ATE_API_LOG_LEVEL=LEVEL` | ate-api-server log level: `debug`, `info`, `warn`, or `error`. Written to the `ate-api-config` ConfigMap on every deploy when set; unset keeps the installed level (`info` on a new install). The server picks up a change without restarting |

‎cmd/ate-setup/internal/config/config.go‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ type Config struct {
223223

224224
// IngressAllowedSPIFFEIDs are the SPIFFE IDs the ingress router lets
225225
// reach actors over its TLS listeners (ATE_INGRESS_ALLOWED_SPIFFE_IDS).
226-
// See RequireIngressAllowedSPIFFEIDs.
226+
// Empty means no client may reach actors through the router.
227227
IngressAllowedSPIFFEIDs []string
228228

229229
// AdditionalEgressExtprocService is the optional NS/SVC:PORT external processor filter.
@@ -282,17 +282,6 @@ func (c *Config) Resolved() *Resolved {
282282
return c.resolved
283283
}
284284

285-
// RequireIngressAllowedSPIFFEIDs fails when the install would deploy an
286-
// ingress router without an allowlist. Envoy and
287-
// AgentGateway both authenticate clients on their TLS listeners and use the
288-
// allowlist to decide which authenticated identities may reach actors.
289-
func (c *Config) RequireIngressAllowedSPIFFEIDs() error {
290-
if len(c.IngressAllowedSPIFFEIDs) > 0 {
291-
return nil
292-
}
293-
return c.Resolved().Require("ingressAllowedSPIFFEIDs")
294-
}
295-
296285
// TransferServiceAccount is the email of the snapshot transfer service
297286
// account, built from TransferGSAName and ProjectID as tools/setup-gcp builds
298287
// it. It is empty when either is.

‎cmd/ate-setup/internal/config/config_test.go‎

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -316,34 +316,6 @@ func TestLoadIngressAllowedSPIFFEIDs(t *testing.T) {
316316
}
317317
}
318318

319-
// Both ingress dataplanes require an allowlist.
320-
func TestRequireIngressAllowedSPIFFEIDs(t *testing.T) {
321-
for _, tc := range []struct {
322-
name string
323-
cfg Config
324-
wantErr bool
325-
}{
326-
{name: "envoy without IDs", cfg: Config{Router: RouterEnvoy}, wantErr: true},
327-
{name: "envoy with IDs", cfg: Config{Router: RouterEnvoy, IngressAllowedSPIFFEIDs: []string{"spiffe://cluster.local/ns/a/sa/a"}}},
328-
{name: "agentgateway without IDs", cfg: Config{Router: RouterAgentgateway}, wantErr: true},
329-
{name: "agentgateway with IDs", cfg: Config{Router: RouterAgentgateway, IngressAllowedSPIFFEIDs: []string{"spiffe://cluster.local/ns/a/sa/a"}}},
330-
} {
331-
t.Run(tc.name, func(t *testing.T) {
332-
err := tc.cfg.RequireIngressAllowedSPIFFEIDs()
333-
if !tc.wantErr {
334-
if err != nil {
335-
t.Fatalf("RequireIngressAllowedSPIFFEIDs() = %v, want nil", err)
336-
}
337-
return
338-
}
339-
var required *RequiredError
340-
if !errors.As(err, &required) || required.Setting.Key != "ingressAllowedSPIFFEIDs" {
341-
t.Fatalf("RequireIngressAllowedSPIFFEIDs() = %v, want a RequiredError for ingressAllowedSPIFFEIDs", err)
342-
}
343-
})
344-
}
345-
}
346-
347319
// The credential exchange impersonates the transfer account only on GCS, so
348320
// only a GKE deploy needs one, and its email needs both the name and the
349321
// project.

‎cmd/ate-setup/internal/config/setting.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ var Registry = []Setting{
311311
Key: "ingressAllowedSPIFFEIDs", Env: "ATE_INGRESS_ALLOWED_SPIFFE_IDS", Flag: "ingress-allowed-spiffe-ids",
312312
Kind: KindString,
313313
Usage: "SPIFFE IDs (exact match, comma-separated) of the clients the ingress router lets reach actors; " +
314-
"any listed client may reach any actor. Required to deploy the router with " +
315-
"either dataplane. The podidentity signer issues spiffe://cluster.local/ns/<namespace>/sa/<service-account>",
314+
"any listed client may reach any actor. Unset, no client may reach actors through the router. " +
315+
"The podidentity signer issues spiffe://cluster.local/ns/<namespace>/sa/<service-account>",
316316
},
317317
{
318318
Key: "otlpEndpoint", Env: "ATE_OTLP_ENDPOINT", Flag: "otlp-endpoint", Kind: KindString,

‎cmd/ate-setup/internal/steps/deploy.go‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,7 @@ func (e *Env) DeployAteSystem(ctx context.Context, opts DeployOptions) error {
6868
if err != nil {
6969
return err
7070
}
71-
// Likewise a router that would refuse to start without an allowlist, and
72-
// a credential exchange without a transfer service account.
73-
if err := e.Cfg.RequireIngressAllowedSPIFFEIDs(); err != nil {
74-
return err
75-
}
71+
// Likewise a credential exchange without a transfer service account.
7672
if err := e.Cfg.RequireTransferServiceAccount(); err != nil {
7773
return err
7874
}
@@ -538,9 +534,6 @@ func (e *Env) DeployAtenet(ctx context.Context) error {
538534
if err != nil {
539535
return err
540536
}
541-
if err := e.Cfg.RequireIngressAllowedSPIFFEIDs(); err != nil {
542-
return err
543-
}
544537
if err := e.EnsureCRDs(ctx); err != nil {
545538
return err
546539
}

‎cmd/ate-setup/internal/steps/overlay.go‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,12 @@ func (e *Env) setAgentgatewayIngressAllowedSPIFFEIDs(raw []byte) ([]byte, error)
206206
if e.Cfg.Router != config.RouterAgentgateway {
207207
return raw, nil
208208
}
209-
if err := e.Cfg.RequireIngressAllowedSPIFFEIDs(); err != nil {
210-
return nil, err
209+
// nil would marshal as null, which agentgateway's networkAuthorization CEL rule can't evaluate.
210+
allowed := e.Cfg.IngressAllowedSPIFFEIDs
211+
if allowed == nil {
212+
allowed = []string{}
211213
}
212-
213-
ids, err := json.Marshal(e.Cfg.IngressAllowedSPIFFEIDs)
214+
ids, err := json.Marshal(allowed)
214215
if err != nil {
215216
return nil, fmt.Errorf("encoding AgentGateway ingress SPIFFE IDs: %w", err)
216217
}
@@ -297,10 +298,10 @@ func patchAtenetEgressEnvoyConcurrency(raw []byte, concurrency int) ([]byte, err
297298
// patchAtenetRouterAllowedSPIFFEIDs appends --ingress-allowed-spiffe-ids to the
298299
// atenet-router container's args in the Envoy router Deployment. The base
299300
// manifest carries no allowlist, because which clients may reach actors is the
300-
// install's to decide.
301+
// install's to decide. Without one the router serves no traffic.
301302
func (e *Env) patchAtenetRouterAllowedSPIFFEIDs(raw []byte) ([]byte, error) {
302-
if err := e.Cfg.RequireIngressAllowedSPIFFEIDs(); err != nil {
303-
return nil, err
303+
if len(e.Cfg.IngressAllowedSPIFFEIDs) == 0 {
304+
return raw, nil
304305
}
305306
return appendContainerArgs(raw, "atenet-router", "atenet-router",
306307
"--ingress-allowed-spiffe-ids="+strings.Join(e.Cfg.IngressAllowedSPIFFEIDs, ","))

‎cmd/ate-setup/internal/steps/overlay_test.go‎

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package steps
1616

1717
import (
1818
"context"
19-
"errors"
2019
"fmt"
2120
"os"
2221
"reflect"
@@ -887,7 +886,7 @@ func TestRenderE2ETuning(t *testing.T) {
887886
}
888887

889888
// Both paths that deliver the Envoy router pass it the install's allowlist,
890-
// whatever the overlay, and refuse to render without one.
889+
// whatever the overlay, and pass none when the install sets none.
891890
func TestRenderRouterAllowedSPIFFEIDs(t *testing.T) {
892891
const a, b = "spiffe://cluster.local/ns/a/sa/a", "spiffe://cluster.local/ns/b/sa/b"
893892
src := images.Source{Repo: "example.com/substrate", Tag: "v1.2.3"}
@@ -938,10 +937,14 @@ func TestRenderRouterAllowedSPIFFEIDs(t *testing.T) {
938937
t.Run("without IDs", func(t *testing.T) {
939938
cfg := cfg
940939
cfg.IngressAllowedSPIFFEIDs = nil
941-
_, err := tc.render(&Env{Cfg: &cfg, resolver: resolver})
942-
var required *config.RequiredError
943-
if !errors.As(err, &required) {
944-
t.Fatalf("render error = %v, want a RequiredError", err)
940+
rendered, err := tc.render(&Env{Cfg: &cfg, resolver: resolver})
941+
if err != nil {
942+
t.Fatalf("render: %v", err)
943+
}
944+
for _, arg := range routerArgs(t, rendered) {
945+
if strings.HasPrefix(arg, "--ingress-allowed-spiffe-ids") {
946+
t.Errorf("atenet-router args include %q, want no allowlist", arg)
947+
}
945948
}
946949
})
947950
})
@@ -1066,10 +1069,18 @@ func TestRenderAgentgatewayStaticMTLS(t *testing.T) {
10661069

10671070
t.Run("without IDs", func(t *testing.T) {
10681071
cfg.IngressAllowedSPIFFEIDs = nil
1069-
_, err := tc.render(e)
1070-
var required *config.RequiredError
1071-
if !errors.As(err, &required) {
1072-
t.Fatalf("render error = %v, want a RequiredError", err)
1072+
manifest, err := tc.render(e)
1073+
if err != nil {
1074+
t.Fatalf("rendering static-mtls AgentGateway manifests: %v", err)
1075+
}
1076+
var gateway map[string]interface{}
1077+
if err := yaml.Unmarshal([]byte(agentgatewayRouterConfig(t, manifest).Data["config.yaml"]), &gateway); err != nil {
1078+
t.Fatalf("parsing rendered AgentGateway config: %v", err)
1079+
}
1080+
authorization := gateway["frontendPolicies"].(map[string]interface{})["networkAuthorization"].(map[string]interface{})
1081+
wantRules := []interface{}{map[string]interface{}{"allow": "source.spiffeId in []"}}
1082+
if got := authorization["rules"]; !reflect.DeepEqual(got, wantRules) {
1083+
t.Errorf("network authorization rules = %v, want %v", got, wantRules)
10731084
}
10741085
})
10751086
})

‎cmd/atenet/internal/router/README.md‎

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ Right now the only "authorization" policy is to check the client's SPIFFE ID
216216
against a static allowlist. Any ID on the allowlist may use the ingress router
217217
to contact any actor. Richer authorization policies may be added post-GA. Use
218218
the `--ingress-allowed-spiffe-ids` flag to set the allowlist (comma-separated
219-
list).
219+
list). With an empty allowlist, the Envoy router serves no listener, so no
220+
traffic reaches actors through it.
220221

221222
### Common setups
222223

@@ -257,15 +258,22 @@ volumes:
257258
258259
Add the pod's SPIFFE ID to `--ingress-allowed-spiffe-ids`.
259260

260-
**Client outside the cluster, pod identity CA.** A demo on your machine can
261-
follow the e2e tests in `internal/e2e/ingressauth.go`. It creates a
262-
PodCertificateRequest for the podidentity signer that names a pod, node and
263-
ServiceAccount that don't exist. kube-apiserver checks those only for requests
264-
from a kubelet, and the signer issues the SPIFFE ID of the named namespace and
265-
ServiceAccount. The client keeps the private key, reads the chain from the
266-
request's status, and reads the servicedns ClusterTrustBundle to verify the
267-
router. Creating PodCertificateRequests needs RBAC for that resource in the
268-
namespace.
261+
**Client outside the cluster, pod identity CA.** `kubectl ate proxy actor`
262+
forwards local TCP ports to an actor through the router's CONNECT listener. It
263+
presents a certificate for
264+
`spiffe://cluster.local/ns/ate-system/sa/atenet-client`, so that ID must be in
265+
`--ingress-allowed-spiffe-ids`. It requests the certificate the way
266+
`internal/podidentity` does: a PodCertificateRequest for the podidentity
267+
signer that names a pod, node and ServiceAccount that don't exist.
268+
kube-apiserver checks those only for requests from a kubelet, and the signer
269+
issues the SPIFFE ID of the named namespace and ServiceAccount. The client
270+
keeps the private key, reads the chain from the request's status, and reads
271+
the servicedns ClusterTrustBundle to verify the router.
272+
273+
Creating PodCertificateRequests needs RBAC for that resource in `ate-system`.
274+
That RBAC can request a certificate for any SPIFFE ID in `ate-system`,
275+
including those of atelet, ate-controller and ate-api-server, so grant it only
276+
to users you would trust with those components.
269277

270278
## status page
271279

‎cmd/atenet/internal/router/cmd.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func bindRouterFlags(fs *pflag.FlagSet, cfg *routerConfig) {
7272

7373
// Flags for client authentication and authorization in ingress mode.
7474
fs.StringVar(&cfg.IngressAuth.ClientCAFile, "ingress-client-ca-file", "", "PEM bundle of the CAs allowed to sign ingress client certificates. Envoy reads the file, so it must be mounted at this path in the Envoy container as well. Required for the Envoy ingress dataplane")
75-
fs.StringSliceVar(&cfg.IngressAuth.AllowedSPIFFEIDs, "ingress-allowed-spiffe-ids", nil, "SPIFFE IDs (exact match) allowed to connect to actors through the ingress dataplane. Comma-separated or repeated. Required for the Envoy ingress dataplane")
75+
fs.StringSliceVar(&cfg.IngressAuth.AllowedSPIFFEIDs, "ingress-allowed-spiffe-ids", nil, "SPIFFE IDs (exact match) allowed to connect to actors through the ingress dataplane. Comma-separated or repeated. Without any, the Envoy ingress dataplane serves no traffic")
7676

7777
fs.StringVar(&cfg.UpstreamCredentialBundlePath, "upstream-credential-bundle", "/run/podidentity.podcert.ate.dev/credential-bundle.pem", "PEM credential bundle (cert+key) the router presents as the client cert when dialing the actor's atunnel ingress server over mTLS. Empty disables upstream mTLS (legacy plaintext pod-IP:80) and needs --upstream-connect=false.")
7878
fs.StringVar(&cfg.UpstreamTrustBundlePath, "upstream-trust-bundle", "/run/podidentity.podcert.ate.dev/trust-bundle.pem", "PEM trust bundle used to validate the actor's atunnel ingress server certificate.")

0 commit comments

Comments
 (0)