-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace laravel auth app with mock-oauth2-server running in docker #2813
Conversation
|
Just dropping in to say this is cool! 😎 Reviewed to try and learn a bit more about how we are handling auth 👍 |
@tristan-orourke requested review from tristan, since there's UAT server steps, but anyone else is welcome to try before we merge. cc @petertgiles |
@petertgiles no no, you're right: We now assemble the public key from the modulus and exponent, instead of needing a PEM format cert in x5c (which was an uncommon approach). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoah, I love this so much. ❤️ ❤️ ❤️. Another patcon wizard PR. I love seeing +321 −31,458
at the top of the PR page. I've got a few "questions, concerns, threats" below but I'm so excited for this.
This is a killer review peter! Will get on this tomorrow :) |
K, I think I address all the feedback, or am waiting for a response on that one part 🙌 |
@petertgiles Ok, figured out how to get mock-oauth2-server working behind apache proxy. It's a little more than I expected, and I need to work outside htaccess to get proxy working, but lemme know if it looks ok! The main confusing bit (for which I tried to document in case anyone wants to unwind what's happening later), is that both the API code (running inside the container) and the host browser (running outside the container) need to be able to find the auth server at the same url. It's explained best in comments within |
My attempt to document our auth flow a little bit (WIP): sequenceDiagram
autonumber
participant browser as Browser (User)
participant admin as React Admin App
participant api as Laravel API App
participant auth as Auth Server (Mock)
Note right of auth: localStorage:{stored_locale: "fr"}
Note right of auth: cookies: none
browser->>admin: GET /admin
admin-->>browser: 200 OK. App HTML & JS.
Note left of browser: check localStorage.stored_locale
browser->>browser: /fr/admin
Note left of browser: check localStorage.id_token (null)
Note left of browser: render Login button
browser->>api: GET /login?from=/fr/admin&locale=fr
api-->>browser: 302 Found. Set-Cookie: api_session=<...>, Location: <...>
Note right of auth: cookies: api_session=<...>
Note left of browser: Redirect
browser->>auth: GET /oxauth/authorize? ... {client_id,redirect_uri,response_type,scope,state,nonce,acr_values,ui_locales}
Note right of auth: checks client_id (no-op on mock)
auth-->>browser: 200 OK. Login Form.
Note left of browser: Form field: [email protected]
browser->>auth: POST /oxauth/authorize? ... {client_id,redirect_uri,response_type,scope,state,nonce,acr_values,ui_locales} [email protected]
Note right of auth: validates user (no-op on mock)
auth-->>browser: 302 Redirect. Location: <...>
Note left of browser: Redirect
browser->>api: GET /auth-callback?code=...&state=...
Note right of api: check cookie: api_session
api-->>browser: 302 Redirect. Location: <...>
Note left of browser: Redirect
browser->>admin: GET /fr/admin? ... {token_type,id_token, access_token, refresh_token,expires_in}
admin-->>browser: 200 OK.
Note right of auth: localStorage:{stored_locale: "fr", id_token: "<...>"}
browser->>browser: /fr/admin/dashboard
Note left of browser: check localStorage.id_token (present)
Note left of browser: render Logout button
browser->>api: POST /graphql operationName=getMe
Note right of api: TODO token validation
api-->>browser: 200 OK.
Note left of browser: render admin menu.
browser->>api: POST /graphql operationName=me
api-->>browser: 200 OK.
Note left of browser: render dashboard.
browser->>api: POST /graphql operationName=getPools
api-->>browser: 200 OK.
Note left of browser: render pool list.
Open Questions
|
aside from my stretch goal of writing some high level docs in response to some of peter's questions, this is ready for review! (i also stubbed out some ideas in #2671 for end-to-end tests the would exercise some security edge-cases and ensure we handle those |
The api_session is used only to choose where to redirect. If the api_session cookie disappeared between going to the auth server and coming back, authentication should still work fine. I don't think we're using XSRF-TOKEN at all? Laravel may be setting it by default. |
By the time I've found time to read through this, I think Peter has already asked all the really important questions! I'm really curious to understand the proxy better, I'll find some time to talk through a few questions about it. |
Thanks @petertgiles! I'm spinning up fresh and investigating. Musings: wondering if it has to do with us using Also, since What version and commands are you using? I'm using
|
# REQUEST FROM HOST BROWSER: | ||
# localhost:8000 (host) => localhost:80 (php container) => mock-auth:8080 (mock-auth container) | ||
# | ||
# REQUEST FROM API APP: | ||
# localhost:8000 (php container) => mock-auth:8080 (mock-auth container) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tristan-orourke this is the comment where I explain the logic. Hit me up if this and the surrounding context needs any additional discussion!
https://recordit.co/pCmAXSuZp2 Hm. Not sure what's up @petertgiles, I built fresh into /tmp, and just ran this, and it works as above:
|
Just added "run |
Hmm, it works fine fine for me, no problems |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I'm not sure what went wrong for me. I tried again today (maybe more carefully?) and it ran fine! I also deployed it to the dev server and it seems OK. It's still up there now if you want to poke at it.
Here are my tips if you want to include them in your "help people to get their environment going again" post:
|
k, thanks peter! Adapted from your recommendations (but favouring after-pull steps in case ppl don't notice msg) (added After pull:
|
Closes: #2755
Supercedes: #2716 and #2741
This PR removes our old auth app and replaces it with a mock oauth2 server. Best way to review is to step through commits, as the removal commit is quite a bit noisier than the rest :)
Screencast
Link to full video
Steps to review
api/.env.example
intoapi/.env
(override prior local auth values)docker-compose up --detach --build
to spin up the newmock-auth
container (and rebuildphp
container)add this line to your hosts file:127.0.0.1 auth.talent.canada.test
docker-compose run --rm maintenance bash refresh_api.sh
to install new composer dependenciesTo Dos
api
to work withoutx5c
jwks propauth
appbcmath
is on UAT or can be -- @petertgilesphp -m
(and findbcmath
)gmp
andbcmath
loaded for CLI php on development serverif not there, and no package for something likephp-bcmath
, then we can easily switch togmp
, which may be simpler: https://stackoverflow.com/questions/40010197/how-to-install-gmp-for-php7-on-ubuntumaintenance/README.md
Replace laravel auth app with mock-oauth2-server running in docker #2813 (comment)