Skip to content

feat: logs for remote access - #26

Open
aln730 wants to merge 18 commits into
ComputerScienceHouse:masterfrom
aln730:remote-access-logs
Open

feat: logs for remote access#26
aln730 wants to merge 18 commits into
ComputerScienceHouse:masterfrom
aln730:remote-access-logs

Conversation

@aln730

@aln730 aln730 commented Aug 2, 2026

Copy link
Copy Markdown
Member

What

title

Why

needs logs to keep eye on rtp powers

Test Plan

comment out:

  if (getDoorStatus(req.params.doorId).guess === "offline") {
    return res.status(409).json({ message: "Door is offline" });
  }

in routes/doors.js

It is somewhat similar stuff to physical door acess logs

Discard the stuff below. I made a stacked PR that'll make testing easy cus doors are offline

In frontend. ahhh create a new branch without the head commit

ALSO why does vscode keep fucking up whitespaces OMG

Env Vars

N/A

Documentation

N/A

Checklist

  • Tested all changes locally

@BigSpaceships BigSpaceships left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

W all around

Comment thread routes/doors.js Outdated
Comment thread routes/doors.js
Comment thread routes/doors.js Outdated
Comment thread routes/doors.js
Comment on lines +68 to +73
await recordDoorUnlock(req.ctx.db, {
doorId: req.params.doorId,
doorName: doorDoc?.name,
username: req.ctx.username ?? req.ctx.userId,
name: req.ctx.name,
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why are we only recording when a door is unlocked when the user is authed with SSO and not any other possible method?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ahh okay it seems like recordDoorUnlock is really only intended for the web. But I guess the question still stands, is there a reason we don't want to record all unlocks in the audit logs?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Physical door taps are logged separately in server.js

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just as a console.log?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, it is inserted into the collection. It still has a console.log which I was using for debugging. That can be cleaned

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

They get logged in the db, if you change the date range locally or on gatekeeper.csh to be when doors were online and people were on floor you can see them

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think I understand this a little better now, but I'm still confused. It seems like there are only two auth methods: secret and oidc. Why would we not want to log for both (and other methods if we ever add them)?

@aln730 aln730 Aug 4, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

secret is meant for non-oidc api calls using secrets like GK_DRINK_SECRETS for Drink. It shouldn't be used for unlocking doors because there is no identity attached to it. Good catch W.

What we can do instead is check for userId rather than checking for oidc and deny secret from being used and it also leaves room to add more auth methods later. Physical access is handled via MQTT so there won't be any issue there. Thoughts?

Comment thread routes/doors.js
Comment on lines +68 to +73
await recordDoorUnlock(req.ctx.db, {
doorId: req.params.doorId,
doorName: doorDoc?.name,
username: req.ctx.username ?? req.ctx.userId,
name: req.ctx.name,
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ahh okay it seems like recordDoorUnlock is really only intended for the web. But I guess the question still stands, is there a reason we don't want to record all unlocks in the audit logs?

Comment thread access.js Outdated
username,
name: name,
doorsId: null,
keyId: "Remote Access",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems like the wrong way of indicating this was a remote unlock. Could this maybe be a separate field?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ahh okay it seems like recordDoorUnlock is really only intended for the web. But I guess the question still stands, is there a reason
we don't want to record all unlocks in the audit logs?

Physical door access is logged in the mqtt handler in server.js, and both physical and remote access land in the same collection. audit logs stores rtp actions for viewing/updating sutff.

This seems like the wrong way of indicating this was a remote unlock. Could this maybe be a separate field?

Yeah, fair, I can add a separate field for that

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Where does the physical access get logged? I can't seem to find it.

@aln730 aln730 Aug 2, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Physical access is logged in the accessLogs collection. If you want to find it on the website you'll have to go back to April or early May. The website shows the past 7 days by default.

edit: I should document stuff on the wiki for future purposes

@aln730 aln730 Aug 2, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Also instead of adding a new field I just made keyId: null for remote access and edited the case for that in the frontend. It is understandable that an entry is remote access if doorsId, keyId, and uid are all null if you are looking the database.

@costowell costowell Aug 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This still seems pretty unintuitive... Why not just add a type field if its important to distinguish between remote and physical accesses?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fair, and I don't disagree that it's less intuitive. I already handle this in the frontend but having it in the database would help too.

I can also add a type field in the keys collection to differentiate NFC card/fob from mobile key. That can be another PR.

…dDoorUnlock, and added a function specifically for checking if door is offline
Comment thread routes/doors.js
Comment on lines +8 to +22
function getDoorStatus(doorId){
// If it's been more than 1 minute, we assume something is broken...
const lastHeartbeat = doorHeartbeats.get(req.params.doorId);
const lastHeartbeat = doorHeartbeats.get(doorId);
if (lastHeartbeat) {
res.json({
return {
guess: Date.now() - lastHeartbeat > 1000 * 60 ? "offline" : "online",
lastHeartbeat,
});
};
} else {
res.json({
return {
guess: "offline",
lastHeartbeat: 0,
});
};
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could this use isDoorOffline too so that all that logic is in one spot?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good call

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants