Skip to content

Commit b267b23

Browse files
authored
Merge branch 'master' into dependabot/pip/pip-21.1
2 parents 96f3aff + 67baa6b commit b267b23

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1704
-1985
lines changed

.github/workflows/codeql.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches: [ "master" ]
17+
pull_request:
18+
# The branches below must be a subset of the branches above
19+
branches: [ "master" ]
20+
schedule:
21+
- cron: '39 14 * * 1'
22+
23+
jobs:
24+
analyze:
25+
name: Analyze
26+
runs-on: ubuntu-latest
27+
permissions:
28+
actions: read
29+
contents: read
30+
security-events: write
31+
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
language: [ 'python' ]
36+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37+
# Use only 'java' to analyze code written in Java, Kotlin or both
38+
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
39+
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
40+
41+
steps:
42+
- name: Checkout repository
43+
uses: actions/checkout@v3
44+
45+
# Initializes the CodeQL tools for scanning.
46+
- name: Initialize CodeQL
47+
uses: github/codeql-action/init@v2
48+
with:
49+
languages: ${{ matrix.language }}
50+
# If you wish to specify custom queries, you can do so here or in a config file.
51+
# By default, queries listed here will override any specified in a config file.
52+
# Prefix the list here with "+" to use these queries and those in the config file.
53+
54+
# 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
55+
# queries: security-extended,security-and-quality
56+
57+
58+
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
59+
# If this step fails, then you should remove it and run the build manually (see below)
60+
- name: Autobuild
61+
uses: github/codeql-action/autobuild@v2
62+
63+
# ℹ️ Command-line programs to run using the OS shell.
64+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
65+
66+
# If the Autobuild fails above, remove it and uncomment the following three lines.
67+
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
68+
69+
# - run: |
70+
# echo "Run, Build Application using script"
71+
# ./location_of_script_within_repo/buildscript.sh
72+
73+
- name: Perform CodeQL Analysis
74+
uses: github/codeql-action/analyze@v2
75+
with:
76+
category: "/language:${{matrix.language}}"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Dependency Review Action
2+
#
3+
# This Action will scan dependency manifest files that change as part of a Pull Request, surfacing known-vulnerable versions of the packages declared or updated in the PR. Once installed, if the workflow run is marked as required, PRs introducing known-vulnerable packages will be blocked from merging.
4+
#
5+
# Source repository: https://github.com/actions/dependency-review-action
6+
# Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement
7+
name: 'Dependency Review'
8+
on: [pull_request]
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
dependency-review:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: 'Checkout Repository'
18+
uses: actions/checkout@v3
19+
- name: 'Dependency Review'
20+
uses: actions/dependency-review-action@v2

.github/workflows/pull_request.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ jobs:
33
pre-commit:
44
runs-on: ubuntu-18.04
55
steps:
6-
- name: Checkout
7-
uses: actions/checkout@v1
8-
- name: Setup python 3.6
9-
uses: actions/setup-python@v1
6+
- name: Checkout repository
7+
uses: actions/checkout@v3
8+
- name: Setup python 3.8
9+
uses: actions/setup-python@v4
1010
with:
11-
python-version: 3.6
11+
python-version: 3.8
1212
- name: Install pre-commit
1313
run: pip install pre-commit
1414
- name: Run pre-commit
1515
run: pre-commit run --all-files
1616
license-check:
1717
runs-on: ubuntu-18.04
1818
steps:
19-
- name: Checkout
20-
uses: actions/checkout@v1
19+
- name: Checkout repository
20+
uses: actions/checkout@v3
2121
- name: Setup Ruby 2.x
2222
uses: actions/setup-ruby@v1
2323
with:
@@ -26,10 +26,10 @@ jobs:
2626
run: gem install license_finder
2727
- name: Allow gevent Zope license
2828
run: license_finder permitted_licenses add "Zope Public License"
29-
- name: Setup python 3.6
30-
uses: actions/setup-python@v1
29+
- name: Setup python 3.8
30+
uses: actions/setup-python@v4
3131
with:
32-
python-version: 3.6
32+
python-version: 3.8
3333
- name: Install apt dependencies
3434
run: sudo apt-get update -y && sudo apt-get install -y python3-dev openssl libssl-dev gcc pkg-config libffi-dev libxml2-dev libxmlsec1-dev
3535
- name: Install dependencies
@@ -39,12 +39,12 @@ jobs:
3939
test:
4040
runs-on: ubuntu-18.04
4141
steps:
42-
- name: Checkout
43-
uses: actions/checkout@v1
44-
- name: Setup python 3.6
45-
uses: actions/setup-python@v1
42+
- name: Checkout repository
43+
uses: actions/checkout@v3
44+
- name: Setup python 3.8
45+
uses: actions/setup-python@v4
4646
with:
47-
python-version: 3.6
47+
python-version: 3.8
4848
- name: Install apt dependencies
4949
run: sudo apt-get update -y && sudo apt-get install -y python3-dev openssl libssl-dev gcc pkg-config libffi-dev libxml2-dev libxmlsec1-dev
5050
- name: Install dependencies

.github/workflows/push.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ jobs:
1010
name: Build and publish docs
1111
runs-on: ubuntu-18.04
1212
steps:
13-
- name: Checkout
14-
uses: actions/checkout@v1
15-
- name: Setup python 3.6
16-
uses: actions/setup-python@v1
13+
- name: Checkout repository
14+
uses: actions/checkout@v3
15+
- name: Setup python 3.8
16+
uses: actions/setup-python@v4
1717
with:
18-
python-version: 3.6
18+
python-version: 3.8
1919
- name: Install virtualenv
2020
run: pip install virtualenv
2121
- name: Build docs
@@ -33,12 +33,12 @@ jobs:
3333
name: Build and publish python module to pypi
3434
runs-on: ubuntu-18.04
3535
steps:
36-
- name: Checkout
37-
uses: actions/checkout@v1
38-
- name: Setup python 3.6
39-
uses: actions/setup-python@v1
36+
- name: Checkout repository
37+
uses: actions/checkout@v3
38+
- name: Setup python 3.8
39+
uses: actions/setup-python@v4
4040
with:
41-
python-version: 3.6
41+
python-version: 3.8
4242
- name: Add wheel dependency
4343
run: pip install wheel
4444
- name: Generate dist
@@ -53,8 +53,8 @@ jobs:
5353
name: Build and publish docker image
5454
runs-on: ubuntu-18.04
5555
steps:
56-
- name: Checkout
57-
uses: actions/checkout@v1
56+
- name: Checkout repository
57+
uses: actions/checkout@v3
5858
- name: Publish to Registry
5959
uses: elgohr/[email protected]
6060
with:

.pre-commit-config.yaml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
11
exclude: '^docs/.*$'
2+
default_language_version:
3+
python: python3.8
24
repos:
35
- repo: https://github.com/pre-commit/pre-commit-hooks
4-
rev: v2.1.0
6+
rev: v4.4.0
7+
hooks:
8+
- id: check-docstring-first
9+
- id: check-executables-have-shebangs
10+
- id: check-json
11+
- id: check-merge-conflict
12+
- id: check-yaml
13+
- id: debug-statements
14+
- id: end-of-file-fixer
15+
- id: trailing-whitespace
16+
- repo: https://github.com/psf/black
17+
rev: 23.1.0
18+
hooks:
19+
- id: black
20+
- repo: https://github.com/pycqa/flake8
21+
rev: 5.0.4
522
hooks:
623
- id: flake8
724
additional_dependencies:
8-
- flake8==3.3.0
9-
- flake8-tidy-imports==1.0.6
25+
- flake8-bugbear==22.10.27
26+
- flake8-builtins==2.0.1
27+
- flake8-comprehensions==3.10.1
28+
- flake8-tidy-imports==4.8.0
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
22
"payload": "{\"type\":\"view_submission\",\"token\":\"ABCDEFGHIJKLMNOPQRSTUVWX\",\"team\":{\"id\":\"TEST_TEAM_ID\",\"domain\":\"test-team-name\"},\"user\":{\"id\":\"TEST_USER_ID\",\"name\":\"testusername\"},\"view\":{\"id\":\"VNHU13V36\",\"type\":\"modal\",\"title\":{ \"a\":\"b\" },\"submit\":{ \"a\":\"b\" },\"blocks\":[],\"private_metadata\":\"shhh-its-secret\",\"callback_id\":\"modal-with-inputs\",\"state\":{\"values\":{\"multiline\":{\"mlvalue\":{\"type\":\"plain_text_input\",\"value\":\"This is my example inputted value\"}},\"target_channel\":{\"target_select\":{\"type\":\"conversations_select\",\"selected_conversation\":\"C123B12DE\"}}}},\"hash\":\"156663117.cd33ad1f\",\"response_urls\":[{\"block_id\":\"target_channel\",\"action_id\":\"target_select\",\"channel_id\":\"C123B12DE\",\"response_url\":\"https:\\/\\/hooks.slack.com\\/app\\/ABC12312\\/1234567890\\/A100B100C100d100\"}]}}"
3-
}
3+
}

omnibot/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from os import getenv
22
import importlib
33

4-
logging = importlib.import_module(getenv('LOG_MODULE', 'logging'))
4+
logging = importlib.import_module(getenv("LOG_MODULE", "logging"))

omnibot/authnz/__init__.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
import re
1515
from functools import wraps
1616

17-
from flask import (
18-
abort,
19-
request
20-
)
17+
from flask import abort, request
2118

2219
from omnibot import logging
2320
from omnibot import settings
@@ -42,24 +39,26 @@ def enforce_checks(f):
4239
Checks will be executed in the order defined by the list. All checks must
4340
pass for a request to be accepted.
4441
"""
42+
4543
@wraps(f)
4644
def decorated(*args, **kwargs):
47-
checks = settings.AUTHORIZATION.get('checks', [])
45+
checks = settings.AUTHORIZATION.get("checks", [])
4846
if not checks:
4947
logger.warning(
50-
'No checks set in the authorization section of the configuration;'
51-
' denying access to API calls for sanity sake'
48+
"No checks set in the authorization section of the configuration;"
49+
" denying access to API calls for sanity sake"
5250
)
5351
return abort(403)
5452
for check in checks:
55-
module_name, function_name = check['module'].split(':')
53+
module_name, function_name = check["module"].split(":")
5654
module = importlib.import_module(module_name)
5755
function = getattr(module, function_name)
58-
func_kwargs = check.get('kwargs', {})
56+
func_kwargs = check.get("kwargs", {})
5957
response = function(**func_kwargs)
6058
if not response:
6159
return abort(403)
6260
return f(*args, **kwargs)
61+
6362
return decorated
6463

6564

omnibot/authnz/envoy_checks.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def _match_subject(subject_to_match, subject):
2323
return False
2424

2525

26-
def envoy_internal_check(header='x-envoy-internal'):
26+
def envoy_internal_check(header="x-envoy-internal"):
2727
"""
2828
Perform a check to ensure that the ``x-envoy-internal`` is set to 'true'.
2929
By default this check will apply to all routes, if enabled. It's possible
@@ -45,44 +45,44 @@ def envoy_internal_check(header='x-envoy-internal'):
4545
"""
4646
# Flask provides all headers as strings. The only acceptable string here
4747
# is 'true'
48-
envoy_internal = request.headers.get(header) == 'true'
48+
envoy_internal = request.headers.get(header) == "true"
4949
# Easy case. The header says the request is internal.
5050
if envoy_internal:
5151
return True
5252
# If the request isn't internal, let's see if we have a permission that
5353
# matches, which has internal_only set to False
54-
permissions = settings.AUTHORIZATION.get('permissions', {})
54+
permissions = settings.AUTHORIZATION.get("permissions", {})
5555
for policy_name, policy in permissions.items():
56-
method_match = request.method in policy['methods']
57-
path_match = _match_path(request.path, policy['paths'])
58-
internal_only = policy.get('internal_only', True)
56+
method_match = request.method in policy["methods"]
57+
path_match = _match_path(request.path, policy["paths"])
58+
internal_only = policy.get("internal_only", True)
5959
if (method_match and path_match) and not internal_only:
6060
return True
6161
logger.warning(
62-
'Received an external request to internal endpoint',
62+
"Received an external request to internal endpoint",
6363
extra={
64-
'endpoint': request.path,
65-
'method': request.method,
66-
'header_value': envoy_internal,
64+
"endpoint": request.path,
65+
"method": request.method,
66+
"header_value": envoy_internal,
6767
},
6868
)
6969
return False
7070

7171

7272
def _check_permission(permission):
73-
permissions = settings.AUTHORIZATION.get('permissions', {})
73+
permissions = settings.AUTHORIZATION.get("permissions", {})
7474
policy = permissions.get(permission, {})
7575
# TODO: envoy RBAC spec allows for matching methods and paths as
7676
# individual checks. So for instance, a permission may allow for all GETs
7777
# without a particular path, or may allow all methods on particular paths.
78-
method_match = request.method in policy.get('methods', [])
79-
path_match = _match_path(request.path, policy.get('paths', []))
78+
method_match = request.method in policy.get("methods", [])
79+
path_match = _match_path(request.path, policy.get("paths", []))
8080
if method_match and path_match:
8181
return True
8282
return False
8383

8484

85-
def envoy_permissions_check(header='x-envoy-downstream-service-cluster'):
85+
def envoy_permissions_check(header="x-envoy-downstream-service-cluster"):
8686
"""
8787
Perform a check against the defined permissions and bindings in the
8888
authorization configuration to ensure the service defined in the
@@ -122,17 +122,17 @@ def envoy_permissions_check(header='x-envoy-downstream-service-cluster'):
122122
envoy_identity = request.headers.get(header)
123123
if envoy_identity is None:
124124
return False
125-
bindings = settings.AUTHORIZATION.get('bindings', {})
125+
bindings = settings.AUTHORIZATION.get("bindings", {})
126126
for subject, permissions in bindings.items():
127127
if _match_subject(envoy_identity, subject):
128128
for permission in permissions:
129129
if _check_permission(permission):
130130
return True
131131
logger.warning(
132-
'Received an unauthorized request',
132+
"Received an unauthorized request",
133133
extra={
134-
'from': envoy_identity,
135-
'endpoint': request.path,
134+
"from": envoy_identity,
135+
"endpoint": request.path,
136136
},
137137
)
138138
return False

0 commit comments

Comments
 (0)