github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/website/content/docs/internals/security.mdx (about)

     1  ---
     2  layout: docs
     3  page_title: Security Model
     4  sidebar_title: Security Model
     5  description: >-
     6    Nomad relies on both a lightweight gossip mechanism and an RPC system to
     7    provide various features. Both of the systems have different security
     8    mechanisms that stem from their designs. However, the security mechanisms of
     9    Nomad have a common goal: to provide confidentiality, integrity, and
    10    authentication.
    11  ---
    12  
    13  ## Overview
    14  
    15  Nomad is a flexible workload orchestrator to deploy and manage any containerized
    16  or legacy application using a single, unified workflow. It can run diverse
    17  workloads including Docker, non-containerized, microservice, and batch
    18  applications.
    19  
    20  Nomad utilizes a lightweight gossip and RPC system, [similar to
    21  Consul](https://www.consul.io/docs/internals/security), which provides
    22  various essential features. Both of these systems provide security mechanisms
    23  which should be utilized to help provide [confidentiality, integrity and
    24  authentication](https://en.wikipedia.org/wiki/Information_security).
    25  
    26  Using defense in depth is crucial for cluster security, and deployment
    27  requirements may differ drastically depending on your use case. Further security
    28  features for multi-tenant deployments are offered exclusively in the enterprise
    29  version. This documentation may need to be adapted to your deployment situation,
    30  but the general mechanisms for a secure Nomad deployment revolve around:
    31  
    32  - **[mTLS](https://learn.hashicorp.com/tutorials/nomad/security-enable-tls)** -
    33    Mutual authentication of both the TLS server and client x509 certificates
    34    prevents internal abuse by preventing unauthenticated access to network
    35    components within the cluster.
    36  
    37  - **[ACLs](https://learn.hashicorp.com/collections/nomad/access-control)** - Enables
    38    authorization for authenticated connections by granting capabilities to ACL
    39    tokens.
    40  
    41  - **[Namespaces](https://learn.hashicorp.com/tutorials/nomad/namespaces)**
    42  
    43    - Access to read and write to a namespace can be
    44      controlled to allow for granular access to job information managed within a
    45      multi-tenant cluster.
    46  
    47  - **[Sentinel Policies](https://learn.hashicorp.com/tutorials/nomad/sentinel)**
    48    (**Enterprise Only**) - Sentinel policies allow for granular control over
    49    components such as task drivers within a cluster.
    50  
    51  ### Personas
    52  
    53  When thinking about Nomad, it helps to consider the following types of base
    54  personas when managing the security requirements for the cluster deployment. The
    55  granularity may change depending on your team's use case where rigorous roles
    56  can be accurately defined and managed using the [Nomad backend secret engine for
    57  Vault](https://www.vaultproject.io/docs/secrets/nomad). This is
    58  described further with getting started steps using a development server
    59  [here](https://learn.hashicorp.com/collections/nomad/access-control).
    60  
    61  It's important to note that there's no traditional concept of a user
    62  within Nomad itself.
    63  
    64  - **System Administrator** - This is someone who has access to the underlying
    65    infrastructure to a Nomad cluster. Often she has access to SSH or RDP
    66    directly into a server within a cluster through a bastion host. Ultimately
    67    they have read, write and execute permissions for the actual Nomad binary.
    68    This binary is the same for server and client nodes using different
    69    configuration files. These users potentially have something like sudo,
    70    administrative, or some other super-user access to the underlying compute
    71    resource. Users like these are essentially totally trusted by Nomad as they
    72    have administrative rights to the system and can start or stop the agent.
    73  
    74  - **Nomad Administrator** - This is someone (probably the same **System
    75    Administrator**) who has access to define the Nomad agent configurations
    76    for servers and clients, and/or have a Nomad management ACL token. They also
    77    have total rights to all of the parts in the Nomad system including the
    78    ability to start and stop all jobs within a cluster.
    79  
    80  - **Nomad Operator** - This is someone who likely has selective access with
    81    restricted capabilities to manage jobs applicable to their namespace within
    82    a cluster.
    83  
    84  - **User** - This is someone who is a user of an application being run on the
    85    system. In some cases applications may be public facing and exposed to the
    86    internet such as a web server. This is someone who shouldn't have any
    87    network access to the Nomad server API.
    88  
    89  ### Secure Configuration
    90  
    91  Nomad's security model is applicable only if all parts of the system are running
    92  with a secure configuration; **Nomad is not secure-by-default.** Without the following
    93  mechanisms enabled in Nomad's configuration, it may be possible to abuse access
    94  to a cluster. Like all security considerations, one must appropriately determine
    95  what concerns they have for their environment and adapt to these security
    96  recommendations accordingly.
    97  
    98  #### Requirements
    99  
   100  - **[mTLS enabled](https://learn.hashicorp.com/tutorials/nomad/security-enable-tls)**
   101  
   102    - Mutual TLS (mTLS) enables [mutual
   103      authentication](https://en.wikipedia.org/wiki/Mutual_authentication) with
   104      security properties to prevent the following problems:
   105  
   106    * Unauthorized access because both server and clients must provide valid TLS
   107      [X.509](https://en.wikipedia.org/wiki/X.509) certificates signed by the same
   108      valid [CA](https://en.wikipedia.org/wiki/Certificate_authority) in order to
   109      communicate within the cluster.
   110  
   111    * Observing or tampering communication between nodes is thwarted due to the
   112      traffic being encrypted using the well known network security protocol
   113      [TLS](https://en.wikipedia.org/wiki/Transport_Layer_Security) version 1.2,
   114      with a [configurable minimal
   115      version](/docs/configuration/tls#tls_min_version).
   116      Both server and client agents must be configured to validate each other's
   117      certificates to ensure mTLS is actually enabled. This requires appropriate
   118      certificates to be distributed to servers, clients, machines, or operators
   119      for things like CLI usage. It is recommended to use
   120      [Vault](https://learn.hashicorp.com/tutorials/nomad/vault-pki-nomad)
   121      to securely manage the certificate creation and rotation for nodes.
   122  
   123    * Agent role misconfiguration is prevented using the X.509
   124      [SAN](https://en.wikipedia.org/wiki/Subject_Alternative_Name) extension.
   125      This is essentially a domain name that is used to identify and verify a
   126      node's region and role name are configured as expected (e.g.
   127      `client.us-east.nomad`).
   128  
   129    * Using the previously mentioned role name prevents maliciously masquerading
   130      as a server or client node, and allows other services to be signed easily by
   131      the same CA. This also avoids any potential pitfalls with certificates using
   132      the IP or Hostname of nodes within a cluster.
   133  
   134  - **[ACLs enabled](https://learn.hashicorp.com/collections/nomad/access-control)** - The
   135    access control list (ACL) system provides a capability-based control
   136    mechanism for Nomad administrators allowing for custom roles (typically
   137    within Vault) to be tied to an individual human or machine operator
   138    identity. This allows for access to capabilities within the cluster to be
   139    restricted to specific users.
   140  
   141  - **[Sentinel Policies](https://learn.hashicorp.com/tutorials/nomad/sentinel)**
   142    (**Enterprise Only**) - [Sentinel](https://www.hashicorp.com/sentinel/) is
   143    a feature which enables
   144    [policy-as-code](https://docs.hashicorp.com/sentinel/concepts/policy-as-code/)
   145    to enforce further restrictions on operators. This is used to augment the
   146    built-in ACL system for fine-grained control over jobs.
   147  
   148  - **[Namespaces](https://learn.hashicorp.com/tutorials/nomad/namespaces)**
   149    (**Enterprise Only**) - This feature allows for a cluster to be shared by
   150    multiple teams within a company. Using this logical separation is important
   151    for multi-tenant clusters to prevent users without access to that namespace
   152    from conflicting with each other. This requires ACLs to be enabled in order
   153    to be enforced.
   154  
   155  - **[Resource Quotas](https://learn.hashicorp.com/tutorials/nomad/quotas)**
   156    (**Enterprise Only**) - Can limit a namespace's access to the underlying
   157    compute resources in the cluster by setting upper-limits for operators.
   158    Access to these resource quotas can be managed via ACLs to ensure read-only
   159    access for operators so they can't just change their quotas.
   160  
   161  #### Recommendations
   162  
   163  The following are security recommendations that can help significantly improve
   164  the security of your cluster depending on your use case. We recommend always
   165  practicing defense in depth when architecting the security mechanisms for your
   166  environment.
   167  
   168  - **Rotate credentials** - Using short-lived credentials or rotating them
   169    frequently is highly recommended to reduce damage of accidentally leaked
   170    credentials.
   171  
   172    - Use [Vault](/docs/integrations/vault-integration) to create and manage
   173      dynamic, rotated credentials prevent secrets from being easily exposed
   174      within the [job specification](/docs/job-specification) itself
   175      which may be leaked into version control or otherwise be accidentally stored
   176      on disk on an operator's local machine.
   177  
   178    - Rotate credentials used by the Nomad agent; e.g. [integrate with Vault's
   179      PKI secret engine](https://learn.hashicorp.com/tutorials/nomad/vault-pki-nomad) to
   180      automatically generate and renew dynamic, unique X.509 certificates for each
   181      Nomad node with a short [TTL](https://en.wikipedia.org/wiki/Time_to_live).
   182  
   183  - **[Running without Root](https://groups.google.com/forum/#!topic/nomad-tool/pSyMwC_FSFA)** -
   184    Nomad servers can be run as unprivileged users that only require access to
   185    the data directory.
   186  
   187  - **Containers with Sandbox Runtimes** - In some situations, such as running
   188    untrusted code as a service, it may be worth considering using different
   189    container runtimes such as [gVisor](https://gvisor.dev/) or [Kata
   190    Containers](https://katacontainers.io/). These types of runtimes provide
   191    sandboxing features which help prevent raw access to the underlying shared
   192    kernel for other containers and the Nomad client agent itself. Docker driver
   193    allows [customizing runtimes](/docs/drivers/docker#runtime).
   194  
   195  - **[Disable Unused Drivers](/docs/configuration/client#driver-denylist)** -
   196    Each driver provides different degrees of isolation, and bugs may allow
   197    unintended privilege escalation. If a task driver is not needed, you can
   198    disable it to reduce risk.
   199  
   200  - **Linux Security Modules** - Use of security modules that can be directly
   201    integrated into operating systems such as AppArmor, SElinux, and Seccomp on
   202    both the Nomad hosts and applied to containers for an extra layer of
   203    security. Seccomp profiles are able to be passed directly to containers
   204    using the
   205    **[`security_opt`](/docs/drivers/docker#security_opt)**
   206    parameter available in the default [Docker
   207    driver](/docs/drivers/docker).
   208  
   209  - **[Service Mesh](https://www.hashicorp.com/resources/service-mesh-microservices-networking)** -
   210    Integrating service mesh technologies such as
   211    **[Consul](https://www.consul.io/)** can be extremely useful for limiting
   212    and efficiently load balancing network connectivity within a cluster.
   213  
   214  - **[TLS Settings](/docs/configuration/tls)** -
   215    TLS settings, such as the available [cipher suites](/docs/configuration/tls#tls_cipher_suites), should be tuned to fit the needs of your environment.
   216  
   217  - **[HTTP Headers](/docs/configuration#http_api_response_headers)** -
   218    Additional security [headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers), such as [`X-XSS-Protection`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection), can be [configured](/docs/configuration#http_api_response_headers) for HTTP API responses.
   219  
   220  ### Threat Model
   221  
   222  The following are parts of the Nomad threat model:
   223  
   224  - **Nomad agent-to-agent communication** - Transport encryption for
   225    agent-to-agent communication is required to prevent eavesdropping. TCP and
   226    UDP based protocols within Nomad provide different mechanisms for enabling
   227    encryption including symmetric (shared gossip encryption keys) and
   228    asymmetric keys (TLS).
   229  
   230  - **Tampering of data in transit** - Any tampering should be detectable via mTLS
   231    and cause Nomad to avoid processing the request.
   232  
   233  - **Access to data without authentication or authorization** - Requests to the
   234    server should be authenticated and authorized using mTLS and ACLs
   235    respectively.
   236  
   237  - **State modification or corruption due to malicious messages** - Improperly
   238    formatted messages are discarded while properly formatted messages require
   239    authentication and authorization.
   240  
   241  - **Non-server members accessing raw data** - All servers that join the cluster
   242    require proper authentication and authorization in order to begin
   243    participating in Raft. All data in Raft should be encrypted with TLS.
   244  
   245  - **Denial of Service against a node** - DoS attacks against a single node
   246    should not compromise the security posture of Nomad.
   247  
   248  The following are not part of the threat model for server agents:
   249  
   250  - **Access (read or write) to the Nomad data directory** - Information about the
   251    jobs managed by Nomad is persisted to a server's data directory.
   252  
   253  - **Access (read or write) to the Nomad configuration directory** - Access to
   254    Nomad's configuration file(s) directory can enable and disable features for
   255    a cluster.
   256  
   257  - **Memory access to a running Nomad server agent** - Direct access to the
   258    memory of the Nomad server agent process (usually requiring a shell on the
   259    system through various means) results in almost all aspects of the agent
   260    being compromised including access to certificates and other secrets.
   261  
   262  The following are not part of the threat model for client agents:
   263  
   264  - **Access (read or write) to the Nomad data directory** - Information about the
   265    allocations scheduled to a Nomad client is persisted to its data directory.
   266    This would include any secrets in any of the allocation's file systems.
   267  
   268  - **Access (read or write) to the Nomad configuration directory** - Access to a
   269    client's configuration file can enable and disable features for a client
   270    including insecure drivers such as
   271    [`raw_exec`](/docs/drivers/raw_exec).
   272  
   273  - **Memory access to a running Nomad client agent** - Direct access to the
   274    memory of the Nomad client agent process allows an attack to extract secrets
   275    from clients such as Vault tokens.
   276  
   277  - **Lax Client Driver Sandbox** - Drivers may allow some privileged operations,
   278    e.g. filesystem access to configuration directories, or raw accesses to host
   279    devices. Such privileges can be used to facilitate compromise other workloads,
   280    or cause denial-of-service attacks.
   281  
   282  #### Internal Threats
   283  
   284  - **Job Operator** - Someone with a valid mTLS certificate and ACL token may still be a
   285    threat to your cluster in certain situations, especially in multi-team
   286    cluster deployments. They may accidentally or intentionally use a malicious
   287    job to harm a cluster which can help be protected against using
   288    Quotas, Namespace, and Sentinel policies.
   289  
   290  - **Workload** - Workloads may have host network access within a cluster which
   291    can lead to SSRF due to application security issues outside of the scope of
   292    Nomad which may lead to internal access within the cluster. Using mTLS, ACLs
   293    and Sentinel policies together can add layers of protection against
   294    malicious workloads.
   295  
   296  - **RPC / API Access** - RPC and HTTP API endpoints without mTLS can expose
   297    clusters to abuse within the cluster from malicious workloads.
   298  
   299  - **Client driver** - Drivers implement various workload types for a cluster,
   300    and the backend configuration of these drivers should be considered to
   301    implement defense in depth. For example, a custom Docker driver that limits
   302    the ability to mount the host file system may be subverted by network access
   303    to an exposed Docker daemon API through other means such as the [`raw_exec`](/docs/drivers/raw_exec)
   304    driver.
   305  
   306  #### External Threats
   307  
   308  There are two main components to consider to for external threats in a Nomad cluster:
   309  
   310  - **Server agent** - Internal cluster leader elections and replication is
   311    managed via Raft between server agents encrypted in transit. However,
   312    information about the server is stored unencrypted at rest in the agent's
   313    data directory. This may contain sensitive information such as ACL tokens
   314    and TLS certificates.
   315  
   316  - **Client agent** - Client-to-server communication within a cluster is
   317    encrypted and authenticated using mTLS. Information about the allocations on
   318    a client node is unencrypted in the agent's data and configuration
   319    directory.
   320  
   321  ### Network Ports
   322  
   323  | **Port / Protocol**  | Agents  | Description                                                                                                                                                                         |
   324  | -------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
   325  | **4646** / TCP       | All     | [HTTP](https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol) to provide [UI](https://learn.hashicorp.com/tutorials/nomad/web-ui-access) and [API](/api-docs) access to agents. |
   326  | **4647** / TCP       | Servers | [RPC](https://en.wikipedia.org/wiki/Remote_procedure_call) protocol used by agents.                                                                                                 |
   327  | **4648** / TCP + UDP | Servers | [gossip](/docs/internals/gossip) protocol to manage server membership using [Serf](https://www.serf.io/).                                                                           |