[Epic] Auth Schema #32
Labels
awaiting-review
An issue or pull request that needs to be reviewed
enhancement
New feature or enhancement of existing functionality
epic
A feature idea that is large enough to require a sprint (5 days) or more and has smaller sub-issues.
in-progress
An issue or pull request that is being worked on by the assigned person
T1d
Time Estimate 1 Day
technical
A technical issue that requires understanding of the code, infrastructure or dependencies
On Monday we drew out the basic auth schema on the witeboard in the Office together:
This issue/epic is our attempt to capture as much detail as we can so we can implement it.
The schema defined herein is not meant to be "set in stone", rather it's a starting point which will allow us to ship and then iterate as new requirements surface.
Schema/Table/Record Naming?
While the photo of the schema above uses the word "users", this was only for the purposes of "sketching" it out on the whiteboard and is not the table/schema name we are going to use.
For more detail on why we are choosing to name the schema
people
, see: dwyl/app#33people
👤At the most basic level, we need a table to store encrypted email addresses and hashed passwords to allow a person to register and login to the app/service where
auth
is being used.Schema
inserted_at
- (standard ecto/phoenix schema type::naive_datetime
) when a record is inserted. Automatically set by the database which ensures record integrity.cid
(Primary Key. Ecto type:string
) - the hash of the data being inserted (the Ectochangeset
minus theinserted_at
timestamp) such that we know that a record is unique and verifiable.This will use our
excid
implementation: https://github.com/dwyl/cidperson_id
(Ecto type:string
) - this is a unique id for the person which allows queries to be performed across the table. For example, the following query will return the latest version of person record:SELECT * FROM people WHERE person_id = 'e096' ORDER BY inserted_at DESC LIMIT 1;
prev
(Ecto type:string
) - the reference to the previouscid
for the record.This is "metadata" included by
alog
which the person using the app will never see but is useful in an "audit trail" if we ever need to determine if a "rogue" DBA has altered records. If you haven't had exposure to data fraud/forensics see: wikipedia.org/wiki/Forensic_data_analysisemail_encrypted
(Ecto type:binary
) - encrypted email address which can be decrypted if/when we need to send someone an email from our App. This will useFields.EmailEncrypted
to transparently apply strong encryption to the data before storing it.email_hash
(Ecto type:binary
. UsesFields.EmailHash
. Unique Index) - a (per application) saltedsha256
hash of the person's email address which allows for fast lookup when the person is attempting to authenticate. This will useFields.EmailHash
to transparently hash the email address. For more detail on why this is needed and how it works,see: https://github.com/dwyl/phoenix-ecto-encryption-example
verified
(Ecto type:naive_datetime
) - the timestamp when the email address was verified. If this field isnull
(not yet set) it means that the email address has not been verified. This will appear on the person's Profile asemail unverified
and limit their actions in the App.For example: on CS it will mean their reviews of a drinks/venues will only be visible to admins/editors until the email address is verified. This is to avoid spam content.
password_hash
- (Ecto type:binary
, usesFields.Password
) - theArgon2
hash of the person's password, safely stored to avoid any risk of reversal in the unlikely event of a "database breach".first_name
- (Ecto type:binary
, usesFields.Encrypted
) the person's name. How we address them in emails and in UI customisations.people
Table Example (Encrypted/Hashed)1In the following example, the
person
record "progresses"2 through various stages, these correspond to therow
number:person_id
- the person wants to have a specific "alias" in the App, so they update theirperson_id
to their desired handle.inserted_at
cid
(PK)person_id
prev
email_encrypted
email_hash
verified
password_hash
first_name
1541609554
null
null
null
null
null
null
1541609554
null
null
null
1541609876
null
null
1541610203
wKIGu6djDt
null
1541611381
wKIGu6djDt
NzKibHfx
1541612984
wKIGu6djDt
NzKibHfx
## Anonymous
More Schemas/Tables?
As you noticed, the tables from the Whiteboard photo (above) are not all included in this issue.
This is because we don't want this issue to be enormous so instead we are splitting out the remaining tables into linked sub-issues. And, in the case of Analytics a sub-project: https://github.com/dwyl/atm
sessions
: [Epic] Session Management #30roles
,permissions
&people_roles
: [Epic] Roles, Permissions and Grants #31analytics
: What? Why? Who? How? atm#23Todo
alog
stores and retrieves records.alog
andfields
to create thepeople
schema.The text was updated successfully, but these errors were encountered: