-
Notifications
You must be signed in to change notification settings - Fork 35
check network access for Request an Account page #1476
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
base: master
Are you sure you want to change the base?
Changes from all commits
d80d20d
694e316
9ca0473
f06cd6e
aeebed5
4475262
c4cb580
b4dd40b
965139d
4c59e6b
b5ce516
9fa35bc
1861b5e
12fd7af
f4f12c2
17073ce
5534a1e
a5c7093
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| check network access for account creation |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| check network access for login page |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,8 @@ | |
| ObjectNotFound, | ||
| _, | ||
| get_validator, | ||
| request | ||
| request, | ||
| abort, | ||
| ) | ||
|
|
||
| from ckanext.canada import validators | ||
|
|
@@ -68,6 +69,7 @@ class CanadaSecurityPlugin(CkanSecurityPlugin): | |
| p.implements(p.IResourceController, inherit=True) | ||
| p.implements(p.IValidators, inherit=True) | ||
| p.implements(p.IConfigurer) | ||
| p.implements(p.IAuthenticator, inherit=True) | ||
|
|
||
| def update_config(self, config): | ||
| # Disable auth settings | ||
|
|
@@ -102,6 +104,22 @@ def get_validators(self): | |
| 'canada_security_upload_presence': | ||
| validators.canada_security_upload_presence} | ||
|
|
||
| # IAuthenticator | ||
| def identify(self): | ||
| controller, action = p.toolkit.get_endpoint() | ||
| blueprint = '.'.join((controller, action)) | ||
| restricted_blueprints = [ | ||
| 'canada.login', | ||
| 'user.login', | ||
| 'user.request_reset', | ||
| 'canada.recover_username', | ||
| 'canada.register', | ||
| 'canada.action', | ||
| 'api.action', # change if need to narrow down the scope | ||
| ] | ||
| if blueprint in restricted_blueprints and not helpers.registry_network_access(): | ||
| return abort(403) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might want to log failed access attempts so we can report on them
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea. Do you think we need a separate log handler for "Registry Access"? As we will need to also log failed login attempts and all login sessions. We could have a new log handler for Or should we just keep it in the normal logs and have Log Analytics handle all this stuff @wardi ?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @JVickery-TBS I don't have a strong opinion either way. As long as the data can be pulled out of Log Analytics it shouldn't matter.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @wardi and @JVickery-TBS let's implement logging as a separate feature for both registry network access and login access. It is one of the requirements given to us by imtd/security. I would prefer to implement it as a separate log handler so that it is easier for us to investigate any issues reported by helpdesk. |
||
|
|
||
|
|
||
| class CanadaDatasetsPlugin(SchemingDatasetsPlugin): | ||
| """ | ||
|
|
@@ -392,6 +410,7 @@ def get_helpers(self): | |
| 'canada_check_access', | ||
| 'get_user_email', | ||
| 'get_loader_status_badge', | ||
| 'registry_network_access', | ||
| ]) | ||
|
|
||
| # IConfigurable | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,37 @@ | ||
| import os | ||
| import pytest | ||
| from io import StringIO | ||
| from ckan.lib import uploader | ||
| from pyfakefs import fake_filesystem | ||
|
|
||
| real_open = open | ||
| real_isfile = os.path.isfile | ||
| MOCK_IP_ADDRESS = u'174.116.80.148' | ||
| MOCK_IP_LIST_FILE = u'test_ip_list' | ||
| _fs = fake_filesystem.FakeFilesystem() | ||
| _mock_file_open = fake_filesystem.FakeFileOpen(_fs) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_uploads(ckan_config, monkeypatch, tmp_path): | ||
| monkeypatch.setitem(ckan_config, "ckan.storage_path", str(tmp_path)) | ||
| monkeypatch.setattr(uploader, "_storage_path", str(tmp_path)) | ||
|
|
||
|
|
||
| def _mock_open(*args, **kwargs): | ||
| try: | ||
| return real_open(*args, **kwargs) | ||
| except (OSError, IOError): | ||
| return _mock_file_open(*args, **kwargs) | ||
|
|
||
|
|
||
| def mock_isfile(filename): | ||
| if MOCK_IP_LIST_FILE in filename: | ||
| return True | ||
| return real_isfile(filename) | ||
|
|
||
|
|
||
| def mock_open_ip_list(*args, **kwargs): | ||
| if args and MOCK_IP_LIST_FILE in args[0]: | ||
| return StringIO(MOCK_IP_ADDRESS) | ||
| return _mock_open(*args, **kwargs) |
Uh oh!
There was an error while loading. Please reload this page.