Authorization Policy

Linkerd’s authorization policy allows you to control which types of traffic are allowed to meshed pods. See the Authorization Policy feature description for more information on what this means.

Linkerd’s policy is configured using two mechanisms:

  1. A set of default policies, which can be set at the cluster, namespace, and workload level through Kubernetes annotations.
  2. A set of CRDs that specify fine-grained policy for specific ports, routes, workloads, etc.

Default policies

During a Linkerd install, the proxy.defaultInboundPolicy field is used to specify the cluster-wide default policy. This field can be one of the following:

  • all-unauthenticated: allow all traffic. This is the default.
  • all-authenticated: allow traffic from meshed clients in the same or from a different cluster (with multi-cluster).
  • cluster-authenticated: allow traffic from meshed clients in the same cluster.
  • cluster-unauthenticated: allow traffic from both meshed and non-meshed clients in the same cluster.
  • deny: all traffic are denied.

This cluster-wide default can be overridden for specific resources by setting the annotation config.linkerd.io/default-inbound-policy on either a pod spec or its namespace.

Dynamic policy resources

For dynamic control of policy, and for finer-grained policy than what the default polices allow, Linkerd provides a set of CRDs which control traffic policy in the cluster: Server, HTTPRoute, ServerAuthorization, AuthorizationPolicy, MeshTLSAuthentication, and NetworkAuthentication.

Server

A Server selects a port on a set of pods in the same namespace as the server. It typically selects a single port on a pod, though it may select multiple ports when referring to the port by name (e.g. admin-http). While the Server resource is similar to a Kubernetes Service, it has the added restriction that multiple Server instances must not overlap: they must not select the same pod/port pairs. Linkerd ships with an admission controller that prevents overlapping Servers from being created.

Server Spec

A Server spec may contain the following top level fields:

fieldvalue
podSelectorA podSelector selects pods in the same namespace.
portA port name or number. Only ports in a pod spec’s ports are considered.
proxyProtocolConfigures protocol discovery for inbound connections. Supersedes the config.linkerd.io/opaque-ports annotation. Must be one of unknown,HTTP/1,HTTP/2,gRPC,opaque,TLS. Defaults to unknown if not set.

podSelector

This is the same labelSelector field in Kubernetes. All the pods that are part of this selector will be part of the Server group. A podSelector object must contain exactly one of the following fields:

fieldvalue
matchExpressionsmatchExpressions is a list of label selector requirements. The requirements are ANDed.
matchLabelsmatchLabels is a map of {key,value} pairs.

See the Kubernetes LabelSelector reference for more details.

Server Examples

A Server that selects over pods with a specific label, with gRPC as the proxyProtocol.

apiVersion: policy.linkerd.io/v1beta1
kind: Server
metadata:
  namespace: emojivoto
  name: emoji-grpc
spec:
  podSelector:
    matchLabels:
      app: emoji-svc
  port: grpc
  proxyProtocol: gRPC

A Server that selects over pods with matchExpressions, with HTTP/2 as the proxyProtocol, on port 8080.

apiVersion: policy.linkerd.io/v1beta1
kind: Server
metadata:
  namespace: emojivoto
  name: backend-services
spec:
  podSelector:
    matchExpressions:
    - {key: app, operator: In, values: [voting-svc, emoji-svc]}
    - {key: environment, operator: NotIn, values: [dev]}
  port: 8080
  proxyProtocol: "HTTP/2"

HTTPRoute

An HTTPRoute represents a subset of traffic handled by a Server. HTTPRoutes are “attached” to Servers and have match rules which determine which requests match. Matches can be based on path, headers, query params, and/or verb. AuthorizationPolicies may target HTTPRoute resources, thereby authorizing traffic to that HTTPRoute only rather than to the entire Server. HTTPRoutes may also define filters which add processing steps that must be completed during the request or response lifecycle.

HTTPRoute Spec

An HTTPRoute spec may contain the following top level fields:

fieldvalue
parentRefsA set of ParentReferences which indicate which Servers this HTTPRoute attach to.
hostnamesA set of hostnames that should match against the HTTP Host header.
rulesAn array of HTTPRouteRules.

parentReference

A reference to the Servers this HTTPRoute is a part of.

fieldvalue
groupThe group of the referent. This must be set to “group.linkerd.io”.
kindThe kind of the referent. This must be set to “Server”.
namespaceThe namespace of the referent. When unspecified (or empty string), this refers to the local namespace of the Route.
nameThe name of the referent.

httpRouteRule

HTTPRouteRule defines semantics for matching an HTTP request based on conditions (matches) and processing it (filters).

fieldvalue
matchesA list of httpRouteMatches. Each match is independent, i.e. this rule will be matched if any one of the matches is satisfied.
filtersA list of httpRouteFilters which will be applied to each request which matches this rule.

httpRouteMatch

HTTPRouteMatch defines the predicate used to match requests to a given action. Multiple match types are ANDed together, i.e. the match will evaluate to true only if all conditions are satisfied.

fieldvalue
pathAn httpPathMatch. If this field is not specified, a default prefix match on the “/” path is provided.
headersAn httpHeaderMatch.
queryParamsAn httpQueryParamMatch.
methodWhen specified, this route will be matched only if the request has the specified method.

httpPathMatch

HTTPPathMatch describes how to select a HTTP route by matching the HTTP request path.

fieldvalue
typeHow to match against the path Value. One of: Exact, PathPrefix, RegularExpresion.
valueThe HTTP path to match against.

httpHeaderMatch

HTTPHeaderMatch describes how to select a HTTP route by matching HTTP request headers.

fieldvalue
typeHow to match against the value of the header. One of: Exact, RegularExpresion.
nameThe HTTP Header to be matched against. Name matching MUST be case insensitive.
valueValue of HTTP Header to be matched.

httpQueryParamMatch

HTTPQueryParamMatch describes how to select a HTTP route by matching HTTP query parameters.

fieldvalue
typeHow to match against the value of the query parameter. One of: Exact, RegularExpresion.
nameThe HTTP query param to be matched. This must be an exact string match.
valueValue of HTTP query param to be matched.

httpRouteFilter

HTTPRouteFilter defines processing steps that must be completed during the request or response lifecycle.

fieldvalue
typeOne of: RequestHeaderModifier, RequestRedirect.
requestHeaderModifierAn httpRequestHeaderFilter.
requestRedirectAn httpRequestRedirectFilter.

httpRequestHeaderFilter

A filter which modifies request headers.

fieldvalue
setA list of httpHeaders to overwrites on the request.
addA list of httpHeaders to add on the request, appending to any existing value.
removeA list of header names to remove from the request.

httpHeader

HTTPHeader represents an HTTP Header name and value as defined by RFC 7230.

fieldvalue
nameName of the HTTP Header to be matched. Name matching MUST be case insensitive.
valueValue of HTTP Header to be matched.

httpRequestRedirectFilter

HTTPRequestRedirect defines a filter that redirects a request.

fieldvalue
schemeThe scheme to be used in the value of the Location header in the response. When empty, the scheme of the request is used.
hostnameThe hostname to be used in the value of the Location header in the response. When empty, the hostname of the request is used.
pathAn httpPathModfier which modifies the path of the incoming request and uses the modified path in the Location header.
portThe port to be used in the value of the Location header in the response. When empty, port (if specified) of the request is used.
statusThe HTTP status code to be used in response.

httpPathModfier

HTTPPathModifier defines configuration for path modifiers.

fieldvalue
typeOne of: ReplaceFullPath, ReplacePrefixMatch.
replaceFullPathThe value with which to replace the full path of a request during a rewrite or redirect.
replacePrefixMatchThe value with which to replace the prefix match of a request during a rewrite or redirect.

HTTPRoute Examples

An HTTPRoute which matches GETs to /authors.json or /authors/*.

apiVersion: policy.linkerd.io/v1beta1
kind: HTTPRoute
metadata:
  name: authors-get-route
  namespace: booksapp
spec:
  parentRefs:
    - name: authors-server
      kind: Server
      group: policy.linkerd.io
  rules:
    - matches:
      - path:
          value: "/authors.json"
        method: GET
      - path:
          value: "/authors/"
          type: "PathPrefix"
        method: GET

AuthorizationPolicy

An AuthorizationPolicy provides a way to authorize traffic to a Server or an HTTPRoute. AuthorizationPolicies are a replacement for ServerAuthorizations which are more flexible because they can target HTTPRoutes instead of only being able to target Servers.

AuthorizationPolicy Spec

An AuthorizationPolicy spec may contain the following top level fields:

fieldvalue
targetRefA TargetRef which references a resource to which the authorization policy applies.
requiredAuthenticationRefsA list of TargetRefs representing the required authentications. In the case of multiple entries, all authentications must match.

targetRef

A TargetRef identifies an API object to which this AuthorizationPolicy applies. The API objects supported are:

  • A Server, indicating that the AuthorizationPolicy applies to all traffic to the Server.
  • An HTTPRoute, indicating that the AuthorizationPolicy applies to all traffic matching the HTTPRoute.
  • A namespace (kind: Namespace), indicating that the AuthorizationPolicy applies to all traffic to all Servers and HTTPRoutes defined in the namespace.
fieldvalue
groupGroup is the group of the target resource. For namespace kinds, this
should be omitted.
kindKind is kind of the target resource.
namespaceThe namespace of the target resource. When unspecified (or empty string), this refers to the local namespace of the policy.
nameName is the name of the target resource.

AuthorizationPolicy Examples

An AuthorizationPolicy which authorizes clients that satisfy the authors-get-authn authentication to send to the authors-get-route HTTPRoute.

apiVersion: policy.linkerd.io/v1alpha1
kind: AuthorizationPolicy
metadata:
  name: authors-get-policy
  namespace: booksapp
spec:
  targetRef:
    group: policy.linkerd.io
    kind: HTTPRoute
    name: authors-get-route
  requiredAuthenticationRefs:
    - name: authors-get-authn
      kind: MeshTLSAuthentication
      group: policy.linkerd.io

An AuthorizationPolicy which authorizes the webapp ServiceAccount to send to the authors Server.

apiVersion: policy.linkerd.io/v1alpha1
kind: AuthorizationPolicy
metadata:
  name: authors-policy
  namespace: booksapp
spec:
  targetRef:
    group: policy.linkerd.io
    kind: Server
    name: authors
  requiredAuthenticationRefs:
    - name: webapp
      kind: ServiceAccount

An AuthorizationPolicy which authorizes the webapp ServiceAccount to send to all policy “targets” within the booksapp namespace.

apiVersion: policy.linkerd.io/v1alpha1
kind: AuthorizationPolicy
metadata:
  name: authors-policy
  namespace: booksapp
spec:
  targetRef:
    kind: Namespace
    name: booksapp
  requiredAuthenticationRefs:
    - name: webapp
      kind: ServiceAccount

MeshTLSAuthentication

A MeshTLSAuthentication represents a set of mesh identities. When an AuthorizationPolicy has a MeshTLSAuthentication as one of its requiredAuthenticationRefs, this means that clients must be in the mesh and must have one of the specified identities in order to be authorized to send to the target.

MeshTLSAuthentication Spec

A MeshTLSAuthentication spec may contain the following top level fields:

fieldvalue
identitiesA list of mTLS identities to authenticate.
identityRefsA list of targetRefs to ServiceAccounts to authenticate.

MeshTLSAuthentication Examples

A MeshTLSAuthentication which authenticates the books and webapp mesh identities.

apiVersion: policy.linkerd.io/v1alpha1
kind: MeshTLSAuthentication
metadata:
  name: authors-get-authn
  namespace: booksapp
spec:
  identities:
    - "books.booksapp.serviceaccount.identity.linkerd.cluster.local"
    - "webapp.booksapp.serviceaccount.identity.linkerd.cluster.local"

A MeshTLSAuthentication which authenticate thes books and webapp mesh identities. This is an alternative way to specify the same thing as the above example.

apiVersion: policy.linkerd.io/v1alpha1
kind: MeshTLSAuthentication
metadata:
  name: authors-get-authn
  namespace: booksapp
spec:
  identityRefs:
    - kind: ServiceAccount
      name: books
    - kind: ServiceAccount
      name: webapp

NetworkAuthentication

A NetworkAuthentication represents a set of IP subnets. When an AuthorizationPolicy has a NetworkAuthentication as one of its requiredAuthenticationRefs, this means that clients must be in one of the specified networks in order to be authorized to send to the target.

NetworkAuthentication Spec

A NetworkAuthentication spec may contain the following top level fields:

fieldvalue
networksA list of networks to authenticate.

network

A network defines an authenticated IP subnet.

fieldvalue
cidrA subnet in CIDR notation to authenticate.
exceptA list of subnets in CIDR notation to exclude from the authentication.

NetworkAuthentication Examples

A NetworkAuthentication that authenticates clients which belong to any of the specified CIDRs.

apiVersion: policy.linkerd.io/v1alpha1
kind: NetworkAuthentication
metadata:
  name: cluster-network
  namespace: booksapp
spec:
  networks:
  - cidr: 10.0.0.0/8
  - cidr: 100.64.0.0/10
  - cidr: 172.16.0.0/12
  - cidr: 192.168.0.0/16

ServerAuthorization

A ServerAuthorization provides a way to authorize traffic to one or more Servers.

ServerAuthorization Spec

A ServerAuthorization spec must contain the following top level fields:

fieldvalue
clientA client describes clients authorized to access a server.
serverA serverRef identifies Servers in the same namespace for which this authorization applies.

serverRef

A serverRef object must contain exactly one of the following fields:

fieldvalue
nameReferences a Server instance by name.
selectorA selector selects servers on which this authorization applies in the same namespace.

selector

This is the same labelSelector field in Kubernetes. All the servers that are part of this selector will have this authorization applied. A selector object must contain exactly one of the following fields:

fieldvalue
matchExpressionsA list of label selector requirements. The requirements are ANDed.
matchLabelsA map of {key,value} pairs.

See the Kubernetes LabelSelector reference for more details.

client

A client object must contain exactly one of the following fields:

fieldvalue
meshTLSA meshTLS is used to authorize meshed clients to access a server.
unauthenticatedA boolean value that authorizes unauthenticated clients to access a server.

Optionally, it can also contain the networks field:

fieldvalue
networksLimits the client IP addresses to which this authorization applies. If unset, the server chooses a default (typically, all IPs or the cluster’s pod network).

meshTLS

A meshTLS object must contain exactly one of the following fields:

fieldvalue
unauthenticatedTLSA boolean to indicate that no client identity is required for communication. This is mostly important for the identity controller, which must terminate TLS connections from clients that do not yet have a certificate.
identitiesA list of proxy identity strings (as provided via mTLS) that are authorized. The * prefix can be used to match all identities in a domain. An identity string of * indicates that all authentication clients are authorized.
serviceAccountsA list of authorized client serviceAccounts (as provided via mTLS).

serviceAccount

A serviceAccount field contains the following top level fields:

fieldvalue
nameThe ServiceAccount’s name.
namespaceThe ServiceAccount’s namespace. If unset, the authorization’s namespace is used.

ServerAuthorization Examples

A ServerAuthorization that allows meshed clients with *.emojivoto.serviceaccount.identity.linkerd.cluster.local proxy identity i.e. all service accounts in the emojivoto namespace.

apiVersion: policy.linkerd.io/v1beta1
kind: ServerAuthorization
metadata:
  namespace: emojivoto
  name: emoji-grpc
spec:
  # Allow all authenticated clients to access the (read-only) emoji service.
  server:
    selector:
      matchLabels:
        app: emoji-svc
  client:
    meshTLS:
      identities:
        - "*.emojivoto.serviceaccount.identity.linkerd.cluster.local"

A ServerAuthorization that allows any unauthenticated clients.

apiVersion: policy.linkerd.io/v1beta1
kind: ServerAuthorization
metadata:
  namespace: emojivoto
  name: web-public
spec:
  server:
    name: web-http
  # Allow all clients to access the web HTTP port without regard for
  # authentication. If unauthenticated connections are permitted, there is no
  # need to describe authenticated clients.
  client:
    unauthenticated: true
    networks:
      - cidr: 0.0.0.0/0
      - cidr: ::/0

A ServerAuthorization that allows meshed clients with a specific service account.

apiVersion: policy.linkerd.io/v1beta1
kind: ServerAuthorization
metadata:
  namespace: emojivoto
  name: prom-prometheus
spec:
  server:
    name: prom
  client:
    meshTLS:
      serviceAccounts:
        - namespace: linkerd-viz
          name: prometheus