Commit Graph

6 Commits

Author SHA1 Message Date
Eliza Weisman 64bec5c536
policy: validate that `HTTPRoute` paths are absolute (#8962)
The proxy won't handle httproute paths (in URI rewrites or matches) when
paths are relative. The policy admission controller and indexer should
catch this case and fail to handle routes that deal in paths that do not
start in `/`.

This branch adds validation to the admission controller and indexer to
ensure that all paths in an `httproute` rule are absolute.
2022-07-26 09:53:52 -07:00
Eliza Weisman 753c73e0a0
policy: add `policy.linkerd.io` `HTTPRoute` CRD (#8949)
Our use of the `gateway.networking.k8s.io` types is not compliant with
the gateway API spec in at least a few ways:

1. We do not support the `Gateway` types. This is considered a "core"
   feature of the `HTTPRoute` type.
2. We do not currently update `HTTPRoute` status fields as dictated by
   the spec.
3. Our use of Linkerd-specific `parentRef` types may not work well with
   the gateway project's admission controller (untested).

Issue #8944 proposes solving this by replacing our use of
`gateway.networking.k8s.io`'s `HTTPRoute` type with our own
`policy.linkerd.io` version of the same type. That issue suggests that
the new `policy.linkerd.io` types be added separately from the change
that removes support for the `gateway.networking.k8s.io` versions, so
that the migration can be done incrementally.

This branch does the following:

* Add new `HTTPRoute` CRDs. These are based on the
  `gateway.networking.k8s.io` CRDs, with the following changes:
   - The group is `policy.linkerd.io`,
   - The API version is `v1alpha1`,
   - `backendRefs` fields are removed, as Linkerd does not support them,
   - filter types Linkerd does not support (`RequestMirror` and
     `ExtensionRef`), are removed.
* Add Rust bindings for the new `policy.linkerd.io` versions of
  `HTTPRoute` types in `linkerd-policy-controller-k8s-api`.

  The Rust bindings define their own versions of the `HttpRoute`,
  `HttpRouteRule`, and `HttpRouteFilter` types, because these types'
  structures are changed from the Gateway API versions (due to the
  removal of unsupported filter types and fields). For other types,
  which are identical to the upstream Gateway API versions (such as the
  various match types and filter types), we re-export the existing
  bindings from the `k8s-gateway-api`crate to minimize duplication.
* Add conversions to `InboundRouteBinding` from the `policy.linkerd.io`
  `HTTPRoute` types.

  When possible, I tried to factor out the code that was shared between
  the conversions for Linkerd's `HTTPRoute` types and the upstream
  Gateway API versions.

* Implement `kubert`'s `IndexNamespacedResource` trait for
  `linkerd_policy_controller_k8s_api::policy::HttpRoute`, so that the
  policy controller can index both versions of the `HTTPRoute` CRD.

* Adds validation for `policy.linkerd.io` `HTTPRoute`s to  the policy
  controller's validating admission webhook.

* Updated the policy controller tests to test both versions of
  `HTTPRoute`.

## Notes

A couple questions I had about this approach:
 - Is re-using bindings from the `k8s-gateway-api` crate appropriate
   here, when the type has not changed from the Gateway API version? If
   not, I can change this PR to vendor those types as well, but it will
   result in a lot more code duplication.
 - Right now, the indexer stores all `HTTPRoute`s in the same index.
   This means that applying a `policy.linkerd.io` version of `HTTPRoute`
   and then applying the Gateway API version with the same ns/name will
   update the same value in the index. Is this what we want? I wasn't
   entirely sure...

See #8944.
2022-07-22 13:35:23 -07:00
Oliver Gould c1a1430d1a
Introduce AuthorizationPolicy CRDs (#8007)
Issue #7709 proposes new Custom Resource types to support generalized
authorization policies:

- `AuthorizationPolicy`
- `MeshTLSAuthentication`
- `NetworkAuthentication`

This change introduces these CRDs to the default linkerd installation
(via the `linkerd-crds` chart) and updates the policy controller's
to handle these resource types. The policy admission controller
validates that these resource reference only suppported types.

This new functionality is tested at multiple levels:

* `linkerd-policy-controller-k8s-index` includes unit tests for the
  indexer to test how events update the index;
* `linkerd-policy-test` includes integration tests that run in-cluster
  to validate that the gRPC API updates as resources are manipulated;
* `linkerd-policy-test` includes integration tests that exercise the
  admission controller's resource validation; and
* `linkerd-policy-test` includes integration tests that ensure that
  proxies honor authorization resources.

This change does NOT update Linkerd's control plane and extensions to
use these new authorization primitives. Furthermore, the `linkerd` CLI
does not yet support inspecting these new resource types. These
enhancements will be made in followup changes.

Signed-off-by: Oliver Gould <ver@buoyant.io>
2022-03-30 12:26:45 -07:00
Oliver Gould 00954d71c6
policy: Add end-to-end ServerAuthorization tests (#8155)
In preparation for new policy CRD resources, this change adds end-to-end
tests to validate policy enforcement for `ServerAuthorization`
resources.

In adding these tests, it became clear that the OpenAPI validation for
`ServerAuthorization` resources is too strict. Various `oneof`
constraints have been removed in favor of admission controller
validation. These changes are semantically compatible and do not
necessitate an API version change.

The end-to-end tests work by creating `curl` pods that call an `nginx`
pod. In order to test network policies, the `curl` pod may be created
before the nginx pod, in which case an init container blocks execution
until a `curl-lock` configmap is deleted from the cluster. If the
configmap is not present to begin with, no blocking occurs.

Signed-off-by: Oliver Gould <ver@buoyant.io>
2022-03-28 14:03:24 -07:00
Oliver Gould 3f84c68f1a
Reorganize the policy controller (#7993)
In preparation for introducing new policy types, this change reorganizes
the policy controller to keep more of each indexing module private.

Signed-off-by: Oliver Gould <ver@buoyant.io>
2022-03-07 12:50:41 -08:00
Oliver Gould 5cbad1fdb4
Update Rust to v1.56.0 (#7136)
Adopt the [2021 edition][ed2021].

[ed2021]: https://doc.rust-lang.org/edition-guide/rust-2021/index.html
2021-10-22 09:40:53 -07:00