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

Models, routes and views for creating OIDC publishers #10753

Merged
merged 93 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
48ab12e
warehouse/oidc: rough model skeleton
woodruffw Feb 14, 2022
7db2c2c
warehouse/oidc: fix imports
woodruffw Feb 14, 2022
eab5e70
warehouse/migrations: add migration for OIDC models
woodruffw Feb 14, 2022
09d0966
warehouse/migrations: reformat
woodruffw Feb 14, 2022
24b9eab
warehouse/oidc: add basic verification logic
woodruffw Feb 14, 2022
c56476f
oidc/services: reduce clock skew leeway to 30s
woodruffw Feb 14, 2022
41a1ca0
warehouse/oidc: refactor claim verification
woodruffw Feb 15, 2022
63d16a2
oidc/models: fill in missing properties
woodruffw Feb 15, 2022
50549ec
warehouse/migrations: remove original OIDC migration
woodruffw Feb 15, 2022
f1d7162
warehouse: add OIDC migration, fix association
woodruffw Feb 15, 2022
5479c81
warehouse: reformat
woodruffw Feb 15, 2022
1e0f26c
warehouse: OIDC route/view skeleton work
woodruffw Feb 16, 2022
bf5859b
warehouse: form, view logic for adding OIDC providers
woodruffw Feb 17, 2022
a62a917
manage/views: disable HTTP cache, add TODO
woodruffw Feb 17, 2022
ed1559c
warehouse: move oidc views to "publishing"
woodruffw Feb 18, 2022
971ccf2
warehouse: provider deletion routing
woodruffw Feb 18, 2022
4aad8ee
warehouse: shore up constraints, better error flashes
woodruffw Feb 18, 2022
ac48e82
Merge branch 'main' into tob-oidc-db-models
woodruffw Feb 18, 2022
ba1a39d
Merge branch 'main' into tob-oidc-db-models
woodruffw Feb 25, 2022
100120c
warehouse/migrations: rebase revision
woodruffw Feb 25, 2022
1ca025a
warehouse/templates: update OIDC language
woodruffw Feb 25, 2022
d54dd38
warehouse: OIDC rate limiting groundwork
woodruffw Feb 25, 2022
c700c92
manage/views: clean up OIDC events
woodruffw Feb 25, 2022
d215931
warehouse: use GitHub token for API requests, when available
woodruffw Feb 25, 2022
232ae6f
oidc/forms: special casing for rate limiting
woodruffw Feb 25, 2022
62a795f
warehouse: split user/repo form inputs apart
woodruffw Feb 25, 2022
5ed70bc
warehouse/templates: link to GitHub's OIDC docs
woodruffw Feb 25, 2022
2c9722d
oidc/models: remove actor from checked claims
woodruffw Feb 25, 2022
be82d1b
templates/email: add OIDC email templates
woodruffw Feb 28, 2022
6c00487
warehouse: fix templates, add email sending logic
woodruffw Feb 28, 2022
a6aa4a0
warehouse: add an AdminFlag for OIDC control
woodruffw Feb 28, 2022
e259dc8
oidc/models: use set operators
woodruffw Feb 28, 2022
d0b37d2
oidc/forms: exception driven handling for GitHub API errors
woodruffw Feb 28, 2022
1fc826a
warehouse: OIDC ratelimiting logic
woodruffw Mar 2, 2022
ae1f6bb
Merge branch 'main' into tob-oidc-db-models
woodruffw Mar 2, 2022
f307de7
warehouse/locale: update translations
woodruffw Mar 2, 2022
bd568c8
Merge remote-tracking branch 'upstream/main' into tob-oidc-db-models
woodruffw Mar 7, 2022
5bfba05
Merge branch 'main' into tob-oidc-db-models
woodruffw Mar 7, 2022
67fb78c
warehouse: lintage
woodruffw Mar 7, 2022
d249c6b
templates/manage/settings: remove vestigial HTML
woodruffw Mar 9, 2022
07a7119
warehouse: address feedback
woodruffw Mar 9, 2022
788ddfa
manage/views: more feedback addressing
woodruffw Mar 9, 2022
77c30d9
Update warehouse/manage/views.py
woodruffw Mar 9, 2022
7c6a293
manage/views: fixups
woodruffw Mar 9, 2022
b864d94
warehouse: add "OIDC provider removed" emails
woodruffw Mar 9, 2022
f726919
oidc/forms: use GH org regex in callable validator body
woodruffw Mar 9, 2022
901615a
Merge remote-tracking branch 'upstream/main' into tob-oidc-db-models
woodruffw Mar 9, 2022
63caa2a
warehouse/locale: update translations
woodruffw Mar 9, 2022
69ba7db
tests, warehouse: begin writing unit tests
woodruffw Mar 9, 2022
c72357b
More tests, restructure for testing
woodruffw Mar 9, 2022
45e2721
tests: fill in GitHubProviderForm tests
woodruffw Mar 9, 2022
f6fde8d
tests, warehouse: more tests, adaptations for testing
woodruffw Mar 10, 2022
17b2473
tests: more manage/view tests
woodruffw Mar 10, 2022
6d3130b
tests, warehouse: ratelimit tests, fix bug
woodruffw Mar 10, 2022
8bd4d04
tests: round out ratelimiting
woodruffw Mar 10, 2022
e8f1a8d
tests: more tests
woodruffw Mar 10, 2022
d12c66e
Merge remote-tracking branch 'upstream/main' into tob-oidc-db-models
woodruffw Mar 11, 2022
ce65932
tests, warehouse: OIDC deletion tests
woodruffw Mar 11, 2022
792b306
tests, warehouse: fill in model checks
woodruffw Mar 11, 2022
2215f39
oidc/models: type hints
woodruffw Mar 11, 2022
1a21b4f
warehouse/locale: `make translations`
woodruffw Mar 11, 2022
7bb51bb
Merge branch 'main' into tob-oidc-db-models
woodruffw Mar 14, 2022
cc0c21a
tests, warehouse: site-wide OIDC feature flag
woodruffw Mar 14, 2022
3fa705e
warehouse: `make translations`
woodruffw Mar 14, 2022
c2ca980
treewide: route to 404 when OIDC is disabled
woodruffw Mar 17, 2022
9c459d6
Merge remote-tracking branch 'upstream/main' into tob-oidc-db-models
woodruffw Mar 17, 2022
f6b2cf0
warehouse: `make translations`
woodruffw Mar 17, 2022
8912a40
Update warehouse/templates/manage/publishing.html
woodruffw Mar 21, 2022
a9a9175
Merge branch 'main' into tob-oidc-db-models
woodruffw Mar 21, 2022
7482d78
oidc/{interfaces,services}: simplify API
woodruffw Mar 21, 2022
17eae83
tests: update
woodruffw Mar 22, 2022
c94b2b8
warehouse/migrations: rebase
woodruffw Mar 22, 2022
1d4e12b
tests, warehouse: move ratelimit hit up
woodruffw Mar 22, 2022
41f4426
Merge branch 'main' into tob-oidc-db-models
woodruffw Mar 28, 2022
7e380c9
warehouse: `make translations`
woodruffw Mar 28, 2022
5dafd98
warehouse: plug in more OIDC metrics
woodruffw Mar 29, 2022
0ff3f01
warehouse/oidc: add a `verify_for_helper` iface method
woodruffw Mar 29, 2022
c945ee7
manage/views: add provider names to metrics
woodruffw Mar 29, 2022
32cfd38
oidc/services: add project tag to metrics during JWT verification
woodruffw Mar 29, 2022
63bce66
oidc/services: include provider name in metrics too
woodruffw Mar 29, 2022
b677a8d
tests/unit: plumb metrics through OIDC unit tests
woodruffw Mar 30, 2022
f9813ad
tests/unit: fill in coverage
woodruffw Mar 30, 2022
dd95500
warehouse: `make translations`
woodruffw Mar 30, 2022
8df5ccd
Merge branch 'main' into tob-oidc-db-models
woodruffw Mar 31, 2022
c9705fe
Merge branch 'main' into tob-oidc-db-models
woodruffw Apr 1, 2022
04c7261
tests, warehouse: disable `job_workflow_ref`
woodruffw Apr 1, 2022
de52f9f
Merge branch 'main' into tob-oidc-db-models
woodruffw Apr 4, 2022
4609559
Apply suggestions from code review
woodruffw Apr 5, 2022
52c4e15
tests, warehouse: update tests for changes
woodruffw Apr 5, 2022
73eef39
warehouse, tests: email all users on OIDC changes
woodruffw Apr 5, 2022
4651ce8
warehouse, tests: include publisher info in OIDC emails
woodruffw Apr 5, 2022
e090ad3
warehouse: `make translations`
woodruffw Apr 5, 2022
eeb599d
Merge branch 'main' into tob-oidc-db-models
di Apr 5, 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: 1 addition & 0 deletions dev/environment
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ GITHUB_TOKEN_SCANNING_META_API_URL="http://notgithub:8000/meta/public_keys/token
TWOFACTORREQUIREMENT_ENABLED=true
TWOFACTORMANDATE_AVAILABLE=true
TWOFACTORMANDATE_ENABLED=true
OIDC_ENABLED=true
93 changes: 93 additions & 0 deletions tests/unit/email/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -3575,3 +3575,96 @@ def test_recovery_code_emails(
},
)
]


class TestOIDCProviderEmails:
@pytest.mark.parametrize(
"fn, template_name",
[
(email.send_oidc_provider_added_email, "oidc-provider-added"),
(email.send_oidc_provider_removed_email, "oidc-provider-removed"),
],
)
def test_oidc_provider_emails(
self, pyramid_request, pyramid_config, monkeypatch, fn, template_name
):
stub_user = pretend.stub(
id="id",
username="username",
name="",
email="email@example.com",
primary_email=pretend.stub(email="email@example.com", verified=True),
)
subject_renderer = pyramid_config.testing_add_renderer(
f"email/{ template_name }/subject.txt"
)
subject_renderer.string_response = "Email Subject"
body_renderer = pyramid_config.testing_add_renderer(
f"email/{ template_name }/body.txt"
)
body_renderer.string_response = "Email Body"
html_renderer = pyramid_config.testing_add_renderer(
f"email/{ template_name }/body.html"
)
html_renderer.string_response = "Email HTML Body"

send_email = pretend.stub(
delay=pretend.call_recorder(lambda *args, **kwargs: None)
)
pyramid_request.task = pretend.call_recorder(lambda *args, **kwargs: send_email)
monkeypatch.setattr(email, "send_email", send_email)

pyramid_request.db = pretend.stub(
query=lambda a: pretend.stub(
filter=lambda *a: pretend.stub(
one=lambda: pretend.stub(user_id=stub_user.id)
)
),
)
pyramid_request.user = stub_user
pyramid_request.registry.settings = {"mail.sender": "noreply@example.com"}

project_name = "test_project"
fakeprovider = pretend.stub(provider_name="fakeprovider")
# NOTE: Can't set __str__ using pretend.stub()
monkeypatch.setattr(
fakeprovider.__class__, "__str__", lambda s: "fakespecifier"
)

result = fn(
pyramid_request, stub_user, project_name=project_name, provider=fakeprovider
)

assert result == {
"username": stub_user.username,
"project_name": project_name,
"provider_name": "fakeprovider",
"provider_spec": "fakespecifier",
}
subject_renderer.assert_()
body_renderer.assert_(username=stub_user.username, project_name=project_name)
html_renderer.assert_(username=stub_user.username, project_name=project_name)
assert pyramid_request.task.calls == [pretend.call(send_email)]
assert send_email.delay.calls == [
pretend.call(
f"{stub_user.username} <{stub_user.email}>",
{
"subject": "Email Subject",
"body_text": "Email Body",
"body_html": (
"<html>\n<head></head>\n"
"<body><p>Email HTML Body</p></body>\n</html>\n"
),
},
{
"tag": "account:email:sent",
"user_id": stub_user.id,
"additional": {
"from_": "noreply@example.com",
"to": stub_user.email,
"subject": "Email Subject",
"redact_ip": False,
},
},
)
]
26 changes: 25 additions & 1 deletion tests/unit/manage/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,37 @@ def view(context, request):
assert request.session.needs_reauthentication.calls == needs_reauth_calls


def test_includeme():
def test_includeme(monkeypatch):
settings = {
"warehouse.manage.oidc.user_registration_ratelimit_string": "10 per day",
"warehouse.manage.oidc.ip_registration_ratelimit_string": "100 per day",
}

config = pretend.stub(
add_view_deriver=pretend.call_recorder(lambda f, over, under: None),
register_service_factory=pretend.call_recorder(lambda s, i, **kw: None),
registry=pretend.stub(
settings=pretend.stub(get=pretend.call_recorder(lambda k: settings.get(k)))
),
)

rate_limit_class = pretend.call_recorder(lambda s: s)
rate_limit_iface = pretend.stub()
monkeypatch.setattr(manage, "RateLimit", rate_limit_class)
monkeypatch.setattr(manage, "IRateLimiter", rate_limit_iface)

manage.includeme(config)

assert config.add_view_deriver.calls == [
pretend.call(manage.reauth_view, over="rendered_view", under="decorated_view")
]
assert config.register_service_factory.calls == [
pretend.call(
"10 per day", rate_limit_iface, name="user_oidc.provider.register"
),
pretend.call("100 per day", rate_limit_iface, name="ip_oidc.provider.register"),
]
assert config.registry.settings.get.calls == [
pretend.call("warehouse.manage.oidc.user_registration_ratelimit_string"),
pretend.call("warehouse.manage.oidc.ip_registration_ratelimit_string"),
]
Loading