Commit Graph

85 Commits

Author SHA1 Message Date
David McDonald
52d3df49d4 Make ADMIN_CLIENT_SECRET a list of a single secret
And support this change across our code. Note, this is a halfway step
where it is not a list rather than a string but still only supports a
single secret, ie one item in the list.
2020-02-20 13:43:10 +00:00
David McDonald
f861da1843 Improve text for error messages 2020-02-14 14:15:41 +00:00
David McDonald
7a019df5a2 Catch previously uncaught jwt exceptions added in python client 5.5.0
This fixes the test in the previous commit and means we will catch other
unexpected jwt errors which are now raised as `TokenError`s and raise an
AuthError based on this.

This will stop us serving 5xx to users when we don't catch an exception.

Also runs make freeze-requirements
2020-02-14 14:14:13 +00:00
David McDonald
946ba993b5 Catch TokenAlgorithmError
Instead of letting it go uncaught and causing an error, we now show the
user an appropriate error message.
2019-12-12 10:23:28 +00:00
Leo Hemsted
267c4fc07b bump requirements, fix pyflake8 things, unpin botocore/awscli 2018-11-07 13:39:08 +00:00
Athanasios Voutsadakis
463f1eefaf Move proxy header check to auth-requiring endpoints
The main drive behind this is to allow us to enable http healthchecks on
the `/_status` endpoint. The healthcheck requests are happening directly
on the instances without going to the proxy to get the header properly
set.

In any case, endpoints like `/_status` should be generally accessible by
anything without requiring any form of authorization.
2018-03-27 17:37:09 +01:00
Leo Hemsted
e8967c5b05 tweak log output 2017-12-20 14:40:07 +00:00
Leo Hemsted
a0b87396ef change token expiry err msg for clarity 2017-12-20 13:57:34 +00:00
Leo Hemsted
9297c6d430 log user agents on api call auth.
this'll be useful for trying to figure out which services are using what
2017-12-20 13:57:34 +00:00
Leo Hemsted
687cf8526b log service id and api key id during auth
example log line:
```
API AuthError: AuthError({'token': ['Invalid token: signature, api token is not valid']}, 403, service_id=3e1ed7ea-8a05-4b4e-93ec-d7bebfea6cae, api_key_id=None)"
```
2017-12-20 13:57:34 +00:00
venusbb
568dcaa63d remove ip whitelist inbound sms codes 2017-12-18 10:25:37 +00:00
Leo Hemsted
28d5f9b87f flake8 - remove unused imports and ensure they're always at the top of the file 2017-11-28 14:28:01 +00:00
Athanasios Voutsadakis
0f696aa3e8 Use function from utils to check secret header value
This adds a before_request handler to check whether all incoming
requests have the proxy header configured.
2017-11-14 14:26:00 +00:00
venusbb
cae42fe862 Changed logging way 2017-11-06 13:40:20 +00:00
venusbb
03fc781b8c create new method to validate secret header, new tests 2017-11-06 11:56:57 +00:00
venusbb
f4d005c7fb initial logging for route protection 2017-11-03 14:43:56 +00:00
venusbb
0f0110a1d1 removed printout of route secret 2017-11-03 10:41:53 +00:00
venusbb
eb840585a7 Inbound sms ip messages 2017-09-28 10:17:59 +01:00
venusbb
6a7013fa7a Enable Inbound sms IP blocking 2017-09-26 10:59:09 +01:00
venusbb
db977be8d0 delete old variable ip 2017-09-15 10:54:25 +01:00
venusbb
449bc8d8d0 fixing minor problem, logged ip variable name changed 2017-09-14 13:53:08 +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
Leo Hemsted
74cd1b2904 log ip address as separate field to allow analysis of messages
if you log a dictionary, python-json-logger will pass that through to
the json output. In the ip restriction wrapper, lets log the ip_address
and whether it was found in the whitelist, to a nested `log_contents`
dict.

when logging json, it looks like this:
{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/Users/leohemsted/.virtualenvs/api/lib/python3.5/site-packages/notifications_utils/logging.py", "lineno": 98, "log_contents": {"thing": 1, "foo": "bar"}, "requestId": "no-request-id", "time": "2017-07-31T18:09:39", "application": "api", "logType": "application"}

when logging via stdout locally, it looks like this:
2017-07-31T18:11:31 api app INFO no-request-id "{'log_contents': {'foo': 'bar', 'thing': 1}, 'message': 'Logging configured'}" [in /Users/leohemsted/.virtualenvs/api/lib/python3.5/site-packages/notifications_utils
2017-07-31 18:28:25 +01:00
venusbb
9da5682c70 Experiment with logging a custom request header 2017-07-25 17:17:06 +01:00
venusbb
a5cf8ff60f put more log messages to view what env returns 2017-07-12 13:49:20 +01:00
venusbb
d3db4a6a01 Added a unit test to validate traffic from more than 3 hops 2017-07-11 09:59:41 +01:00
venusbb
5d57189187 changed name of test fixture 2017-07-11 09:50:09 +01:00
venusbb
226ae5784b reading ip address 3rd from the back rather than the first one 2017-07-10 17:33:13 +01:00
venusbb
50d01d18c5 reading ip address 3rd from the back rather than the first one 2017-07-10 17:25:38 +01:00
venusbb
5089a4d53b retrieve sms ip whitelist from credentials on paas 2017-07-10 17:03:43 +01:00
venusbb
b1a7ed46eb syntax changes 2017-07-06 12:31:01 +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
c182ceca90 Check ip unit test and modify ways to parse IP address 2017-07-06 12:30:08 +01:00
venusbb
2ff9204a61 modified the parsing of return ip address 2017-07-06 12:30:08 +01:00
venusbb
0c8e5394a1 modified the parsing of return ip address 2017-07-06 12:30:08 +01:00
venusbb
d6c69bf437 Check inbound sms IP address stage 1
IP address checked
2017-07-06 12:29:37 +01:00
venusbb
bf387ae1d0 checked displayed log message 2017-06-30 10:37:21 +01:00
venusbb
16571c5b3c IP restriction for inbound sms test 2 2017-06-29 10:47:27 +01:00
Rebecca Law
3a66027d6a Refactor ApiKeys.secret and ServiceInboundApi.bearer_token to use the same encryption method and get rid of the duplicate code. 2017-06-19 14:32:22 +01:00
Martyn Inglis
0c160c3419 Store the service we have used to authenticate the client API user against the request.
We can then use this later - saving an extra DB query on every client facing API call

- Note this doesn't affect admin calls which do not use the service from the api key, but use the one passed as part of the URL path.
2017-05-05 15:19:57 +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
fd00351ad2 Testing out adding a admin authentication requirement per blueprint. 2017-03-15 16:52:44 +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
Martyn Inglis
23ca62a7ac Records the service ID if present, or if an ADMIN api call the string admin-api.
this is used later in logging of requests.
2016-11-30 10:59:55 +00:00
Leo Hemsted
95764af6ea Merge pull request #723 from alphagov/active-service
deactivate a service
2016-11-11 15:25:32 +00:00
Rebecca Law
26d6a0c1a9 Merge branch 'master' into change-v2-error-resp 2016-11-10 14:21:20 +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