Skip to content

Commit d5c577e

Browse files
committed
Handle key exception and beef up docs
1 parent 5dd39f1 commit d5c577e

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

README.md

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[![Build Status](https://travis-ci.org/ucsc-cgp/bouncer.svg?branch=master)](https://travis-ci.org/ucsc-cgp/bouncer)
22

33
# bouncer
4-
The whitelist checker for authentication with CGP HCA Data Store
4+
Simple email whitelist checker backed by the AWS Secrets Manager
55

66
## setup
77

@@ -23,27 +23,43 @@ To test, run
2323
python -m unittest -v test.py
2424
```
2525
## how to use
26+
27+
### setting up the whitelist
28+
1. Go to the AWS Console and find the **Secrets Manager** service.
29+
1. Select **Store a new secret**.
30+
1. For secret type select **Other type of secrets**.
31+
1. Under the **Secret key/value** tab enter `email` as the key and a
32+
comma separated (no spaces) list of whitelisted emails as the
33+
value. Select **Next**.
34+
1. Name your secret something descriptive, such as
35+
`commons/dev/whitelist` and give it a description. Select **Next**.
36+
1. Make sure **Disable automatic rotation** is selected. Then select
37+
**Next**.
38+
1. Review your configuration and select **Store**.
39+
40+
### adding someone to the whitelist
41+
1. Go to the AWS Console and find the **Secrets Manager** service.
42+
1. Find the secret to which you want to add. For example, one might
43+
search for `commons/dev/whitelist`.
44+
1. Under **Secret value**, select **Retrieve secret value**. Then
45+
select **Edit**.
46+
1. Add your email with **NO WHITESPACE** to the comma separated list
47+
under the key `email` and select **Save**.
48+
49+
### using bouncer to check the whitelist
2650
Using is simple!
2751

2852
Here's an example
2953

3054
```python
3155
>>> from bouncer import Bouncer
3256
>>> b = Bouncer('commons/dev/whitelist')
33-
>>> b.is_authorized('jrbrenna@ucsc.edu')
57+
>>> b.is_authorized('valid.email@example.com')
3458
True
35-
>>> b.is_authorized('evil.gnomes@ucsc.edu')
59+
>>> b.is_authorized('evil.gnomes@example.com')
3660
False
3761
```
3862

3963
This checks the AWS Secret Keeper called `commons/dev/whitelist` to see
40-
if the users `jrbrenna@ucsc.edu` and `evil.gnomes@ucsc.edu` are in the
41-
whitelist.
42-
43-
## adding users to the whitelist
44-
1. Go to the AWS Console and find the **AWS Secrets Manager** service.
45-
1. Find the secret to which you want to add. For example, one might
46-
search for `commons/dev/whitelist`.
47-
1. Under **Secret value** select **Edit**.
48-
1. Add your email with **NO WHITESPACE** to the comma separated list
49-
under the key `email`.
64+
if the users `valid.email@example.com` and `evil.gnomes@example.com`
65+
are in the whitelist.

bouncer/bouncer.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def is_authorized(self, email: str) -> bool:
3333
3434
:param email: Google email address for which authorization is to be determined
3535
:return: True if the email address is authorized, False if not authorized
36-
:exception: <TBD> If an error occurs.
36+
:exception SecretManagerException: If an error occurs.
3737
"""
3838
return email in self.whitelist()
3939

@@ -50,4 +50,8 @@ def whitelist(self):
5050
else:
5151
secret_string = get_secret_value_response['SecretString']
5252
secret_dict = json.loads(secret_string)
53-
return secret_dict[SECRET_KEY].split(',')
53+
try:
54+
return secret_dict[SECRET_KEY].split(',')
55+
except KeyError as e:
56+
raise SecretManagerException(f"Your secret is misformatted. Expected key: {SECRET_KEY}, "
57+
f"actually found: {list(secret_dict.keys())}")

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def read(fname):
1616

1717
setup(
1818
name="cgp-bouncer",
19-
description="The whitelist checker for authentication with CGP HCA Data Store",
19+
description="Simple email whitelist checker backed by the AWS Secrets Manager",
2020
packages=find_packages(), # include all packages
2121
url="https://github.com/ucsc-cgp/bouncer",
2222
long_description=read('README.md'),

0 commit comments

Comments
 (0)