Closed faraonc closed 5 years ago
5. If the email and password are:
- valid - then return the User without password + code.Ok - DISCONNECTED
8. In order to be AUTHORIZED, Chrome has to call
GetToken
fromapp-gateway-svc
.
Why doesn't authenticateUser
in user-svc
also return the Token after valid credentials?
I guess I am not understanding why we need both authenticated and authorized states.
I also don't understand why we need to look up email and password twice, once for authentication, and again soon after just to get the token.
- User password are encrypted twice, browser to
app-gateway-svc
anduser-svc
to DB
Are we now encrypting password? Not hashing? Because even with hashing in browser, if hacker gets access to the hash from the browser, they essentially have the password.
- If the email and password are:
- valid - then return the User without password + code.Ok - DISCONNECTED
- In order to be AUTHORIZED, Chrome has to call
GetToken
fromapp-gateway-svc
.Why doesn't
authenticateUser
inuser-svc
also return the Token after valid credentials?
Chrome dials to app-gateway-svc
first using the following which I believe is not able to return a custom type such as a Token
: (convert this to Typescript)
conn, err := grpc.DialContext(ctx, net.JoinHostPort(addr, port),
grpc.WithTransportCredentials(credentials.NewClientTLSFromCert(insecure.CertPool, "")),
grpc.WithPerRPCCredentials(basicAuth{
username: username,
password: password,
}),
)
I guess I am not understanding why we need both authenticated and authorized states.
I also don't understand why we need to look up email and password twice, once for authentication, and again soon after just to get the token.
Because app-gateway-svc
does not know who is the client after dialing, so we need to authorize again just to get a token. This time we are not using a built-in GRPC function but our own implementations which can return a Token.
- User password are encrypted twice, browser to
app-gateway-svc
anduser-svc
to DBAre we now encrypting password? Not hashing? Because even with hashing in browser, if hacker gets access to the hash from the browser, they essentially have the password.
We are using https://godoc.org/golang.org/x/crypto/bcrypt which I believe is a form of encryption. Your implementation is acceptable.
I am changing the Token into
{
"header": {"Alg": “HS256”,"Typ": “JWT”}
"payload": {"uuid": "1234567890", "permission": "ADMIN","expiration_time": 1549093910}
"signature" : "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJ1dWlkIjoiMTIzNDU2Nzg5MCIsInBlcm1pc3Npb24iOiJUb2tlbi5BRE1JTiIsImV4cGlyYXRpb25fdGltZSI6MTU0OTA5MzkxMH0.OZFQ_zU1F2BJm6kyYzsBns5qmOxbVbUnQV2SU1B_kyPfXPOmUd0fddRvF0I3IqaDz-55H7Q80w8zQyldMQ7AAg"
}
I am changing the Token into
{ "header": {"Alg": “HS256”,"Typ": “JWT”} "payload": {"uuid": "1234567890", "permission": "ADMIN","expiration_time": 1549093910} "signature" : "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJ1dWlkIjoiMTIzNDU2Nzg5MCIsInBlcm1pc3Npb24iOiJUb2tlbi5BRE1JTiIsImV4cGlyYXRpb25fdGltZSI6MTU0OTA5MzkxMH0.OZFQ_zU1F2BJm6kyYzsBns5qmOxbVbUnQV2SU1B_kyPfXPOmUd0fddRvF0I3IqaDz-55H7Q80w8zQyldMQ7AAg" }
We decided not to do this
Updated:
- `user-svc` has to provide `GetAuthToken`, `VerifyAuthToken`, `GetSecret`, `MakeNewSecret`
- `app-gateway-svc` has to implement `BasicAuth` and `TokenAuth`, and to provide `GetAuthToken`
Objective
The Chrome user has to be authenticated within
hwsc
cluster.Purpose
For every single request within a cluster a token is passed for authorization.
Prerequisites
app-gateway-svc
anduser-svc
to DBStates
app-gateway-svc
, but not authorizedapp-gateway-svc
app-gateway-svc
Procedure
app-gateway-svc
parses the header - DISCONNECTEDapp-gateway-svc
callsAuthenticateUser
from theuser-svc
- DISCONNECTEDAuthenticaUser
returns code.Unauthenticated toapp-gateway-svc
: a.app-gateway-svc
returns code.Unauthenticated to Chrome - DISCONNECTED b. Chrome renders failed login - DISCONNECTEDAuthenticateUser
returns code.Ok +Identification
toapp-gateway-svc
, thenapp-gateway-svc
return code.Ok +token_string
as metadata in the context to Chrome - AUTHENTICATEDGetAuthToken
fromapp-gateway-svc
or parse thetoken_string
from the context's metadata.token string
is defined below this documentGetAuthToken
fromapp-gateway-svc
with email and password -AUTHENTICATEDapp-gateway-svc
callsGetAuthToken
fromuser-svc
- AUTHENTICATEDuser-svc
validates from the DB. - AUTHENTICATEDuser-svc
returns code.Unauthenticated toapp-gateway-svc
- AUTHENTICATED b.app-gateway-svc
returns code.Unauthenticated to Chrome - AUTHENTICATED c. Chrome renders failed login - AUTHENTICATEDuser-svc
generates and returnsIdentification
, to `app-gateway-svc - AUTHORIZEDIdentification
contains aSecret
andtoken string
user-svc
encodes the token string usinghwsc-lib
NewToken
token string
expires in 2 hoursuser-svc
has to record everything in a DBapp-gateway-svc
returns thetoken string
to Chrome - AUTHORIZEDtoken_string
to authorized the actor or user - AUTHORIZEDhwsc-lib
to decode and validate thetoken string
, and if it is invalid would return code.Unauthenticated ~(remember that the secret key also expires)~ - AUTHORIZEDtoken string
is not expired usinghwsc-lib
- AUTHORIZEDtoken string
is about to expire within 15 minutes, and callsGetToken
fromapp-gateway-svc
to get a new token. AUTHORIZEDtoken string
has expired, Chrome redirects to login page. DISCONNECTEDtoken string
is valid, services provide the appropriate RPC- AUTHORIZEDapp-gateway-svc
withtoken_string
from theToken
- DISCONNECTEDapp-gateway-svc
callsVerifyToken
fromuser-svc
- DISCONNECTEDuser-svc
verifies thetoken string
from DB - DISCONNECTEDtoken_string
is:user-svc returns code.Unauthenticated to
app-gateway-svc` - DISCONNECTEDapp-gateway-svc
returns code.Unauthenticated to Chrome - DISCONNECTEDuser-svc
returnsIdentification
+ code.Ok toapp-gateway-svc
AUTHORIZEDtoken string
,Identification
token string
is exchanged by Chrome andapp-gateway-svc
struct Secret
containsstring key
andcreated_timestamp
struct Identification
containsstruct Secret
andtoken string
Identification
is utilized in the requests foruser-svc
,document-svc
, andfile-transaction-svc
Identification
is also returned in the response ofuser-svc
toapp-gateway-svc
token string
expires in 2 hourstoken string
has 3 levels permission (feel free to add more)USER
- can only perform CRUD on his/her own pageADMIN
- can perform CRUD with on any user's pagetoken_string
are the following:HS256
HS512
JWT
An example AUTHORIZED token will look like the following: Changed from:"eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJ1dWlkIjoiMTIzNDU2Nzg5MCIsInBlcm1pc3Npb24iOiJUb2tlbi5BRE1JTiIsImV4cGlyYXRpb25fdGltZSI6MTU0OTA5MzkxMH0.OZFQ_zU1F2BJm6kyYzsBns5qmOxbVbUnQV2SU1B_kyPfXPOmUd0fddRvF0I3IqaDz-55H7Q80w8zQyldMQ7AAg"
Secret
that contains the secret key as a string, and created date. and expiration date timestamp is required to generate a new secret key every week on Monday 3am ~EST~ UTC.Identification
will be defined in the api-blocks as a messageuser-svc
has to provideGetAuthToken
,VerifyAuthToken
,GetSecret
,MakeNewSecret
app-gateway-svc
has to implementBasicAuth
andTokenAuth
, and to provideGetAuthToken