Create Rules

Overview

Rules are the fundamental building blocks of a Hardpoint Connect network.

They are a simple way to control:

  • What peers can enter your Hardpoint network
  • What services those peers can connect to

They achieve this without relying on traditional infrastructure techniques like IP whitelists or shared secrets. Instead, they rely on the verifiable identity of the two points at either end of the request loop, the Application (typically making a request via the SDK) and the Service (gated by an agent). Rules are evaluated in the Relay Mesh, the central, managed network fabric connecting the two.

sequenceDiagram
    participant C as Application
    participant R as Relay Mesh
    participant S as Service

    C->>R: Request

    activate R
    R->>R: Evaluate rules
    alt Rule matches
        R->>S: Forward request
        S-->>R: Response
    else Rule rejects
        R-->>C: Error response
    end
    deactivate R

    R-->>C: Forward response

Rule Expressions

All rules in Hardpoint Connect are simple predicate expressions that evaluate to true or false. They're written in the Common Expression Language (CEL), a small, high-performance language designed for rapid evaluation in a request path.

If you've ever used control flow primitives in any C-like language, you already know 90% of CEL:

source_region == "us-east-1" && org_id == "o-abc1234567"

Rule Matching

You can define any number of rule expressions in your Hardpoint Connect network, but for a tunnel to be established between your application and a remote service. Just like nftables or cloud security groups, Hardpoint Connect rules do not allow any traffic by default.

To allow traffic into the Relay Mesh, you must write at least 2 matching rules: an ingress rule and a service rule.

If we consider that an SDK connection request consists of 3 parts:

  • Service name - what the SDK wants to connect to (e.g. postgres )
  • Request identity - attests to the legitimacy of the request, signed by a known identity provider, e.g. a
  • Request context - extra key-value information about the nature of the environment the request came from (e.g. deployment environment)

Ingress Rules

Ingress rules evaluate whether a connection request can proceed based on the request identity. They commonly validate environment specific claims in a provided JWT token.

How they look depends on your execution environment.

Supported ingress types

Hardpoint Connect currently supports application traffic coming from the following environments:

The SDK can automatically detect the environment your application is running in and extract the correct credentials to present to the Relay Mesh with zero extra configuration.


Ingress Rule Examples

These are some illustrative examples of typical rules for supported execution environments. See the Rules Reference for more environment-specific information on available variables and limitations.

Vercel

Allow all traffic from a team

owner_id == "team_abc123"

You can find your Vercel Team ID in your Vercel Dashboard:

Select your team -> click Settings in the sidebar -> select General from the left-hand navigation.


Only allow a specific project

project_id == "prj_123456"

You can find your Vercel Project ID in your Vercel Dashboard:

Select your project from the dashboard -> open Settings -> General -> scroll down to Project ID (usually starts with prj_)

Fly.io
Amazon Elastic Kubernetes Service (EKS)
GitHub Actions

Service Rules

Service rules evaluate whether a connection request can proceed based on the service name and request context. They are orthogonal to ingress rules (however if no ingress rules match an incoming request, no service rules will be evaluated).

They answer the question, "is a request with this context allowed to reach this service?"

For example, given a connection request with service name postgres and request context {"env":"prod"}, you may write a service selector for a postgres service like:

env != "prod"

In which case the request would fail, even if an ingress rule matched.


Service Discovery

Service names do not have to be globally unique, however they must be unique per agent group

Service names do not have to be globally unique.

This is useful for decoupling service name from application context. For example, it's valid to have 2 services which are both named postgres which are members of different agent groups. The application simply connects to "postgres" and lets Hardpoint Connect decide which service it should open a tunnel.

If our second service has the following rule:

env == "prod"

...then the original request would succeed and a tunnel would be established.


Multiple Ingress

A service can declare multiple service rules.

This can be useful in the case of heterogeneous networks where legitimate traffic may need to be supported from multiple ingress points. For example you might have an architecture consisting of:

  • A workload running in a Kubernetes pod
  • A Vercel app

There are valid cases where both apps may need to access the same underlying service. In this case you may want to check a request context property which holds across both execution environments. For example, if you want to restrict service access to a group of tenants, the application may specify a tenant key from an SDK call in their application:

const sdk = Sdk.init({orgId: process.env.HARDPOINT_ORG_ID});

// in a real application the string would come from somewhere dynamic
// such as a database, an HTTP header, e.t.c
const tenantD = TenantKey.from("tenant_d");

// connect to service named 'postgres'
const tunnel = await sdk.connect('postgres');