Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
bba2796
warehouse: begin using security policies
woodruffw Apr 20, 2022
7bc9904
Merge remote-tracking branch 'origin/main' into tob-pyramid-2-securit…
woodruffw Apr 20, 2022
03ffbc3
Remove pyramid-multiauth, begin switching to security policies
woodruffw Apr 20, 2022
6beb4dd
migrations: remove incorrectly checked in migrations
woodruffw Apr 20, 2022
4efbccf
warehouse: fix principals a little bit
woodruffw Apr 20, 2022
9da307d
warehouse: begin using real security policies
woodruffw Apr 20, 2022
00afa6e
warehouse: port basic auth
woodruffw Apr 20, 2022
a211e35
warehouse: port macaroon policy, remove transition shim
woodruffw Apr 20, 2022
1be99d8
utils/security_policy: fix principals
woodruffw Apr 20, 2022
936b633
warehouse: fix lint
woodruffw Apr 20, 2022
8f95b0e
tests/unit: rename-o-rama
woodruffw Apr 20, 2022
090ef01
Improve the readabililty of the overall diff
di Apr 21, 2022
0b788d9
warehouse: refactor security policies
woodruffw Apr 21, 2022
0bc2083
macaroons/security_policy: remove redundant route check
woodruffw Apr 21, 2022
8f858e3
Merge remote-tracking branch 'upstream/main' into tob-pyramid-2-secur…
woodruffw Apr 21, 2022
231a46d
accounts/security_policy: lint
woodruffw Apr 21, 2022
e2242ec
Update warehouse/utils/security_policy.py
woodruffw Apr 25, 2022
5cdb53a
macaroons/security_policy: avoid a DB roundtrip
woodruffw Apr 25, 2022
593d199
utils/security_policy: simplify principals, add comment
woodruffw Apr 25, 2022
44d1463
utils/security_policy: re-add id principal
woodruffw Apr 25, 2022
3e0c525
warehouse: disambiguate user IDs inside the principal set
woodruffw Apr 25, 2022
366b5e3
Merge remote-tracking branch 'upstream/main' into tob-pyramid-2-secur…
woodruffw Apr 25, 2022
6be5ae7
Merge remote-tracking branch 'upstream/main' into tob-pyramid-2-secur…
woodruffw Apr 25, 2022
840c301
packaging/models: blacken
woodruffw Apr 25, 2022
52c3120
tests, warehouse: the long and winding road
woodruffw Apr 25, 2022
9c7f8cd
tests/packaging: fix ACL tests
woodruffw Apr 26, 2022
f4f608b
tests, warehouse: rewrite account security policy tests
woodruffw Apr 26, 2022
5db0a10
macaroons: make the tests pass
woodruffw Apr 26, 2022
ab12fd3
tests: finish tests
woodruffw Apr 26, 2022
29b40f9
warehouse: move session invalidation to session authn
woodruffw Apr 26, 2022
f2ee9e9
tests, warehouse: update tests
woodruffw Apr 26, 2022
250a2a7
Merge remote-tracking branch 'upstream/main' into tob-pyramid-2-secur…
woodruffw Apr 26, 2022
42f7beb
Merge remote-tracking branch 'upstream/main' into tob-pyramid-2-secur…
woodruffw Apr 28, 2022
222b293
Merge remote-tracking branch 'upstream/main' into tob-pyramid-2-secur…
woodruffw Apr 28, 2022
ec2c563
utils/security_policy: authenticated_userid only works for user ident…
woodruffw Apr 28, 2022
8cb31c8
tests: update utils/security_policy tests
woodruffw Apr 28, 2022
6e6d039
Merge branch 'main' into tob-pyramid-2-security-policies
di May 2, 2022
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
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ module = [
"pyramid.*", # https://github.com/Pylons/pyramid/issues/2638
"pyramid_jinja2.*",
"pyramid_mailer.*",
"pyramid_multiauth.*",
"pyramid_retry.*",
"pyramid_rpc.*",
"pyqrcode.*",
Expand Down
1 change: 0 additions & 1 deletion requirements/main.in
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ pycurl
pyqrcode
pyramid>=2.0
pymacaroons
pyramid-multiauth
pyramid_jinja2>=2.5
pyramid_mailer>=0.14.1
pyramid_retry>=0.3
Expand Down
5 changes: 0 additions & 5 deletions requirements/main.txt
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,6 @@ pyramid==2.0 \
# -r requirements/main.in
# pyramid-jinja2
# pyramid-mailer
# pyramid-multiauth
# pyramid-retry
# pyramid-rpc
# pyramid-services
Expand All @@ -1000,10 +999,6 @@ pyramid-mailer==0.15.1 \
--hash=sha256:28d4a7829ebc19dd40e712d8cb1998cec03c296ba675b2c112a503539738bdc1 \
--hash=sha256:ec0aff54d9179b2aa2922ff82c2016a4dc8d1da5dc3408d6594f0e2096446f9b
# via -r requirements/main.in
pyramid-multiauth==1.0.1 \
--hash=sha256:6d8785558e1d0bbe0d0da43e296efc0fbe0de5071d1f9b1091e891f0e4ec9682 \
--hash=sha256:c265258af8021094e5b98602e8bfe094eec1350eebb56473f36cd0e076910822
# via -r requirements/main.in
pyramid-retry==2.1.1 \
--hash=sha256:b5129a60eb9d7409234ea52839006426d2ae887b4a1f0530c75ec336cabf2476 \
--hash=sha256:baa8276ae68babad09e5f2f94efc4f7421f3b8fb526151df522052f8cd3ec0c9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from pyramid.security import Allowed, Denied
from zope.interface.verify import verifyClass

from warehouse.accounts import auth_policy
from warehouse.accounts import security_policy
from warehouse.accounts.interfaces import IUserService
from warehouse.errors import WarehouseDenied

Expand All @@ -30,7 +30,7 @@
class TestBasicAuthAuthenticationPolicy:
def test_verify(self):
assert verifyClass(
IAuthenticationPolicy, auth_policy.BasicAuthAuthenticationPolicy
IAuthenticationPolicy, security_policy.BasicAuthAuthenticationPolicy
)

def test_unauthenticated_userid_no_userid(self, monkeypatch):
Expand All @@ -41,11 +41,11 @@ def test_unauthenticated_userid_no_userid(self, monkeypatch):
extract_http_basic_credentials,
)

policy = auth_policy.BasicAuthAuthenticationPolicy(check=pretend.stub())
policy = security_policy.BasicAuthAuthenticationPolicy(check=pretend.stub())

vary_cb = pretend.stub()
add_vary_cb = pretend.call_recorder(lambda *v: vary_cb)
monkeypatch.setattr(auth_policy, "add_vary_callback", add_vary_cb)
monkeypatch.setattr(security_policy, "add_vary_callback", add_vary_cb)

request = pretend.stub(
add_response_callback=pretend.call_recorder(lambda cb: None)
Expand All @@ -66,11 +66,11 @@ def test_unauthenticated_userid_with_userid(self, monkeypatch):
extract_http_basic_credentials,
)

policy = auth_policy.BasicAuthAuthenticationPolicy(check=pretend.stub())
policy = security_policy.BasicAuthAuthenticationPolicy(check=pretend.stub())

vary_cb = pretend.stub()
add_vary_cb = pretend.call_recorder(lambda *v: vary_cb)
monkeypatch.setattr(auth_policy, "add_vary_callback", add_vary_cb)
monkeypatch.setattr(security_policy, "add_vary_callback", add_vary_cb)

userid = uuid.uuid4()
service = pretend.stub(
Expand All @@ -92,15 +92,15 @@ def test_unauthenticated_userid_with_userid(self, monkeypatch):
class TestSessionAuthenticationPolicy:
def test_verify(self):
assert verifyClass(
IAuthenticationPolicy, auth_policy.SessionAuthenticationPolicy
IAuthenticationPolicy, security_policy.SessionAuthenticationPolicy
)

def test_unauthenticated_userid(self, monkeypatch):
policy = auth_policy.SessionAuthenticationPolicy()
policy = security_policy.SessionAuthenticationPolicy()

vary_cb = pretend.stub()
add_vary_cb = pretend.call_recorder(lambda *v: vary_cb)
monkeypatch.setattr(auth_policy, "add_vary_callback", add_vary_cb)
monkeypatch.setattr(security_policy, "add_vary_callback", add_vary_cb)

userid = pretend.stub()
request = pretend.stub(
Expand All @@ -116,17 +116,17 @@ def test_unauthenticated_userid(self, monkeypatch):
class TestTwoFactorAuthorizationPolicy:
def test_verify(self):
assert verifyClass(
IAuthorizationPolicy, auth_policy.TwoFactorAuthorizationPolicy
IAuthorizationPolicy, security_policy.TwoFactorAuthorizationPolicy
)

def test_permits_no_active_request(self, monkeypatch):
get_current_request = pretend.call_recorder(lambda: None)
monkeypatch.setattr(auth_policy, "get_current_request", get_current_request)
monkeypatch.setattr(security_policy, "get_current_request", get_current_request)

backing_policy = pretend.stub(
permits=pretend.call_recorder(lambda *a, **kw: pretend.stub())
)
policy = auth_policy.TwoFactorAuthorizationPolicy(policy=backing_policy)
policy = security_policy.TwoFactorAuthorizationPolicy(policy=backing_policy)
result = policy.permits(pretend.stub(), pretend.stub(), pretend.stub())

assert result == WarehouseDenied("")
Expand All @@ -135,27 +135,27 @@ def test_permits_no_active_request(self, monkeypatch):
def test_permits_if_context_is_not_permitted_by_backing_policy(self, monkeypatch):
request = pretend.stub()
get_current_request = pretend.call_recorder(lambda: request)
monkeypatch.setattr(auth_policy, "get_current_request", get_current_request)
monkeypatch.setattr(security_policy, "get_current_request", get_current_request)

permits_result = Denied("Because")
backing_policy = pretend.stub(
permits=pretend.call_recorder(lambda *a, **kw: permits_result)
)
policy = auth_policy.TwoFactorAuthorizationPolicy(policy=backing_policy)
policy = security_policy.TwoFactorAuthorizationPolicy(policy=backing_policy)
result = policy.permits(pretend.stub(), pretend.stub(), pretend.stub())

assert result == permits_result

def test_permits_if_non_2fa_requireable_context(self, monkeypatch):
request = pretend.stub()
get_current_request = pretend.call_recorder(lambda: request)
monkeypatch.setattr(auth_policy, "get_current_request", get_current_request)
monkeypatch.setattr(security_policy, "get_current_request", get_current_request)

permits_result = Allowed("Because")
backing_policy = pretend.stub(
permits=pretend.call_recorder(lambda *a, **kw: permits_result)
)
policy = auth_policy.TwoFactorAuthorizationPolicy(policy=backing_policy)
policy = security_policy.TwoFactorAuthorizationPolicy(policy=backing_policy)
result = policy.permits(pretend.stub(), pretend.stub(), pretend.stub())

assert result == permits_result
Expand All @@ -167,13 +167,13 @@ def test_permits_if_context_does_not_require_2fa(self, monkeypatch, db_request):
"warehouse.two_factor_requirement.enabled": True,
}
get_current_request = pretend.call_recorder(lambda: db_request)
monkeypatch.setattr(auth_policy, "get_current_request", get_current_request)
monkeypatch.setattr(security_policy, "get_current_request", get_current_request)

permits_result = Allowed("Because")
backing_policy = pretend.stub(
permits=pretend.call_recorder(lambda *a, **kw: permits_result)
)
policy = auth_policy.TwoFactorAuthorizationPolicy(policy=backing_policy)
policy = security_policy.TwoFactorAuthorizationPolicy(policy=backing_policy)
context = ProjectFactory.create(
owners_require_2fa=False,
pypi_mandates_2fa=False,
Expand All @@ -193,13 +193,13 @@ def test_flashes_if_context_requires_2fa_but_not_enabled(
db_request.session.flash = pretend.call_recorder(lambda m, queue: None)
db_request.user = pretend.stub(has_two_factor=False)
get_current_request = pretend.call_recorder(lambda: db_request)
monkeypatch.setattr(auth_policy, "get_current_request", get_current_request)
monkeypatch.setattr(security_policy, "get_current_request", get_current_request)

permits_result = Allowed("Because")
backing_policy = pretend.stub(
permits=pretend.call_recorder(lambda *a, **kw: permits_result)
)
policy = auth_policy.TwoFactorAuthorizationPolicy(policy=backing_policy)
policy = security_policy.TwoFactorAuthorizationPolicy(policy=backing_policy)
context = ProjectFactory.create(
owners_require_2fa=False,
pypi_mandates_2fa=True,
Expand Down Expand Up @@ -239,13 +239,13 @@ def test_permits_if_user_has_2fa(
user = pretend.stub(has_two_factor=True)
db_request.user = user
get_current_request = pretend.call_recorder(lambda: db_request)
monkeypatch.setattr(auth_policy, "get_current_request", get_current_request)
monkeypatch.setattr(security_policy, "get_current_request", get_current_request)

permits_result = Allowed("Because")
backing_policy = pretend.stub(
permits=pretend.call_recorder(lambda *a, **kw: permits_result)
)
policy = auth_policy.TwoFactorAuthorizationPolicy(policy=backing_policy)
policy = security_policy.TwoFactorAuthorizationPolicy(policy=backing_policy)
context = ProjectFactory.create(
owners_require_2fa=owners_require_2fa, pypi_mandates_2fa=pypi_mandates_2fa
)
Expand Down Expand Up @@ -276,13 +276,13 @@ def test_denies_if_2fa_is_required_but_user_doesnt_have_2fa(
user = pretend.stub(has_two_factor=False)
db_request.user = user
get_current_request = pretend.call_recorder(lambda: db_request)
monkeypatch.setattr(auth_policy, "get_current_request", get_current_request)
monkeypatch.setattr(security_policy, "get_current_request", get_current_request)

permits_result = Allowed("Because")
backing_policy = pretend.stub(
permits=pretend.call_recorder(lambda *a, **kw: permits_result)
)
policy = auth_policy.TwoFactorAuthorizationPolicy(policy=backing_policy)
policy = security_policy.TwoFactorAuthorizationPolicy(policy=backing_policy)
context = ProjectFactory.create(
owners_require_2fa=owners_require_2fa, pypi_mandates_2fa=pypi_mandates_2fa
)
Expand All @@ -308,7 +308,7 @@ def test_principals_allowed_by_permission(self):
lambda *a: principals
)
)
policy = auth_policy.TwoFactorAuthorizationPolicy(policy=backing_policy)
policy = security_policy.TwoFactorAuthorizationPolicy(policy=backing_policy)

assert (
policy.principals_allowed_by_permission(pretend.stub(), pretend.stub())
Expand Down
Loading