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

Export Via Key Functionality #155

Merged
merged 10 commits into from
Sep 30, 2017
1 change: 0 additions & 1 deletion client/js/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,6 @@ settingsUpdateButton.addEventListener("click", e => {
let adminEmailData = new FormData();
adminEmailData.append("adminString", (document.getElementById("admin-emails") as HTMLInputElement).value);
adminEmailData.append("addAdmins", (document.getElementById("add-admins") as HTMLInputElement).checked ? "true" : "false");

let branchRoleData = new FormData();
let branchRoles = document.querySelectorAll("div.branch-role") as NodeListOf<HTMLDivElement>;
for (let i = 0; i < branchRoles.length; i++) {
Expand Down
1 change: 1 addition & 0 deletions deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ health:
path: /version

secrets:
- ADMIN_KEY_SECRET
- SESSION_SECRET
- EMAIL_USERNAME
- EMAIL_PASSWORD
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "registration",
"version": "1.10.7",
"version": "1.10.8",
"description": "TBD",
"main": "server/app.js",
"scripts": {
Expand Down
27 changes: 17 additions & 10 deletions server/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ import { IConfig } from "./schema";
import { storageEngines } from "./storage";
class Config implements IConfig.Main {
public secrets: IConfig.Secrets = {
"session": crypto.randomBytes(32).toString("hex"),
"github": {
"id": "",
"secret": ""
adminKey: crypto.randomBytes(32).toString("hex"),
session: crypto.randomBytes(32).toString("hex"),
github: {
id: "",
secret: ""
},
"google": {
"id": "",
"secret": ""
google: {
id: "",
secret: ""
},
"facebook": {
"id": "",
"secret": ""
facebook: {
id: "",
secret: ""
}
};
public email: IConfig.Email = {
Expand Down Expand Up @@ -126,6 +127,12 @@ class Config implements IConfig.Main {
}
protected loadFromEnv(): void {
// Secrets
if (process.env.ADMIN_KEY_SECRET) {
this.secrets.adminKey = process.env.ADMIN_KEY_SECRET!;
}
else {
console.warn("Setting random admin key! Cannot use the service-to-service APIs.");
}
if (process.env.SESSION_SECRET) {
this.secrets.session = process.env.SESSION_SECRET!;
this.sessionSecretSet = true;
Expand Down
15 changes: 14 additions & 1 deletion server/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,20 @@ export function isUserOrAdmin(request: express.Request, response: express.Respon
export function isAdmin(request: express.Request, response: express.Response, next: express.NextFunction) {
response.setHeader("Cache-Control", "private");
let user = request.user as IUser;
if (!request.isAuthenticated()) {
const auth = request.headers.authorization;

if (auth && typeof auth === "string" && auth.indexOf(" ") > -1) {
const key = new Buffer(auth.split(" ")[1], "base64").toString();
if (key === config.secrets.adminKey) {
next();
}
else {
response.status(401).json({
"error": "Incorrect auth token!"
});
}
}
else if (!request.isAuthenticated()) {
response.status(401).json({
"error": "You must log in to access this endpoint"
});
Expand Down
2 changes: 1 addition & 1 deletion server/routes/api/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ settingsRoutes.route("/qr_enabled")
catch (err) {
console.error(err);
response.status(500).json({
"error": "An error occurred while enabling or disabling teams"
"error": "An error occurred while enabling or disabling qr codes"
});
}
});
Expand Down
1 change: 1 addition & 0 deletions server/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {Questions} from "./config/questions.schema";
// Secrets JSON file schema
export namespace IConfig {
export interface Secrets {
adminKey: string;
session: string;
github: {
id: string;
Expand Down