Skip to content

Anubis: a flexible policy enforcement solution for NGSI APIs (and beyond!)

License

Notifications You must be signed in to change notification settings

SURAJKALLOLI/anubis-dev

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

79 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Anubis

FIWARE Security License: APACHE-2.0 Docker Status Support Documentation badge

Welcome to Anubis!

📚 Documentation 🐳 Docker Hub

What is the project about?

Anubis

Anubis is a flexible Policy Enforcement solution that makes easier to reuse security policies across different services, assuming the policies entail the same resource. In short we are dealing with policy portability :) What do you mean by that?

Let's think of a user that register some data in platform A. To control who can access his data he develops a set of policies. If he moves the data to platform B, most probably he will have to define again the control access policies for that data also in platform B.

Anubis aims to avoid that :) or at least simplify this as much as possible for the data owner. How? Leveraging open source solutions (e.g. Envoy, OPA) and reference standards (e.g. W3C WAC, W3C ODRL, OAUTH2).

Of course, the support for distributed policies management may be of value also for a single platform deployed distributedly, e.g. to synch policies across the cloud-edge.

Why this project?

Data portability often focuses on the mechanisms to exchange data and the formalisation of data representation: the emphasis is rarely put on the portability of security & privacy data policies. Enabling security and privacy data policy portability is clearly a step forward in enabling data sovereignty across different services.

This project aims at enabling data sovereignty by introducing data privacy and security policy portability and prototyping distributed data privacy and security policy management, thus contributing to increase trust toward data sharing APIs and platforms.

Approaches as the one proposed, increasing control by owners over their data and portability of data assets, are key to boost the establishment of trusted data spaces.

The project is looking into

  • Open standardized security & privacy data policies vocabulary.
  • Linking an existing user profiling vocabulary to the security & privacy data policies vocabulary as a way to increase portability of policies and their compatibility to existing standards.
  • A middleware supporting decentralised control and audit of security & privacy data policies by data owners (in the context of RESTful APIs).
  • Translation from the security & privacy data policies vocabulary to other policy languages or APIs that are actually used for PEP.

While Anubis is not subject to GDPR per se, it allows API owners to implement effective GDPR in their solutions.

Why did you pick Anubis as name?

Anubis is an ancient Egyptian god, that has multiple roles in the mythology of ancient Egypt. In particular, we opted for this name, because he decides the fate of souls: based on their weights he allows the souls to ascend to a heavenly existence, or condemn them to be devoured by Ammit. Indeed, Anubis was a Policy Enforcement system for souls :)

Architecture

Policy Enforcement

In term of policy enforcement, Anubis adopts a standard architecture: a client request for a resource to an API, and based on the defined policies, the client is able or not to access the resource. The figure below shows the current architecture.

                            ┌──────────────┐        ┌──────────────┐
                            │   Policy     │   3    │    Policy    │
                            │   Decision   ├───────►│Administration│
                            │   Point      │        │    Point     │
                            └──────────────┘        └──────────────┘
                                   ▲
                                 2 │
                                   │
    ┌──────────────┐        ┌──────┴──────┐        ┌───────────────┐
    │              │   1    │   Policy    │   4    │   Protected   │
    │    Client    ├───────►│ Enforcement ├───────►│               │
    │              │        │    Point    │        │      API      │
    └──────────────┘        └─────────────┘        └───────────────┘
  1. A client requests for a resource via the Policy Enforcement Point (PEP) - implemented using an Envoy's proxy authz filter.
  2. The PEP pass over the request to the PDP (Policy Decision Point), provided by OPA which evaluates a set of rules that apply the abstract policies to the specific API to be protected;
  3. In combination with the policies stored in the PAP (Policy Administration Point), provided by the Policy Management API;
  4. If the evaluation of the policies returns allowed, then the request is forwarded to the Protected API.

Policy Management

Anubis currently supports only Role Based Access Control policies. Policies are stored in the policy management api, that supports the translation to WAC and to a data input format supported by OPA, the engine that performs the policy evaluation.

At the time being, the API specific rules have been developed specifically for the NGSIv2 Context Broker, Anubis management, and JWT-based authentication. You can see Orion rules in this rego file.

Policy Distribution

The policy distribution architecture relies on libp2p middleware to distribute policies across differed Policies Administration Points. The architecture decouples the PAP from the distribution middleware. This allows:

  • different PAP to share the same distribution node.
  • deployment without the distribution functionalities (and hence with a smaller footprint), when this is not required.

The distribution middleware is called Policy Distribution Point.

    ┌──────────────┐        ┌──────────────┐
    │   Policy     │        │    Policy    │
    │ Distribution │◄──────►│Administration│
    │   Point 1    │        │    Point 1   │
    └──────────────┘        └──────────────┘
           ▲
         2 │
           ▼
    ┌──────────────┐        ┌──────────────┐
    │   Policy     │        │    Policy    │
    │ Distribution │◄──────►│Administration│
    │   Point 2    │        │    Point 2   │
    └──────────────┘        └──────────────┘

There are two distribution modalities:

  • public, i.e. when the different middleware belong to different organisations in the public internet. In this case:

    • resources are considered to be univocally identifiable (if they have the same id they are the same resource);

    • only user specific policies are distributed;

    • only resource specific policies are distributed.

  • private, i.e. when the different middleware belong to the same organisation. In this case:

    • resources are considered to be univocally identifiable only within the same service and service path;

    • all policies are distributed (including the ones for roles and groups and * and default resource policies).

Policies

The formal policy specification is defined by the oc-acl vocabulary as en extension to Web Access control. The internal representation is json-based, see policy management api for details.

In general, a policy is defined by:

  • actor: The user, group or role, that is linked to the policy
  • action: The action allowed on this resource (e.g. acl:Read for GET requests)
  • resource: The urn of the resource being targeted (e.g. urn:entity:x)
  • resource_type: The type of the resource.
  • constraint (to be implemented): The constraint that has to be satisfied to authorize access.

The authorization rules currently in place supports the following resource types:

  • entity: NGSI entity
  • entity_type: NGSI entity type
  • subscription: NGSI subscription
  • policy: A policy of the Anubis Management API (to allow users to have control over the policies that are created)

This can be extended by creating new authorisation rules, and setting up the necessary filters in the envoy configuration.

Additionally, in relation to FIWARE APIs, a policy may include also:

  • tenant: The tenant this permission falls under
  • service_path: The service path this permission falls under

Authentication

The authentication per se is not covered by the PEP, the assumption is that the client authenticates before issuing and obtains a valid JWT token.

Currently the PEP only verifies that the token is valid by checking against its expiration.

Of course, more complex validations are possible. See OPA Docs for additional examples.

Currently, the token, when decoded, should contain:

  • The ID of the user making the request
  • The groups the user belongs to and their respective tenants
  • The roles the user has under their respective tenants

Demo

Requirements

To run this demo you'll need to have the following installed:

Deployment

To enable tenant creation in both Anubis and Keycloak, for obvious security reasons, the hostname of the token issuer (Keycloak) in the docker services and in your browser, needs to be the same. To ensure that, add the following entry in your /etc/hosts:

127.0.0.1       keycloak

NOTE: If you don't want to edit your /etc/hosts and you are not interested in testing tenant creation and deletion, in the .env file replace REACT_APP_OIDC_ISSUER=http://keycloak:8080/realms/default with REACT_APP_OIDC_ISSUER=http://localhost:8080/realms/default.

To deploy the demo that includes the Auth API, OPA, Keycloak, and a Context Broker, run the following script:

$ source .env
$ cd scripts
$ ./run_demo.sh

You can now login with username [email protected] and password admin.

You can run a script to make a few test API calls. You can run the test script with:

$ cd scripts
$ ./test_context_broker.sh

To clean up the deployment after you're done, run:

$ cd scripts
$ ./clean.sh

Demo for distributed policy management

To deploy the demo that includes two instances of the Auth API, two instances of the distribution middleware (plus as well OPA, Keycloak, and a Context Broker), run the following script:

$ cd scripts
$ ./run_demo_with_middleware.sh

You can run a script to make a few test API calls. You can run the test script with:

$ cd scripts
$ ./test_middleware.sh

To clean up the deployment after you're done, run:

$ cd scripts
$ ./clean.sh

Installation

Anubis is available as a docker container and as a python package.

Requirements to allow policy enforcement using Anubis (PAP) are:

An example docker compose is provided in this repository that deploy all the dependencies and demonstrates how to protect an Orion Context Broker instance.

To install the python package:

$ pip install anubis-policy-api

This will allow you to reuse Anubis apis also for other projects.

Configuration

The following environment variables are used by the rego policy for configuration (see the docker-compose file):

  • AUTH_API_URI: Specifies the URI of the auth management API.
  • VALID_ISSUERS: Specifies the valid issuers of the auth tokens (coming from Keycloak). This can be a list of issuers, separated by ;.
  • VALID_AUDIENCE: The valid aud value for token verification.

For the policy API, the following env variables are also available:

  • CORS_ALLOWED_ORIGINS: A ; separated list of the allowed CORS origins (e.g. http://localhost;http://localhost:3000)
  • CORS_ALLOWED_METHODS: A ; separated list of the allowed CORS methods (e.g. GET;POST:DELETE)
  • CORS_ALLOWED_HEADERS: A ; separated list of the allowed CORS headers (e.g. content-type;some-other-header)
  • DEFAULT_POLICIES_CONFIG_FILE: Specifies the path of the configuration file of the default policies to create upon tenant creation.
  • DEFAULT_WAC_CONFIG_FILE: Specifies the path of the configuration file of the wac serialization.
  • KEYCLOACK_ENABLED: Enable creation of tenant also in Keycloak.
  • TENANT_ADMIN_ROLE_ID: Role id for tenant admins (you need to retrieve it from a running keycloak using a different template).
  • KEYCLOACK_ADMIN_ENDPOINT: The endpoint of the admin api of Keycloak.
  • DB_TYPE: The database type to be used by the API. Valid options for now are postgres and sqlite.
  • MIDDLEWARE_ENDPOINT: The endpoint of the policy distribution middleware (if None the policy distribution is disabled).

If postgres is the database being used, the following variables are available as well:

  • DB_HOST: The host for the database.
  • DB_USER: The user for the database.
  • DB_PASSWORD: The password for the database user.
  • DB_NAME: The name of the database.

The policy distribution middleware is an add-on the basic Anubis deployment. The following environment variables can be configured:

  • SERVER_PORT: The port where the middleware API is exposed.
  • ANUBIS_API_URI: The anubis management api instance linked to the middleware.
  • LISTEN_ADDRESS: The multiaddress format address the middleware listens on.
  • IS_PRIVATE_ORG: The middleware modality to public or private.

For customizing the default policies that are created alongside a tenant, see the configuration file that's mounted as a volume in the policy-api service from the docker-compose file.

Similarly, a configuration file for the wac serialization is available to configure the prefixes and URIs of the various resource types in relation to tenants.

Load Testing

To measure the overhead introduced by Anubis, we developed a simple script. From the scripts folder, launch the demo set-up and then execute the script:

cd scripts
./run_demo.sh
./test_load.sh

Run load test with Anubis in front of Orion
===============================================================
Requests      [total, rate, throughput]         50, 10.21, 10.06
Duration      [total, attack, wait]             4.971s, 4.899s, 71.35ms
Latencies     [min, mean, 50, 90, 95, 99, max]  69.158ms, 74.566ms, 74.024ms, 79.429ms, 84.087ms, 93.997ms, 93.997ms
Bytes In      [total, mean]                     6550, 131.00
Bytes Out     [total, mean]                     0, 0.00
Success       [ratio]                           100.00%
Status Codes  [code:count]                      200:50  
Error Set:

Run load test without Anubis in front of Orion
===============================================================
Requests      [total, rate, throughput]         50, 10.20, 10.20
Duration      [total, attack, wait]             4.904s, 4.9s, 4.32ms
Latencies     [min, mean, 50, 90, 95, 99, max]  3.241ms, 6.561ms, 5.462ms, 9.934ms, 20.038ms, 23.212ms, 23.212ms
Bytes In      [total, mean]                     6550, 131.00
Bytes Out     [total, mean]                     0, 0.00
Success       [ratio]                           100.00%
Status Codes  [code:count]                      200:50  
Error Set:

As of today, Anubis introduces an average overhead of 69msec, while this is not a bad number, it's not impressive. Still there is a very good news, we know how to improve :) See #14.

Test rego

To test the rego policy locally:

  1. Install the opa client, e.g.:

    cd scripts
    curl -L -o opa https://openpolicyagent.org/downloads/v0.37.2/opa_linux_amd64_static
    chmod 755 ./opa
  2. Run:

    $ source .env
    $ test_rego.sh

Status and Roadmap

Release Notes provide a summary of implemented features and fixed bugs.

For additional planned features you can check the pending issues and their mapping to milestones.

Related repositories

Credits

Sponsors

  • Anubis received funding as part of the Cascade Funding mechanisms of the EC project DAPSI - GA 871498.

About

Anubis: a flexible policy enforcement solution for NGSI APIs (and beyond!)

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 43.5%
  • Lua 23.3%
  • Open Policy Agent 12.6%
  • Shell 10.8%
  • JavaScript 9.5%
  • Dockerfile 0.3%