Skip to content

Commit

Permalink
Role work
Browse files Browse the repository at this point in the history
  • Loading branch information
andyslack committed Sep 2, 2024
1 parent c439566 commit 8d7d5a9
Show file tree
Hide file tree
Showing 39 changed files with 2,008 additions and 2,515 deletions.
92 changes: 92 additions & 0 deletions .github/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
schedule:
- cron: '29 7 * * 2'

jobs:
analyze:
name: Analyze (${{ matrix.language }})
# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners (GitHub.com only)
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
permissions:
# required for all workflows
security-events: write

# required to fetch internal or private CodeQL packs
packages: read

# only required for workflows in private repositories
actions: read
contents: read

strategy:
fail-fast: false
matrix:
include:
- language: javascript-typescript
build-mode: none
# CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
# Use `c-cpp` to analyze code written in C, C++ or both
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
steps:
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

# If the analyze step fails for one of the languages you are analyzing with
# "We were unable to automatically build your code", modify the matrix above
# to set the build mode to "manual" for that language. Then modify this step
# to build your code.
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
- if: matrix.build-mode == 'manual'
shell: bash
run: |
echo 'If you are using a "manual" build mode for one or more of the' \
'languages you are analyzing, replace this with the commands to build' \
'your code, for example:'
echo ' make bootstrap'
echo ' make release'
exit 1
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "npm"
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
4 changes: 0 additions & 4 deletions .prettierrc

This file was deleted.

42 changes: 33 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ We are working to support all major databases, if you would like to contribute t

- [ ] Authentication

- [ ] Auth testing files (hosts, apikey)

- [ ] Role based default permissions, e.g.

```
Expand Down Expand Up @@ -73,22 +71,31 @@ We are working to support all major databases, if you would like to contribute t

- [ ] setup auth login endpoint

- [ ] get endpoints, support deeper tables (e.g. content_keywords) with format, content/1/keywords

- [ ] finish endpoint support for mysql

note: on create/update/upsert, do type checking on data, numbers, enums matching etc
note: delete options (SOFT/HARD). if soft specify name of delete column in table.

- [ ] add full testing

- [ ] Move these docs to juicyllama.com/llana, landing page + docs

- [ ] Add redis support for faster performance (e.g. schema caching)
- [ ] Add redis support for faster performance (e.g. schema caching, user_identity)

- [ ] containerize and publish to docker

- [ ] use on first external client project

- [ ] move remaining items to github issues

- [ ] add column exclusions (global and by table, e.g. deleted_at, password)

- [ ] Adding more database integrations (postgres, etc)

- [ ] Interface for managing configuration

- [ ] Scope Llana cloud option for non-technical users

- [ ] Scope out Setup / Install service (pay to deploy on your database)
Expand Down Expand Up @@ -119,6 +126,14 @@ Replace the database connection string `DATABASE_URI` in the `.env` file.

### Authentication

We currently support two types of authentication:

#### API KEY

By defualt, this expects a table named `users_api_keys` with the field `api_key`, you can override these settings in in the `src/config/auth.config.ts` file.

#### JWT Token

We provide a special extra endpoint, the only one not generated based on your database schema.

* `/auth/login`
Expand All @@ -127,17 +142,26 @@ This endpoint will take the users login credentials and return back a JWT token,

By defualt, this expects a table named `users` with the fields `email` and `password`, you can override these settings in in the `src/config/auth.config.ts` file.

### Restrictions
#### Routes

By default any authentications required will apply to all endpoints, you can add exclusions to the config. There is an option to add inclusions for more granular inclusion/exclusion support.

Out of the box we provide an two example restrictions in the `src/config/restrictions.config.ts` which requires users to either authenticate (via the `/auth/login` endpoint) and pass the JWT token to all other endpoints or by providing an API Key.
This allows you to open and close specific endpoints to the public.
</div>

By default the API Key expect a table named `users` with the field `api_key`, you can override these settings in in the `src/config/auth.config.ts` file.
### Roles

You can update `src/config/restrictions.config.ts` to enforce different types of restrictions on data access.
User roles are an important part of granting the correct permissions to perform relevent actions on the API endpoints.

By default restrictions will apply to all endpoints, you can add exclusions to the config. There is an option to add inclusions for more granular inclusion/exclusion support.
By default, everything is locked down and no actions can be performed (`NONE`). You can set role `defualts` which will be the fallback if no specific table role permissions have been added.

</div>
We provide a defualt configutation you can update/expand `src/config/roles.config.ts`

You can grant roles the ability to `DELETE` which means they can also `READ` and `WRITE`, granting `WRITE` access also allows users to `READ` and finally `READ` access is just that. If you don't want to give a role any permissions then use `NONE`

If the user has insufficent permmissions they will get a `403 Forbidden` response.

*Note:* User roles work in combination with [Authentication](#authentication), if you don't have authentications setup, your API will be fully open and roles do not apply.

## Building Requests

Expand Down
7 changes: 4 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 16 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"**/*.ts\"",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:docker": "docker compose --project-name llana up --build --detach",
"test": "jest"
"start:ngrok": "~/ngrok http http://localhost:3030/ --subdomain=llana",
"test": "jest --runInBand --detectOpenHandles --forceExit"
},
"dependencies": {
"@juicyllama/utils": "^0.10.4",
Expand All @@ -36,6 +38,7 @@
"@nestjs/platform-express": "^10.3.2",
"@nestjs/serve-static": "^4.0.2",
"@nestjs/swagger": "^7.4.0",
"axios": "^1.7.7",
"class-validator": "^0.14.1",
"jwt-simple": "^0.5.6",
"lodash": "^4.17.21",
Expand Down Expand Up @@ -84,5 +87,16 @@
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
},
"prettier": {
"singleQuote": true,
"trailingComma": "all",
"tabWidth": 4,
"useTabs": true,
"semi": false,
"printWidth": 120,
"arrowParens": "avoid",
"bracketSpacing": true,
"bracketSameLine": true
}
}
}
2 changes: 1 addition & 1 deletion src/app.constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const NON_FIELD_PARAMS = ['fields', 'limit', 'offset', 'sort', 'page', 'relations']
export const NON_FIELD_PARAMS = ['fields', 'limit', 'offset', 'sort', 'page', 'relations']
Loading

0 comments on commit 8d7d5a9

Please sign in to comment.