58 Commits

Author SHA1 Message Date
leigh-mil
c2814416fb Update atst to atat 2020-03-04 11:51:15 -05:00
graham-dds
108f65f928 Use pendulum for datetime operations when possible
Currently, we use both Python's built-in datetime library and Pendulum
to do datetime operations. For the sake of consistency, we should try to
stick to one library for datetimes. We could have used either, but
Pendulum has a more ergonomic API, so I decided to go with it when
possible.

The places where were we didn't / couldn't replace datetime are:
- checking instances of datetimes. Pendulum's objects are subclasses of
  python native datetime objects, so it's still useful to import
  datetime in those cases of using is_instance()
- WTForms date validators expect datetime style string formats --
  Pendulum has its own format for formatting/ parsing strings. As such,
  our custom validator DateRange needs to use datetime.stptime() to
  account for this format.
2020-02-17 10:38:52 -05:00
leigh-mil
bdc03fb0a2 Remove /help route and templates 2020-01-22 16:53:11 -05:00
dandds
1ab0c26365 Log details about user login and logout.
To satisfy security requirements, we need to explicitly track:

- when a user attempts to log in, successful or not
- when a user logs out
- whether or not the user associated with a request is logged in

The first two are satisfied by extra log statements and the last is a
new boolean field on the JSON logs.
2020-01-10 10:20:35 -05:00
leigh-mil
74ff581570 Remove route for /portfolios 2019-12-03 15:43:06 -05:00
dandds
1b6239893b Maintain static list of CRL URIs and issuers.
The previous solution (ad-hoc stream-parsing the CRLs to obtain their
issuers and nextUpdate) was too cute. It began breaking on CRLs that had
an addition hex 0x30 byte somewhere in their header. I thought that 0x30
was a reserved character only to be used for tags in ASN1 encoded with
DER; turns out that's not true. Rather than write a full-fledged ASN1
stream-parser, the simplest solution is to just maintain the list of
issuers as a constant in the codebase. This is fine because the issuer
for a specific CRL URI should not change. If it does, we've probably got
bigger problems.

This also removes the Flask app's functionality for updating the local
CRL cache. This is being handled out-of-band by a Kubernetes CronJob
and is not a concern of the app's. This means that instances of the
CRLCache do not have to explicitly track expirations for CRLs.
Previously, the in-memory dictionary or CRL issuers and locations
included expirations; now it is flattened to not include that
information.

The CRLCache class has been updated to accept a crl_list kwargs so that
unit tests can provide their own alternative CRL lists, since we now
hard-code the expected CRLs and issuers. The nightly CRL check job has
been updated to check that the hard-coded list of issuers matches what
we get when we actually sync the CRLs.
2019-11-12 05:43:11 -05:00
dandds
0b5acde4c4 Stream-parse CRLs for caching file locations.
AT-AT needs to maintain a key-value CRL cache where each key is the DER
byte-string of the issuer and the value is a dictionary of the CRL file
path and expiration. This way when it checks a client certificate, it
can load the correct CRL by comparing the issuers. This is preferable to
loading all of the CRLs in-memory. However, it still requires that AT-AT
load and parse each CRL when the application boots. Because of the size
of the CRLs and their parsed, in-memory size, this leads to the
application spiking to use nearly 900MB of memory (resting usage is
around 50MB).

This change introduces a small function to ad-hoc parse the CRL and
obtain the information in the CRL we need: the issuer and the
expiration. It does this by reading the CRL byte-by-byte until it
reaches the ASN1 sequence that corresponds to the issuer, and then looks
ahead to find the nextUpdate field (i.e., the expiration date). The
CRLCache class uses this function to build its cache and JSON-serializes
the cache to disk. If another AT-AT application process finds the
serialized version, it will load that copy instead of rebuilding it. It
also entails a change to the function signature for the init method of
CRLCache: now it expects the CRL directory as its second argument,
instead of a list of locations.

The Python script invoked by `script/sync-crls` will rebuild the
location cache each time it's run. This means that when the Kubernetes
CronJob for CRLs runs, it will refresh the cache each time. When a new
application container boots, it will get the refreshed cache.

This also adds a nightly CircleCI job to sync the CRLs and test that the
ad-hoc parsing function returns the same result as a proper parsing
using the Python cryptography library. This provides extra insurance
that the function is returning correct results on real data.
2019-11-04 08:36:03 -05:00
dandds
fc637e933d Specify Flask SERVER_NAME value for Celery worker.
The Celery worker cannot render URLs for the app without having a
SERVER_NAME value set. AT-AT's ability to send notifications when an
environment is ready is broken as a result.

This commit sets a null default value for SERVER_NAME in the default
config file. A setting must exist in the INI file in order to be
over-written by an environment variable, which is why we declare it as
null here. There is an additional kwarg, "allow_no_value", that must be
passed to ConfigParser to allow null values.

This also applies the correct domains as SERVER_NAME environment
variables in the Kubernetes ConfigMaps for the AWS and Azure Celery
workers.
2019-10-16 11:57:18 -04:00
dandds
bd8a469e93 Fix tests that were broken by a fixture CRL expiring.
Adjust the broken tests to use our dynamic fixtures for PKI files. Some
tests still rely on these fixtures, but this is a minimal patch to get
the test suite passing again. Eventually all tests should use the pytest
fixtures.
2019-07-10 11:11:49 -04:00
richard-dds
c653cf2dbf Display a flash message when a user logs out 2019-05-28 16:55:52 -04:00
leigh-mil
610aef428d Add user's last login to the session data 2019-04-03 12:24:02 -04:00
dandds
c4b4cc0912 update atat-wide permission sets 2019-03-21 05:38:28 -04:00
dandds
bec5d11bfe users have permission sets for site-wide perms 2019-03-21 05:38:28 -04:00
dandds
13bc7f56b0
Merge pull request #701 from dod-ccpo/portfolio-perms
Portfolio perms
2019-03-18 08:40:35 -04:00
dandds
1a122c5335 rename role -> permission_set everywhere 2019-03-15 07:14:49 -04:00
Montana
effec85cf9 Raise Error Code 008 for invalid CRLs 2019-03-14 13:42:12 -04:00
dandds
d3d36822df workspace -> portfolio everywhere 2019-01-14 16:00:17 -05:00
dandds
08806eed24 put requests workflow tests behind a feature toggle 2019-01-07 16:05:27 -05:00
Patrick Smith
8bb9c1ab8a Add __repr__ to models 2018-10-02 14:14:39 -04:00
dandds
8a89c519eb on user login, redirect based on next query parameter if available 2018-10-01 16:16:30 -04:00
dandds
8b8d694abd apply destination url path as next parameter to login redirect 2018-10-01 16:16:30 -04:00
Patrick Smith
a27c1b5712 Set current user for public routes as well 2018-09-26 16:50:43 -04:00
dandds
04d03f3c93 fix and refactor test for protected routes 2018-09-24 16:59:08 -04:00
dandds
0e8d5f1390 some cleanup to auth tests 2018-09-17 10:27:49 -04:00
dandds
0d1494ea11 create logout endpoint that clears user data from session 2018-09-17 10:18:14 -04:00
richard-dds
fa105a95e3 Redirect to home after login, which redirects elsewhere 2018-09-05 10:39:05 -04:00
richard-dds
533dc8e0f6 Redirect CCPO to requests index after login 2018-09-04 16:18:43 -04:00
richard-dds
daa8634cb4 Format project 2018-08-23 16:25:36 -04:00
Montana
5f0a9e22d6 Fix tests 2018-08-22 16:05:37 -04:00
dandds
07ce940650 create AuthenticationContext to consolidate auth logic 2018-08-09 15:01:43 -04:00
dandds
05de0665d4 basic implementation of email parsing for CAC user login 2018-08-09 15:01:06 -04:00
dandds
7b8934e0cb add Flask error handlers 2018-08-08 13:54:15 -04:00
dandds
d693db7dbb apply authentication to the whole app, track exceptions 2018-08-06 14:06:06 -04:00
dandds
7ea3f682e0 better test name 2018-08-06 12:59:01 -04:00
dandds
ac95bf371e implement CRL checking from authnid 2018-08-06 11:12:58 -04:00
dandds
be079a62dc apply auth requirement to virtually all endpoints 2018-08-06 10:45:33 -04:00
dandds
ad1e1e771b extract get_current_user, fix tests 2018-08-06 10:44:24 -04:00
dandds
6dce89df1b 401 unauthorized page for bad logins 2018-08-06 10:44:24 -04:00
richard-dds
13146e9362 Implement log_in_user 2018-08-06 10:44:00 -04:00
dandds
45b47c41bf update tests for Flask 2018-08-02 16:03:54 -04:00
dandds
7d3cd04bdd
Merge pull request #75 from dod-ccpo/authz-permissions
Authz permissions
2018-07-18 09:44:46 -04:00
dandds
37ee8f9c7a confirm user site perms are stored in session 2018-07-16 15:58:43 -04:00
richard-dds
e48644fb44 Create authz users on login 2018-07-16 13:19:35 -04:00
dandds
335bbed94d ensure we clear session cookies 2018-07-12 16:43:41 -04:00
dandds
21c970e4b4 rename some handlers with more specificity 2018-07-12 11:39:22 -04:00
dandds
b7d191a8eb do not redirect in get_current_user 2018-07-09 14:04:04 -04:00
dandds
46016faceb test and update to README 2018-06-28 10:24:20 -04:00
richard-dds
118a84560a Add simple session management using redis 2018-06-27 16:07:25 -04:00
richard-dds
0e852ae8ff Fix two linter warnings as well 2018-06-26 10:39:30 -04:00
richard-dds
f9335c7a4e Use black for formatting 2018-06-26 10:31:39 -04:00