Commit Graph

8231 Commits

Author SHA1 Message Date
Rebecca Law
1bf5ce08b2 Add a error log for alert tasks.
Many of the team members do not look at emails from zendesk, adding a current_app.logger.error message for things we care about to give developers a better chance of seeing them.
I have purposely not added an erro log for `check_for_services_with_high_failure_rates_or_sending_to_tv_numbers` because it's not something we need to look at immediately.
2021-05-26 11:06:21 +01:00
Leo Hemsted
70ff00f2c3 Merge pull request #3247 from alphagov/webauthn-login-endpoint
add endpoint for verifying webauthn login
2021-05-21 12:26:02 +01:00
Rebecca Law
7b5eb5f905 Fix import order check 2021-05-19 08:21:35 +01:00
Leo Hemsted
00b0227007 add endpoint for verifying webauthn login
with sms and email auth the api handles verifying logins in the
`/<user_id>/verify/code` endpoint, when it checks the code is valid etc.
The admin app has already done this for webauthn logins, but we still
need an API endpoint so that we can set up the user's db entry to have
a new logged in timestamp, a new session id (this is important for
logging out other browser sessions), etc.

Also, we need to be able to make sure that the user's max login count
isn't exceeded. If it's exceeded, we shouldn't let them log in even with
a valid webauthn check.

This endpoint is a POST where the admin passes in a json dict with key
"succesful" being True or False. True sets up the db stuff as mentioned.
False just increments the failed login count.
2021-05-17 20:37:46 +01:00
Sakis
3702d4eae8 Merge pull request #3246 from alphagov/add-splunk-service
Add splunk service
2021-05-14 18:56:34 +03:00
Pea Tyczynska
d16ceaf3dc Merge pull request #3245 from alphagov/validate-constraint
Validate ck_user_has_mobile_or_other_auth constraint
2021-05-14 10:12:50 +01:00
sakisv
9b34a2a9a2 Add splunk service
This will allow shipping app and router logs to splunk[1]

This will is only bound on the API because we're only interested in
paas router logs for the time being

1: https://github.com/alphagov/paas-csls-splunk-broker/blob/main/docs/user-guide.md
2021-05-14 11:17:26 +03:00
Pea Tyczynska
1f6e225a1b Validate ck_user_has_mobile_or_other_auth constraint
This is second step out of two step migration.
We divided it like this to avoid potentially locking
production database for extended amounts of time.
2021-05-13 17:34:35 +01:00
Pea Tyczynska
4b8c389d56 Merge pull request #3243 from alphagov/add-2fa-type-webauthn
Add webauthn as an auth type
2021-05-13 14:31:53 +01:00
Pea Tyczynska
d6c3b5e0c9 Do not validate constraint when creating it
To avoid locking production database for extended amounts of time.
2021-05-13 14:13:54 +01:00
Pea Tyczynska
251107029a Add webauthn to tests that include other auth types 2021-05-13 12:44:36 +01:00
Pea Tyczynska
098c6f031b Add webauthn as an auth type.
Both in our models and as a migration to add it to auth_types
table.

Make sure that if we downgrade, we first clean up the data.
2021-05-13 12:44:36 +01:00
Leo Hemsted
ef3d6aded4 Merge pull request #3239 from alphagov/add-webauthn
Add webauthn
2021-05-13 10:42:31 +01:00
Leo Hemsted
c190886bfe tweak webauthn rest errors
simplify logic by changing the dao function to require a user id and a
webauthn cred id. Note that this changes the response from a 400 to a
404 if the cred is for a different user than the supplied id.

give a minimum length to the text fields in POSTS to create/update a
credential to avoid surprising unexpected edge cases involving empty
string names etc.
2021-05-12 17:48:38 +01:00
Pea Tyczynska
d6fead7c04 On update, check that webauthn credential belongs to user 2021-05-12 17:48:38 +01:00
Pea Tyczynska
e6291187ba Remove registration_response from webauthn serialize - not needed in admin app
Also fix tests:

First add init file so the tests are found correctly, then update
the tests after we stopped serialising webauthn
registration_response.
2021-05-12 17:48:37 +01:00
Leo Hemsted
e62e050963 add webauthn crud endpoints
added some simple validation to the delete endpoint for sanity, but
generally my assumption is that more validation will happen on the admin
side.

noteably im not checking whether the credentials are duplicated, nor is
there a uniqueness constraint in the database - I'm not sure if the
credential blob will always reliably be equivalent, and I believe the
browser should hopefully take care of dupes.
2021-05-12 17:48:37 +01:00
Leo Hemsted
500feba50d add name/id and consolidate webauthn types in model/table
so we can be in line with what the admin handles, and keep it simple on
the api side and do as little manipulation of binary data as possible.

### Minor changes

* id is a UUID we can use for referencing within notify. No relation to
 the key itself.
* name is a user viewable name that can be set/edited
* fix updated_at to have onupdate, not default

### Simplify the webauthn data

credential_data is the data we store about an authenticator that we'll
use to identify the key when logging in. includes the credential_id, the
public_key, and the aaguid (which identifies the authenticator
make/model)

registration_response is the data containing audit information - in the
future we can use this to ensure that the authenticators used are of
high quality.

both of these fields are CBOR (a kind of binary json), encoded in
base64 so that they can be embedded within our regular JSON api
endpoints. we don't anticipate the api ever needing to interact with
this data directly.
2021-05-12 17:48:37 +01:00
Pea Tyczynska
3798a3bd1d Add webauthn_credential table
This is to store data for registered webauthn credentials, so
platform admins can later use them to log in.
2021-05-12 17:48:36 +01:00
Katie Smith
bb6cbf7a65 Merge pull request #3241 from alphagov/gov-channel
Add "government" as a broadcast channel type
2021-05-12 16:12:11 +01:00
Katie Smith
829b646931 Allow "government" in broadcast_channel schema
This will allow admin to pass through a value of "government" for the
broadcast_channel. We don't have any logic around the value of service.broadcast_channel,
so no updates are needed to the tasks etc.
2021-05-11 16:56:56 +01:00
Katie Smith
7eed63eb80 Add 'government' to broadcast_channel_types table 2021-05-11 16:32:03 +01:00
Katie Smith
32fa8ee418 Merge pull request #3237 from alphagov/null-to-all
Make service_broadcast_settings.provider non-nullable
2021-05-11 13:35:26 +01:00
Richard Baker
41f324451b Merge pull request #3238 from alphagov/revert-dependabot/pip/eventlet-0.31.0
Revert "Bump eventlet from 0.30.2 to 0.31.0"
2021-05-11 11:12:44 +01:00
Richard Baker
2e34f7b18e Force pyup to ignore eventlet
Signed-off-by: Richard Baker <richard.baker@digital.cabinet-office.gov.uk>
2021-05-11 10:12:01 +01:00
Richard Baker
9acf0f839c Freeze dependencies
Signed-off-by: Richard Baker <richard.baker@digital.cabinet-office.gov.uk>
2021-05-10 18:05:37 +01:00
Richard Baker
ab7c8b3946 Revert "Bump eventlet from 0.30.2 to 0.31.0"
Signed-off-by: Richard Baker <richard.baker@digital.cabinet-office.gov.uk>
2021-05-10 17:42:44 +01:00
Richard Baker
e8a898d269 Merge pull request #3236 from alphagov/ensure-correct-encoding-of-broadcast-events
Normalise content for non-templated broadcast events
2021-05-10 16:45:40 +01:00
Katie Smith
c4d855a1a0 Remove references to broadcast provider_restriction being None
None is not a value that is allowed any more.
2021-05-10 15:59:22 +01:00
Katie Smith
4624328c36 Make service_broadcast_settings.provider non-nullable
We set all existing null values to "all", then make the column
non-nullable. Admin is already passing through the value of "all".
2021-05-10 15:59:22 +01:00
Chris Hill-Scott
0a3be6a662 Normalise content for non-templated broadcast events
We found that non-templated broadcast messages weren’t having their
content normalised before saving into an event.

This means that stuff like `\r\n` and curly quotes were being passed
through to the CBC proxy.

This commit firstly changes templated events to use
`str(BroadcastMessageTemplate)` to normalise the content, because it’s
non-obvious that calling
`BroadcastMessageTemplate.content_with_placeholders_filled_in` also
normalises content.

Then it changes the non-templated route to also call
`str(BroadcastMessageTemplate)`, where previously it was passing the
content straight through.
2021-05-10 15:55:08 +01:00
Richard Baker
96cb30d640 Merge pull request #3235 from alphagov/dependabot/pip/eventlet-0.31.0
Bump eventlet from 0.30.2 to 0.31.0
2021-05-10 15:49:52 +01:00
Katie Smith
6fb3401ca7 Merge pull request #3233 from alphagov/broadcast-provider-types
Add a type table for broadcast providers
2021-05-10 11:41:39 +01:00
dependabot[bot]
c7ae2ee06a Bump eventlet from 0.30.2 to 0.31.0
Bumps [eventlet](https://github.com/eventlet/eventlet) from 0.30.2 to 0.31.0.
- [Release notes](https://github.com/eventlet/eventlet/releases)
- [Changelog](https://github.com/eventlet/eventlet/blob/master/NEWS)
- [Commits](https://github.com/eventlet/eventlet/compare/v0.30.2...v0.31.0)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-08 16:37:31 +00:00
Katie Smith
1767535def Allow service.allowed_broadcast_provider to be "all"
We want to replace the value `None` for
service.allowed_broadcast_provider with the value of "all". As a first
step, we need to allow both values. Once notifications-admin has been
changed to pass through "all" and all the data in the database has been
updated, we can update the code to stop supporting both values.
2021-05-06 15:32:02 +01:00
Katie Smith
aec631f208 Add a type table for broadcast providers
This adds a type table for broadcast providers, which is the pattern we
follow with our models (e.g. we have a `broadcast_channel_types` table).

As well as the four providers, the migration populates it with `all`
which is the value that will replace `null` in a later change.

It should be safe to add the foreign key constraint to the
`service_broadcast_settings` in the same migration since the column is
still nullable and we don't have data in that column that is not in the
types table.
2021-05-06 15:30:04 +01:00
Katie Smith
46fe3fca23 Merge pull request #3230 from alphagov/zipfile-names
Change letter zip file names for Insolvency Service letters
2021-05-06 13:57:18 +01:00
Ben Thorner
2ff187400d Merge pull request #3234 from alphagov/increase-sms-fail-thresh
Increase warning threshold for SMS failures
2021-05-06 10:52:38 +01:00
Katie Smith
8a34dccda0 Remove redundant join
This was left over from when we needed to tell if a notification was
sent by a crown or non-crown service.
2021-05-06 09:34:46 +01:00
Katie Smith
8365c749e4 Change letter zip file names for Insolvency Service letters
DVLA would like to be able to identify letters sent by the Insolvency
Service, so we are changing the zipfile name. They need all zipfile
names to have the same structure, so we can't just add a marker to files
sent by that service - we have to change all filenames.

The new format is like this:
`{NOTIFY}.{DATE}.{SEQUENCE_ID}.{UNIQUE_ID}.{SERVICE_ID}.{ORG_NAME}.{EXTENSION}`
2021-05-06 09:18:44 +01:00
Ben Thorner
bd45d788c0 Increase warning threshold for SMS failures
Second attempt [1]. This increases the threshold so:

- It's a more substantial amount of money lost (£16).

- It's 10% of the minimum free allowance for a service.

- It's greater than the threshold we have for TV numbers (500).

Having a higher threshold for this alert will help prevent wasted
effort investigating more negligible failures, and reduces the
ambiguity of whether we should take action: we should.

[1]: https://github.com/alphagov/notifications-api/pull/3221
2021-05-05 17:54:43 +01:00
Ben Thorner
4bbba69e0b Merge pull request #3232 from alphagov/rewrite-migration-readme
Rewrite migration README
2021-05-05 14:46:07 +01:00
Ben Thorner
618ce14842 Rewrite migration README
This clarifies how we generate migration filenames, and points to
the official docs and help commands, instead of repeating them.
2021-05-05 14:27:05 +01:00
Rebecca Law
0161adca06 Merge pull request #3228 from alphagov/sqlalchemy-update
SQLAlchemy update
2021-05-04 14:03:05 +01:00
Rebecca Law
590f29b28a SQLAlchemy 1.4 requires SQLALCHEMY_DATABASE_URI to use postgresql rather than postgres for the connection uri to the database.
When deploying to paas the database postgres environment variables are set using VCAP_SERVICES provided by PaaS. When we start up the app and set the properties we need to replace the postgres string with postgresql for the app to start up properly.
This wasn't caught locally or with the unit tests because we were setting this property with postgresql.
2021-04-29 13:49:37 +01:00
Rebecca Law
424796bdcc Add unit test for archiving a template with a template folder 2021-04-29 13:32:36 +01:00
Rebecca Law
4f196316aa Change the query to get the services to purge to use query on the db.Model rather than db.session.query.
`service_ids_to_purge` is a list of `row` object rather than a list of `UUID`.

NOTE: db.session.query(Service).filter(Service.id.notin_(services_with_data_retention)).all() would have also worked. It seems that only selecting attributes from the db.Model has caused the change.
2021-04-29 13:32:36 +01:00
Rebecca Law
68d28aa83b The update of SQLAlchemy 1.4.10 has caused some conflicts in our code. This PR fixes most of those conflicts.
- sqlalchemy.sql.expression.case must include an else statement.
- clearly define list of columns for inbound_sms_history insert, getting the list from InboundSmsHistory.__table__.c was causing data type errors.
- remove relationships when not needed, the foreign key relationship is established in the creation of the column. This will get rid of the warnings referenced here: http://sqlalche.me/e/14/qzyx.
- update queries now that he user relationship in ServiceUser db model has been removed.
- move the check that a template is archived to the view instead of the dao method. The check was clearing the session before the version history could be done.

Deleting notifications in the night tasks still needs to be
investigated. The raw sql is causing an error.
2021-04-29 13:32:36 +01:00
Pea Tyczynska
df19a91b7f Update error messages after SQLAlchemy version update 2021-04-29 13:32:36 +01:00
Pea Tyczynska
317ae5dbd4 Apply requirements update 2021-04-29 13:32:36 +01:00