Giter Club home page Giter Club logo

csaf_backend's Introduction

CSAF Backend API

Based on this work, a CSAF Content Management System is developed at Secvisogram/CSAF-CMS-Backend. This PoC is not longer maintained.

Architecture

Architecture

Installation

First, clone the project:

git clone https://github.com/pdamian/csaf_backend.git && cd csaf_backend/

Then, create a file named .env that stores your secrets (update with your own set of values):

cat << EOF > .env
# Keycloak IDP
KEYCLOAK_USER="<KEYCLOAK_ADMIN_USER>"
KEYCLOAK_PASSWORD="<KEYCLOAK_ADMIN_PASSWORD>"
KEYCLOAK_DB_USER="<KEYCLOAK_DB_USER>"
KEYCLOAK_DB_PASSWORD="<KEYCLOAK_DB_PASSWORD>"

# Keycloak OIDC
OIDC_PROVIDER="http://<IP-OPENID_PROVIDER>:8080"        # OpenID Provider
OIDC_CLIENT_SECRET="<CLIENT_SECRET>"                    # Client Secret
OIDC_REDIRECT_URIS="*"                                  # Comma-separated redirect URIs

# CSAF API Database
MONGO_ROOT="<MONGODB_ADMIN_USER>"
MONGO_ROOT_PASSWORD="<MONGODB_ADMIN_PASSWORD>"
MONGO_USER="<MONGODB_USER>"
MONGO_USER_PASSWORD="<MONGODB_PASSWORD>"
EOF

Requirements

Ensure that you have Docker and Docker Compose installed.

The development setup further requires the packages python3 and python3-venv being installed.

Setup

Start the containers either for testing or development. Note that both setups are not recommended to be used in production.

Testing

Launch the containers:

docker-compose -f docker-compose.test.yml up -d

After a while, the Keycloak IdP and CSAF Backend API specification should become accessible at:

curl http://localhost:8080/
curl http://localhost:5000/api/specs/

If needed, the containers can be stopped with (add --volumes to drop all persisted data, e.g. users added to Keycloak or stored advisories):

docker-compose -f docker-compose.test.yml down

Development

Launch the containers:

docker-compose -f docker-compose.dev.yml up -d

Manually launch the CSAF backend API:

# Environment variables
export $(cat .env | sed -E 's/#.*$|//g' | xargs)
export FLASK_ENV=development

# Python virtual environment
python3 -mvenv .venv
source .venv/bin/activate
pip install wheel
pip install -r requirements.txt

# Flask server
flask run --host=0.0.0.0

After a while, the Keycloak IdP and CSAF Backend API specification should become accessible at:

curl http://localhost:8080/
curl http://localhost:5000/api/specs/

If needed, the containers can be stopped with (add --volumes to drop all persisted data, e.g. users added to Keycloak or stored advisories):

docker-compose -f docker-compose.dev.yml down

Use the following commands if you want to unset the previously configured environment variables:

unset $(cat .env | sed -E 's/#.*$|\=.*$//g' | xargs)
unset FLASK_ENV

How To

Keycloak Test User

  1. Using a web browser, access and login to the Keycloak Administration Console (use your specified secrets)
  2. Select the CSAF realm, and go to Manage/Users
  3. Click Add User
  4. Enter a Username and click Save
  5. Switch to the Credentials tab, enter a Password and Password Confirmation and click Set Password

CSAF Backend API Test

  1. Simulate a Keycloak user login to receive an access token for the Backend API:
curl -L -X POST 'http://<KEYCLOAK_IP>:8080/auth/realms/CSAF/protocol/openid-connect/token' \
        -H 'Content-Type: application/x-www-form-urlencoded' \
        --data-urlencode 'client_id=csaf-client' \
        --data-urlencode 'grant_type=password' \
        --data-urlencode 'client_secret=<CLIENT_SECRET>' \
        --data-urlencode 'scope=openid' \
        --data-urlencode 'username=<USER>' \
        --data-urlencode 'password=<PASSWORD>'
  1. Use the access token to query the CSAF Backend API:
curl -L -X GET 'http://<CSAF_BACKEND_IP>:5000/api/advisories' -H 'Authorization: Bearer <ACCESS_TOKEN>'

Note: The access token can also be used at the CSAF Backend API specification.

Note

This project was developed by the armasuisse Cyber-Defense Campus.

csaf_backend's People

Contributors

pdamian avatar tschmidtb51 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

sthagen

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.