Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor relationships service and other changes #358

Merged
merged 27 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7363cf8
refactoring service and repo
vsun757 Dec 8, 2023
627368a
refactored tests
vsun757 Dec 8, 2023
92592ce
refactored controller
vsun757 Dec 8, 2023
528b4e7
added base service call
vsun757 Dec 8, 2023
8de55ce
feat: add relationships-repository
seansica Jan 7, 2025
100617f
fix: move attackObjectsService.setDefaultMarkingDefinitions to system…
seansica Jan 7, 2025
1162b24
feat: refactored relationships-service
seansica Jan 7, 2025
d5d7af3
Merge branch 'refactor-relationships-service' of https://github.com/c…
seansica Jan 7, 2025
e487260
fix: no-unused-vars in relationships.spec.js
seansica Jan 7, 2025
a0224df
fix: syntax error/typo in relationships-controller.js
seansica Jan 7, 2025
1ca35c1
fix: resolve linting issues in relationships-controller.js
seansica Jan 7, 2025
d068258
fix: remove lazy loading from attack-objects-service
seansica Jan 7, 2025
3d99040
feat: add prettier for automated formatting
seansica Jan 7, 2025
deddee9
style: apply prettier formatting
seansica Jan 7, 2025
df4c700
fix: remove random artifact from past contributor
seansica Jan 8, 2025
9d52875
feat: introduce magic string anti-pattern for object types
seansica Jan 8, 2025
f513dea
fix: refactor tests/shared/pagination from callbacks to promises
seansica Jan 8, 2025
4bb170e
style: cleanup + formatting
seansica Jan 8, 2025
b5ee996
refactor: remove unused variables
seansica Jan 8, 2025
9c2a8f6
refactor: redo relationships-repository from scratch
seansica Jan 8, 2025
bc93e3d
fix: circular dependencies
seansica Jan 8, 2025
6122e44
refactor: attack-objects-service
seansica Jan 8, 2025
5ea3ab6
refactor: identities-service
seansica Jan 8, 2025
b6e350f
refactor: relationships-service
seansica Jan 8, 2025
ea58ced
fix: modify eslint config to interop with prettier
seansica Jan 9, 2025
99fd996
fix: resolve linting issues + various biz logic issues
seansica Jan 9, 2025
6c3f3aa
Override 'class-methods-use-this' linting rule for two BaseService me…
seansica Jan 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions .c8rc
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{
"all": true,
"include": [
"app/**/*.js"
],
"exclude": [
"app/tests/**/*.js"
]
"include": ["app/**/*.js"],
"exclude": ["app/tests/**/*.js"]
}
16 changes: 6 additions & 10 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ env:
es6: true
mocha: true
node: true
extends: 'eslint:recommended'
extends:
- 'eslint:recommended'
- 'plugin:prettier/recommended'
globals:
Atomics: readonly
SharedArrayBuffer: readonly
Expand All @@ -20,9 +22,7 @@ rules:
array-callback-return: 'off'
array-element-newline: 'off'
arrow-body-style: error
arrow-parens:
- error
- as-needed
arrow-parens: 'off' # Let Prettier handle arrow function parentheses
arrow-spacing:
- error
- after: true
Expand Down Expand Up @@ -66,9 +66,7 @@ rules:
id-blacklist: error
id-length: 'off'
id-match: error
implicit-arrow-linebreak:
- error
- beside
implicit-arrow-linebreak: 'off' # Allow arrow function expressions to span multiple lines
indent: 'off'
indent-legacy: 'off'
init-declarations: 'off'
Expand Down Expand Up @@ -219,9 +217,7 @@ rules:
one-var: 'off'
one-var-declaration-per-line: 'off'
operator-assignment: 'off'
operator-linebreak:
- error
- after
operator-linebreak: 'off' # Let Prettier handle operator line breaks
padded-blocks: 'off'
padding-line-between-statements: error
prefer-arrow-callback: 'off'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: run static checks

on:
on:
push:
branches: [master, develop]
pull_request:
Expand Down
25 changes: 10 additions & 15 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@ name: Build and Publish Docker Image
on:
push:
branches:
- "master"
- "develop"
- 'master'
- 'develop'
tags:
- "v*.*.*"
- 'v*.*.*'

jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Checkout
- name: Checkout
uses: actions/checkout@v3
-
name: Set Docker Image and Tags
- name: Set Docker Image and Tags
id: meta
uses: docker/metadata-action@v4
with:
Expand All @@ -31,27 +29,24 @@ jobs:
type=semver,pattern=v{{major}}.{{minor}}.{{patch}}
# set git short commit as Docker tag (e.g., sha-ad132f5)
type=sha
-
name: Set up Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Login to GHCR
- name: Login to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build and push
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
BUILDTIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
REVISION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
REVISION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"singleQuote": true,
"printWidth": 100,
"trailingComma": "all",
"tabWidth": 2
}
15 changes: 4 additions & 11 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceFolder}/bin/www",
"outputCapture": "std",
"envFile": "${workspaceFolder}/.env"
Expand All @@ -19,18 +17,13 @@
"type": "node",
"request": "launch",
"name": "Run Regression Tests",
"skipFiles": [
"<node_internals>/**"
],
"skipFiles": ["<node_internals>/**"],
"runtimeExecutable": "npm",
"args": [
"run",
"test"
],
"args": ["run", "test"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"outputCapture": "std",
"envFile": "${workspaceFolder}/.env"
}
]
}
}
Empty file.
82 changes: 43 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
# ATT&CK Workbench REST API

The ATT&CK Workbench is an application allowing users to **explore**, **create**, **annotate**, and **share** extensions of the MITRE ATT&CK® knowledge base.
The ATT&CK Workbench is an application allowing users to **explore**, **create**, **annotate**, and **share** extensions of the MITRE ATT&CK® knowledge base.

This repository contains the REST API service for storing, querying, and editing ATT&CK objects. It is a Node.js application that uses a MongoDB database for persisting data.
This repository contains the REST API service for storing, querying, and editing ATT&CK objects. It is a Node.js application that uses a MongoDB database for persisting data.

The ATT&CK Workbench application requires additional components for full operation. The [ATT&CK Workbench Frontend](https://github.com/center-for-threat-informed-defense/attack-workbench-frontend) repository contains the full documentation of the scope and function of the project. See the [install and run](#install-and-run) instructions for more details about setting up the entire project.

## REST API Documentation

When running with the NODE_ENV environment variable set to `development`, the app hosts a description of the REST API using the Swagger UI module.
The REST API documentation can be viewed using a browser at the path `/api-docs`.
The REST API documentation can be viewed using a browser at the path `/api-docs`.

For a basic installation on the local machine this documentation can be accessed at `http://localhost:3000/api-docs`.

The [docs](/docs/README.md) folder contains additional documentation about using the REST API:

- [changelog](/docs/changelog.md): records of updates to the REST API.
- [workbench data model](/docs/data-model.md): additional information about data model of objects stored via the REST API.
- [standalone docker installation](/docs/docker.md): instructions for setting up the REST API via docker. Note that this is not the same as the full [ATT&CK Workbench Docker Installation](https://github.com/center-for-threat-informed-defense/attack-workbench-frontend/blob/master/docs/docker-compose.md).
Expand All @@ -22,16 +23,19 @@ The [docs](/docs/README.md) folder contains additional documentation about using
## Install and run

The ATT&CK Workbench application is made up of several repositories. For the full application to operate each needs to be running at the same time. The [docker install instructions](https://github.com/center-for-threat-informed-defense/attack-workbench-frontend/blob/master/docs/docker-compose.md) will install all components and is recommended for most deployments.
- [ATT&CK Workbench Frontend](https://github.com/center-for-threat-informed-defense/attack-workbench-frontend)


- [ATT&CK Workbench Frontend](https://github.com/center-for-threat-informed-defense/attack-workbench-frontend)

The front-end user interface for the ATT&CK Workbench tool, and the primary interface through which the knowledge base is accessed.

- [ATT&CK Workbench REST API](https://github.com/center-for-threat-informed-defense/attack-workbench-rest-api) (this repository)

REST API service for storing, querying and editing ATT&CK objects.

The manual install instructions in each repository describe how each component to be deployed to a separate machine or with customized settings.
The manual install instructions in each repository describe how each component to be deployed to a separate machine or with customized settings.

### Installing using Docker

Please refer to our [Docker install instructions](https://github.com/center-for-threat-informed-defense/attack-workbench-frontend/blob/master/docs/docker-compose.md) for information on installing and deploying the app using Docker. The docker setup is the easiest way to deploy the application.

### Manual Installation
Expand All @@ -40,7 +44,7 @@ Please refer to our [Docker install instructions](https://github.com/center-for-

- [Node.js](https://nodejs.org) version `18.12.1` or greater
- An instance of [MongoDB](https://www.mongodb.com/) version `4.4.x` or greater

#### Installation

##### Step 1. Clone the git repository
Expand All @@ -66,17 +70,17 @@ Note that any values set in a configuration file take precedence over values set

###### Using Environment Variables

| name | required | default | description |
|--------------------------------------|----------|---------------|-----------------------------------------------------------|
| **PORT** | no | `3000` | Port the HTTP server should listen on |
| **ENABLE_CORS_ANY_ORIGIN** | no | `true` | Allows requests from any domain to access the REST API endpoints |
| **NODE_ENV** | no | `development` | Environment that the app is running in |
| **DATABASE_URL** | yes | none | URL of the MongoDB server |
| **AUTHN_MECHANISM** | no | `anonymous` | Mechanism to use for authenticating users |
| **DEFAULT_INTERVAL** | no | `300` | How often collection indexes should check for updates (in seconds) |
| **JSON_CONFIG_PATH** | no | `` | Location of a JSON file containing configuration values |
| **LOG_LEVEL** | no | `info` | Level of messages to be written to the log (error, warn, http, info, verbose, debug) |
| **WB_REST_STATIC_MARKING_DEFS_PATH** | no | `./app/lib/default-static-marking-definitions/` | Path to a directory containing static marking definitions |
| name | required | default | description |
| ------------------------------------ | -------- | ----------------------------------------------- | ------------------------------------------------------------------------------------ |
| **PORT** | no | `3000` | Port the HTTP server should listen on |
| **ENABLE_CORS_ANY_ORIGIN** | no | `true` | Allows requests from any domain to access the REST API endpoints |
| **NODE_ENV** | no | `development` | Environment that the app is running in |
| **DATABASE_URL** | yes | none | URL of the MongoDB server |
| **AUTHN_MECHANISM** | no | `anonymous` | Mechanism to use for authenticating users |
| **DEFAULT_INTERVAL** | no | `300` | How often collection indexes should check for updates (in seconds) |
| **JSON_CONFIG_PATH** | no | `` | Location of a JSON file containing configuration values |
| **LOG_LEVEL** | no | `info` | Level of messages to be written to the log (error, warn, http, info, verbose, debug) |
| **WB_REST_STATIC_MARKING_DEFS_PATH** | no | `./app/lib/default-static-marking-definitions/` | Path to a directory containing static marking definitions |

A typical value for DATABASE_URL when running on a development machine is `mongodb://localhost/attack-workspace`.
This assumes that a MongoDB server is running on the same machine and is listening on the standard port of 27017.
Expand All @@ -86,14 +90,14 @@ The MongoDB server can be running natively or in a Docker container.

If the `JSON_CONFIG_PATH` environment variable is set, the app will also read configuration settings from a JSON file at that location.

| name | type | corresponding environment variable |
|-------------------------------------|----------|------------------------------------|
| **server.port** | int | PORT |
| **server.enableCorsAnyOrigin** | boolean | ENABLE_CORS_ANY_ORIGIN |
| **app.env** | string | NODE_ENV |
| **database.url** | string | DATABASE_URL |
| **collectionIndex.defaultInterval** | int | DEFAULT_INTERVAL |
| **logging.logLevel** | string | LOG_LEVEL |
| name | type | corresponding environment variable |
| ----------------------------------- | ------- | ---------------------------------- |
| **server.port** | int | PORT |
| **server.enableCorsAnyOrigin** | boolean | ENABLE_CORS_ANY_ORIGIN |
| **app.env** | string | NODE_ENV |
| **database.url** | string | DATABASE_URL |
| **collectionIndex.defaultInterval** | int | DEFAULT_INTERVAL |
| **logging.logLevel** | string | LOG_LEVEL |

Sample configuration file setting the server port and database url:

Expand Down Expand Up @@ -123,17 +127,17 @@ Workbench supports OIDC authentication for users, allowing you to integrate Work
In order to use OIDC authentication, your Workbench instance must be registered with your organization's OIDC authentication server.
The details depend on your authentication server, but the following values should cover most of what you need:

* Workbench uses the *Authorization Code Flow* for authenticating users
* Claims:
- Workbench uses the _Authorization Code Flow_ for authenticating users
- Claims:

| claim | required | description |
|------------------------|----------|-------------------------------------------------------------------------------------------------------------------------------------------------|
| **email** | yes | Identifies the user account associated with an authenticated user |
| claim | required | description |
| ---------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| **email** | yes | Identifies the user account associated with an authenticated user |
| **preferred_username** | no | If present, the `preferred_username` claim is used to set the `name` property of the user account when the user initially registers with Workbench |
| **name** | no | If present, the `name` claim is used to set the `displayName` property of the user account when the user initially registers with Workbench |
| **name** | no | If present, the `name` claim is used to set the `displayName` property of the user account when the user initially registers with Workbench |

* Grant Types: *Client Credentials*, *Authorization Code* and *Refresh Token*
* Redirect URL: `<host_url>/api/authn/oidc/callback`
- Grant Types: _Client Credentials_, _Authorization Code_ and _Refresh Token_
- Redirect URL: `<host_url>/api/authn/oidc/callback`

After registering with the OIDC authentication system, you will need the `client_id` and `client_secret` assigned as part of that process.
You will also need the Issuer URL for the OIDC Identity Server.
Expand All @@ -143,7 +147,7 @@ You will also need the Issuer URL for the OIDC Identity Server.
Configuring Workbench to use OIDC can be done using environment variables or the corresponding properties in a configuration file.

| environment variable | required | description | configuration file property name |
|--------------------------------|----------|-------------------------------------------------------------------------------------------------------|----------------------------------|
| ------------------------------ | -------- | ----------------------------------------------------------------------------------------------------- | -------------------------------- |
| **AUTHN_MECHANISM** | yes | Must be set to `oidc` | userAuthn.mechanism |
| **AUTHN_OIDC_CLIENT_ID** | yes | Client ID assigned to the Workbench instance when registering with the OIDC authentication system | userAuthn.oidc.clientId |
| **AUTHN_OIDC_CLIENT_SECRET** | yes | Client secret assigned to the Workbench instance when registering with the OIDC authentication system | userAuthn.oidc.clientSecret |
Expand Down Expand Up @@ -192,15 +196,15 @@ This project is configured to run a Github workflow when one or more commits are

The workflow is defined in `.github/workflows/ci-workflow.yml`

## Notice
## Notice

Copyright 2020-2024 MITRE Engenuity. Approved for public release. Document number CT0020

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

This project makes use of ATT&CK®

Expand Down
2 changes: 1 addition & 1 deletion app/api/definitions/components/assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ components:
description:
type: string
required:
- name
- name
1 change: 0 additions & 1 deletion app/api/definitions/components/sessions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ components:
$ref: 'identities.yml#/components/schemas/identity'
registered:
type: boolean

Loading
Loading