Skip to content
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

Use Ground Truth for authentication #264

Merged
merged 16 commits into from Jun 25, 2019
Merged

Use Ground Truth for authentication #264

merged 16 commits into from Jun 25, 2019

Conversation

petschekr
Copy link
Member

@petschekr petschekr commented Mar 20, 2019

Switches to using HackGT Ground Truth for authentication and removes all auth related code from the codebase.

Ground Truth is implemented as the only login strategy which could make initial setup of registration for organizations that don't already host a Ground Truth instance slightly more complicated. Two possible mitigations:

  • Users can use the 2.x.x branch of registration
  • Ground Truth supports applications hosted on any domain for any organization. HackGT admins can authorize applications for other organizations if they are ok having their users authenticate via the HackGT Ground Truth instance.

Fixes #252
Fixes #254
Fixes #262

@petschekr petschekr added bug enhancement Adds or suggests a new feature, rewrite, or other enhancement to the codebase high priority pending review This PR is pending review by a maintainer labels Mar 20, 2019
@hackgt-beekeeper hackgt-beekeeper bot had a problem deploying to registration-ground-truth-pr March 21, 2019 04:06 Failure
@hackgt-beekeeper hackgt-beekeeper bot had a problem deploying to registration-ground-truth-pr March 21, 2019 04:19 Failure
@hackgt-beekeeper hackgt-beekeeper bot temporarily deployed to registration-ground-truth-pr March 21, 2019 04:26 Inactive
@hackgt-beekeeper hackgt-beekeeper bot temporarily deployed to registration-ground-truth-pr March 21, 2019 05:52 Inactive
@hackgt-beekeeper hackgt-beekeeper bot temporarily deployed to registration-ground-truth-pr March 21, 2019 06:01 Inactive
@petschekr petschekr force-pushed the ground-truth branch 3 times, most recently from 77ac737 to 80c5ee4 Compare March 21, 2019 06:27
@hackgbot
Copy link

Hey y'all! A deployment of this PR can be found here:
https://registration-ground-truth.pr.hack.gt

Copy link
Member

@ehsanmasdar ehsanmasdar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to do some functional testing once we get it deployed, but the code so far looks good to me

@hackgt-beekeeper hackgt-beekeeper bot temporarily deployed to registration-ground-truth-pr March 28, 2019 04:37 Inactive
@hackgt-beekeeper hackgt-beekeeper bot temporarily deployed to registration-ground-truth-pr May 6, 2019 12:29 Inactive
@hackgt-beekeeper hackgt-beekeeper bot had a problem deploying to registration-dev June 16, 2019 18:25 Failure
@hackgt-beekeeper hackgt-beekeeper bot temporarily deployed to registration-dev June 16, 2019 18:35 Inactive
if (anonymous) {
let email = request.body["anonymous-registration-email"] as string;
let name = request.body["anonymous-registration-name"] as string;
if (await User.findOne({email})) {
if (await User.findOne({ email })) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So walk-up registration will be done completely outside the ground truth flow. If they later created an account that matched this email using ground truth, would the accounts properly sync up?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also did registration ever get a chance to allow walk up for people who started an application but didn't finish?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joel99 No that's not implemented yet (and I don't think it's covered by an existing issue)
@ehsanmasdar I don't remember if that's the case. We should do some investigating but that shouldn't block HackGT 6 initial release because walk-up won't happen until day-of

if (request.session) {
request.session.loginAction = "render";
}
response.redirect("/login");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we redirect user to registration login or ground truth login

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would GT know to redirect back?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It redirects to /login so that we can tell the user that they've successfully logged out. If we redirect to Ground Truth, the user will be told to login again even if that isn't what they want to do

}
}
user.accountConfirmed = true;
authRoutes.get("/validatehost/:nonce", (request, response) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this? What does this achieve that's not handled by the oauth client library

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is here because we use the Host header when generating links and callback URLs in the auth code. This verifies that the server behind the domain in the Host header is actually us and not some malicious other instance. Not sure if it's overengineered because Host headers can only be crafted by non-browser HTTP libraries (AJAX requests and JavaScript in browsers cannot override the Host header)

@ehsanmasdar ehsanmasdar requested a review from joel99 June 16, 2019 18:56
@ehsanmasdar
Copy link
Member

ehsanmasdar commented Jun 16, 2019

adding @joel99 would like to get a second set of eyes since it's so critical

Copy link

@joel99 joel99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ehsanmasdar can you help spin up a test deployment so we can QA this?
@petschekr embodying refactor as you go 👍

README.md Outdated Show resolved Hide resolved
}
// Email
if (process.env.EMAIL_FROM) {
this.email.from = process.env.EMAIL_FROM!;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason a lot of these became optional?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The types for Node.js were updated sometime after this code was written to make arbitrary properties on the process.env object not throw a possibly undefined compiler error. Therefore the non-null assertion operator, !, is no longer required here (and elsewhere).

if (anonymous) {
let email = request.body["anonymous-registration-email"] as string;
let name = request.body["anonymous-registration-name"] as string;
if (await User.findOne({email})) {
if (await User.findOne({ email })) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also did registration ever get a chance to allow walk up for people who started an application but didn't finish?

if (request.session) {
request.session.loginAction = "render";
}
response.redirect("/login");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would GT know to redirect back?

// Load and compile Handlebars templates
let [
indexTemplate,
loginTemplate,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there some feature that automatically makes a class variable? How does loadTemplate get this.file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constructor of the Template class has constructor(private readonly file: string) {} which makes the first argument when called with new a private readonly property automatically. This is shorthand supported by TypeScript

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neat

@ehsanmasdar ehsanmasdar added this to the HackGT 6 Launch milestone Jun 17, 2019
Dockerfile Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
client/login.html Outdated Show resolved Hide resolved
server/config/config.example.json Show resolved Hide resolved
server/middleware.ts Show resolved Hide resolved
server/routes/api/graphql.ts Outdated Show resolved Hide resolved
@@ -442,14 +462,14 @@ userRoutes.route("/export").get(isAdmin, async (request, response): Promise<void
for (let branchName of await Branches.BranchConfig.getNames()) {
// TODO: THIS IS A PRELIMINARY VERSION FOR HACKGT CATALYST
// TODO: Change this to { "accepted": true }
let attendingUsers: IUserMongoose[] = await User.find({ "applied": true, "applicationBranch": branchName });
let attendingUsers = await User.find({ "applied": true, "applicationBranch": branchName });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uhhh should probably fix those TODOs above

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ehsanmasdar @joel99 Do you think I can just get rid of this /export endpoint? It's kind of a hidden feature that we haven't used since Catalyst 1 I think

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, didn't realize that. We have graphiql and checkin2 can do CSV exports, so I'm guessing we don't need it.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Export data? Yeah, we can grab what we need from db if it becomes relevant if this is an issue. I'd prefer to leave and mark as legacy code for now if it's not blocking, though.

server/routes/templates.ts Show resolved Hide resolved
@hackgt-beekeeper hackgt-beekeeper bot temporarily deployed to registration-dev June 23, 2019 22:48 Inactive
@hackgt-beekeeper hackgt-beekeeper bot temporarily deployed to registration-dev June 23, 2019 22:53 Inactive
@hackgt-beekeeper hackgt-beekeeper bot temporarily deployed to registration-dev June 23, 2019 22:57 Inactive
@hackgt-beekeeper hackgt-beekeeper bot temporarily deployed to registration-dev June 23, 2019 23:01 Inactive
@hackgt-beekeeper hackgt-beekeeper bot temporarily deployed to registration-dev June 23, 2019 23:05 Inactive
@hackgt-beekeeper hackgt-beekeeper bot temporarily deployed to registration-dev June 23, 2019 23:14 Inactive
Copy link
Member

@evan10s evan10s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, lots of long-needed stuff!

@hackgt-beekeeper hackgt-beekeeper bot temporarily deployed to registration-dev June 25, 2019 13:14 Inactive
@petschekr petschekr merged commit 5aacf38 into master Jun 25, 2019
@ayush-goyal ayush-goyal deleted the ground-truth branch December 29, 2020 03:40
rahulrajus pushed a commit that referenced this pull request Jul 22, 2021
Use Ground Truth for authentication
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug enhancement Adds or suggests a new feature, rewrite, or other enhancement to the codebase high priority pending review This PR is pending review by a maintainer
Projects
None yet
5 participants