* Modify plugin.json to support RBAC role registration * defines 26 new custom roles in plugin.json. The main roles are: - Admin: read/write access to everything in OnCall - Reader: read access to everything in OnCall - OnCaller : read access to everything in OnCall + edit access to Alert Groups and Schedules - <object-type> Editor: read/write access to everything related to <object-type> - <object-type> Reader: read access for <object-type> - User Settings Admin: read/write access to all user's settings, not just own settings. This is in comparison to User Settings Editor which can only read/write own settings * update changelog and documentation (#686) * implement RBAC for OnCall backend This commit refactors backend authorization. It trys to use RBAC authorization if the org's grafana instance supports it, otherwise it falls back to basic role authorization. * update RBAC backend tests * add tests for RBAC changes - run backend tests as matrix where RBAC is enabled/disabled. When RBAC is enabled, the permissions granted are read from the role grants in the frontend's plugin.json file (instead of relying what we specify in RBACPermission.Permissions) - remove --reuse-db --nomigrations flags from engine/tox.ini - minor autoformatting changes to docker-compose-developer.yml * remove --ds=settings.ci-test from pytest CI command DJANGO_SETTINGS_MODULE is already specified as an env var so this is just unecessary duplication * update gitignore * update github action job name for "test" * RBAC frontend changes * refactors the use of basic roles (ex. Viewer, Editor, Admin) use RBAC permissions (when supported), or falling back to basic roles when RBAC is not supported. - updates the UserAction enum in grafana-plugin/src/state/userAction.ts. Previously this was hardcoded to a list of strings that were being returned by the OnCall API. Now the values here correspond to the permissions in plugin.json (plus a fallback role) * changes per Gabriel's comments: - get rid of group attribute in rbac roles - remove displayName role attribute - remove hidden role attribute - add back role to includes section * don't try to update user timezone if they don't have permission
167 lines
4.8 KiB
YAML
167 lines
4.8 KiB
YAML
name: ci
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- dev
|
|
pull_request:
|
|
|
|
jobs:
|
|
lint:
|
|
runs-on: ubuntu-latest
|
|
container: python:3.9
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
- uses: actions/setup-node@v3
|
|
with:
|
|
node-version: 14.17.0
|
|
- name: Build
|
|
run: |
|
|
pip install $(grep "pre-commit" engine/requirements.txt)
|
|
npm install -g yarn
|
|
cd grafana-plugin/
|
|
yarn --network-timeout 500000
|
|
yarn build
|
|
- name: Lint All
|
|
run: |
|
|
pre-commit run --all-files
|
|
|
|
test-frontend:
|
|
runs-on: ubuntu-latest
|
|
container: python:3.9
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
- uses: actions/setup-node@v3
|
|
with:
|
|
node-version: 14.17.0
|
|
- name: Unit Testing Frontend
|
|
run: |
|
|
pip install $(grep "pre-commit" engine/requirements.txt)
|
|
npm install -g yarn
|
|
cd grafana-plugin/
|
|
yarn --network-timeout 500000
|
|
yarn test
|
|
|
|
test-technical-documentation:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: "Check out code"
|
|
uses: "actions/checkout@v3"
|
|
- name: "Build website"
|
|
# -e HUGO_REFLINKSERRORLEVEL=ERROR prevents merging broken refs with the downside
|
|
# that no refs to external content can be used as these refs will not resolve in the
|
|
# docs-base image.
|
|
run: |
|
|
docker run -v ${PWD}/docs/sources:/hugo/content/docs/oncall/latest -e HUGO_REFLINKSERRORLEVEL=ERROR --rm grafana/docs-base:latest /bin/bash -c 'make hugo'
|
|
|
|
unit-test-backend-mysql-rabbitmq:
|
|
name: "Backend Tests: MySQL + RabbitMQ (RBAC enabled: ${{ matrix.rbac_enabled }})"
|
|
runs-on: ubuntu-latest
|
|
container: python:3.9
|
|
strategy:
|
|
matrix:
|
|
rbac_enabled: ["True", "False"]
|
|
env:
|
|
DJANGO_SETTINGS_MODULE: settings.ci-test
|
|
SLACK_CLIENT_OAUTH_ID: 1
|
|
services:
|
|
rabbit_test:
|
|
image: rabbitmq:3.7.19
|
|
env:
|
|
RABBITMQ_DEFAULT_USER: rabbitmq
|
|
RABBITMQ_DEFAULT_PASS: rabbitmq
|
|
mysql_test:
|
|
image: mysql:5.7.25
|
|
env:
|
|
MYSQL_DATABASE: oncall_local_dev
|
|
MYSQL_ROOT_PASSWORD: local_dev_pwd
|
|
steps:
|
|
- uses: actions/checkout@v2
|
|
- name: Unit Test Backend
|
|
run: |
|
|
apt-get update && apt-get install -y netcat
|
|
cd engine/
|
|
pip install -r requirements.txt
|
|
./wait_for_test_mysql_start.sh && ONCALL_TESTING_RBAC_ENABLED=${{ matrix.rbac_enabled }} pytest -x
|
|
|
|
unit-test-backend-postgresql-rabbitmq:
|
|
name: "Backend Tests: PostgreSQL + RabbitMQ (RBAC enabled: ${{ matrix.rbac_enabled }})"
|
|
runs-on: ubuntu-latest
|
|
container: python:3.9
|
|
strategy:
|
|
matrix:
|
|
rbac_enabled: ["True", "False"]
|
|
env:
|
|
DATABASE_TYPE: postgresql
|
|
DJANGO_SETTINGS_MODULE: settings.ci-test
|
|
SLACK_CLIENT_OAUTH_ID: 1
|
|
services:
|
|
rabbit_test:
|
|
image: rabbitmq:3.7.19
|
|
env:
|
|
RABBITMQ_DEFAULT_USER: rabbitmq
|
|
RABBITMQ_DEFAULT_PASS: rabbitmq
|
|
postgresql_test:
|
|
image: postgres:14.4
|
|
env:
|
|
POSTGRES_DB: oncall_local_dev
|
|
POSTGRES_PASSWORD: local_dev_pwd
|
|
# Set health checks to wait until postgres has started
|
|
options: >-
|
|
--health-cmd pg_isready
|
|
--health-interval 10s
|
|
--health-timeout 5s
|
|
--health-retries 5
|
|
steps:
|
|
- uses: actions/checkout@v2
|
|
- name: Unit Test Backend
|
|
run: |
|
|
cd engine/
|
|
pip install -r requirements.txt
|
|
ONCALL_TESTING_RBAC_ENABLED=${{ matrix.rbac_enabled }} pytest -x
|
|
|
|
unit-test-backend-sqlite-redis:
|
|
name: "Backend Tests: SQLite + Redis (RBAC enabled: ${{ matrix.rbac_enabled }})"
|
|
runs-on: ubuntu-latest
|
|
container: python:3.9
|
|
strategy:
|
|
matrix:
|
|
rbac_enabled: ["True", "False"]
|
|
env:
|
|
DATABASE_TYPE: sqlite3
|
|
BROKER_TYPE: redis
|
|
REDIS_URI: redis://redis_test:6379
|
|
DJANGO_SETTINGS_MODULE: settings.ci-test
|
|
SLACK_CLIENT_OAUTH_ID: 1
|
|
services:
|
|
redis_test:
|
|
image: redis:7.0.5
|
|
options: >-
|
|
--health-cmd "redis-cli ping"
|
|
--health-interval 10s
|
|
--health-timeout 5s
|
|
--health-retries 5
|
|
steps:
|
|
- uses: actions/checkout@v2
|
|
- name: Unit Test Backend
|
|
run: |
|
|
apt-get update && apt-get install -y netcat
|
|
cd engine/
|
|
pip install -r requirements.txt
|
|
ONCALL_TESTING_RBAC_ENABLED=${{ matrix.rbac_enabled }} pytest -x
|
|
|
|
docker-build:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v2
|
|
- name: Test docker build (no push)
|
|
id: docker_build
|
|
uses: docker/build-push-action@v2
|
|
with:
|
|
context: ./engine
|
|
file: ./engine/Dockerfile
|
|
push: false
|
|
target: prod
|
|
- name: Image digest
|
|
run: echo ${{ steps.docker_build.outputs.digest }}
|