Commit Graph

102 Commits

Author SHA1 Message Date
venusbb
f4d005c7fb initial logging for route protection 2017-11-03 14:43:56 +00:00
venusbb
9ad75ff726 Tests modified 2017-09-27 10:15:29 +01:00
venusbb
6a7013fa7a Enable Inbound sms IP blocking 2017-09-26 10:59:09 +01:00
venusbb
160b878745 Minor change in how we inteprete Incoming IP 2017-09-13 17:23:23 +01:00
venusbb
9efc17a941 Use ipaddress library for the masked bits 2017-09-13 14:08:23 +01:00
venusbb
c285ab0b45 inbound sms monitoring 24bit mask 2017-09-13 11:29:11 +01:00
venusbb
a5cf8ff60f put more log messages to view what env returns 2017-07-12 13:49:20 +01:00
venusbb
5d57189187 changed name of test fixture 2017-07-11 09:50:09 +01:00
venusbb
5089a4d53b retrieve sms ip whitelist from credentials on paas 2017-07-10 17:03:43 +01:00
venusbb
1d8d6b1ef1 Add list of IP address that X-Forwarded-For return to add more visibility to the traffic 2017-07-06 12:31:00 +01:00
venusbb
a307fa6dcd Check ip unit test and modify ways to parse IP address 2017-07-06 12:30:09 +01:00
venusbb
c182ceca90 Check ip unit test and modify ways to parse IP address 2017-07-06 12:30:08 +01:00
Rebecca Law
78242812ef Register a before_request event for all blueprints, that defines the authentication requirement.
There are three authentication methods:
 - requires_no_auth - public endpoint that does not require an Authorisation header
 - requires_auth - public endpoints that need an API key in the Authorisation header
 - requires_admin_auth - private endpoint that requires an Authorisation header which contains the API key for the defined as the client admin user
2017-03-16 18:15:49 +00:00
Rebecca Law
f880604c85 First attempt at securing the endpoints.
Started with adding a before_request event to the service_blueprint, which executes the requires_admin_auth method rather than the require_auth method.

Obviously this is not done but want to get this in front of people to get an opinion.
2017-03-16 10:42:45 +00:00
Chris Hill-Scott
b6b9b3b225 Give a more helpful error when token has expired
We’ve seen quite a few developers encounter the `Invalid token: expired`
error message when they’re getting started using the Notify API. When
this happens they either raise a support ticket or ask for help on
Slack.

In every case this has been because the clock on their
machine/environment/container isn’t accurate. The error message doesn’t
help them figure this out.

This commit adds extra detail to the error message so they can fix the
problem without having to come to us for help.
2017-01-17 10:44:00 +00:00
Leo Hemsted
17cf582502 Merge branch 'master' into active-service 2016-11-10 13:54:02 +00:00
Leo Hemsted
abecb5ff98 Merge pull request #726 from alphagov/auth-500
update python client to 2.0.0
2016-11-10 13:47:34 +00:00
Leo Hemsted
e8c3a5cdde add check for inactive services to auth handler
cleaned up some auth code to marginally improve efficiency of error checking
and hopefully make it easier to read

fixed some incorrect auth headers in the deactivate tests
2016-11-10 11:07:12 +00:00
Chris Hill-Scott
9248e72c50 Make bearer prefix on auth header case insensitive
From a support ticket:

> the "Bearer" prefix on the auth header is case sensitive. Can this be
> made case-insensitive?

Sure can 🙃
2016-11-07 10:49:05 +00:00
Leo Hemsted
f089b75129 update python client to 2.0.0
this is to prevent 500 errors because <2.0.0 raised AssertionError
if supplied JWT tokens were incorrectly formatted

tests added
2016-11-03 17:05:25 +00:00
Rebecca Law
f5aac5796c Improve the error message when the service id is not the right data type.
Improve the error message is the api key is not valid.
2016-09-23 11:07:49 +01:00
Chris Hill-Scott
d44a0b72bb Rewrite authentication error messages more English 2016-09-16 08:57:55 +01:00
Chris Hill-Scott
1ce91997e8 Give specifc error when service doesn’t exist
If you sign a token with a service ID that doesn’t exist (say, for
example, that you get service ID and API key mixed up) then you get
an error saying that “no API keys exist for the service”. This is wrong
because the service doesn’t even exist.

This commit adds:
- code to check if the service does exist
- a specific error message for this case

The check does mean an extra database call to look up the service.
However this only happens _after_ looping through all the API keys. So
it shouldn’t have a performance implication for anyone using a valid API
key.
2016-09-16 08:49:49 +01:00
Chris Hill-Scott
6b3c899127 Add a test for auth-ing with non-existant service
If you create a token signed with a service ID that doesn’t exist, you
will get an error (as you should).

However we didn’t have a test that explicitly checks for this. This
commit adds one.
2016-09-16 08:46:32 +01:00
Rebecca Law
ecd4b76080 Fix bug with expired token error response 2016-07-22 15:10:37 +01:00
Leo Hemsted
3838715077 refactored the requires_auth handler to raise exceptions
hopefully cleans up code flow and readability [a tiny bit].
raise an AuthException in auth.py, and catch it in errors.py to
save on returning error_repsonse values throughout the function
2016-06-30 10:44:21 +01:00
Leo Hemsted
39519e3f36 attach api_key to app
we previously attached the service id and the key's secret
also more refactoring of auth.py
2016-06-30 10:44:21 +01:00
Leo Hemsted
adbe02783d refactor authentication code
moved api_key secret manipulation (generating and getting) into
authentiation/utils, and added a property on the model, to facilitate
easier matching of authenticated requests and the api keys they used
2016-06-30 10:44:21 +01:00
Leo Hemsted
e9482c7fe1 add new key_type table
* single-column static data table that currently contains two types: 'normal' and 'team'
* key_type foreign-keyed from api_keys
  - must be not null
  - existing rows set to 'normal'
* key_type foreign-keyed from notifications
  - nullable
  - existing rows set to null
* api_key foreign-keyed from notifications
  - nullable
  - existing rows set to null
2016-06-24 15:56:54 +01:00
Rebecca Law
acee87fc63 Refactor the api_key_dao.
The only update we should be doing to an api key is to expire/revoke the api key.
Removed the update_dict from the the save method.
Added an expire_api_key method that only updates the api key with an expiry date.
2016-06-22 15:27:28 +01:00
Rebecca Law
40fa394226 Update auth module to return consistently formed error messages.
We are trying to get all the error messages to return in the following format:
{result: error,
 message: ['what caused error': 'reason for error']
}
2016-06-17 14:22:58 +01:00
Nicholas Staples
03f15d6af9 Update now to utcnow. All tests passing. 2016-05-11 10:56:24 +01:00
Rebecca Law
b53fdf1f3f Update python client to version 1.0.0.
This version of the client removed the request method, path and body from the encode and decode methods.
The biggest changes here is to the unit tests.
2016-05-04 16:08:23 +01:00
Rebecca Law
11c4696775 Update to test as per review comments.
However, I am curious if there is evidence that using fake_uuid over creating one in the test is actually faster.
2016-04-29 14:36:10 +01:00
Rebecca Law
8c14b5a8ab This pull request fixes a bug in authentication.
If the service does not have any api keys, there would be an error but it was not formed well.
2016-04-29 10:24:02 +01:00
Nicholas Staples
b56e324a4c Working tests and provider stats table.
Fix for tests and import error.

Added tests and updated for code review comments.
2016-04-25 12:20:06 +01:00
Adam Shimali
74ac5b5f30 Added version history to api keys. This needed a bit of change
to create history to handle foreign keys better. There may yet
be a better way of doing this that I have not found yet in sqlalchemy
docs.
2016-04-21 14:47:58 +01:00
Rebecca Law
c9761cd58a remove unused import 2016-04-15 10:59:00 +01:00
Rebecca Law
282a62e636 Use the new version of the notifications-python-client. This version no longer adds the req and pay to the claims of the jwt.
The change is backward compatible so an older client that sends a jwt with the extra claims will pass authentication.
Once all the clients have been updated to not include the extra claims some updates to exclude them from the method signatures will happen as well.
2016-04-14 18:12:33 +01:00
Nicholas Staples
90f0505a3d Update limit to message_limit.
Further db changes and updates.

Remove traceback print out.

Fix bug in passing template id to a task.
2016-04-11 16:53:40 +01:00
Rebecca Law
fe9bf13064 Format authentication error messages for the client. 2016-03-14 15:51:04 +00:00
Martyn Inglis
dc294c32ae Fix all other dependant classes that are affected by the DAO / Service / Model changes 2016-02-19 15:54:11 +00:00
Martyn Inglis
d38ba0d36a bumped client version 2016-02-09 18:48:02 +00:00
Rebecca Law
416dd00ac8 Added a test for the case when there is no secret for the api client.
Fix codestyle
2016-02-08 11:33:24 +00:00
Rebecca Law
b5c662eca8 Change services.id to a UUID
Ideally all the primary keys in the db would be UUID in order to guarantee unique ids across distributed dbs.
This updates the services.id to a UUID. All the tables with a foreign key to the services.id are also updated.
The endpoints no longer state a data type of the <service_id> path param.
All the tests are updated to reflect this update.

The thing to pay attention to is the 0011_uuid_service_id.py migration script.
This commit must go with a commit on the notifications_admin app to keep things working.
There will be a small outage until both deploys have happened.
2016-02-02 14:22:22 +00:00
Rebecca Law
8fa1cac1c6 Fix the user url.
Add test for authentication to test paths with path params
2016-01-22 09:59:02 +00:00
Rebecca Law
27a381c3e9 Allow services to have multiple api keys.
/service/<service_id>/api-key/renew has been renamed to /service/<service_id>/api-key
/service/<service_id>/api-key now creates a token and no longer expires the existing api key.
Moved test for this endpoint to it's own file.
2016-01-20 10:57:46 +00:00
Rebecca Law
1db57dca8c Allow for multiple api keys for a service. 2016-01-19 18:25:21 +00:00
Martyn Inglis
fa30782d70 Removed Status endpoints from requiring Auth tokens
- auth tests now use service endpoints

- one test commented out and needs reworked
2016-01-19 15:32:33 +00:00
Rebecca Law
4fc5c34320 Change Tokens to ApiKey
Added name to ApiKey model
2016-01-19 12:13:47 +00:00